Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Categorized tenants #10586

Merged
merged 16 commits into from
Feb 2, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace OrchardCore.Tenants.Controllers
{
public class AdminController : Controller
{
private static readonly string DefaultCategory = "All";
hishamco marked this conversation as resolved.
Show resolved Hide resolved

private readonly IShellHost _shellHost;
private readonly IShellSettingsManager _shellSettingsManager;
private readonly IEnumerable<DatabaseProvider> _databaseProviders;
Expand Down Expand Up @@ -98,6 +100,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 @@ -120,15 +123,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) && options?.Category != DefaultCategory)
hishamco marked this conversation as resolved.
Show resolved Hide resolved
{
entries = entries.Where(t => t.Category == options.Category).ToList();
hishamco marked this conversation as resolved.
Show resolved Hide resolved
}

switch (options.Status)
{
case TenantsFilter.Disabled:
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 @@ -153,7 +161,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 @@ -167,11 +176,19 @@ 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))
hishamco marked this conversation as resolved.
Show resolved Hide resolved
hishamco marked this conversation as resolved.
Show resolved Hide resolved
.ToList();

model.Options.TenantsCategories.Insert(0, new SelectListItem(S["All"], DefaultCategory, selected: true));
hishamco marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -192,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 @@ -335,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 @@ -384,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 @@ -441,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 Expand Up @@ -657,12 +678,12 @@ private void SetConfigurationShellValues(EditTenantViewModel model)

model.DatabaseConfigurationPreset = !string.IsNullOrEmpty(configurationShellConnectionString) || !string.IsNullOrEmpty(configurationDatabaseProvider);

if(!string.IsNullOrEmpty(configurationShellConnectionString))
if (!string.IsNullOrEmpty(configurationShellConnectionString))
{
model.ConnectionString = configurationShellConnectionString;
}

if(!string.IsNullOrEmpty(configurationDatabaseProvider))
if (!string.IsNullOrEmpty(configurationDatabaseProvider))
{
model.DatabaseProvider = configurationDatabaseProvider;
}
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 @@ -97,7 +97,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 @@ -116,6 +117,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