Skip to content
Permalink
Browse files

Features bulk actions (#3528)

Fixes #1752
Fixes #2764
  • Loading branch information...
agriffard authored and sebastienros committed Apr 29, 2019
1 parent 5d61bc1 commit 47227488a5f21d7f1e3b2d62fb7d403173ea94c1
@@ -91,15 +91,14 @@ public async Task<ActionResult> Features()
}

[HttpPost, ActionName("Features")]
[FormValueRequired("submit.BulkExecute")]
public async Task<ActionResult> FeaturesPOST(FeaturesBulkAction bulkAction, IList<string> featureIds, bool? force)
public async Task<ActionResult> FeaturesPOST(BulkActionViewModel model, bool? force)
{
if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageFeatures))
{
return Unauthorized();
}

if (featureIds == null || !featureIds.Any())
if (model.FeatureIds == null || !model.FeatureIds.Any())
{
ModelState.AddModelError("featureIds", T["Please select one or more features."].ToString());
}
@@ -108,13 +107,13 @@ public async Task<ActionResult> FeaturesPOST(FeaturesBulkAction bulkAction, ILis
{
var availableFeatures = _extensionManager.GetFeatures();
var features = availableFeatures.Where(feature => FeatureIsAllowed(feature)).ToList();
var selectedFeatures = features.Where(x => featureIds.Contains(x.Id)).ToList();
var selectedFeatures = features.Where(x => model.FeatureIds.Contains(x.Id)).ToList();
var allEnabledFeatures = await _shellFeaturesManager.GetEnabledFeaturesAsync(); //features.Where(x => x.IsEnabled && featureIds.Contains(x.Id)).Select(x => x.Descriptor.Id).ToList();
var idFeaturesEnabled = allEnabledFeatures.Where(x => featureIds.Contains(x.Id)).ToList();
var idFeaturesEnabled = allEnabledFeatures.Where(x => model.FeatureIds.Contains(x.Id)).ToList();
var allDisabledFeatures = await _shellFeaturesManager.GetDisabledFeaturesAsync(); // DisabledFeaturesAsync //features.Where(x => !x.IsEnabled && featureIds.Contains(x.Id)).Select(x => x.Descriptor.Id).ToList();
var idFeaturesDisabled = allDisabledFeatures.Where(x => featureIds.Contains(x.Id)).ToList();
var idFeaturesDisabled = allDisabledFeatures.Where(x => model.FeatureIds.Contains(x.Id)).ToList();

switch (bulkAction)
switch (model.BulkAction)
{
case FeaturesBulkAction.None:
break;
@@ -149,24 +148,6 @@ public async Task<ActionResult> FeaturesPOST(FeaturesBulkAction bulkAction, ILis
_notifier.Success(T["{0} was disabled", featureName]);
}
break;
case FeaturesBulkAction.Update:
//var featuresThatNeedUpdate = _dataMigrationManager.GetFeaturesThatNeedUpdate();
//var selectedFeaturesThatNeedUpdate = selectedFeatures.Where(x => featuresThatNeedUpdate.Contains(x.Id));

//foreach (var feature in selectedFeaturesThatNeedUpdate)
//{
// var id = feature.Descriptor.Id;
// try
// {
// _dataMigrationManager.Update(id);
// _notifier.Success(T["The feature {0} was updated successfully", id]);
// }
// catch (Exception exception)
// {
// _notifier.Error(T["An error occurred while updating the feature {0}: {1}", id, exception.Message]);
// }
//}
break;
default:
throw new ArgumentOutOfRangeException();
}
@@ -12,12 +12,17 @@ public class FeaturesViewModel
public Func<IFeatureInfo, bool> IsAllowed { get; set; }
}

public class BulkActionViewModel
{
public FeaturesBulkAction BulkAction { get; set; }
public string[] FeatureIds { get; set; }
}

public enum FeaturesBulkAction
{
None,
Enable,
Disable,
Update,
Toggle
}
}
@@ -3,50 +3,40 @@
@model FeaturesViewModel

