mirror of https://github.com/abpframework/abp.git
16 changed files with 203 additions and 4 deletions
@ -0,0 +1,12 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards |
|||
{ |
|||
public static class WidgetOptionsExtensions |
|||
{ |
|||
public static void AddDashboards<T>(this DashboardOptions options) |
|||
where T : IDashboardDefinitionProvider, new() |
|||
{ |
|||
var widgets = new T().GetDefinitions(); |
|||
options.Dashboards.AddRange(widgets); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards |
|||
{ |
|||
public interface IDashboardDefinitionProvider |
|||
{ |
|||
List<DashboardDefinition> GetDefinitions(); |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Dashboards |
|||
{ |
|||
public class WidgetLocation |
|||
{ |
|||
public int X { get; set; } |
|||
|
|||
public int Y { get; set; } |
|||
|
|||
public WidgetLocation(int x, int y) |
|||
{ |
|||
X = x; |
|||
Y = y; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using System.Collections.Generic; |
|||
using DashboardDemo.Localization.DashboardDemo; |
|||
using DashboardDemo.Widgets; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Dashboards; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace DashboardDemo.Dashboards |
|||
{ |
|||
public class DashboardDefinitionProvider : IDashboardDefinitionProvider |
|||
{ |
|||
public List<DashboardDefinition> GetDefinitions() |
|||
{ |
|||
var myDashboard = new DashboardDefinition( |
|||
DashboardNames.MyDashboard, |
|||
new LocalizableString(typeof(DashboardDemoResource), "MyDashboard") |
|||
); |
|||
|
|||
myDashboard.AvailableWidgets.Add( |
|||
new DashboardWidgetConfiguration(WidgetNames.MyWidget) |
|||
); |
|||
myDashboard.AvailableWidgets.Add( |
|||
new DashboardWidgetConfiguration(WidgetNames.DemoStatistics, new WidgetDimensions(8,2)) |
|||
); |
|||
|
|||
|
|||
var dashboards = new List<DashboardDefinition> |
|||
{ |
|||
myDashboard |
|||
}; |
|||
|
|||
return dashboards; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Reflection; |
|||
|
|||
namespace DashboardDemo.Dashboards |
|||
{ |
|||
public static class DashboardNames |
|||
{ |
|||
public const string MyDashboard = "MyDashboard"; |
|||
|
|||
public static string[] GetAll() |
|||
{ |
|||
return ReflectionHelper.GetPublicConstantsRecursively(typeof(DashboardNames)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
@page |
|||
@using Microsoft.Extensions.Localization |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets |
|||
@inject IWidgetRenderer WidgetRenderer |
|||
@inject IStringLocalizerFactory localizer |
|||
@model DashboardDemo.Pages.MyDashboardModel |
|||
@{ |
|||
} |
|||
<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> |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using DashboardDemo.Dashboards; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.RazorPages; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Dashboards; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Widgets; |
|||
|
|||
namespace DashboardDemo.Pages |
|||
{ |
|||
public class MyDashboardModel : DashboardDemoPageModelBase |
|||
{ |
|||
public DashboardDefinition Dashboard { get; set; } |
|||
|
|||
private readonly DashboardOptions _dashboardOptions; |
|||
private readonly WidgetOptions _widgetOptions; |
|||
|
|||
public MyDashboardModel(IOptions<DashboardOptions> dashboardOptions, IOptions<WidgetOptions> widgetOptions) |
|||
{ |
|||
_dashboardOptions = dashboardOptions.Value; |
|||
_widgetOptions = widgetOptions.Value; |
|||
} |
|||
|
|||
public void OnGet() |
|||
{ |
|||
Dashboard = _dashboardOptions.Dashboards.Single(d => d.Name.Equals(DashboardNames.MyDashboard)); |
|||
} |
|||
|
|||
public WidgetDefinition GetWidget(string name) |
|||
{ |
|||
return _widgetOptions.Widgets.Single(d => d.Name.Equals(name)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
@page |
|||
@model DashboardDemo.Pages.widgets.DemoStatisticsViewComponentModel |
|||
@{ |
|||
} |
|||
|
|||
Demo statistics |
|||
@ -0,0 +1,13 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
|
|||
namespace DashboardDemo.Pages.widgets |
|||
{ |
|||
[ViewComponent] |
|||
public class DemoStatisticsViewComponentModel : ViewComponent |
|||
{ |
|||
public IViewComponentResult Invoke() |
|||
{ |
|||
return View("/Pages/widgets/DemoStatisticsViewComponent.cshtml", new DemoStatisticsViewComponentModel()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue