From fc16050064d951d729623cfce64016a5583bafbc Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 22 May 2019 16:27:02 +0300 Subject: [PATCH] DashboardRenderer --- framework/Volo.Abp.sln | 4 +-- .../Properties/launchSettings.json | 27 +++++++++++++++++++ ...lo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj | 22 +++++++++++++-- .../AbpAspNetCoreMvcUiDashboardsModule.cs | 11 ++++++-- .../DashboardViewComponent.cshtml.cs | 17 ++++++++++++ .../Dashboard/DashboardViewModel.cs | 27 +++++++++++++++++++ .../Components/Dashboard/Default.cshtml | 21 +++++++++++++++ .../Mvc/UI/Dashboards/DashboardRenderer.cs | 14 +++------- .../Mvc/UI/Dashboards/IDashboardRenderer.cs | 2 +- .../Mvc/UI/Dashboards/_ViewImports.cshtml | 3 +++ .../Pages/MyDashboard.cshtml | 19 +++---------- .../Pages/MyDashboard.cshtml.cs | 4 +-- 12 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Properties/launchSettings.json create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewComponent.cshtml.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewModel.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/Default.cshtml create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/_ViewImports.cshtml diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index a2a423ff74..be77f0ab24 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -234,9 +234,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Specifications.Tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Cli.Core.Tests", "test\Volo.Abp.Cli.Core.Tests\Volo.Abp.Cli.Core.Tests.csproj", "{F006B0B4-F25D-4511-9FB3-F17AA44BDCEA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.UI.Widgets", "src\Volo.Abp.AspNetCore.Mvc.UI.Widgets\Volo.Abp.AspNetCore.Mvc.UI.Widgets.csproj", "{EE1AAB08-3FBD-487F-B0B4-BEBA4B69528A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.UI.Widgets", "src\Volo.Abp.AspNetCore.Mvc.UI.Widgets\Volo.Abp.AspNetCore.Mvc.UI.Widgets.csproj", "{EE1AAB08-3FBD-487F-B0B4-BEBA4B69528A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.UI.Dashboards", "src\Volo.Abp.AspNetCore.Mvc.UI.Dashboards\Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj", "{054D766D-5992-460E-A4D8-936D80BE2C1A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.AspNetCore.Mvc.UI.Dashboards", "src\Volo.Abp.AspNetCore.Mvc.UI.Dashboards\Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj", "{054D766D-5992-460E-A4D8-936D80BE2C1A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Properties/launchSettings.json b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Properties/launchSettings.json new file mode 100644 index 0000000000..0ce91a367d --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:57333/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Volo.Abp.AspNetCore.Mvc.UI.Dashboards": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:57343/" + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj index f887ac867a..c2e85e8239 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo.Abp.AspNetCore.Mvc.UI.Dashboards.csproj @@ -1,4 +1,4 @@ - + @@ -6,11 +6,29 @@ netstandard2.0 Volo.Abp.AspNetCore.Mvc.UI.Dashboards Volo.Abp.AspNetCore.Mvc.UI.Dashboards + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + true + Library - + + + + + + + + + + + + + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/AbpAspNetCoreMvcUiDashboardsModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/AbpAspNetCoreMvcUiDashboardsModule.cs index 5acd00334c..6fcb11d28e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/AbpAspNetCoreMvcUiDashboardsModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/AbpAspNetCoreMvcUiDashboardsModule.cs @@ -1,13 +1,20 @@ using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.Abp.Modularity; +using Volo.Abp.VirtualFileSystem; namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards { [DependsOn( typeof(AbpAspNetCoreMvcUiWidgetsModule) - )] + )] public class AbpAspNetCoreMvcUiDashboardsModule : AbpModule { - + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.FileSets.AddEmbedded(); + }); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewComponent.cshtml.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewComponent.cshtml.cs new file mode 100644 index 0000000000..01d14cb7f1 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewComponent.cshtml.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards.Components.Dashboard +{ + public class DashboardViewComponent : AbpViewComponent + { + public async Task InvokeAsync(string dashboardName, DashboardOptions dashboardOptions, WidgetOptions widgetOptions) + { + var model = new DashboardViewModel(dashboardName, dashboardOptions, widgetOptions); + return View("~/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/Default.cshtml", model); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewModel.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewModel.cs new file mode 100644 index 0000000000..4658078a3a --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/DashboardViewModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards.Components.Dashboard +{ + public class DashboardViewModel + { + public DashboardDefinition Dashboard { get; set; } + public DashboardOptions DashboardOptions { get; set; } + public WidgetOptions WidgetOptions { get; set; } + + public DashboardViewModel(string dashboardName, DashboardOptions dashboardOptions, WidgetOptions widgetOptions) + { + Dashboard = dashboardOptions.Dashboards.Single(d => d.Name.Equals(dashboardName)); + DashboardOptions = dashboardOptions; + WidgetOptions = widgetOptions; + } + + public WidgetDefinition GetWidget(string name) + { + return WidgetOptions.Widgets.Single(d => d.Name.Equals(name)); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/Default.cshtml new file mode 100644 index 0000000000..524bf6d79e --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/Components/Dashboard/Default.cshtml @@ -0,0 +1,21 @@ +@using Microsoft.Extensions.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Widgets +@inject IWidgetRenderer WidgetRenderer +@inject IStringLocalizerFactory localizer +@model Volo.Abp.AspNetCore.Mvc.UI.Dashboards.Components.Dashboard.DashboardViewModel +@{ +} + + @foreach (var widgetConfiguration in Model.Dashboard.AvailableWidgets) + { + var widgetDefinition = Model.GetWidget(widgetConfiguration.WidgetName); + widgetDefinition.DefaultDimensions = widgetConfiguration.Dimensions ?? widgetDefinition.DefaultDimensions ?? new WidgetDimensions(5, 5); + + + + @await WidgetRenderer.RenderAsync(Component, widgetDefinition.Name) + + } + \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/DashboardRenderer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/DashboardRenderer.cs index 60c9fd5766..8f479622db 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/DashboardRenderer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/DashboardRenderer.cs @@ -5,24 +5,16 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc.UI.Dashboards.Components.Dashboard; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards { public class DashboardRenderer : IDashboardRenderer { - private readonly WidgetOptions _widgetOptions; - private readonly DashboardOptions _dashboardOptions; - - public DashboardRenderer(IOptions widgetOptions, IOptions dashboardOptions) - { - _widgetOptions = widgetOptions.Value; - _dashboardOptions = dashboardOptions.Value; - } - - public Task RenderAsync(IViewComponentHelper componentHelper, string dashboardName, object args = null) + public async Task RenderAsync(IViewComponentHelper componentHelper, object args = null) { - throw new NotImplementedException(); + return await componentHelper.InvokeAsync(typeof(DashboardViewComponent), args ?? new object()); } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/IDashboardRenderer.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/IDashboardRenderer.cs index 1a8f5ea04c..64e149696f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/IDashboardRenderer.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/IDashboardRenderer.cs @@ -10,6 +10,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards { public interface IDashboardRenderer : ITransientDependency { - Task RenderAsync(IViewComponentHelper componentHelper, string dashboardName, object args = null); + Task RenderAsync(IViewComponentHelper componentHelper, object args = null); } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/_ViewImports.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/_ViewImports.cshtml new file mode 100644 index 0000000000..225780c2c2 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Dashboards/Volo/Abp/AspNetCore/Mvc/UI/Dashboards/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap +@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml index 5055883e1d..f847778ba4 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml @@ -1,7 +1,10 @@ @page +@using DashboardDemo.Dashboards @using Microsoft.Extensions.Localization +@using Volo.Abp.AspNetCore.Mvc.UI.Dashboards @using Volo.Abp.AspNetCore.Mvc.UI.Widgets @inject IWidgetRenderer WidgetRenderer +@inject IDashboardRenderer DashboardRenderer @inject IStringLocalizerFactory localizer @model DashboardDemo.Pages.MyDashboardModel @{ @@ -9,19 +12,5 @@ @section scripts { } -

@Model.Dashboard.DisplayName.Localize(localizer)

- - @foreach (var widgetConfiguration in Model.Dashboard.AvailableWidgets) - { - var widgetDefinition = Model.GetWidget(widgetConfiguration.WidgetName); - widgetDefinition.DefaultDimensions = widgetConfiguration.Dimensions ?? widgetDefinition.DefaultDimensions ?? new WidgetDimensions(5,5); - - - @await WidgetRenderer.RenderAsync(Component, widgetDefinition.Name) - - } - - +@await DashboardRenderer.RenderAsync(Component, new { dashboardName = DashboardNames.MyDashboard, dashboardOptions = Model._dashboardOptions, widgetOptions = Model._widgetOptions }) \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs index c7b561700a..14d582808e 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs @@ -10,8 +10,8 @@ namespace DashboardDemo.Pages { public DashboardDefinition Dashboard { get; set; } - private readonly DashboardOptions _dashboardOptions; - private readonly WidgetOptions _widgetOptions; + public readonly DashboardOptions _dashboardOptions; + public readonly WidgetOptions _widgetOptions; public MyDashboardModel(IOptions dashboardOptions, IOptions widgetOptions) {