From f16a2a52d65a6838acfb39b2b3cbe09c96986663 Mon Sep 17 00:00:00 2001 From: Lupei Nicolae Date: Wed, 11 Mar 2020 15:45:52 +0200 Subject: [PATCH] feat: add menu configuration for dashboard module --- .../Extensions/ServiceCollectionExtensions.cs | 14 ++++- .../GR.Dashboard.Razor.csproj | 1 + .../Helpers/DashboardMenuInitializer.cs | 60 +++++++++++++++++++ .../Helpers/DashboardRazorResources.cs | 15 +++++ .../Helpers/NotificationsMenuInitializer.cs | 10 ++-- 5 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardMenuInitializer.cs create mode 100644 src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardRazorResources.cs diff --git a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Extensions/ServiceCollectionExtensions.cs b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Extensions/ServiceCollectionExtensions.cs index 3eca877b..aae35d81 100755 --- a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Extensions/ServiceCollectionExtensions.cs +++ b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Extensions/ServiceCollectionExtensions.cs @@ -1,6 +1,10 @@ -using Microsoft.Extensions.DependencyInjection; +using GR.Core; +using GR.Core.Extensions; +using Microsoft.Extensions.DependencyInjection; using GR.Dashboard.Abstractions.ServiceBuilder; using GR.Dashboard.Razor.Helpers; +using GR.UI.Menu.Abstractions; +using GR.UI.Menu.Abstractions.Events; namespace GR.Dashboard.Razor.Extensions { @@ -14,6 +18,14 @@ public static class ServiceCollectionExtensions public static IDashboardServiceCollection AddDashboardRazorUIModule(this IDashboardServiceCollection services) { services.Services.ConfigureOptions(typeof(DashBoardFileConfiguration)); + + MenuEvents.Menu.OnMenuSeed += (sender, args) => + { + GearApplication.BackgroundTaskQueue.PushBackgroundWorkItemInQueue(async x => + { + await x.InjectService().AppendMenuItemsAsync(new DashboardMenuInitializer()); + }); + }; return services; } } diff --git a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/GR.Dashboard.Razor.csproj b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/GR.Dashboard.Razor.csproj index 31a911bc..f5dc3694 100755 --- a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/GR.Dashboard.Razor.csproj +++ b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/GR.Dashboard.Razor.csproj @@ -33,6 +33,7 @@ + diff --git a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardMenuInitializer.cs b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardMenuInitializer.cs new file mode 100644 index 00000000..594d4e35 --- /dev/null +++ b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardMenuInitializer.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using GR.Core; +using GR.UI.Menu.Abstractions.Helpers; + +namespace GR.Dashboard.Razor.Helpers +{ + public class DashboardMenuInitializer : BaseMenuInitializer + { + public override MenuInitBuilder Builder => + new MenuInitBuilder + { + MenuGroup = MenuResources.AppMenuId, + Configs = new List + { + new MenuItemConfig(DashboardRazorResources.Menu.DashboardConfiguration) + { + Name = "Dashboard configuration", + ParentMenuItemId = MenuResources.MenuItems.ConfigurationItem, + Href = MenuResources.MenuItems.None, + AllowedRoles = new List + { + GlobalResources.Roles.ADMINISTRATOR + } + }, + new MenuItemConfig(DashboardRazorResources.Menu.AllDashboard) + { + Name = "All dashboards", + ParentMenuItemId = DashboardRazorResources.Menu.DashboardConfiguration, + Href = "/dashboard", + AllowedRoles = new List + { + GlobalResources.Roles.ADMINISTRATOR + } + }, + new MenuItemConfig(DashboardRazorResources.Menu.WidgetGroups) + { + Name = "Widget groups", + ParentMenuItemId = DashboardRazorResources.Menu.DashboardConfiguration, + Href = "/WidgetGroup", + Translate = "system_widget_groups", + AllowedRoles = new List + { + GlobalResources.Roles.ADMINISTRATOR + } + }, + new MenuItemConfig(DashboardRazorResources.Menu.Widgets) + { + Name = "Widgets", + ParentMenuItemId = DashboardRazorResources.Menu.DashboardConfiguration, + Href = "/Widget", + Translate = "system_widgets", + AllowedRoles = new List + { + GlobalResources.Roles.ADMINISTRATOR + } + } + } + }; + } +} diff --git a/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardRazorResources.cs b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardRazorResources.cs new file mode 100644 index 00000000..021e67a2 --- /dev/null +++ b/src/GR.Extensions/GR.Dashboard.Extension/GR.Dashboard.Razor/Helpers/DashboardRazorResources.cs @@ -0,0 +1,15 @@ +using System; + +namespace GR.Dashboard.Razor.Helpers +{ + public static class DashboardRazorResources + { + public static class Menu + { + public static Guid DashboardConfiguration = Guid.Parse("52a430e6-c41b-4b73-8a23-95b22769894e"); + public static Guid AllDashboard = Guid.Parse("9448a77d-a90d-4461-9d78-1a4acd708dd3"); + public static Guid WidgetGroups = Guid.Parse(""); + public static Guid Widgets = Guid.Parse(""); + } + } +} diff --git a/src/GR.Extensions/GR.Notifications.Extension/GR.Notifications.Razor/Helpers/NotificationsMenuInitializer.cs b/src/GR.Extensions/GR.Notifications.Extension/GR.Notifications.Razor/Helpers/NotificationsMenuInitializer.cs index e95cd7b4..13458d02 100644 --- a/src/GR.Extensions/GR.Notifications.Extension/GR.Notifications.Razor/Helpers/NotificationsMenuInitializer.cs +++ b/src/GR.Extensions/GR.Notifications.Extension/GR.Notifications.Razor/Helpers/NotificationsMenuInitializer.cs @@ -4,16 +4,15 @@ namespace GR.Notifications.Razor.Helpers { - public class NotificationsMenuInitializer: BaseMenuInitializer + public class NotificationsMenuInitializer : BaseMenuInitializer { public override MenuInitBuilder Builder => new MenuInitBuilder { MenuGroup = MenuResources.AppMenuId, Configs = new List { - new MenuItemConfig + new MenuItemConfig(NotificationsRazorResources.Menu.Notifications) { - Id = NotificationsRazorResources.Menu.Notifications, Name = "Notifications", ParentMenuItemId = MenuResources.MenuItems.ConfigurationItem, Href = MenuResources.MenuItems.None, @@ -23,11 +22,10 @@ public class NotificationsMenuInitializer: BaseMenuInitializer GlobalResources.Roles.ADMINISTRATOR } }, - new MenuItemConfig + new MenuItemConfig(NotificationsRazorResources.Menu.Subscriptions) { - Id = NotificationsRazorResources.Menu.Subscriptions, Name = "Notifications subscriptions", - ParentMenuItemId = MenuResources.MenuItems.ConfigurationItem, + ParentMenuItemId = NotificationsRazorResources.Menu.Notifications, Href = "/NotificationSubscriptions", AllowedRoles = new List {