Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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)));
            }
        }
Exemplo n.º 4
0
 public MenuRegistration(IMenuPlacementStrategy strategy, IStringTokenMatcher matcher, MenuNode node)
 {
     _strategy = strategy;
     _matcher  = matcher;
     _node     = node;
 }
Exemplo n.º 5
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddChild(node);
 }
Exemplo n.º 6
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddBefore(node);
 }
Exemplo n.º 7
0
        private void addToLastKey(MenuNode node)
        {
            var key = _lastKey;

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

            _registrations.Add(registration);
        }
Exemplo n.º 9
0
 public void Apply(IMenuNode dependency, MenuNode node)
 {
     dependency.AddAfter(node);
 }