Skip to content

Commit

Permalink
nopSolutions#5842 Don't load reports on the admin dashboard if charts…
Browse files Browse the repository at this point in the history
… are collapsed
  • Loading branch information
DmitriyKulagin committed Mar 6, 2023
1 parent 682fba7 commit 64c980e
Show file tree
Hide file tree
Showing 11 changed files with 474 additions and 237 deletions.
43 changes: 43 additions & 0 deletions src/Presentation/Nop.Web/Areas/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Nop.Web.Areas.Admin.Factories;
using Nop.Web.Areas.Admin.Models.Common;
using Nop.Web.Areas.Admin.Models.Home;
using Nop.Web.Framework.Models.DataTables;

namespace Nop.Web.Areas.Admin.Controllers
{
Expand Down Expand Up @@ -100,6 +101,48 @@ public virtual async Task<IActionResult> NopCommerceNewsHideAdv()
return Content("Setting changed");
}

public virtual async Task<IActionResult> GetPopularSearchTerm()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PreparePopularSearchTermReportModelAsync(model);
return PartialView("Table", model);
}

public virtual async Task<IActionResult> GetBestsellersBriefReportByAmount()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PrepareBestsellersBriefReportByAmountModelAsync(model);
return PartialView("Table", model);
}

public virtual async Task<IActionResult> GetBestsellersBriefReportByQuantity()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PrepareBestsellersBriefReportByQuantityModelAsync(model);
return PartialView("Table", model);
}

public virtual async Task<IActionResult> GetLatestOrders()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PrepareLatestOrdersModelAsync(model);
return PartialView("Table", model);
}

public virtual async Task<IActionResult> GetOrderIncomplete()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PrepareOrderIncompleteModelAsync(model);
return PartialView("Table", model);
}

public virtual async Task<IActionResult> GetOrderAverage()
{
var model = new DataTablesModel();
model = await _homeModelFactory.PrepareOrderAverageModelAsync(model);
return PartialView("Table", model);
}

#endregion
}
}
303 changes: 299 additions & 4 deletions src/Presentation/Nop.Web/Areas/Admin/Factories/HomeModelFactory.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Nop.Web.Areas.Admin.Models.Home;
using Nop.Web.Framework.Models.DataTables;

namespace Nop.Web.Areas.Admin.Factories
{
Expand All @@ -18,6 +19,46 @@ public partial interface IHomeModelFactory
/// </returns>
Task<DashboardModel> PrepareDashboardModelAsync(DashboardModel model);

/// <summary>
/// Prepare popular search term report model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PreparePopularSearchTermReportModelAsync(DataTablesModel model);

/// <summary>
/// Prepare bestsellers brief by amount report model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PrepareBestsellersBriefReportByAmountModelAsync(DataTablesModel model);

/// <summary>
/// Prepare bestsellers brief by quantity report model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PrepareBestsellersBriefReportByQuantityModelAsync(DataTablesModel model);

/// <summary>
/// Prepare latest orders model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PrepareLatestOrdersModelAsync(DataTablesModel model);

/// <summary>
/// Prepare nopCommerce news model
/// </summary>
Expand All @@ -26,5 +67,25 @@ public partial interface IHomeModelFactory
/// The task result contains the nopCommerce news model
/// </returns>
Task<NopCommerceNewsModel> PrepareNopCommerceNewsModelAsync();

/// <summary>
/// Prepare incomplete orders report model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PrepareOrderIncompleteModelAsync(DataTablesModel model);

/// <summary>
/// Prepare order average report model
/// </summary>
/// <param name="model">DataTables model</param>
/// <returns>
/// A task that represents the asynchronous operation
/// The task result contains the dashboard model
/// </returns>
Task<DataTablesModel> PrepareOrderAverageModelAsync(DataTablesModel model);
}
}
17 changes: 0 additions & 17 deletions src/Presentation/Nop.Web/Areas/Admin/Models/Home/DashboardModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,10 @@ namespace Nop.Web.Areas.Admin.Models.Home
/// </summary>
public partial record DashboardModel : BaseNopModel
{
#region Ctor

public DashboardModel()
{
PopularSearchTerms = new PopularSearchTermSearchModel();
BestsellersByAmount = new BestsellerBriefSearchModel();
BestsellersByQuantity = new BestsellerBriefSearchModel();
}

#endregion

#region Properties

public bool IsLoggedInAsVendor { get; set; }

public PopularSearchTermSearchModel PopularSearchTerms { get; set; }

public BestsellerBriefSearchModel BestsellersByAmount { get; set; }

public BestsellerBriefSearchModel BestsellersByQuantity { get; set; }

#endregion
}
}
7 changes: 4 additions & 3 deletions src/Presentation/Nop.Web/Areas/Admin/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}

<link rel="stylesheet" href="~/lib_npm/ionicons/css/ionicons.min.css" />
<script src="~/js/admin.table.js" asp-location="Footer"></script>

