DashboardRenderer

pull/1144/head
Yunus Emre Kalkan 7 years ago
parent d21c882d52
commit fc16050064

@ -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

@ -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/"
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">
<Import Project="..\..\..\common.props" />
@ -6,11 +6,29 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AspNetCore.Mvc.UI.Dashboards</AssemblyName>
<PackageId>Volo.Abp.AspNetCore.Mvc.UI.Dashboards</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<IsPackable>true</IsPackable>
<OutputType>Library</OutputType>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.UI.Widgets\Volo.Abp.AspNetCore.Mvc.UI.Widgets.csproj" />
<EmbeddedResource Include="Volo\Abp\AspNetCore\Mvc\UI\Dashboards\Components\**\*.cshtml" />
<Content Remove="Volo\Abp\AspNetCore\Mvc\UI\Dashboards\Components\**\*.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Remove="Volo\Abp\AspNetCore\Mvc\UI\Dashboards\_ViewImports.cshtml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Volo\Abp\AspNetCore\Mvc\UI\Dashboards\_ViewImports.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.UI.Widgets\Volo.Abp.AspNetCore.Mvc.UI.Widgets.csproj" />
</ItemGroup>
</Project>

@ -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<VirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpAspNetCoreMvcUiDashboardsModule>();
});
}
}
}

@ -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<IViewComponentResult> 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);
}
}
}

@ -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));
}
}
}

@ -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
@{
}
<abp-row>
@foreach (var widgetConfiguration in Model.Dashboard.AvailableWidgets)
{
var widgetDefinition = Model.GetWidget(widgetConfiguration.WidgetName);
widgetDefinition.DefaultDimensions = widgetConfiguration.Dimensions ?? widgetDefinition.DefaultDimensions ?? new WidgetDimensions(5, 5);
<abp-column class="col-@widgetDefinition.DefaultDimensions.Width"
style="height: @(widgetDefinition.DefaultDimensions.Height * 100)px"
abp-border="Danger">
@await WidgetRenderer.RenderAsync(Component, widgetDefinition.Name)
</abp-column>
}
</abp-row>

@ -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> widgetOptions, IOptions<DashboardOptions> dashboardOptions)
{
_widgetOptions = widgetOptions.Value;
_dashboardOptions = dashboardOptions.Value;
}
public Task<IHtmlContent> RenderAsync(IViewComponentHelper componentHelper, string dashboardName, object args = null)
public async Task<IHtmlContent> RenderAsync(IViewComponentHelper componentHelper, object args = null)
{
throw new NotImplementedException();
return await componentHelper.InvokeAsync(typeof(DashboardViewComponent), args ?? new object());
}
}
}

@ -10,6 +10,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards
{
public interface IDashboardRenderer : ITransientDependency
{
Task<IHtmlContent> RenderAsync(IViewComponentHelper componentHelper, string dashboardName, object args = null);
Task<IHtmlContent> RenderAsync(IViewComponentHelper componentHelper, object args = null);
}
}

@ -0,0 +1,3 @@
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling

@ -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 {
<abp-script-bundle name="MyDashboard" />
}
<h2>@Model.Dashboard.DisplayName.Localize(localizer)</h2>
<abp-row>
@foreach (var widgetConfiguration in Model.Dashboard.AvailableWidgets)
{
var widgetDefinition = Model.GetWidget(widgetConfiguration.WidgetName);
widgetDefinition.DefaultDimensions = widgetConfiguration.Dimensions ?? widgetDefinition.DefaultDimensions ?? new WidgetDimensions(5,5);
<abp-column class="col-@widgetDefinition.DefaultDimensions.Width"
style="height: @(widgetDefinition.DefaultDimensions.Height * 100)px"
abp-border="Danger">
@await WidgetRenderer.RenderAsync(Component, widgetDefinition.Name)
</abp-column>
}
</abp-row>
@await DashboardRenderer.RenderAsync(Component, new { dashboardName = DashboardNames.MyDashboard, dashboardOptions = Model._dashboardOptions, widgetOptions = Model._widgetOptions })

@ -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> dashboardOptions, IOptions<WidgetOptions> widgetOptions)
{

Loading…
Cancel
Save