feature: user details are individually exported; shared export field renderer

This commit is contained in:
Gary Sharp
2025-02-26 13:23:24 +11:00
parent 539503133a
commit a9687b5f25
65 changed files with 1559 additions and 2743 deletions
@@ -4,10 +4,6 @@
Authorization.RequireAny(Claims.Config.UserFlag.Export);
ViewBag.Title = Html.ToBreadcrumb("Configuration", MVC.Config.Config.Index(), "User Flags", MVC.Config.UserFlag.Index(null), "Export");
var optionsMetadata = ModelMetadata.FromLambdaExpression(m => m.Options, ViewData);
var optionGroups = optionsMetadata.Properties.Where(p => p.ShortDisplayName != null && p.ModelType == typeof(bool) && p.PropertyName != "CurrentOnly")
.GroupBy(m => m.ShortDisplayName);
}
<div id="UserFlag_Export">
@using (Html.BeginForm(MVC.API.UserFlag.Export(), FormMethod.Post, new { @data_saveaction = Url.Action(MVC.API.UserFlag.SaveExport()) }))
@@ -48,89 +44,21 @@
</tr>
</table>
</div>
<div id="UserFlag_Export_Fields" class="form" style="width: 570px; margin-top: 15px;">
<h2>Export Fields <a id="UserFlag_Export_Fields_Defaults" href="#">(Defaults)</a></h2>
<table>
@foreach (var optionGroup in optionGroups)
{
var optionFields = optionGroup.ToList();
var itemsPerColumn = (int)Math.Ceiling((double)optionFields.Count / 2);
<tr>
<th style="width: 120px;">
@optionGroup.Key
@if (optionFields.Count > 2)
{
<span style="display: block;" class="select"><a class="selectAll" href="#">ALL</a> | <a class="selectNone" href="#">NONE</a></span>
}
</th>
<td>
<div class="UserFlag_Export_Fields_Group">
<table class="none">
<tr>
<td style="width: 50%">
<ul class="none">
@foreach (var optionItem in optionFields.Take(itemsPerColumn))
{
<li title="@optionItem.Description">
<input type="checkbox" id="Options_@optionItem.PropertyName" name="Options.@optionItem.PropertyName" value="true" @(((bool)optionItem.Model) ? "checked " : null) /><label for="Options_@optionItem.PropertyName">@optionItem.DisplayName</label>
</li>
}
</ul>
</td>
<td style="width: 50%">
<ul class="none">
@foreach (var optionItem in optionFields.Skip(itemsPerColumn))
{
<li title="@optionItem.Description">
<input type="checkbox" id="Options_@optionItem.PropertyName" name="Options.@optionItem.PropertyName" value="true" @(((bool)optionItem.Model) ? "checked " : null) /><label for="Options_@optionItem.PropertyName">@optionItem.DisplayName</label>
</li>
}
</ul>
</td>
</tr>
</table>
</div>
</td>
</tr>
}
</table>
</div>
@Html.Partial(MVC.Shared.Views._ExportFields, Model.Fields.FieldGroups)
<script>
$(function () {
var exportDefaultFields = ['Name', 'AddedDate', 'UserId', 'UserDisplayName', 'Comments'];
var $exportFields = $('#UserFlag_Export_Fields');
var $exportScope = $('#UserFlag_Export_Scope');
var $form = $exportScope.closest('form');
var $exportingDialog = null;
const $exportFields = $('#Export_Fields');
const $form = $exportFields.closest('form');
let $exportingDialog = null;
$exportFields.on('click', 'a.selectAll,a.selectNone', function () {
var $this = $(this);
$this.closest('tr').find('input').prop('checked', $this.is('.selectAll'));
return false;
});
$('#UserFlag_Export_Fields_Defaults').click(function () {
$exportFields.find('input').prop('checked', false);
$.each(exportDefaultFields, function (index, value) {
$('#Options_' + value).prop('checked', true);
});
return false;
});
// Submit Validation
function submitHandler() {
var exportFieldCount = $exportFields.find('input:checked').length;
$.validator.unobtrusive.parse($form);
$form.data("validator").settings.submitHandler = function () {
const exportFieldCount = $exportFields.find('input:checked').length;
if (exportFieldCount > 0) {
if ($exportingDialog == null) {
$exportingDialog = $('#UserFlag_Export_Exporting').dialog({
$exportingDialog = $('#Export_Exporting').dialog({
width: 400,
height: 164,
resizable: false,
@@ -141,24 +69,16 @@
$exportingDialog.dialog('open');
$form[0].submit();
return;
}
else
alert('Select at least one field to export.');
}
$.validator.unobtrusive.parse($form);
$form.data("validator").settings.submitHandler = submitHandler;
$('#UserFlag_Export_Download_Dialog').dialog({
width: 400,
height: 164,
resizable: false,
modal: true,
autoOpen: true
});
$('#UserFlag_Export_Button').click(function () {
alert('Select at least one field to export.');
};
$('#UserFlag_Export_Button').on('click', function () {
$form.submit();
});
$('#UserFlag_Export_Save_Button').click(function () {
$('#UserFlag_Export_Save_Button').on('click', function () {
$form.attr('action', $form[0].dataset.saveaction);
$form.submit();
});
@@ -168,7 +88,7 @@
</div>
@if (Model.ExportId.HasValue)
{
<div id="UserFlag_Export_Download_Dialog" class="dialog" title="Export User Flags">
<div id="Export_Download_Dialog" class="dialog" title="Export User Flags">
@if (Model.ExportResult.RecordCount == 0)
{
<h4>No records matched the filter criteria</h4>
@@ -181,7 +101,7 @@
</div>
<script>
$(function () {
$('#UserFlag_Export_Download_Dialog')
$('#Export_Download_Dialog')
.dialog({
width: 400,
height: 164,
@@ -192,7 +112,7 @@
});
</script>
}
<div id="UserFlag_Export_Exporting" class="dialog" title="Exporting User Flags...">
<div id="Export_Exporting" class="dialog" title="Exporting User Flags...">
<h4><i class="fa fa-lg fa-cog fa-spin" title="Please Wait"></i>Exporting user flags...</h4>
</div>
<div class="actionBar">