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); }
// 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); }
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))); } }
public MenuRegistration(IMenuPlacementStrategy strategy, IStringTokenMatcher matcher, MenuNode node) { _strategy = strategy; _matcher = matcher; _node = node; }
public void Apply(IMenuNode dependency, MenuNode node) { dependency.AddChild(node); }
public void Apply(IMenuNode dependency, MenuNode node) { dependency.AddBefore(node); }
private void addToLastKey(MenuNode node) { var key = _lastKey; _registrations.Add(new MenuRegistration(new AddChild(), new Literal(key), node)); }
public void AddChildNode(StringToken parent, MenuNode node) { var registration = new MenuRegistration(new AddChild(), new Literal(parent), node); _registrations.Add(registration); }
public void Apply(IMenuNode dependency, MenuNode node) { dependency.AddAfter(node); }