Exemplo n.º 1
0
 public void AddToLastViewed(Guid viewID, Guid userID, string name, string url)
 {
     List<UserMenuItem> viewed = this.GetLastViewed(userID).OrderBy(v => v.CreatedDate).ToList();
     IList<UserMenuItem> exists = viewed.Where(v => v.ViewID == viewID).ToList();
     if (exists.Count == 0)
     {
         if (viewed.Count >= 10)
         {
             DeleteFromLastViewed(viewed[0].ID);
         }
         UserMenuItem item = new UserMenuItem()
         {
             ID = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Name = name,
             UserID = userID,
             UserMenuTypeID = UserMenuType.LastViewed,
             ViewID = viewID,
             Url = url
         };
         UserMenuItems.InsertOnSubmit(item);
         this.SubmitChanges();
     }
     else
     {
         foreach (UserMenuItem item in exists)
         {
             item.CreatedDate = DateTime.Now;
         }
         this.SubmitChanges();
     }
 }
Exemplo n.º 2
0
 public void AddToFavorites(Guid viewID, Guid userID, string name, string url)
 {
     List<UserMenuItem> list = this.GetFavorites(userID).OrderBy(v => v.CreatedDate).ToList();
     if (list.Where(v => v.ViewID == viewID).Count() == 0)
     {
         UserMenuItem item = new UserMenuItem()
         {
             ID = Guid.NewGuid(),
             CreatedDate = DateTime.Now,
             Name = name,
             UserID = userID,
             UserMenuTypeID = UserMenuType.Favorites,
             ViewID = viewID,
             Url = url
         };
         UserMenuItems.InsertOnSubmit(item);
         this.SubmitChanges();
     }
 }
Exemplo n.º 3
0
        public static NgMenu MenuItemToNgMenu(this UserMenuItem userMenuItem)
        {
            if (userMenuItem == null)
            {
                return(null);
            }
            var menu = new NgMenu();

            menu.key      = userMenuItem.Url;
            menu.text     = userMenuItem.Name;
            menu.link     = userMenuItem.Url;
            menu.icon     = userMenuItem.Icon;
            menu.hide     = !userMenuItem.IsVisible;
            menu.target   = userMenuItem.Target;
            menu.i18n     = string.Empty;
            menu.acl      = string.Empty;
            menu.shortcut = true;
            //menu.children = Array.ConvertAll<UserMenuItem, NgMenu>(userMenuItem.Items.ToArray(), x => x.MenuItemToNgMenu());


            return(menu);
        }
Exemplo n.º 4
0
        private void CreateMenuItems()
        {
            foreach (var item in this.notifyContextMenu.Items.OfType <ModuleMenuItem>().ToList())
            {
                this.notifyContextMenu.Items.Remove(item);
                item.Dispose();
            }

            foreach (var module in this.Modules)
            {
                var toolStripModule = new ModuleMenuItem(module);

                foreach (var user in this.Users)
                {
                    var toolStripUser = new UserMenuItem(user);
                    toolStripModule.DropDownItems.Add(toolStripUser);
                }

                notifyContextMenu.Items.Insert(0, toolStripModule);
            }

            notifyContextMenu.Refresh();
        }
Exemplo n.º 5
0
        private static void AppendMenuItem(int indentLength, StringBuilder sb, UserMenuItem menuItem)
        {
            sb.AppendLine("{");

            sb.AppendLine(new string(' ', indentLength + 4) + "name: '" + menuItem.Name + "',");

            if (!string.IsNullOrEmpty(menuItem.Icon))
            {
                sb.AppendLine(new string(' ', indentLength + 4) + "icon: '" + menuItem.Icon.Replace("'", @"\'") + "',");
            }

            if (!string.IsNullOrEmpty(menuItem.Url))
            {
                sb.AppendLine(new string(' ', indentLength + 4) + "url: '" + menuItem.Url.Replace("'", @"\'") + "',");
            }

            if (menuItem.DisplayName != null)
            {
                sb.AppendLine(new string(' ', indentLength + 4) + "displayName: '" + menuItem.DisplayName.Replace("'", @"\'") + "',");
            }

            sb.Append(new string(' ', indentLength + 4) + "items: [");

            for (int i = 0; i < menuItem.Items.Count; i++)
            {
                AppendMenuItem(24, sb, menuItem.Items[i]);
                if (menuItem.Items.Count - 1 > i)
                {
                    sb.Append(" , ");
                }
            }

            sb.AppendLine("]");

            sb.Append(new string(' ', indentLength) + "}");
        }
 public HeaderMenuItemViewModel(UserMenuItem menuItem, int currentLevel, string currentPageName)
 {
     MenuItem        = menuItem;
     CurrentLevel    = currentLevel;
     CurrentPageName = currentPageName;
 }
 public static bool IsMenuActive(this UserMenuItem menuItem, string pageName)
 {
     return(menuItem.Name.Equals(pageName));
 }
 public static string CalculateUrl(this UserMenuItem menuItem, string rootUrl)
 {
     return(rootUrl + menuItem.Url);
 }
