From 36e3eeecaac184bc3dbea4a4fd3709277372dd29 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Sun, 19 Jul 2020 14:22:26 -0700 Subject: [PATCH 1/2] Allow sorting apps by store, name or app type close #1568 --- BTCPayServer/Controllers/AppsController.cs | 35 ++++++++++++++++- BTCPayServer/Views/Apps/ListApps.cshtml | 45 ++++++++++++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/BTCPayServer/Controllers/AppsController.cs b/BTCPayServer/Controllers/AppsController.cs index 45496f7ee..ef756f1b1 100644 --- a/BTCPayServer/Controllers/AppsController.cs +++ b/BTCPayServer/Controllers/AppsController.cs @@ -47,9 +47,42 @@ namespace BTCPayServer.Controllers public string CreatedAppId { get; set; } - public async Task ListApps() + public async Task ListApps( + string sortOrder = null, + string sortOrderColumn = null + ) { var apps = await _AppService.GetAllApps(GetUserId()); + + if (sortOrder != null && sortOrderColumn != null) + { + apps = apps.OrderByDescending(app => + { + switch (sortOrderColumn) + { + case "Name": + return app.AppName; + case "Store": + return app.StoreName; + case "AppType": + return app.AppType; + default: + return app.Id; + } + }).ToArray(); + + switch (sortOrder) + { + case "desc": + ViewData[$"{sortOrderColumn}SortOrder"] = "asc"; + break; + case "asc": + apps = apps.Reverse().ToArray(); + ViewData[$"{sortOrderColumn}SortOrder"] = "desc"; + break; + } + } + return View(new ListAppsViewModel() { Apps = apps diff --git a/BTCPayServer/Views/Apps/ListApps.cshtml b/BTCPayServer/Views/Apps/ListApps.cshtml index a218a312b..51babba39 100644 --- a/BTCPayServer/Views/Apps/ListApps.cshtml +++ b/BTCPayServer/Views/Apps/ListApps.cshtml @@ -31,9 +31,48 @@ - - - + + + From 25527ec1dd99712d438353c4cb9cc9684514f24e Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Mon, 20 Jul 2020 20:02:14 -0700 Subject: [PATCH 2/2] Use nameof() instead of strings --- BTCPayServer/Controllers/AppsController.cs | 6 +++--- BTCPayServer/Views/Apps/ListApps.cshtml | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/BTCPayServer/Controllers/AppsController.cs b/BTCPayServer/Controllers/AppsController.cs index ef756f1b1..3a788e384 100644 --- a/BTCPayServer/Controllers/AppsController.cs +++ b/BTCPayServer/Controllers/AppsController.cs @@ -60,11 +60,11 @@ namespace BTCPayServer.Controllers { switch (sortOrderColumn) { - case "Name": + case nameof(app.AppName): return app.AppName; - case "Store": + case nameof(app.StoreName): return app.StoreName; - case "AppType": + case nameof(app.AppType): return app.AppType; default: return app.Id; diff --git a/BTCPayServer/Views/Apps/ListApps.cshtml b/BTCPayServer/Views/Apps/ListApps.cshtml index 51babba39..4d296f6e6 100644 --- a/BTCPayServer/Views/Apps/ListApps.cshtml +++ b/BTCPayServer/Views/Apps/ListApps.cshtml @@ -34,28 +34,28 @@
StoreNameApp type + + Store @if (ViewData["StoreSortOrder"] != null) + { + + } + + + + Name @if (ViewData["NameSortOrder"] != null) + { + + } + + + + App Type @if (ViewData["AppTypeSortOrder"] != null) + { + + } + + Actions
- Store @if (ViewData["StoreSortOrder"] != null) + Store @if (ViewData["StoreNameSortOrder"] != null) { - + } - Name @if (ViewData["NameSortOrder"] != null) + Name @if (ViewData["AppNameSortOrder"] != null) { - + }