private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
        {
            var handler = TreeNodesRendering;

            if (handler != null)
            {
                handler(instance, e);
            }
        }
コード例 #2
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);
                        }
                    }
                }
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        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");
                    }
                }
            }
        }
コード例 #6
0
 private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
 {
     var handler = TreeNodesRendering;
     if (handler != null) handler(instance, e);
 }
コード例 #7
0
        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
            }
        }
コード例 #8
0
        private static void OnTreeNodesRendering(TreeControllerBase instance, TreeNodesRenderingEventArgs e)
        {
            var handler = TreeNodesRendering;

            handler?.Invoke(instance, e);
        }