Update #4: Import Location Lists
This commit is contained in:
@@ -2158,24 +2158,25 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
throw new InvalidOperationException("Unknown Location Mode Configured");
|
||||
}
|
||||
|
||||
var locationReferences = ManagedJobList.OpenJobsTable(j => j).Items.JobLocationReferences().ToDictionary(lr => lr.Location);
|
||||
var locationReferences = ManagedJobList.OpenJobsTable(j => j).Items.JobLocationReferences(locations);
|
||||
|
||||
var results = locations.Select(location =>
|
||||
var results = locationReferences.Select(locRef =>
|
||||
{
|
||||
JobLocationReference reference;
|
||||
string reference = null;
|
||||
|
||||
if (locationReferences.TryGetValue(location, out reference))
|
||||
if (locRef.References == null && locRef.References.Count > 0)
|
||||
{
|
||||
return new Models.Job.DeviceHeldLocationModel()
|
||||
{
|
||||
Location = location,
|
||||
References = (reference.References.Count == 1 ? string.Format("Job {0}", reference.References.First().JobId) : string.Format("{0} jobs", reference.References.Count))
|
||||
};
|
||||
if (locRef.References.Count == 1)
|
||||
reference = string.Format("Job {0}", locRef.References[0].JobId);
|
||||
else
|
||||
reference = string.Format("{0} jobs", locRef.References.Count);
|
||||
}
|
||||
else
|
||||
|
||||
return new Models.Job.DeviceHeldLocationModel()
|
||||
{
|
||||
return new Models.Job.DeviceHeldLocationModel() { Location = location };
|
||||
}
|
||||
Location = locRef.Location,
|
||||
References = reference
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return Json(results, JsonRequestBehavior.AllowGet);
|
||||
|
||||
@@ -50,7 +50,53 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[DiscoAuthorize(Claims.Config.JobPreferences.Configure)]
|
||||
public virtual ActionResult UpdateLocationList(string[] LocationList, bool redirect = false)
|
||||
{
|
||||
Database.DiscoConfiguration.JobPreferences.LocationList = LocationList.Where(i => !string.IsNullOrWhiteSpace(i)).Select(i => i.Trim()).OrderBy(i => i).ToList();
|
||||
var list = LocationList
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||
.Select(i => i.Trim())
|
||||
.Distinct(StringComparer.InvariantCultureIgnoreCase)
|
||||
.OrderBy(i => i);
|
||||
|
||||
Database.DiscoConfiguration.JobPreferences.LocationList = list.ToList();
|
||||
Database.SaveChanges();
|
||||
|
||||
if (redirect)
|
||||
return RedirectToAction(MVC.Config.JobPreferences.Index());
|
||||
else
|
||||
return Json("OK", JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Config.JobPreferences.Configure)]
|
||||
public virtual ActionResult ImportLocationList(string LocationList, bool AutomaticList = false, bool Override = false, bool redirect = false)
|
||||
{
|
||||
IEnumerable<string> list;
|
||||
|
||||
if (AutomaticList == true)
|
||||
{
|
||||
var jobDateThreshold = DateTime.Now.AddYears(-1);
|
||||
list = Database.Jobs
|
||||
.Where(j => (j.OpenedDate > jobDateThreshold || !j.ClosedDate.HasValue) && j.DeviceHeldLocation != null)
|
||||
.Select(j => j.DeviceHeldLocation).Distinct().ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
list = LocationList
|
||||
.Split(new string[] { Environment.NewLine, ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
if (!Override)
|
||||
{
|
||||
// Incorporate existing list
|
||||
list = list.Concat(Database.DiscoConfiguration.JobPreferences.LocationList);
|
||||
}
|
||||
|
||||
// Remove duplicates & Order
|
||||
list = list
|
||||
.Where(l => !string.IsNullOrWhiteSpace(l))
|
||||
.Select(l => l.Trim())
|
||||
.Distinct(StringComparer.InvariantCultureIgnoreCase)
|
||||
.OrderBy(i => i);
|
||||
|
||||
Database.DiscoConfiguration.JobPreferences.LocationList = list.ToList();
|
||||
Database.SaveChanges();
|
||||
|
||||
if (redirect)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="Config_Location_List">
|
||||
<a id="Config_Location_List_Button" href="#" class="button small">Update List</a>
|
||||
<a id="Config_Location_List_Button" href="#" class="button small">Update List</a> <a id="Config_Location_List_ImportButton" href="#" class="button small">Import List</a>
|
||||
<div id="Config_Location_List_Dialog" class="dialog" title="Locations">
|
||||
<div id="Config_Location_List_Dialog_ListContainer">
|
||||
<span id="Config_Location_List_Dialog_None" class="smallMessage">The List is Empty</span>
|
||||
@@ -38,6 +38,18 @@
|
||||
</div>
|
||||
<form id="Config_Location_List_Dialog_Form" action="@(Url.Action(MVC.API.JobPreferences.UpdateLocationList(null, redirect: true)))" method="post"></form>
|
||||
</div>
|
||||
<div id="Config_Location_ListImport_Dialog" class="dialog" title="Import Locations">
|
||||
<form id="Config_Location_ListImport_Dialog_Form" action="@(Url.Action(MVC.API.JobPreferences.ImportLocationList(null, redirect: true)))" method="post">
|
||||
<input type="hidden" id="Config_Location_ListImport_Dialog_AutomaticList" name="AutomaticList" value="False" />
|
||||
<div id="Config_Location_ListImport_Dialog_Overwrite_Container">
|
||||
<input type="checkbox" id="Config_Location_ListImport_Dialog_Overwrite" name="Override" value="True" /><label for="Config_Location_ListImport_Dialog_Overwrite">Override Existing List</label>
|
||||
</div>
|
||||
<textarea id="Config_Location_ListImport_Dialog_LocationList" name="LocationList"></textarea>
|
||||
<div style="padding: 0.7em 0.7em; margin-top: 10px;" class="ui-state-highlight ui-corner-all">
|
||||
<i class="fa fa-info-circle information"></i> Enter multiple locations separated by <code><new line></code>, commas (<code>,</code>) or semicolons (<code>;</code>).
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="Config_Location_Optional">
|
||||
<div style="padding: 0.7em 0.7em;" class="ui-state-highlight ui-corner-all">
|
||||
@@ -220,6 +232,43 @@
|
||||
dialog.dialog("disable");
|
||||
dialog.dialog("option", "buttons", null);
|
||||
}
|
||||
|
||||
// Import
|
||||
var dialogImport, formImport;
|
||||
|
||||
$('#Config_Location_List_ImportButton').click(showDialogImport);
|
||||
|
||||
function showDialogImport() {
|
||||
if (!dialogImport) {
|
||||
dialogImport = $('#Config_Location_ListImport_Dialog').dialog({
|
||||
resizable: false,
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
width: 350,
|
||||
height: 420,
|
||||
buttons: {
|
||||
"Build Automatic List": function () {
|
||||
$('#Config_Location_ListImport_Dialog_AutomaticList').val('True').closest('form').submit();
|
||||
dialogImport.dialog("disable");
|
||||
dialogImport.dialog("option", "buttons", null);
|
||||
},
|
||||
"Import List": function () {
|
||||
$('#Config_Location_ListImport_Dialog_LocationList').closest('form').submit();
|
||||
dialogImport.dialog("disable");
|
||||
dialogImport.dialog("option", "buttons", null);
|
||||
},
|
||||
Cancel: function () {
|
||||
dialogImport.dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dialogImport.dialog('open');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -148,7 +148,15 @@ WriteLiteral(" href=\"#\"");
|
||||
|
||||
WriteLiteral(" class=\"button small\"");
|
||||
|
||||
WriteLiteral(">Update List</a>\r\n <div");
|
||||
WriteLiteral(">Update List</a> <a");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_List_ImportButton\"");
|
||||
|
||||
WriteLiteral(" href=\"#\"");
|
||||
|
||||
WriteLiteral(" class=\"button small\"");
|
||||
|
||||
WriteLiteral(">Import List</a>\r\n <div");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_List_Dialog\"");
|
||||
|
||||
@@ -246,19 +254,93 @@ WriteLiteral(">Add</a>\r\n </div>\r\n
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_List_Dialog_Form\"");
|
||||
|
||||
WriteAttribute("action", Tuple.Create(" action=\"", 2359), Tuple.Create("\"", 2446)
|
||||
WriteAttribute("action", Tuple.Create(" action=\"", 2447), Tuple.Create("\"", 2534)
|
||||
|
||||
#line 39 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
, Tuple.Create(Tuple.Create("", 2368), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.JobPreferences.UpdateLocationList(null, redirect: true))
|
||||
, Tuple.Create(Tuple.Create("", 2456), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.JobPreferences.UpdateLocationList(null, redirect: true))
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
, 2368), false)
|
||||
, 2456), false)
|
||||
);
|
||||
|
||||
WriteLiteral(" method=\"post\"");
|
||||
|
||||
WriteLiteral("></form>\r\n </div>\r\n </div>\r\n");
|
||||
WriteLiteral("></form>\r\n </div>\r\n <div");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog\"");
|
||||
|
||||
WriteLiteral(" class=\"dialog\"");
|
||||
|
||||
WriteLiteral(" title=\"Import Locations\"");
|
||||
|
||||
WriteLiteral(">\r\n <form");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog_Form\"");
|
||||
|
||||
WriteAttribute("action", Tuple.Create(" action=\"", 2766), Tuple.Create("\"", 2853)
|
||||
|
||||
#line 42 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
, Tuple.Create(Tuple.Create("", 2775), Tuple.Create<System.Object, System.Int32>(Url.Action(MVC.API.JobPreferences.ImportLocationList(null, redirect: true))
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
, 2775), false)
|
||||
);
|
||||
|
||||
WriteLiteral(" method=\"post\"");
|
||||
|
||||
WriteLiteral(">\r\n <input");
|
||||
|
||||
WriteLiteral(" type=\"hidden\"");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog_AutomaticList\"");
|
||||
|
||||
WriteLiteral(" name=\"AutomaticList\"");
|
||||
|
||||
WriteLiteral(" value=\"False\"");
|
||||
|
||||
WriteLiteral(" />\r\n <div");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog_Overwrite_Container\"");
|
||||
|
||||
WriteLiteral(">\r\n <input");
|
||||
|
||||
WriteLiteral(" type=\"checkbox\"");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog_Overwrite\"");
|
||||
|
||||
WriteLiteral(" name=\"Override\"");
|
||||
|
||||
WriteLiteral(" value=\"True\"");
|
||||
|
||||
WriteLiteral(" /><label");
|
||||
|
||||
WriteLiteral(" for=\"Config_Location_ListImport_Dialog_Overwrite\"");
|
||||
|
||||
WriteLiteral(">Override Existing List</label>\r\n </div>\r\n " +
|
||||
" <textarea");
|
||||
|
||||
WriteLiteral(" id=\"Config_Location_ListImport_Dialog_LocationList\"");
|
||||
|
||||
WriteLiteral(" name=\"LocationList\"");
|
||||
|
||||
WriteLiteral("></textarea>\r\n <div");
|
||||
|
||||
WriteLiteral(" style=\"padding: 0.7em 0.7em; margin-top: 10px;\"");
|
||||
|
||||
WriteLiteral(" class=\"ui-state-highlight ui-corner-all\"");
|
||||
|
||||
WriteLiteral(">\r\n <i");
|
||||
|
||||
WriteLiteral(" class=\"fa fa-info-circle information\"");
|
||||
|
||||
WriteLiteral(@"></i> Enter multiple locations separated by <code><new line></code>, commas (<code>,</code>) or semicolons (<code>;</code>).
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
");
|
||||
|
||||
WriteLiteral(" <div");
|
||||
|
||||
@@ -304,7 +386,7 @@ WriteLiteral(">\r\n $(function () {\r\n
|
||||
" null,\r\n \'");
|
||||
|
||||
|
||||
#line 57 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
#line 69 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
Write(Url.Action(MVC.API.JobPreferences.UpdateLocationMode()));
|
||||
|
||||
|
||||
@@ -400,11 +482,35 @@ WriteLiteral("\',\r\n \'LocationMode\');\r\n\r\n
|
||||
"en\'\r\n }).val(location));\r\n\r\n " +
|
||||
" }).get();\r\n\r\n form.submit();\r\n\r\n " +
|
||||
" dialog.dialog(\"disable\");\r\n dialog.dial" +
|
||||
"og(\"option\", \"buttons\", null);\r\n }\r\n }" +
|
||||
");\r\n </script>\r\n");
|
||||
"og(\"option\", \"buttons\", null);\r\n }\r\n\r\n " +
|
||||
" // Import\r\n var dialogImport, formImport;\r\n\r\n " +
|
||||
" $(\'#Config_Location_List_ImportButton\').click(showDialogImport)" +
|
||||
";\r\n\r\n function showDialogImport() {\r\n " +
|
||||
" if (!dialogImport) {\r\n dialogImport = $(\'" +
|
||||
"#Config_Location_ListImport_Dialog\').dialog({\r\n " +
|
||||
" resizable: false,\r\n modal: true,\r\n " +
|
||||
" autoOpen: false,\r\n " +
|
||||
" width: 350,\r\n height: 420,\r\n " +
|
||||
" buttons: {\r\n \"Build " +
|
||||
"Automatic List\": function () {\r\n $(\'#" +
|
||||
"Config_Location_ListImport_Dialog_AutomaticList\').val(\'True\').closest(\'form\').su" +
|
||||
"bmit();\r\n dialogImport.dialog(\"disabl" +
|
||||
"e\");\r\n dialogImport.dialog(\"option\", " +
|
||||
"\"buttons\", null);\r\n },\r\n " +
|
||||
" \"Import List\": function () {\r\n " +
|
||||
" $(\'#Config_Location_ListImport_Dialog_LocationList\').closest(\'f" +
|
||||
"orm\').submit();\r\n dialogImport.dialog" +
|
||||
"(\"disable\");\r\n dialogImport.dialog(\"o" +
|
||||
"ption\", \"buttons\", null);\r\n },\r\n " +
|
||||
" Cancel: function () {\r\n " +
|
||||
" dialogImport.dialog(\"close\");\r\n " +
|
||||
" }\r\n }\r\n " +
|
||||
" });\r\n }\r\n\r\n dialogImpor" +
|
||||
"t.dialog(\'open\');\r\n\r\n return false;\r\n " +
|
||||
" }\r\n\r\n });\r\n </script>\r\n");
|
||||
|
||||
|
||||
#line 225 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
#line 274 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -413,14 +519,14 @@ WriteLiteral("\',\r\n \'LocationMode\');\r\n\r\n
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 228 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
#line 277 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
Write(Model.LocationModeOptions().First(o => o.Key == Model.LocationMode.ToString()).Value);
|
||||
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
#line 228 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
#line 277 "..\..\Areas\Config\Views\JobPreferences\Parts\Locations.cshtml"
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -988,6 +988,17 @@ div.logEventsViewport table.logEventsViewport > tbody > tr > td.eventType {
|
||||
#Config_Location_List_Dialog #Config_Location_List_Dialog_List li .remove:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
#Config_Location_ListImport_Dialog {
|
||||
display: none;
|
||||
}
|
||||
#Config_Location_ListImport_Dialog #Config_Location_ListImport_Dialog_Overwrite_Container {
|
||||
margin: 6px 0;
|
||||
}
|
||||
#Config_Location_ListImport_Dialog #Config_Location_ListImport_Dialog_LocationList {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#Config_JobQueues_Index i {
|
||||
width: 1.2857142857142858em;
|
||||
text-align: center;
|
||||
|
||||
@@ -1126,6 +1126,20 @@ div.logEventsViewport {
|
||||
}
|
||||
}
|
||||
|
||||
#Config_Location_ListImport_Dialog {
|
||||
display: none;
|
||||
|
||||
#Config_Location_ListImport_Dialog_Overwrite_Container {
|
||||
margin: 6px 0;
|
||||
}
|
||||
|
||||
#Config_Location_ListImport_Dialog_LocationList {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
#Config_JobQueues_Index {
|
||||
i {
|
||||
width: 1.2857142857142858em;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -7718,6 +7718,12 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
{
|
||||
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.UpdateLocationList);
|
||||
}
|
||||
[NonAction]
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
public virtual System.Web.Mvc.ActionResult ImportLocationList()
|
||||
{
|
||||
return new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.ImportLocationList);
|
||||
}
|
||||
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
public JobPreferencesController Actions { get { return MVC.API.JobPreferences; } }
|
||||
@@ -7738,6 +7744,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
public readonly string UpdateStaleJobMinutesThreshold = "UpdateStaleJobMinutesThreshold";
|
||||
public readonly string UpdateLocationMode = "UpdateLocationMode";
|
||||
public readonly string UpdateLocationList = "UpdateLocationList";
|
||||
public readonly string ImportLocationList = "ImportLocationList";
|
||||
}
|
||||
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
@@ -7747,6 +7754,7 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
public const string UpdateStaleJobMinutesThreshold = "UpdateStaleJobMinutesThreshold";
|
||||
public const string UpdateLocationMode = "UpdateLocationMode";
|
||||
public const string UpdateLocationList = "UpdateLocationList";
|
||||
public const string ImportLocationList = "ImportLocationList";
|
||||
}
|
||||
|
||||
|
||||
@@ -7786,6 +7794,17 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
public readonly string LocationList = "LocationList";
|
||||
public readonly string redirect = "redirect";
|
||||
}
|
||||
static readonly ActionParamsClass_ImportLocationList s_params_ImportLocationList = new ActionParamsClass_ImportLocationList();
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
public ActionParamsClass_ImportLocationList ImportLocationListParams { get { return s_params_ImportLocationList; } }
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
public class ActionParamsClass_ImportLocationList
|
||||
{
|
||||
public readonly string LocationList = "LocationList";
|
||||
public readonly string AutomaticList = "AutomaticList";
|
||||
public readonly string Override = "Override";
|
||||
public readonly string redirect = "redirect";
|
||||
}
|
||||
static readonly ViewsClass s_views = new ViewsClass();
|
||||
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
|
||||
public ViewsClass Views { get { return s_views; } }
|
||||
@@ -7849,6 +7868,19 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
return callInfo;
|
||||
}
|
||||
|
||||
partial void ImportLocationListOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, string LocationList, bool AutomaticList, bool Override, bool redirect);
|
||||
|
||||
public override System.Web.Mvc.ActionResult ImportLocationList(string LocationList, bool AutomaticList, bool Override, bool redirect)
|
||||
{
|
||||
var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.ImportLocationList);
|
||||
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "LocationList", LocationList);
|
||||
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "AutomaticList", AutomaticList);
|
||||
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "Override", Override);
|
||||
ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "redirect", redirect);
|
||||
ImportLocationListOverride(callInfo, LocationList, AutomaticList, Override, redirect);
|
||||
return callInfo;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user