Copied to clipboard

Flag this post as spam?

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


  • Carl-Philip Wenz 4 posts 34 karma points
    Oct 18, 2013 @ 10:16
    Carl-Philip Wenz
    0

    Dashboard Extension with MVC

    Hello everybody,

    I would like to extend the Umbraco Dashboard with an own section and an own Tree. And I already found a blog describing how this works with WebForms and in Umbraco 4: (http://www.geckonewmedia.com/blog/2009/08/03/how-to-create-a-custom-section-in-umbraco-4/)

    But I would prefer to use MVC for my Dashboard "Extension". Is this possible? Are Dashboard sections of Umbraco 6 (and 7) developed the same way as in Version 4?

    Best regards, Carl-Philip Wenz

  • Garðar Þorsteinsson 118 posts 564 karma points
    Nov 09, 2013 @ 22:03
    Garðar Þorsteinsson
    0

    Hi Carl-Philip,

    Are you talking about a complete custom Umbraco section or just a dashboard control that appears in the tabs ?

    If you are talking about custom section in MVC I can help you, but the dashboard control has to be a webform usercontrol so far as I know.

    Let me know if you need help with the MVC custom section.

    Best regards,

    Gardar

     

     

  • Justin Spradlin 139 posts 347 karma points
    Nov 11, 2013 @ 16:37
    Justin Spradlin
    0

    Hi, 

    I am interested in the same thing. I'd like to add an entire new section to my app. I was starting a project today and was hoping to go with the 7.0RC bits. I have been reviewing the documentation, but the instructions for custom tree/sections are a "todo" still. Any guidance on this would be very helpful.

    Thanks,

    Justin

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Nov 11, 2013 @ 17:08
    Andy Butland
    2

    I was working on this recenty, and found this post very useful in working out what to do.

  • Justin Spradlin 139 posts 347 karma points
    Nov 11, 2013 @ 17:13
    Justin Spradlin
    0

    Andy, thanks for the link. I'll check it out. My idea is to have a "subscriptions" custom table in the database. I am not sure if that will end up just being a custom tree on the members section, or a whole new section. Either way, I'm sure it'll be a neat little dive into umbraco today.

    Thanks!

  • Garðar Þorsteinsson 118 posts 564 karma points
    Nov 11, 2013 @ 17:31
    Garðar Þorsteinsson
    2

    Hi Justin,

    The link Andy sent you is a great start but it does not cover all the bases.

    The Post Build Events are really nice to know that is described in the post, but it does not f.ex say how to customize the context menu and creating your own actions in the context menu.

    If you want to create a new custom section in MVC for Umbraco I would first create a new empty MVC project, it can inside your current project or seprate it in a hole new project.

    You only need the .dll to be in you Site project and create plugin folder in App_Plugins for the section. There should be all the views and content for the section. That is described better in the post Justin sent you.

     

    This code here populates your Tree and automaticly created a row in Tree.config

     

        [Tree("CustomSection", "CustomSection", "CustomSection")]

        public class populateTree : BaseTree

        {

            public populateTree(string application)

                : base(application)

            { }

     

            protected override void CreateRootNode(ref XmlTreeNode rootNode)

            {

        // Created Root node

                rootNode.Icon = FolderIcon;

                rootNode.OpenIcon = FolderIconOpen;

                rootNode.NodeType = "init" + TreeAlias;

                rootNode.NodeID = "init";

                rootNode.Action = "javascript:openCategory(-1);";

            }

     

            protected override void CreateAllowedActions(ref List<IAction> actions)

            {

                // Customize context menu for all nodes beside root node

                actions.Clear();

                actions.Add(createAction.Instance);

                actions.Add(editAction.Instance);

                actions.Add(umbraco.BusinessLogic.Actions.ActionRefresh.Instance);

                actions.Add(umbraco.BusinessLogic.Actions.ContextMenuSeperator.Instance);

                actions.Add(deleteAction.Instance);

     

            }

     

            protected override void CreateRootNodeActions(ref List<IAction> actions)

            {

        // Customize context menu for root node

                actions.Clear();

                actions.Add(createAction.Instance);

                actions.Add(umbraco.BusinessLogic.Actions.ActionRefresh.Instance);

            }

     

            public override void Render(ref XmlTree tree)

            {

     

                // Get the current database object

                var db = ApplicationContext.Current.DatabaseContext.Database;

     

                // Fetch a collection of categories from the db.

                List<Category> listOfCategories = null;

     

                int key = -1;

     

                if (!string.IsNullOrEmpty(this.NodeKey))

                {

                    key = Convert.ToInt32(this.NodeKey);

                }

     

                listOfCategories = db.Fetch<Category>("SELECT * FROM Categories WHERE deleted=@0 ORDER BY name", false);

     

                if (listOfCategories != null)

                {

     

                    foreach (Category category in listOfCategories.Where(x => x.parentId == key))

                    {

     

                        string id = category.treeId.ToString();

     

                        // Create tree node

                        var node = XmlTreeNode.Create(this);

                        node.NodeID = id;

                        node.Text = category.name;

                        node.Icon = "folder_o.gif";

                        node.Action = "javascript:openCategory(" + node.NodeID + ");";

     

                        // Add child nodes

     

                        bool hasChildren = listOfCategories.Where(x => x.parentId == category.treeId).Any();

     

                        node.Source = hasChildren ? this.GetTreeServiceUrl(node.NodeID) : "";

     

                        // Add the node to the tree

                        tree.Add(node);

     

                    }

     

                }

     

            }

     

            public override void RenderJS(ref StringBuilder Javascript)

            {

                Javascript.Append(@"

                function openCategory(id) {

                    document.getElementById('right').scrolling = 'auto';

                    UmbClientMgr.contentFrame('../App_Plugins/CustomSection/Category/List?id=' + id);

                }

                ");

            }

        }

     

     

     

    Here his the iAction interface

     

        public class editAction : IAction

        {

            //create singleton

            private static readonly editAction _instance = new editAction();

     

     

            public static editAction Instance

            {

                get { return _instance; }

            }

     

            #region IAction Members

     

            public char Letter

            {

                get

                {

                    // TODO:  Add ActionNew.Letter getter implementation

                    return 'æ';

                }

            }

     

            public string JsFunctionName

            {

                get

                {

                    return "openModal('/App_Plugins/CustomSection/Category/Edit?id=' + nodeID, 'Edit Category', 300, 190);";

                }

            }

     

            public string JsSource

            {

                get

                {

                    // TODO:  Add ActionNew.JsSource getter implementation

                    return "";

                }

            }

     

            public string Alias

            {

                get

                {

                    // TODO:  Add ActionNew.Alias getter implementation

                    return "editCategory";

                }

            }

     

            public string Icon

            {

                get

                {

                    // TODO:  Add ActionNew.Icon getter implementation

                    return "Images/pencil.png";

                }

            }

     

            public bool ShowInNotifier

            {

                get

                {

                    // TODO:  Add ActionNew.ShowInNotifier getter implementation

                    return true;

                }

            }

            public bool CanBePermissionAssigned

            {

                get

                {

                    // TODO:  Add ActionNew.ShowInNotifier getter implementation

                    return true;

                }

            }

            #endregion

        }

     

     

    This code plus the post from nibble should get you a long way. If you need any extra help with the code just ask :)

     

     

     

  • Justin Spradlin 139 posts 347 karma points
    Nov 11, 2013 @ 17:36
    Justin Spradlin
    0

    Wow, thank you that is great information! You are right, I think that will get me really far down the road. I have used that pattern for custom IActions only once before, so I am glad that you reminded me about all of those details.

    Thanks!

    Justin

  • Garðar Þorsteinsson 118 posts 564 karma points
    Nov 11, 2013 @ 18:07
    Garðar Þorsteinsson
    0

    Good to know, Remember when you create your own iAction with some name to translate it in the language config in Umbraco/Config/Lang to remove the brackets.

    You can create custom icon for the section, just put it in the /Umbraco/Images/Tray folder.

    In my custom section I implemented custom examine indexer for the custom data so it can be searchable, if you need that kind of a code let me know.

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft