Exemplo n.º 1
0
        public TreeNode GetRootNode(FormDataCollection queryStrings)
        {
            if (queryStrings == null)
            {
                queryStrings = new FormDataCollection("");
            }
            var node = CreateRootNode(queryStrings);

            //add the tree alias to the root
            node.AdditionalData["treeAlias"] = _treeAlias;

            AddQueryStringsToAdditionalData(node, queryStrings);

            //check if the tree is searchable and add that to the meta data as well
            if (this is ISearchableTree)
            {
                node.AdditionalData.Add("searchable", "true");
            }

            //now update all data based on some of the query strings, like if we are running in dialog mode
            if (IsDialog(queryStrings))
            {
                node.RoutePath = "#";
            }

            TreeControllerBase.OnRootNodeRendering(null, new TreeNodeRenderingEventArgs(node, queryStrings));

            return(node);
        }
        private static void OnRootNodeRendering(TreeControllerBase instance, TreeNodeRenderingEventArgs e)
        {
            var handler = RootNodeRendering;

            if (handler != null)
            {
                handler(instance, e);
            }
        }
        private static void OnMenuRendering(TreeControllerBase instance, MenuRenderingEventArgs e)
        {
            var handler = MenuRendering;

            if (handler != null)
            {
                handler(instance, e);
            }
        }
        void TreeControllerBaseMenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            if (sender.TreeAlias == "content" && sender.Security.CurrentUser.UserType.Alias == "admin")
            {
                var menu = new MenuItem("moriyamaDeploy", "Deploy this");
                menu.Icon = "umb-content";

                e.Menu.Items.Add(menu);
            }
        }
Exemplo n.º 5
0
        void TreeControllerBaseMenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            bool isContentTree = sender.TreeAlias == "content";
            bool userIsAdmin = sender.Security.CurrentUser.UserType.Alias == "admin";

            // Add custom menu item
            if (isContentTree && userIsAdmin && IsContentNode(e))
            {
                AddMenuItem(e);
            }
        }
