Skip to content

Commit

Permalink
Categorized tenants (#10586)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Feb 2, 2022
1 parent efcc35a commit d2a06fc
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public async Task<IActionResult> Index(TenantIndexOptions options, PagerParamete
{
var entry = new ShellSettingsEntry
{
Category = x["Category"],
Description = x["Description"],
Name = x.Name,
ShellSettings = x,
Expand All @@ -119,15 +120,20 @@ public async Task<IActionResult> 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;
}
Expand All @@ -152,7 +158,8 @@ public async Task<IActionResult> 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);

Expand All @@ -166,11 +173,22 @@ public async Task<IActionResult> 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<SelectListItem>() {
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<SelectListItem>() {
Expand All @@ -191,7 +209,8 @@ public async Task<IActionResult> 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 }
Expand Down Expand Up @@ -334,6 +353,7 @@ public async Task<IActionResult> 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;
Expand Down Expand Up @@ -383,6 +403,7 @@ public async Task<IActionResult> Edit(string id)

var model = new EditTenantViewModel
{
Category = shellSettings["Category"],
Description = shellSettings["Description"],
Name = shellSettings.Name,
RequestUrlHost = shellSettings.RequestUrlHost,
Expand Down Expand Up @@ -440,6 +461,7 @@ public async Task<IActionResult> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OrchardCore.Tenants.ViewModels
public class AdminIndexViewModel
{
public List<ShellSettingsEntry> ShellSettingsEntries { get; set; } = new List<ShellSettingsEntry>();

public TenantIndexOptions Options { get; set; } = new TenantIndexOptions();

[BindNever]
Expand All @@ -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; }
Expand All @@ -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<SelectListItem> TenantsCategories { get; set; }

[BindNever]
public List<SelectListItem> TenantsStates { get; set; }

Expand All @@ -59,7 +69,7 @@ public class TenantIndexOptions
public List<SelectListItem> TenantsBulkAction { get; set; }
}

public enum TenantsFilter
public enum TenantsState
{
All,
Running,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
<span asp-validation-for="Name" class="text-danger"></span>
<span class="hint">@T["The name of the tenant."]</span>
</div>
<div class="form-group col-md-6">
<label asp-for="Category">@T["Category"]</label>
<input asp-for="Category" class="form-control" />
<span class="hint">@T["The category of the tenant."]</span>
</div>
</div>
<div class="row">
<div class="form-group col-md-6" asp-validation-class-for="Description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<span class="hint">@T["The name of the tenant."]</span>
</div>

<div class="form-group">
<label asp-for="Category">@T["Category"]</label>
<input asp-for="Category" class="form-control" />
<span class="hint">@T["The category of the tenant."]</span>
</div>

<div class="form-group" asp-validation-class-for="Description">
<label asp-for="Description">@T["Description"]</label>
<input asp-for="Description" class="form-control" autofocus />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
</div>
<div class="form-group col mb-n1 filter">
<div class="btn-group float-right mt-1">
<select asp-for="Options.Filter" asp-items="@Model.Options.TenantsStates" class="selectpicker show-tick mr-2" data-header="@T["Filter by state"]" data-width="fit" data-selected-text-format="static" data-dropdown-align-right="true" title="@T["State"]" data-style="btn-sm"></select>
<select asp-for="Options.Category" asp-items="@Model.Options.TenantsCategories" class="selectpicker show-tick mr-2" data-header="@T["Filter by category"]" data-width="fit" data-selected-text-format="static" data-dropdown-align-right="true" title="@T["Category"]" data-style="btn-sm"></select>
<select asp-for="Options.Status" asp-items="@Model.Options.TenantsStates" class="selectpicker show-tick mr-2" data-header="@T["Filter by state"]" data-width="fit" data-selected-text-format="static" data-dropdown-align-right="true" title="@T["State"]" data-style="btn-sm"></select>
<select asp-for="Options.OrderBy" asp-items="@Model.Options.TenantsSorts" class="selectpicker show-tick" data-header="@T["Sort by"]" data-width="fit" data-selected-text-format="static" data-dropdown-align-right="true" title="@T["Sort"]" data-style="btn-sm"></select>
</div>
</div>
Expand All @@ -110,6 +111,10 @@
</div>
<div class="d-inline">
<a class="text-break" href="@GetEncodedUrl(entry, originalPathBase)">@entry.Name</a>
@if(!string.IsNullOrEmpty(entry.Category))
{
<span class="badge ta-badge font-weight-normal"><i class="fa fa-tag text-info" aria-hidden="true"></i> @entry.Category</span>
}
@if (!string.IsNullOrEmpty(entry.ShellSettings["DatabaseProvider"]))
{
<span class="badge ta-badge font-weight-normal"><i class="fa fa-database text-info" aria-hidden="true"></i> @entry.ShellSettings["DatabaseProvider"]</span>
Expand Down

0 comments on commit d2a06fc

Please sign in to comment.