Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 24, 2013 @ 15:30
    Anthony Dang
    1

    What you want and need from uBlogsy MVC?

    I'll be porting uBlogsy to MVC and just wanted some feedback about my current plans.

    My immediate concern is porting all the code. So I'll be doing that and releasing asap. It will be a straight port with (probably) nothing new. 

    In the very near future though I am considering the following (sort of order of preference):

     

    1. Using the html 5 markup and css from the uBlogsy port to Umbraco V5
    2. Adding images to posts by default
    3. Adding Gravatar support
    4. Moving Authors to a subtree and using multi-node tree picker
    5. Refactoring all backend code to use examine for super speed - Involves probably leaving examine result objects in razor code.
    6. Adding recaptcha
    7. Moving commenting and subscription into a separate package
    8. Moving date folders into a separate package
    Thoughts? Suggestions?

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 24, 2013 @ 19:09
    Jeroen Breuer
    0

    What I would like to see is a full MVC version. Currently when you say MVC I assume that you only use the Views and do things like this in it:

    <ul>
        @*Menu*@
        @foreach (var menu in Model.Content.Children.Where(c => c.HasProperty("menuTitle") && !c.GetPropertyValue<bool>("hideInMenu")))
    { var selected = Model.Content.Path.Contains(menu.Id.ToString()) ? " class=\"active\"" : ""; <[email protected](selected)> <a href="@menu.NiceUrl()">@(menu.GetPropertyValue<string>("menuTitle"))</a> </li> } </ul>

    But instead it would be nice if that is done in the Controller and passed to a custom model. So you have something like this:

    public class ExampleModel
    {
        public IEnumerable<MenuItem> MenuItems { get; set; }
    }
    public class MenuItem
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Url { get; set; }
    public HtmlString ActiveClass { get; set; } }
    exampleModel.MenuItems = GetMenuItems(model.Content, model.Content.Path);

     /// <summary> /// Return the menu items. These are the children of the passed in node which are allowed to be displayed. /// </summary> /// <returns></returns> private IEnumerable<MenuItem> GetMenuItems(IPublishedContent content, string path) { return ( from n in content.Children where n.HasProperty("menuTitle") && !n.GetPropertyValue<bool>("hideInMenu") select new MenuItem() { Id = n.Id, Title = n.GetPropertyValue<string>("menuTitle"), Url = n.NiceUrl(),
    ActiveClass = new HtmlString(path.Contains(n.Id.ToString()) ? " class=\"active\"" : "") } ); }

    return CurrentTemplate(exampleModel); 

    Than in your controller you return the custom model which has the all the things you need and your view can look like this:

    <ul>
        @*Menu*@
        @foreach (var menu in Model.MenuItems)
        {
            <[email protected]>
                <a href="@menu.Url">@menu.Title</a>
            </li>
        }
    </ul> 

    As you can see this gives a much better separation of code and cleaner Views. You can read more about it here: http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers

    Jeroen

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 24, 2013 @ 21:29
    Anthony Dang
    0

    Yep! That's pretty much where I want to get it to.

    Regarding the custom model...

    I want to do all the grunt work using Examine. Do you think it is acceptable to return Examine search Result objects in the custom model? So for displaying a single post, a Result object will be passed to the view. For displaying a list, an IEnumerable<Result> would be passed to the listing view etc.

    The reason I say this is because I don't really like double handling data for the sake of data transfer. I'd rather use the Result object in the views than having to create a strongly typed model for each view.

    Does that sound reasonable?

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2013 @ 08:14
    Jeroen Breuer
    0

    That sounds very reasonable :-). I'm already happy that you're hijacking routes. 

    It might be good to remember that I might want to add your custom model to my own model. For example if I have a model for the master page in which I'll add uBlogsy. So I'll need 1 model in which everything for my own master and uBlogsy is available. Somehow it also needs to be extendable for people how don't use controllers and do everything in the view. So it's good if your custom model also has an IPublishedContent property of the current page.

    Is uBlogsy MVC open source? In that case I'll probably just take all your controllers and add them to my own project so It'll be fully integrated with my own Controllers and hijacked routes.

    Jeroen

  • Lee 1130 posts 3088 karma points
    Jan 25, 2013 @ 08:19
    Lee
    0

    I'm with Jeroen actually.

    Would prefer to see strongly typed models used and not just passing in Result objects or PublishedContent objects. Have a mapping class and map everything in one place before passing to the view. I did a site last year that heavily relied on examine, and even with the old Razor non MVC way I still passed in mapped models.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 25, 2013 @ 10:40
    Anthony Dang
    0

    Implementation question...

    uBlogsy has many panels on the right column. eg. latest comments, archive, latest posts etc. I've ported over the code from uBlogsy 2.1.1.1 but the partials still request their own data. This is obviously what we don't want.

    I realized last night that I cant simply get all the data in the hijacking controller because of these 2 scenarios:

    1. When a developer removes a partial, the data retrieval is now redundant.

    2. When a developer copies the the view to their on their own custom page (eg. using the list posts view on their home page) - where does the data come from?

    So... what do you think the best way of passing data into the partials is? And where should I be querying for that data? Main layout? 

    Is it possible to have a different controller for each partial view?

     

     

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2013 @ 13:09
    Jeroen Breuer
    100

    1. I think it's best to use child actions for that. So you can still do all logic in a controller, but if you remove the Html.Action from your razor view it's not used anymore. More info here: http://our.umbraco.org/documentation/Reference/Mvc/child-actions

    2. This is a good one. Like I said I'll probably copy the code from your controller and use it in my own controller, but not everyone will work like that. Perhaps you can also solve that with a child action?

    Jeroen

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 25, 2013 @ 13:31
    Anthony Dang
    0

    To answer my own question about partial view controllers... http://our.umbraco.org/documentation/Reference/Mvc/child-actions

     

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 25, 2013 @ 13:34
    Anthony Dang
    0

    LOL.

    Yes. Child action solves the problem.

    The issue I have now is people who add properties. Those properties wont be strongly typed. However, they will be able to get the value from model.Content.GetProperty("myalias")

     

     

Please Sign in or register to post replies

Write your reply to:

Draft