Exemplo n.º 6
0
        public void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            //if (sender.TreeAlias == "content")
            //{
                //var i = new MenuItem("editCanvas", "Edit in Canvas");
                //i.Icon = "edit";
                //i.LaunchDialogUrl("/umbraco/canvas?pageId=" + e.NodeId,"Edit in Canvas");

                //e.Menu.Items.Insert(3,i);
            //}
        }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            //Get Current User
            var currentUser = User.GetCurrent();

            //This will only run on the analyticsTree & if the user is NOT admin
            if (sender.TreeAlias == "analyticsTree" && !currentUser.IsAdmin())
            {
                //setting node to remove
                var settingNode = e.Nodes.SingleOrDefault(x => x.Id.ToString() == "settings");

                //Ensure we found the node
                if (settingNode != null)
                {
                    //Remove the settings node from the collection
                    e.Nodes.Remove(settingNode);
                }
            }

            //This will only run on the analyticsTree
            if (sender.TreeAlias == "analyticsTree")
            {
                AnalyticsApiController gaApi = new AnalyticsApiController();

                Profile profile = AnalyticsHelpers.GetProfile();

                if (profile != null)
                {
                    var ecommerceNode = e.Nodes.SingleOrDefault(x => x.Id.ToString() == "ecommerce");
                    if (ecommerceNode != null)
                    {
                        try
                        {
                            // check if profile has any ecommerce data for last 3 years
                            StatsApiResult transactions = gaApi.GetTransactions(profile.Id, DateTime.Now.AddYears(-3), DateTime.Now);
                            if (!transactions.ApiResult.Rows.Any())
                            {
                                //Remove the ecommerce node from the collection
                                //If no Rows returned from API - then remove the node from the tree
                                e.Nodes.Remove(ecommerceNode);
                            }
                        }
                        catch
                        {
                            //Remove the ecommerce node from the collection
                            //If the API throws an ex then remove the node from the tree as well
                            e.Nodes.Remove(ecommerceNode);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
 void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
 {
     if (sender.TreeAlias == "content"
         && sender.Security.CurrentUser.UserType.Alias == "admin"
         && e.NodeId != "-1" && e.NodeId != "-20")
     {
         var mi = new MenuItem("pageNotFound", "404 page");
         mi.Icon = "document";
         mi.LaunchDialogView("/App_Plugins/PageNotFoundManager/Backoffice/Dialogs/dialog.html", "404 Page");
         mi.SeperatorBefore = true;
         e.Menu.Items.Insert(e.Menu.Items.Count - 1, mi);
     }
 }
        private void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            int nodeId;
            if (!int.TryParse(e.NodeId, out nodeId)) return;

            var selectedMedia = ApplicationContext.Current.Services.MediaService.GetById(nodeId);
            var mediaType = selectedMedia != null ? selectedMedia.ContentType.Alias : string.Empty;

            if (sender.TreeAlias == "media" && (mediaType.Equals("Folder") || nodeId == Constants.System.Root))
            {
                var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
                var menuItemTitle = umbracoHelper.GetDictionaryValue("ZippyMedia.Labels.UploadZipFile");

                if (string.IsNullOrWhiteSpace(menuItemTitle)) menuItemTitle = "Upload and Unpack ZIP";
                var menuItem = new MenuItem("uploadZipFile", menuItemTitle)
                {
                    Icon = "compress",
                    SeperatorBefore = true
                };
                menuItem.LaunchDialogView("/App_Plugins/zippyMedia/Views/Upload-Zip.html", menuItemTitle);

                e.Menu.Items.Add(menuItem);
            }



            //Upload from server AKA ftp upload comming soon 
            //if (sender.TreeAlias == "media" && mediaType.Equals("Folder") && sender.Security.CurrentUser.UserType.Alias.Equals("admin"))
            //{
            //    var menuItem = new MenuItem("unpackZipFileFromServer", "Unpack ZIP from server");
            //    menuItem.Icon = "server";
            //    menuItem.SeperatorBefore = false;
            //    menuItem.LaunchDialogView("/App_Plugins/zippyMedia/Views/Unpack-Zip.html", "Unpack ZIP archive from server");

            //    e.Menu.Items.Add(menuItem);
            //}

            //if (sender.TreeAlias == "media" && Convert.ToInt32(e.NodeId) == Constants.System.Root && sender.Security.CurrentUser.UserType.Alias.Equals("admin"))
            //{
            //    var menuItem = new MenuItem("unpackZipFileFromServer", "Unpack ZIP from server");
            //    menuItem.Icon = "server";
            //    menuItem.SeperatorBefore = false;
            //    menuItem.LaunchDialogView("/App_Plugins/zippyMedia/Views/Unpack-Zip.html", "Unpack ZIP archive from server");

            //    e.Menu.Items.Add(menuItem);

            //}

        }
        private void TreeControllerBaseOnMenuRendering(TreeControllerBase sender, MenuRenderingEventArgs eventArgs)
        {
            var context = new HttpContextWrapper(HttpContext.Current);
            var urlHelper = new UrlHelper(new RequestContext(context, new RouteData()));
            var treeNodeType = new TreeNodeType(sender.TreeAlias ?? eventArgs.QueryStrings.Get("section"), eventArgs.QueryStrings.Get("treeType"));
            var objectType = Mappings.TreeNodeObjectTypes.ContainsKey(treeNodeType) ?
                Mappings.TreeNodeObjectTypes[treeNodeType] :
                UmbracoObjectTypes.Unknown;
            if (objectType != UmbracoObjectTypes.Unknown && Convert.ToInt32(eventArgs.NodeId) > 0)
            {
                var type = Mappings.TreeNodeObjectTypes[treeNodeType];
                var id = Convert.ToInt32(eventArgs.NodeId);
                var alias = EntityHelper.FindAlias(type, id);

                AddEditRelations(eventArgs, type, alias, urlHelper);
                AddEnableRelations(eventArgs, objectType, urlHelper);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            //Get Current User
            var currentUser = User.GetCurrent();

            //This will only run on the analyticsTree & if the user is NOT admin
            if (sender.TreeAlias == "analyticsTree" && !currentUser.IsAdmin())
            {
                //setting node to remove
                var settingNode = e.Nodes.SingleOrDefault(x => x.Id.ToString() == "settings");

                //Ensure we found the node
                if (settingNode != null)
                {
                    //Remove the settings node from the collection
                    e.Nodes.Remove(settingNode);
                }
            }
        }
Exemplo n.º 12
0
        void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            var db = sender.ApplicationContext.DatabaseContext.Database;

            if (sender.TreeAlias == "content")
            {
                foreach (var node in e.Nodes)
                {

                    var query = new Sql().Select("*").From("lookwhoseditingnow").Where<Edit>(x => x.NodeId == (int)node.Id && x.UserId != sender.Security.CurrentUser.Id);
                    if (db.Fetch<Edit>(query).Any())
                        node.CssClasses.Add("look-whos-editing-too");

                }
            }
            else
            {
                db.Execute("DELETE FROM lookwhoseditingnow WHERE userid=@0", sender.Security.CurrentUser.Id);
            }
        }
Exemplo n.º 13
0
        private static void AddPreviewMenuItem(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            var section = e.QueryStrings.Get("section");
            var treeType = e.QueryStrings.Get("treeType");
            var isDocumentType = section == "settings" && (treeType == "nodeTypes" || treeType == "mediaTypes");
            if (!isDocumentType || e.NodeId == "-1")
                return;

            var insertAfter = e.Menu.Items.FirstOrDefault(extItem => extItem.Alias == "exportDocumentType");

              //creates a menu action that will open /umbraco/currentSection/itemAlias.html
            var i = new MenuItem("previewModelClass", "Preview CodeGen class");
            i.AdditionalData.Add("actionRoute", "settings/codegen/codegen.preview/" + e.NodeId);
            i.Icon = "brackets";

            if (insertAfter != null)
                e.Menu.Items.Insert(e.Menu.Items.IndexOf(insertAfter) + 1, i);
            else
                e.Menu.Items.Add(i);
        }
 void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
 {
     var user = sender.Security.CurrentUser;
     var path = "/App_Plugins/UserGroupPermissions/Views/ApplyUserGroupPermissions.html";
     var title = "Apply User Group Permissions";
     var treeType = e.QueryStrings.Get("treeType");
     var section = e.QueryStrings.Get("section");
     var validTree = "users".InvariantEquals(treeType) && "users".InvariantEquals(section);
     var strUserId = e.NodeId ?? "";
     var userId = default(int);
     var validUserId = int.TryParse(strUserId, out userId) ? userId > 0 : false;
     var validUser = user.IsAdmin();
     if (validTree && validUserId && validUser)
     {
         var menuItem = new MenuItem("ApplyUserGroupPermissions", "Apply Group Permissions")
         {
             Icon = "vcard"
         };
         menuItem.LaunchDialogView(path, title);
         e.Menu.Items.Add(menuItem);
     }
 }
        private void ContentTreeController_MenuRendering(Umbraco.Web.Trees.TreeControllerBase sender, Umbraco.Web.Trees.MenuRenderingEventArgs e)
        {
            switch (sender.TreeAlias)
            {
            case "content":

                //creates a menu action that will open /umbraco/currentSection/itemAlias.html;
                var i = new Umbraco.Web.Models.Trees.MenuItem("duplicateNode", "Duplicate");

                //optional, if you dont want to follow conventions, but do want to use a angular view
                i.AdditionalData.Add("actionView", "/App_Plugins/DuplicateNode/DuplicateNodeView.html");

                //sets the icon to icon-wine-glass
                i.Icon = "user-females-alt";

                //insert at index 5
                if (e.Menu.Items.Count > 5)
                {
                    e.Menu.Items.Insert(5, i);
                }

                break;
            }
        }
        private void TreeControllerBaseOnTreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs eventArgs)
        {
            if (eventArgs.QueryStrings.HasKey("relationEditor"))
            {
                var parentType = (UmbracoObjectTypes)Enum.Parse(typeof(UmbracoObjectTypes), eventArgs.QueryStrings.Get("parentType"));
                var parentAlias = eventArgs.QueryStrings.Get("parentTypeAlias");
                var relationAlias = eventArgs.QueryStrings.Get("relationAlias");

                var config = Configuration.Get(parentType, parentAlias);
                if (!config.Enabled)
                    return;

                var relConfig = config.Get(relationAlias);
                if (!relConfig.Enabled)
                    return;

                var childTypes = relConfig.EnabledChildTypes.Select(t => t.Alias).ToArray();

                if (!childTypes.Any())
                    return;

                var relation = UmbracoContext.Current.Application.Services.RelationService.GetRelationTypeByAlias(relationAlias);
                var childObjectType = UmbracoObjectTypesExtensions.GetUmbracoObjectType(relation.ChildObjectType);

                foreach (var node in eventArgs.Nodes)
                {
                    var id = Convert.ToInt32(node.Id);
                    var alias = EntityHelper.FindAlias(childObjectType, id);
                    if (!childTypes.Contains(alias, IgnoreCase))
                    {
                        node.SetNotPublishedStyle();
                        node.AdditionalData.Add("relationDisallowed", "true");
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void AddPurgeCacheForContentMenu(TreeControllerBase sender, MenuRenderingEventArgs args)
        {
            if(sender.TreeAlias != "content")
            {
                //We aren't dealing with the content menu
                return;
            }

            MenuItem menuItem = new MenuItem("purgeCache", "Purge Cloudflare Cache");

            menuItem.Icon = "umbracoflare-tiny";

            menuItem.LaunchDialogView("/App_Plugins/UmbracoFlare/backoffice/treeViews/PurgeCacheDialog.html", "Purge Cloudflare Cache");

            args.Menu.Items.Insert(args.Menu.Items.Count - 1, menuItem);
        }
Exemplo n.º 18
0
 private static void OnMenuRendering(TreeControllerBase instance, MenuRenderingEventArgs e)
 {
     var handler = MenuRendering;
     if (handler != null) handler(instance, e);
 }
Exemplo n.º 19
0
 private static void OnRootNodeRendering(TreeControllerBase instance, TreeNodeRenderingEventArgs e)
 {
     var handler = RootNodeRendering;
     if (handler != null) handler(instance, e);
 }
        private void FilterTreeNodes(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
        {
            if (!Features.HideCodeFirstEntityTypesInTrees)
            {
                return;
            }
            string alias;
            try
            {
                alias = sender.TreeAlias == null ? e.QueryStrings.Single(x => x.Key.InvariantEquals("treeType")).Value : sender.TreeAlias;
            }
            catch (Exception ex)
            {
                throw new CodeFirstException("No valid legacy or new-style tree alias found for a rendering tree.", ex);
            }

            if (!Modules.IsFrozen)
            {
                throw new CodeFirstException("The module resolver is not frozen. Cannot filter tree nodes.");
            }

            lock (_treeFilterLock)
            {
                if (!_treeFilters.ContainsKey(alias))
                {
                    var list = new List<IEntityTreeFilter>();
                    _treeFilters.Add(alias, list);
                    foreach (var module in Modules)
                    {
                        if (module is IEntityTreeFilter && (module as IEntityTreeFilter).IsFilter(alias))
                        {
                            list.Add(module as IEntityTreeFilter);
                        }
                    }
                }
            }

            bool changesMade = false;
            foreach (var module in _treeFilters[alias])
            {
                module.Filter(e.Nodes, out changesMade);
            }

            if (changesMade)
            {
                //TODO show toast somehow? - functionality due in 7.3.0 - http://issues.umbraco.org/issue/U4-5927
            }
        }
Exemplo n.º 21
0
        private static void OnMenuRendering(TreeControllerBase instance, MenuRenderingEventArgs e)
        {
            var handler = MenuRendering;

            handler?.Invoke(instance, e);
        }
Exemplo n.º 22
0
        // internal for temp class below - kill eventually!
        internal static void OnRootNodeRendering(TreeControllerBase instance, TreeNodeRenderingEventArgs e)
        {
            var handler = RootNodeRendering;

            handler?.Invoke(instance, e);
        }
Exemplo n.º 23
0
        private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
        {
            var handler = TreeNodesRendering;

            handler?.Invoke(instance, e);
        }
        // A context menu is rendering.
        void TreeControllerBase_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {

            // Variables.
            var path = "/App_Plugins/UserGroupPermissions/Views/SetUserGroupPermissions.html";
            var title = "User Group Permissions";

            // Initial check (in content tree and on a node).
            IUser currentUser = sender.Security.CurrentUser;
            var showMenuItem = sender.TreeAlias == "content";
            var strNodeId = e.NodeId;
            var nodeId = default(int);
            if (showMenuItem && int.TryParse(strNodeId, out nodeId))
            {
                showMenuItem = nodeId >= 0;
            }
            else
            {
                showMenuItem = false;
            }

            // Check permissions for non-admin users.
            if (showMenuItem && !currentUser.IsAdmin())
            {
                showMenuItem = false;
                var userService = ApplicationContext.Current.Services.UserService;
                var permissions = userService.GetPermissions(currentUser, nodeId);
                var letter = MenuActions.UserGroupPermissions.Instance.Letter.ToString();
                if(permissions.Any(x => x.AssignedPermissions.InvariantContains(letter)))
                {
                    showMenuItem = true;
                }
            }

            // Add a custom menu item in the content tree.
            if (showMenuItem)
            {

                var menuItem = new MenuItem("UserGroupPermissions", "User Group Permissions")
                {
                    Icon = "vcard"
                };

                menuItem.LaunchDialogView(path, title);

                var permissionsIndex = e.Menu.Items.FindIndex(x =>
                    "Permissions".InvariantEquals(x.Name) ||
                    "Permissions".InvariantEquals(x.Alias));

                // Attempt to insert after the existing "Permissions" menu item.
                if (permissionsIndex >= 0)
                {
                    e.Menu.Items.Insert(permissionsIndex + 1, menuItem);
                }
                else
                {
                    e.Menu.Items.Add(menuItem);
                }

            }

        }