ABP框架系列之三十七:(Navigation-导航)

news/2024/7/5 10:21:02

Every web application has some menu to navigate between pages/screens. ASP.NET Boilerplate provides a common ifrastructure to create and show menu to users.

每个Web应用程序都有一些菜单在页面/屏幕之间导航。ASP.NET提供了一个通用的ifrastructure样板文件创建和显示菜单的用户。

Creating Menus

An application may be consists of different modules and each module can have it's own menu items. To define menu items, we need to create a class derived from NavigationProvider.

Assume that we have a main menu as shown below:

应用程序可以由不同的模块组成,每个模块都可以有自己的菜单项。定义菜单项,我们需要创建一个类派生navigationprovider。

假设我们有一个主菜单,如下所示:

  • Tasks
  • Reports
  • Administration
    • User management
    • Role management

Here, Administration menu item has two sub menu items. Example navigation provider class to create such a menu can be as below:

public class SimpleTaskSystemNavigationProvider : NavigationProvider
{
    public override void SetNavigation(INavigationProviderContext context)
    {
        context.Manager.MainMenu
            .AddItem(
                new MenuItemDefinition(
                    "Tasks",
                    new LocalizableString("Tasks", "SimpleTaskSystem"),
                    url: "/Tasks",
                    icon: "fa fa-tasks"
                    )
            ).AddItem(
                new MenuItemDefinition(
                    "Reports",
                    new LocalizableString("Reports", "SimpleTaskSystem"),
                    url: "/Reports",
                    icon: "fa fa-bar-chart"
                    )
            ).AddItem(
                new MenuItemDefinition(
                    "Administration",
                    new LocalizableString("Administration", "SimpleTaskSystem"),
                    icon: "fa fa-cogs"
                    ).AddItem(
                        new MenuItemDefinition(
                            "UserManagement",
                            new LocalizableString("UserManagement", "SimpleTaskSystem"),
                            url: "/Administration/Users",
                            icon: "fa fa-users",
                            requiredPermissionName: "SimpleTaskSystem.Permissions.UserManagement"
                            )
                    ).AddItem(
                        new MenuItemDefinition(
                            "RoleManagement",
                            new LocalizableString("RoleManagement", "SimpleTaskSystem"),
                            url: "/Administration/Roles",
                            icon: "fa fa-star",
                            requiredPermissionName: "SimpleTaskSystem.Permissions.RoleManagement"
                            )
                    )
            );
    }
}

A MenuItemDefinition can basically have a unique name, a localizable display name, a url and an icon. Also,

一个menuitemdefinition基本上能有一个独特的名字,一个本地化的显示名称,URL和图标

  • A menu item may require a permission to show this menu to a particular user (See authorization document). requiredPermissionName property can be used in this case.
  • A menu item can be depend on a feature. featureDependency property can be used in this case.
  • A menu item can define a customData and order.
  • 菜单项可能需要允许将菜单显示给特定用户(请参阅授权文档)。requiredpermissionname属性可以在这种情况下使用。
    菜单项可以依赖于一个特性。FeatureDependency属性可以在这种情况下使用。
    菜单项可以定义一个customdata和order。

INavigationProviderContext has methods to get existing menu items, add menus and menu items. Thus, different modules can add it's own items to the menu.

There may be one or more menus in an application. context.Manager.MainMenu references the default, main menu. We can create and add more menus using context.Manager.Menus property.

inavigationprovidercontext有方法让现有的菜单项,添加菜单和菜单项。因此,不同的模块可以将自己的项目添加到菜单中。

应用程序中可能有一个或多个菜单。context.manager.mainmenu引用默认的主菜单。我们可以创建和使用context.manager.menus属性添加更多的菜单。

Registering Navigation Provider

After creating the navigation provider, we should register it to ASP.NET Boilerplate configuration on PreInitialize event of our module:

Configuration.Navigation.Providers.Add<SimpleTaskSystemNavigationProvider>(); 

Showing Menu

IUserNavigationManager can be injected and used to get menu items and show to the user. Thus, we can create menu in server side.

