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)
|
||||
|
||||
Reference in New Issue
Block a user