From 46eb5b380ba3b78062503e0139c22d9b4d3e13f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sun, 21 Jul 2019 18:14:32 +0300 Subject: [PATCH] Create initial sample dashboard. --- .../System/AbpDateTimeExtensions.cs | 21 ++++++++++++++ .../System/AbpDayOfWeekExtensions.cs | 2 +- .../CountersWidgetViewComponent.cs | 29 +++++++++++++++++++ .../CountersWidget/CountersWidgetViewModel.cs | 10 +++++++ .../Components/CountersWidget/Default.cshtml | 29 +++++++++++++++++++ .../Components/CountersWidget/Default.css | 17 +++++++++++ .../Pages/MyDashboard.cshtml | 26 +++++++++++++++++ .../Pages/MyDashboard.cshtml.cs | 28 ++++++++++++++++++ .../DashboardDemo.Web/Pages/MyDashboard.css | 3 ++ .../DashboardDemo.Web/Pages/MyWidgets.cshtml | 1 + 10 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.Core/System/AbpDateTimeExtensions.cs create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.css create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs create mode 100644 samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.css diff --git a/framework/src/Volo.Abp.Core/System/AbpDateTimeExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpDateTimeExtensions.cs new file mode 100644 index 0000000000..de7c4a85ff --- /dev/null +++ b/framework/src/Volo.Abp.Core/System/AbpDateTimeExtensions.cs @@ -0,0 +1,21 @@ +namespace System +{ + /// + /// Extension methods for the . + /// + public static class AbpDateTimeExtensions + { + public static DateTime ClearTime(this DateTime dateTime) + { + return dateTime.Subtract( + new TimeSpan( + 0, + dateTime.Hour, + dateTime.Minute, + dateTime.Second, + dateTime.Millisecond + ) + ); + } + } +} diff --git a/framework/src/Volo.Abp.Core/System/AbpDayOfWeekExtensions.cs b/framework/src/Volo.Abp.Core/System/AbpDayOfWeekExtensions.cs index fcc3085011..9546aa09f6 100644 --- a/framework/src/Volo.Abp.Core/System/AbpDayOfWeekExtensions.cs +++ b/framework/src/Volo.Abp.Core/System/AbpDayOfWeekExtensions.cs @@ -1,7 +1,7 @@ namespace System { /// - /// Extension methods for . + /// Extension methods for the . /// public static class AbpDayOfWeekExtensions { diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs new file mode 100644 index 0000000000..a945691194 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewComponent.cs @@ -0,0 +1,29 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Widgets; + +namespace DashboardDemo.Web.Pages.Components.CountersWidget +{ + [Widget( + StyleFiles = new[] { "/Pages/Components/CountersWidget/Default.css" } + )] + public class CountersWidgetViewComponent : AbpViewComponent + { + public async Task InvokeAsync(DateTime startDate, DateTime endDate) + { + /* Instead of hard-coded / calculated values, get counts from a database or a service! + */ + + var dayFactor = (int)Math.Round(endDate.Subtract(startDate).TotalDays + 1); + return View(new CountersWidgetViewModel + { + NewUsers = dayFactor * 86, + ActiveUsers = dayFactor * 58, + TotalIncome = dayFactor * 749.53, + TotalProfit = dayFactor * 239.45, + }); + } + } +} diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs new file mode 100644 index 0000000000..bf532a47bc --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/CountersWidgetViewModel.cs @@ -0,0 +1,10 @@ +namespace DashboardDemo.Web.Pages.Components.CountersWidget +{ + public class CountersWidgetViewModel + { + public int NewUsers { get; set; } + public int ActiveUsers { get; set; } + public double TotalIncome { get; set; } + public double TotalProfit { get; set; } + } +} \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml new file mode 100644 index 0000000000..58c18c506c --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.cshtml @@ -0,0 +1,29 @@ +@model DashboardDemo.Web.Pages.Components.CountersWidget.CountersWidgetViewModel +
+ + +
+
@Model.NewUsers
+
New Users
+
+
+ +
+
@Model.ActiveUsers
+
Active Users
+
+
+ +
+
@Model.TotalIncome.ToString("C")
+
Total Income
+
+
+ +
+
@Model.TotalProfit.ToString("C")
+
Total Profit
+
+
+
+
\ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.css b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.css new file mode 100644 index 0000000000..c23a6499b5 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/Components/CountersWidget/Default.css @@ -0,0 +1,17 @@ +.counters-widget .counters-widget-item { + border: 1px solid #ddd; + border-bottom: 5px solid #bbb; + border-right: 5px solid #ddd; + background-color: #f5f5f5; + text-align: center; + padding: 10px; +} + +.counters-widget .counters-widget-count { + font-size: 2em; + color: #00008b; +} + +.counters-widget .counters-widget-count-name { + color: #666; +} \ 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 new file mode 100644 index 0000000000..b96595ce9a --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml @@ -0,0 +1,26 @@ +@page +@model DashboardDemo.Web.Pages.MyDashboardModel + +@section styles { + +} + +
+ + + + + + + + + + + +
+ +@await Component.InvokeAsync("CountersWidget", new +{ + startDate = @Model.StartDate, + endDate = @Model.EndDate +}) \ 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 new file mode 100644 index 0000000000..f8075bfa89 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.cshtml.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace DashboardDemo.Web.Pages +{ + public class MyDashboardModel : PageModel + { + [BindProperty(SupportsGet = true)] + public DateTime? StartDate { get; set; } + + [BindProperty(SupportsGet = true)] + public DateTime? EndDate { get; set; } + + public void OnGet() + { + if (StartDate == null) + { + StartDate = DateTime.Now.Subtract(TimeSpan.FromDays(6)).ClearTime(); + } + + if (EndDate == null) + { + EndDate = DateTime.Now.AddDays(1).ClearTime(); + } + } + } +} \ No newline at end of file diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.css b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.css new file mode 100644 index 0000000000..7a0560b920 --- /dev/null +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyDashboard.css @@ -0,0 +1,3 @@ +#MyDashboardFilterForm button[type=Submit] { + margin-top: 25px; +} diff --git a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml index f1f6bb09ff..cc4cfa270d 100644 --- a/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml +++ b/samples/DashboardDemo/src/DashboardDemo.Web/Pages/MyWidgets.cshtml @@ -1,6 +1,7 @@ @page @using DashboardDemo.Web.Pages.Components.MySimpleWidget @model DashboardDemo.Web.Pages.MyWidgetsModel + @* Example usage by widget name *@ @await Component.InvokeAsync("MySimpleWidget", new { name = "John" })