Copied to clipboard

Flag this post as spam?

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


  • Mohammad Azeem 31 posts 74 karma points
    Oct 25, 2019 @ 10:52
    Mohammad Azeem
    0

    HTML not rendering in section of the Umbraco backoffice after creating Tree

    i am trying to create custom section named UMTDirectory, and create necessary files under App_Plugins folder by following this link , but unfortunately am unable to render the view in back-office however it appears in menu. following is the structure of folder. enter image description here package.manifest code below

        {
      "javascript": [
        "~/App_Plugins/UMTDirectory/umtDirectory.controller.js",
        "~/App_Plugins/UMTDirectory/umtDirectory.resource.js"
      ],
    
      "sections": [
        {
          "alias": "umtDirectory",
          "name": "UMT Directory",
          "view": "~/App_Plugins/UMTDirectory/umtDirectory.html"
        }
      ]
    
    }
    

    umtDirectory.controller.js

    angular.module("umbraco")
        .controller("My.PersonPickerController", function ($scope, personResource) {
            personResource.getAll().then(function (response) {
                $scope.people = response.data;
            });
        });
    

    umtDirectory.html

    <h1>Love and compassion are necessities, not luxuries </h1>
    <div ng-controller="My.PersonPickerController">
        <ul>
            <li ng-repeat="person in people">
                <a href ng-click="model.value = person.Name">{{person.Name}}</a>
            </li>
        </ul>
    </div>
    

    umtDirectory.resource.js

    angular.module('umbraco.resources').factory('personResource',
        function($q, $http, umbRequestHelper) {
            // the factory object returned
            return {
                // this calls the ApiController we setup earlier
                getAll: function () {
                return umbRequestHelper.resourcePromise(
                    $http.get("backoffice/My/PersonApi/GetAll"),
                "Failed to retrieve all Person data");
                }
            };
        }
    );
    

    Directory Controller

    namespace MyProj.Controllers
    {
        [Tree("umtDirectory", "umtDirectoryAlias", TreeTitle = "UMT Directory",  SortOrder = 5)]
        [PluginController("umtDirectory")]
        public class DirectoryController : TreeController
        {
            protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
            {
                // check if we're rendering the root node's children
                if (id == Constants.System.Root.ToInvariantString())
                {
                    // you can get your custom nodes from anywhere, and they can represent anything...
                    Dictionary<int, string> favouriteThings = new Dictionary<int, string>();
                    //favouriteThings.Add(1, "Add Faculty/Staff Member");
    
                    // create our node collection
                    var nodes = new TreeNodeCollection();
    
                    // loop through our favourite things and create a tree item for each one
                    foreach (var thing in favouriteThings)
                    {
                        // add each node to the tree collection using the base CreateTreeNode method
                        // it has several overloads, using here unique Id of tree item, -1 is the Id of the parent node to create, eg the root of this tree is -1 by convention - the querystring collection passed into this route - the name of the tree node -  css class of icon to display for the node - and whether the item has child nodes
                        var node = CreateTreeNode(thing.Key.ToString(), "-1", queryStrings, thing.Value, "icon-presentation", false);
                        nodes.Add(node);
                    }
                    return nodes;
                }
    
                // this tree doesn't support rendering more than 1 level
                throw new NotSupportedException();
            }
    
            protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
            {
                // create a Menu Item Collection to return so people can interact with the nodes in your tree
                var menu = new MenuItemCollection();
    
                if (id == Constants.System.Root.ToInvariantString())
                {
                    // root actions, perhaps users can create new items in this tree, or perhaps it's not a content tree, it might be a read only tree, or each node item might represent something entirely different...
                    // add your menu item actions or custom ActionMenuItems
                    menu.Items.Add(new CreateChildEntity(Services.TextService));
                    // add refresh menu item (note no dialog)
                    menu.Items.Add(new RefreshNode(Services.TextService, true));
                    return menu;
                }
                // add a delete action to each individual item
                menu.Items.Add<ActionDelete>(Services.TextService, true, opensDialog: true);
    
                return menu;
            }
    
            protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
            {
                var root = base.CreateRootNode(queryStrings);
    
                //optionally setting a routepath would allow you to load in a custom UI instead of the usual behaviour for a tree
                //root.RoutePath = "umtDirectory"; //string.Format("{0}/{1}", "umtDirectory", "umtDirectory.html");
                // set the icon
                root.Icon = "icon-hearts";
                // set to false for a custom tree with a single node.
                root.HasChildren = false;
                //url for menu
                root.MenuUrl = null;
    
                return root;
            }
        }
    }
    

    what i see in backoffice is enter image description here

    please help

    Thanks for your time

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies