示例#1
0
        public virtual MenuItemState DetermineStateFor(MenuNode node)
        {
            if (node.BehaviorChain == null)
            {
                return(MenuItemState.Available);
            }

            var rights = _authorizor.Authorize(node.BehaviorChain, node.UrlInput);

            if (rights != AuthorizationRight.Allow)
            {
                return(node.UnauthorizedState);
            }

            if (_current.OriginatingChain == node.BehaviorChain)
            {
                return(MenuItemState.Active);
            }

            if (_conditionals.IsTrue(node.HideIfConditional))
            {
                return(MenuItemState.Hidden);
            }

            if (_conditionals.IsTrue(node.IsEnabledBy()))
            {
                return(MenuItemState.Available);
            }

            return(MenuItemState.Disabled);
        }
示例#2
0
        // TODO -- this could really use some more end to end testing
        public MenuItemToken BuildToken(MenuNode node)
        {
            var token = new MenuItemToken {
                Children = node.Children.Select(BuildToken).ToArray(),
                Key      = node.Key.Key,
                Text     = node.Key.ToString(),

                MenuItemState = _stateService.DetermineStateFor(node)
            };

            if (node.Icon().IsNotEmpty())
            {
                token.IconUrl = _urls.UrlForAsset(AssetFolder.images, node.Icon());
            }

            if (node.Type == MenuNodeType.Leaf)
            {
                token.Url = _request.ToFullUrl(node.CreateUrl());
            }

            return(token);
        }
示例#3
0
        public IEnumerable <IMenuRegistration> ToMenuRegistrations(BehaviorChain chain)
        {
            if (AddChildTo.IsNotEmpty())
            {
                yield return(new MenuRegistration(new AddChild(), new ByName(AddChildTo), MenuNode.ForChain(Title, chain)));
            }

            if (AddAfter.IsNotEmpty())
            {
                yield return(new MenuRegistration(new AddAfter(), new ByName(AddAfter), MenuNode.ForChain(Title, chain)));
            }

            if (AddBefore.IsNotEmpty())
            {
                yield return(new MenuRegistration(new AddBefore(), new ByName(AddBefore), MenuNode.ForChain(Title, chain)));
            }
        }
示例#4
0
 public MenuRegistration(IMenuPlacementStrategy strategy, IStringTokenMatcher matcher, MenuNode node)
 {
     _strategy = strategy;
     _matcher  = matcher;
     _node     = node;
 }
示例#5
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddChild(node);
 }
示例#6
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddBefore(node);
 }
示例#7
0
        private void addToLastKey(MenuNode node)
        {
            var key = _lastKey;

            _registrations.Add(new MenuRegistration(new AddChild(), new Literal(key), node));
        }
示例#8
0
        public void AddChildNode(StringToken parent, MenuNode node)
        {
            var registration = new MenuRegistration(new AddChild(), new Literal(parent), node);

            _registrations.Add(registration);
        }
示例#9
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddAfter(node);
 }