ASP.NET Boilerplate automatically generates a javascript API to get menu and items in client side. Methods and objects under abp.nav namespace can be used for this purpose. For instance, abp.nav.menus.MainMenucan be used to get main menu of the application. Thus, we can create menu in client side.

ASP.NET Boilerplate templates uses this system to create and show menu to the user. Try to create a template and see source codes for more.

iusernavigationmanager可以注入,用得到的菜单项和显示给用户。因此,我们可以在服务器端创建菜单。

ASP.NET样板自动生成JavaScript API来获取客户端菜单项。在abp.nav命名空间对象和方法可用于这一目的。例如,abp.nav.menus.mainmenucan被用于获得应用程序主菜单。因此,我们可以在客户端创建菜单。

ASP.NET的模板模板使用本系统创建和显示菜单的用户。尝试创建一个模板并查看更多的源代码。


http://www.niftyadmin.cn/n/2133340.html

相关文章

深度学习大概率用到的Pytorch内容基础

Pytorch 基础 文章目录(1) 基本数据类型1.Pytorch 用的比较多 tensor2.类型的检测3.不同维度的数据及用途(2) 创建Tensor1.从numpy中创建Tensor2.从list中创建Tensor3.设定默认type4.随机产生进行初始化5.采用特殊生成进行初始化(3) 索引与切片(4) 维度变换(1) 基本数据类型 1…

61. 搜索区间

给定一个包含 n 个整数的排序数组&#xff0c;找出给定目标值 target的起始和结束位置。 如果目标值不在数组中&#xff0c;则返回[-1, -1] 样例 给出[5, 7, 7, 8, 8, 10]和目标值target8, 返回[3, 4] 挑战 时间复杂度 O(log n) 应该要第一时间反应到二分&#xff0c;就算没有…

深度学习大概率用到的Pytorch内容进阶

Pytorch进阶 文章目录(1) 拼接与拆分(2) 基本运算(3) 统计属性 (4) 高阶操作(1) 拼接与拆分 torch.cat(tensors, dim0)torch.stack(tensors, dim0)注意区别 torch.cat 和 torch.stack&#xff0c;前者是不会产生新的维度的&#xff0c;后者是会产生新的维度&#xff0c;而且注…

outlook/foxmail发邮件退信

Microsoft Outlook向以下收件人或组传递邮件失败: liuyangxxxx.com 电子邮件系统在处理此邮件时遇到问题。该系统不会尝试重新传递此邮件。 供管理员使用的诊断信息: 生成服务器: EXCSE.xxxx.com liuyangxxxx.com #554 5.6.0 STOREDRV.Submit.Exception:PropertyTooBigExceptio…

ospf不同区域的互通

实验名称&#xff1a;ospf不同区域的互通实验拓扑图&#xff1a;3.配置思路 &#xff1a; 首先确定边界路由器&#xff0c;例如在上面图中&#xff0c;AR2,和AR1是边界路由器&#xff0c;然后划分不同的区域&#xff0c;4. 配置步骤 &#xff1a; #首先给所有路由器配置ip地址…

新CSDN文章转成PDF、打印(去空白)

新CSDN文章一键打印、输出PDF&#xff08;自动阅读全文、全清爽模式&#xff09; 之前的方法出现的问题是打印出的预览图会有右边一大片空白&#xff0c;这个方法实现将空白去掉 一、功能及修改方法 使用方法&#xff1a;按“F12”进入开发者工具&#xff0c;将以下js复制到 …

随机过程(基本概念、平稳随机过程)

大三上学习了随机过程&#xff08;实际听不懂就去看了简化版的随机信号&#xff09;&#xff0c;感觉一些概念性的东西比较多&#xff0c;因此这里进行一个简单总结。 文章目录(1)随机过程的基本概念1.对随机过程的理解2.随机过程的概率分布3.随机过程的矩函数4.随机过程的特征…

搭建简单的伪热更新Mock服务

简介 刚开始接触vue-cli&#xff0c;发现用它生成的框架代码是缺少Mock模拟的&#xff0c;于是自己摸索了许久&#xff0c;将自己的摸索的结果通过过程记录下来&#xff0c;希望对别人有所帮助&#xff0c;能少走弯路。 这不是关于vue-cli的&#xff0c;是单纯的模拟数据服务 这…