<div class="content-header">
<h1>
Expand Down Expand Up @@ -101,7 +102,7 @@
<div class="col-md-4">
@if (canManageProducts)
{
@await Html.PartialAsync("_PopularSearchTermsReport", Model.PopularSearchTerms)
@await Html.PartialAsync("_PopularSearchTermsReport")
}
</div>
</div>
Expand All @@ -111,10 +112,10 @@
{
<div class="row">
<div class="col-md-6">
@await Html.PartialAsync("_BestsellersBriefReportByQuantity", Model.BestsellersByQuantity)
@await Html.PartialAsync("_BestsellersBriefReportByQuantity")
</div>
<div class="col-md-6">
@await Html.PartialAsync("_BestsellersBriefReportByAmount", Model.BestsellersByAmount)
@await Html.PartialAsync("_BestsellersBriefReportByAmount")
</div>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@model BestsellerBriefSearchModel
@using Nop.Services.Orders;
@using Nop.Services.Orders;

@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
Expand Down Expand Up @@ -30,45 +29,21 @@
</div>
<script>
$(document).ready(function () {
var collapsed = !$('#@cardId').hasClass('collapsed-card');
if (collapsed) {
$('#bestsellersBriefReportByAmount').load('@Url.Action("GetBestsellersBriefReportByAmount", "Home")');
}
$('#@cardId').on('click', 'button[data-card-widget="collapse"]', function () {
var collapsed = !$('#@cardId').hasClass('collapsed-card');
collapsed = !$('#@cardId').hasClass('collapsed-card');
saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hideCardAttributeName', collapsed);
if (!collapsed) {
$('#bestsellersBriefReportByAmount').load('@Url.Action("GetBestsellersBriefReportByAmount", "Home")');
}
});
});
</script>
<div class="card-body">
@await Html.PartialAsync("Table", new DataTablesModel
{
Name = "bestsellers-byamount-grid",
UrlRead = new DataUrl("BestsellersBriefReportByAmountList", "Order", new RouteValueDictionary { [nameof(Model.OrderBy)] = OrderByEnum.OrderByTotalAmount }),
Length = Model.PageSize,
Dom = "<'row'<'col-md-12't>>" +
"<'row margin-t-5'" +
"<'col-lg-10 col-xs-12'<'float-lg-left'p>>" +
"<'col-lg-2 col-xs-12'<'float-lg-right text-center'i>>" +
">",
ColumnCollection = new List<ColumnProperty>
{
new ColumnProperty(nameof(BestsellerModel.ProductName))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.Name").Text
},
new ColumnProperty(nameof(BestsellerModel.TotalQuantity))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalQuantity").Text
},
new ColumnProperty(nameof(BestsellerModel.TotalAmount))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalAmount").Text
},
new ColumnProperty(nameof(BestsellerModel.ProductId))
{
Title = T("Admin.Common.View").Text,
Width = "80",
ClassName = NopColumnClassDefaults.Button,
Render = new RenderButtonView(new DataUrl("~/Admin/Product/Edit/"))
}
}
})
<div id="bestsellersBriefReportByAmount"></div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@model BestsellerBriefSearchModel
@using Nop.Services.Orders;
@using Nop.Services.Orders;

@inject Nop.Services.Common.IGenericAttributeService genericAttributeService
@inject IWorkContext workContext
Expand Down Expand Up @@ -30,45 +29,21 @@
</div>
<script>
$(document).ready(function () {
var collapsed = !$('#@cardId').hasClass('collapsed-card');
if (collapsed) {
$('#bestsellersBriefReportByQuantity').load('@Url.Action("GetBestsellersBriefReportByQuantity", "Home")');
}
$('#@cardId').on('click', 'button[data-card-widget="collapse"]', function () {
var collapsed = !$('#@cardId').hasClass('collapsed-card');
saveUserPreferences('@(Url.Action("SavePreference", "Preferences"))', '@hideCardAttributeName', collapsed);
if (!collapsed) {
$('#bestsellersBriefReportByQuantity').load('@Url.Action("GetBestsellersBriefReportByQuantity", "Home")');
}
});
});
</script>
<div class="card-body">
@await Html.PartialAsync("Table", new DataTablesModel
{
Name = "bestsellers-byquantity-grid",
UrlRead = new DataUrl("BestsellersBriefReportByQuantityList", "Order", new RouteValueDictionary { [nameof(Model.OrderBy)] = OrderByEnum.OrderByQuantity }),
Length = Model.PageSize,
Dom = "<'row'<'col-md-12't>>" +
"<'row margin-t-5'" +
"<'col-lg-10 col-xs-12'<'float-lg-left'p>>" +
"<'col-lg-2 col-xs-12'<'float-lg-right text-center'i>>" +
">",
ColumnCollection = new List<ColumnProperty>
{
new ColumnProperty(nameof(BestsellerModel.ProductName))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.Name").Text
},
new ColumnProperty(nameof(BestsellerModel.TotalQuantity))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalQuantity").Text
},
new ColumnProperty(nameof(BestsellerModel.TotalAmount))
{
Title = T("Admin.Reports.Sales.Bestsellers.Fields.TotalAmount").Text
},
new ColumnProperty(nameof(BestsellerModel.ProductId))
{
Title = T("Admin.Common.View").Text,
Width = "80",
ClassName = NopColumnClassDefaults.Button,
Render = new RenderButtonView(new DataUrl("~/Admin/Product/Edit/"))
}
}
})
<div id="bestsellersBriefReportByQuantity"></div>
</div>
</div>
Loading

0 comments on commit 64c980e

Please sign in to comment.