From 36e3eeecaac184bc3dbea4a4fd3709277372dd29 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Sun, 19 Jul 2020 14:22:26 -0700 Subject: [PATCH] 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 @@ - - - + + +
StoreNameApp type + + Store @if (ViewData["StoreSortOrder"] != null) + { + + } + + + + Name @if (ViewData["NameSortOrder"] != null) + { + + } + + + + App Type @if (ViewData["AppTypeSortOrder"] != null) + { + + } + + Actions