From d2a06fcdadcf0557b3a11fb55c8428ef389015a1 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Wed, 2 Feb 2022 18:11:05 +0300 Subject: [PATCH] Categorized tenants (#10586) --- .../Controllers/AdminController.cs | 42 ++++++++++++++----- .../ViewModels/AdminIndexViewModel.cs | 14 ++++++- .../ViewModels/EditTenantViewModel.cs | 2 + .../Views/Admin/Create.cshtml | 5 +++ .../Views/Admin/Edit.cshtml | 6 +++ .../Views/Admin/Index.cshtml | 7 +++- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs index fa24104de9f..2ac0cd583f8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/AdminController.cs @@ -97,6 +97,7 @@ public async Task Index(TenantIndexOptions options, PagerParamete { var entry = new ShellSettingsEntry { + Category = x["Category"], Description = x["Description"], Name = x.Name, ShellSettings = x, @@ -119,15 +120,20 @@ public async Task Index(TenantIndexOptions options, PagerParamete (t.ShellSettings.RequestUrlPrefix != null && t.ShellSettings.RequestUrlPrefix.IndexOf(options.Search, StringComparison.OrdinalIgnoreCase) > -1)))).ToList(); } - switch (options.Filter) + if (!String.IsNullOrWhiteSpace(options.Category)) { - case TenantsFilter.Disabled: + entries = entries.Where(t => t.Category.Equals(options.Category, StringComparison.OrdinalIgnoreCase)).ToList(); + } + + switch (options.Status) + { + case TenantsState.Disabled: entries = entries.Where(t => t.ShellSettings.State == TenantState.Disabled).ToList(); break; - case TenantsFilter.Running: + case TenantsState.Running: entries = entries.Where(t => t.ShellSettings.State == TenantState.Running).ToList(); break; - case TenantsFilter.Uninitialized: + case TenantsState.Uninitialized: entries = entries.Where(t => t.ShellSettings.State == TenantState.Uninitialized).ToList(); break; } @@ -152,7 +158,8 @@ public async Task Index(TenantIndexOptions options, PagerParamete // Maintain previous route data when generating page links var routeData = new RouteData(); - routeData.Values.Add("Options.Filter", options.Filter); + routeData.Values.Add("Options.Category", options.Category); + routeData.Values.Add("Options.Status", options.Status); routeData.Values.Add("Options.Search", options.Search); routeData.Values.Add("Options.OrderBy", options.OrderBy); @@ -166,11 +173,22 @@ public async Task Index(TenantIndexOptions options, PagerParamete }; // We populate the SelectLists + model.Options.TenantsCategories = allSettings + .GroupBy(t => t["Category"]) + .Where(t => !String.IsNullOrEmpty(t.Key)) + .Select(t => new SelectListItem(t.Key, t.Key, String.Equals(options.Category, t.Key, StringComparison.OrdinalIgnoreCase))) + .ToList(); + + model.Options.TenantsCategories.Insert(0, new SelectListItem( + S["All"], + String.Empty, + selected: String.IsNullOrEmpty(options.Category))); + model.Options.TenantsStates = new List() { - new SelectListItem() { Text = S["All states"], Value = nameof(TenantsFilter.All) }, - new SelectListItem() { Text = S["Running"], Value = nameof(TenantsFilter.Running) }, - new SelectListItem() { Text = S["Disabled"], Value = nameof(TenantsFilter.Disabled) }, - new SelectListItem() { Text = S["Uninitialized"], Value = nameof(TenantsFilter.Uninitialized) } + new SelectListItem() { Text = S["All states"], Value = nameof(TenantsState.All) }, + new SelectListItem() { Text = S["Running"], Value = nameof(TenantsState.Running) }, + new SelectListItem() { Text = S["Disabled"], Value = nameof(TenantsState.Disabled) }, + new SelectListItem() { Text = S["Uninitialized"], Value = nameof(TenantsState.Uninitialized) } }; model.Options.TenantsSorts = new List() { @@ -191,7 +209,8 @@ public async Task Index(TenantIndexOptions options, PagerParamete public ActionResult IndexFilterPOST(AdminIndexViewModel model) { return RedirectToAction("Index", new RouteValueDictionary { - { "Options.Filter", model.Options.Filter }, + { "Options.Category", model.Options.Category }, + { "Options.Status", model.Options.Status }, { "Options.OrderBy", model.Options.OrderBy }, { "Options.Search", model.Options.Search }, { "Options.TenantsStates", model.Options.TenantsStates } @@ -334,6 +353,7 @@ public async Task Create(EditTenantViewModel model) shellSettings.State = TenantState.Uninitialized; SetConfigurationShellValues(model); + shellSettings["Category"] = model.Category; shellSettings["Description"] = model.Description; shellSettings["ConnectionString"] = model.ConnectionString; shellSettings["TablePrefix"] = model.TablePrefix; @@ -383,6 +403,7 @@ public async Task Edit(string id) var model = new EditTenantViewModel { + Category = shellSettings["Category"], Description = shellSettings["Description"], Name = shellSettings.Name, RequestUrlHost = shellSettings.RequestUrlHost, @@ -440,6 +461,7 @@ public async Task Edit(EditTenantViewModel model) if (ModelState.IsValid) { shellSettings["Description"] = model.Description; + shellSettings["Category"] = model.Category; shellSettings.RequestUrlPrefix = model.RequestUrlPrefix; shellSettings.RequestUrlHost = model.RequestUrlHost; shellSettings["FeatureProfile"] = model.FeatureProfile; diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/AdminIndexViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/AdminIndexViewModel.cs index 6084d0600ee..3555c5a848b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/AdminIndexViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/AdminIndexViewModel.cs @@ -8,6 +8,7 @@ namespace OrchardCore.Tenants.ViewModels public class AdminIndexViewModel { public List ShellSettingsEntries { get; set; } = new List(); + public TenantIndexOptions Options { get; set; } = new TenantIndexOptions(); [BindNever] @@ -28,6 +29,8 @@ public enum BulkAction public class ShellSettingsEntry { + public string Category { get; set; } + public string Description { get; set; } public bool Selected { get; set; } @@ -45,10 +48,17 @@ public class ShellSettingsEntry public class TenantIndexOptions { public string Search { get; set; } - public TenantsFilter Filter { get; set; } + + public string Category { get; set; } + + public TenantsState Status { get; set; } + public TenantsBulkAction BulkAction { get; set; } + public TenantsOrder OrderBy { get; set; } + public List TenantsCategories { get; set; } + [BindNever] public List TenantsStates { get; set; } @@ -59,7 +69,7 @@ public class TenantIndexOptions public List TenantsBulkAction { get; set; } } - public enum TenantsFilter + public enum TenantsState { All, Running, diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/EditTenantViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/EditTenantViewModel.cs index fb0b813aca1..5d9e0d41c5d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/EditTenantViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/EditTenantViewModel.cs @@ -6,6 +6,8 @@ namespace OrchardCore.Tenants.ViewModels { public class EditTenantViewModel { + public string Category { get; set; } + public string Description { get; set; } public string Name { get; set; } diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Create.cshtml b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Create.cshtml index 9890a17d3a9..4b5a21efa75 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Create.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Create.cshtml @@ -12,6 +12,11 @@ @T["The name of the tenant."] +
+ + + @T["The category of the tenant."] +
diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Edit.cshtml index 2beddc86469..964f7ccd8ab 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Edit.cshtml @@ -13,6 +13,12 @@ @T["The name of the tenant."]
+
+ + + @T["The category of the tenant."] +
+
diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Index.cshtml b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Index.cshtml index 9366ab19d45..aa60b35e6fa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Index.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Views/Admin/Index.cshtml @@ -91,7 +91,8 @@
- + +
@@ -110,6 +111,10 @@
@entry.Name + @if(!string.IsNullOrEmpty(entry.Category)) + { + @entry.Category + } @if (!string.IsNullOrEmpty(entry.ShellSettings["DatabaseProvider"])) { @entry.ShellSettings["DatabaseProvider"]