@{
//var lifecycleStatusClassDictionary = new Dictionary<LifecycleStatus, string> {
// { LifecycleStatus.Production, "fa-check" },
// { LifecycleStatus.Preview, "fa-info-circle" },
// { LifecycleStatus.Deprecated, "fa-exclamation-circle" }
//};
}
<h1>@RenderTitleSegments(T["Features"])</h1>

<nav class="admin-toolbar">
<div class="nav justify-content-end">
@*
<fieldset class="form-group">
@Html.Hidden("force", true)
@Html.Hidden("featureIds")
<input id="bulkActions" name="bulkAction" type="hidden" value="@FeaturesBulkAction.None" />
<button name="submit.BulkExecute" type="submit" class="hidden" value="yes">@T["Execute"]</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bolt"></i> @T["Bulk Actions"] <span class="caret"></span>
</button>&nbsp;
<ul class="dropdown-menu" role="menu">
<li><a href="#" data-bulk-action-confirm="@T["Are you sure you want to enable these items?"]" data-bulk-action="@FeaturesBulkAction.Enable">@T["Enable"]</a></li>
<li><a href="#" data-bulk-action-confirm="@T["Are you sure you want to disable these items? "]" data -bulk-action="@FeaturesBulkAction.Disable">@T["Disable"]</a></li>
<li><a href="#" data-bulk-action-confirm="@T["Are you sure you want to update these items? "]" data -bulk-action="@FeaturesBulkAction.Update">@T["Update"]</a></li>
<li><a href="#" data-bulk-action-confirm="@T["Are you sure you want to toggle these items? "]" data -bulk-action="@FeaturesBulkAction.Toggle">@T["Toggle"]</a></li>
</ul>
</div>
<select id="publishActions" name="bulkAction">
<option value="@FeaturesBulkAction.None">@T["Choose action..."]</option>
<option value="@FeaturesBulkAction.Enable">@T["Enable"]</option>
<option value="@FeaturesBulkAction.Disable">@T["Disable"]</option>
<option value="@FeaturesBulkAction.Toggle">@T["Toggle"]</option>
</select>
<button type="submit" name="submit.BulkExecute" value="yes" class="btn-primary">@T["Execute"]</button>
</fieldset>
*@

<form class="form-inline float-right" autocomplete="off" method="get">
<input id="search-box" class="form-control" type="text" placeholder="@T["Search"]" autofocus="autofocus">
</form>
</div>
</nav>
<fieldset class="admin-toolbar container-fluid">
<form asp-action="Index" method="get">
<div class="row">
<div class="col-md-1 col-xl-1 form-group">
<label for="filterResults" class="label col-form-label">@T["Filter:"]</label>
</div>
<div class="col-md-3 col-xl-2 form-group">
<input id="search-box" class="form-control" type="text" placeholder="@T["Search"]" autofocus="autofocus">
</div>
</div>
</form>
</fieldset>

<form asp-action="Features">
<form asp-action="Features" method="post">
<fieldset class="admin-toolbar container-fluid">
<div class="row">
<div class="col-md-2 col-xl-1 form-group">
<label for="bulkAction" class="label col-form-label">@T["Actions:"]</label>
</div>
<div class="col-md-3 col-xl-2 form-group">
<select class="form-control" name="bulkAction">
<option value="@FeaturesBulkAction.Enable.ToString()">@T["Enable"]</option>
<option value="@FeaturesBulkAction.Disable.ToString()">@T["Disable"]</option>
<option value="@FeaturesBulkAction.Toggle.ToString()">@T["Toggle"]</option>
</select>
</div>
<div class="col-md-2 col-xl-1 form-group">
<button type="submit" class="btn btn-secondary">@T["Apply"]</button>
</div>
</div>
</fieldset>
@{
var featureGroups = Model.Features.GroupBy(f => f.Descriptor.Category).ToList(); //.OrderBy(f => f.Descriptor.Category, new DoghouseComparer("Core"))
foreach (var featureGroup in featureGroups)

0 comments on commit 4722748

Please sign in to comment.
You can’t perform that action at this time.