Exemplo n.º 9
0
        //public async Task<IViewComponentResult> InvokeAsync(string activeMenu = "")
        //{
        //    var model = new SideBarNavViewModel
        //    {
        //        MainMenu = await _userNavigationManager.GetMenuAsync("MainMenu", _abpSession.ToUserIdentifier()),
        //        ActiveMenuItemName = activeMenu
        //    };
        //    return View(model);
        //}

        public async Task <IViewComponentResult> InvokeAsync(SideBarNavViewModel allUserMenu, UserMenuItem userMenuItem, string activeMenu = "")
        {
            if (allUserMenu == null)
            {
                var wholeModel = new SideBarNavViewModel
                {
                    MainMenu           = await _userNavigationManager.GetMenuAsync("MainMenu", _abpSession.ToUserIdentifier()),
                    ActiveMenuItemName = activeMenu
                };
                return(View(wholeModel));
            }
            var model = new SideBarNavViewModel
            {
                MainMenu = new UserMenu
                {
                    DisplayName = userMenuItem.DisplayName,
                    CustomData  = userMenuItem.CustomData,
                    Name        = userMenuItem.Name,
                    Items       = userMenuItem.Items,
                },
                ActiveMenuItemName = activeMenu
            };

            return(View(model));
        }
Exemplo n.º 10
0
        private async Task CreateChild(UserIdentifier user, UserMenuItem currentUserMenuIte, IEnumerable <MenuItem> childs)
        {
            using (var scope = _iocResolver.CreateScope())
            {
                var permissionDependencyContext = scope.Resolve <PermissionDependencyContext>();
                permissionDependencyContext.User = user;

                var featureDependencyContext = scope.Resolve <FeatureDependencyContext>();
                featureDependencyContext.TenantId = user == null ? null : user.TenantId;

                foreach (MenuItem menuItem in childs)
                {
                    MenuItemDefinition menuItemDefinition = new MenuItemDefinition(
                        menuItem.Name,
                        L(menuItem.Name),
                        url: menuItem.Route,
                        icon: menuItem.Icon,
                        target: "tab_" + menuItem.Id,
                        requiredPermissionName: menuItem.PermissionName,
                        order: menuItem.Sort
                        );
                    if (menuItemDefinition.RequiresAuthentication && user == null)
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(menuItemDefinition.RequiredPermissionName))
                    {
                        var permissionDependency = new SimplePermissionDependency(menuItemDefinition.RequiredPermissionName);
                        try
                        {
                            if (user == null ||
                                !(await permissionDependency.IsSatisfiedAsync(permissionDependencyContext)))
                            {
                                continue;
                            }
                        }
                        catch (Exception e)
                        {
                            continue;
                        }
                    }

                    if (menuItemDefinition.PermissionDependency != null &&
                        (user == null || !(await menuItemDefinition.PermissionDependency.IsSatisfiedAsync(permissionDependencyContext))))
                    {
                        continue;
                    }

                    if (menuItemDefinition.FeatureDependency != null &&
                        (AbpSession.MultiTenancySide == MultiTenancySides.Tenant || (user != null && user.TenantId != null)) &&
                        !(await menuItemDefinition.FeatureDependency.IsSatisfiedAsync(featureDependencyContext)))
                    {
                        continue;
                    }
                    currentUserMenuIte.Items.Add(new UserMenuItem(menuItemDefinition, _localizationContext));
                }
            }

            //foreach (MenuItem menuItem in childs)
            //{
            //    MenuItemDefinition menuItemDefinition = new MenuItemDefinition(
            //        menuItem.Name,
            //        L(menuItem.Name),
            //        url: menuItem.Route,
            //        icon: menuItem.Icon,
            //        target: "tab_" + menuItem.Id,
            //        requiredPermissionName: menuItem.PermissionName,
            //        order: menuItem.Sort
            //    );
            //    var permissionDependency = new SimplePermissionDependency(menuItemDefinition.RequiredPermissionName);
            //    if (user == null || !(await permissionDependency.IsSatisfiedAsync(permissionDependencyContext)))
            //    {
            //        continue;
            //    }
            //    currentUserMenuIte.Items.Add(new UserMenuItem(menuItemDefinition, _localizationContext));
            //}
        }