Feature: Job Queues
Also UI style, theme and element changes
This commit is contained in:
@@ -1,188 +0,0 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Data.Repository.Monitor;
|
||||
using Disco.Models.BI.Job;
|
||||
using Disco.Models.Repository;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Disco.BI.Extensions;
|
||||
using System.Reactive.Linq;
|
||||
using Disco.Services.Users;
|
||||
|
||||
namespace Disco.BI.JobBI
|
||||
{
|
||||
using FilterFunc = Func<IQueryable<Job>, IQueryable<Job>>;
|
||||
using SortFunc = Func<IEnumerable<Disco.Models.BI.Job.JobTableModel.JobTableItemModel>, IEnumerable<Disco.Models.BI.Job.JobTableModel.JobTableItemModel>>;
|
||||
using Disco.Services.Logging;
|
||||
|
||||
public class ManagedJobList : JobTableModel, IDisposable
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public FilterFunc FilterFunction { get; set; }
|
||||
public SortFunc SortFunction { get; set; }
|
||||
private IDisposable unsubscribeToken;
|
||||
private object updateLock = new object();
|
||||
|
||||
public override List<JobTableItemModel> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Items.PermissionsFiltered(UserService.CurrentAuthorization);
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new InvalidOperationException("Items cannot be manually set in a Managed Job List");
|
||||
}
|
||||
}
|
||||
|
||||
public ManagedJobList Initialize(DiscoDataContext Database)
|
||||
{
|
||||
// Can only Initialize once
|
||||
if (base.Items != null)
|
||||
return ReInitialize(Database);
|
||||
|
||||
lock (updateLock)
|
||||
{
|
||||
// Subscribe for Changes
|
||||
// - Job (or Job Meta) Changes
|
||||
// - Device Profile Address Changes (for multi-campus Schools)
|
||||
// - Device Model Description Changes
|
||||
// - Device's Profile or Model Changes
|
||||
unsubscribeToken = RepositoryMonitor.StreamAfterCommit
|
||||
.Where(n => n.EntityType == typeof(Job) ||
|
||||
n.EntityType == typeof(JobMetaWarranty) ||
|
||||
n.EntityType == typeof(JobMetaNonWarranty) ||
|
||||
n.EntityType == typeof(JobMetaInsurance) ||
|
||||
(n.EventType == RepositoryMonitorEventType.Modified && (
|
||||
(n.EntityType == typeof(DeviceProfile) && n.ModifiedProperties.Contains("DefaultOrganisationAddress")) ||
|
||||
(n.EntityType == typeof(DeviceModel) && n.ModifiedProperties.Contains("Description")) ||
|
||||
(n.EntityType == typeof(Device) && n.ModifiedProperties.Contains("DeviceProfileId") || n.ModifiedProperties.Contains("DeviceModelId"))
|
||||
)))
|
||||
.Subscribe(JobNotification, NotificationError);
|
||||
|
||||
// Initially fill table
|
||||
base.Items = this.SortFunction(this.DetermineItems(Database, this.FilterFunction(Database.Jobs))).ToList();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ManagedJobList ReInitialize(DiscoDataContext Database)
|
||||
{
|
||||
return ReInitialize(Database, null, null);
|
||||
}
|
||||
public ManagedJobList ReInitialize(DiscoDataContext Database, FilterFunc FilterFunction)
|
||||
{
|
||||
return ReInitialize(Database, FilterFunction, null);
|
||||
}
|
||||
public ManagedJobList ReInitialize(DiscoDataContext Database, FilterFunc FilterFunction, SortFunc SortFunction)
|
||||
{
|
||||
if (Database == null)
|
||||
throw new ArgumentNullException("Database");
|
||||
|
||||
lock (updateLock)
|
||||
{
|
||||
if (FilterFunction != null)
|
||||
this.FilterFunction = FilterFunction;
|
||||
if (SortFunction != null)
|
||||
this.SortFunction = SortFunction;
|
||||
|
||||
base.Items = this.SortFunction(this.DetermineItems(Database, this.FilterFunction(Database.Jobs))).ToList();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
private void NotificationError(Exception ex)
|
||||
{
|
||||
SystemLog.LogException(string.Format("Disco.BI.JobBI.ManagedJobList: [{0}]", this.Name), ex);
|
||||
}
|
||||
|
||||
private void JobNotification(RepositoryMonitorEvent e)
|
||||
{
|
||||
List<int> jobIds = null;
|
||||
JobTableItemModel[] existingItems = null;
|
||||
|
||||
if (e.EntityType == typeof(Job))
|
||||
jobIds = new List<int>() { ((Job)e.Entity).Id };
|
||||
else
|
||||
if (e.EntityType == typeof(JobMetaWarranty))
|
||||
jobIds = new List<int>() { ((JobMetaWarranty)e.Entity).JobId };
|
||||
else
|
||||
if (e.EntityType == typeof(JobMetaNonWarranty))
|
||||
jobIds = new List<int>() { ((JobMetaNonWarranty)e.Entity).JobId };
|
||||
else
|
||||
if (e.EntityType == typeof(JobMetaInsurance))
|
||||
jobIds = new List<int>() { ((JobMetaInsurance)e.Entity).JobId };
|
||||
else
|
||||
if (e.EntityType == typeof(DeviceProfile))
|
||||
{
|
||||
int deviceProfileId = ((DeviceProfile)e.Entity).Id;
|
||||
existingItems = base.Items.Where(i => i.DeviceProfileId == deviceProfileId).ToArray();
|
||||
}
|
||||
else
|
||||
if (e.EntityType == typeof(DeviceModel))
|
||||
{
|
||||
int deviceModelId = ((DeviceModel)e.Entity).Id;
|
||||
existingItems = base.Items.Where(i => i.DeviceModelId == deviceModelId).ToArray();
|
||||
}
|
||||
else
|
||||
if (e.EntityType == typeof(Device))
|
||||
{
|
||||
string deviceSerialNumber = ((Device)e.Entity).SerialNumber;
|
||||
existingItems = base.Items.Where(i => i.DeviceSerialNumber == deviceSerialNumber).ToArray();
|
||||
}
|
||||
else
|
||||
return; // Subscription should never reach
|
||||
|
||||
if (jobIds == null)
|
||||
{
|
||||
if (existingItems == null)
|
||||
throw new InvalidOperationException("Notification algorithm didn't indicate any Jobs for update");
|
||||
else
|
||||
jobIds = existingItems.Select(i => i.Id).ToList();
|
||||
}
|
||||
|
||||
if (jobIds.Count == 0)
|
||||
return;
|
||||
else
|
||||
UpdateJobs(e.Database, jobIds, existingItems);
|
||||
}
|
||||
|
||||
private void UpdateJobs(DiscoDataContext Database, List<int> jobIds, JobTableItemModel[] existingItems = null)
|
||||
{
|
||||
lock (updateLock)
|
||||
{
|
||||
// Check for existing items, if not handed them
|
||||
if (existingItems == null)
|
||||
existingItems = base.Items.Where(i => jobIds.Contains(i.Id)).ToArray();
|
||||
|
||||
var updatedItems = this.DetermineItems(Database, this.FilterFunction(Database.Jobs.Where(j => jobIds.Contains(j.Id))));
|
||||
|
||||
var refreshedList = base.Items.ToList();
|
||||
|
||||
// Remove Existing
|
||||
if (existingItems.Length > 0)
|
||||
foreach (var existingItem in existingItems)
|
||||
refreshedList.Remove(existingItem);
|
||||
|
||||
// Add Updated Items
|
||||
if (updatedItems.Count > 0)
|
||||
foreach (var updatedItem in updatedItems)
|
||||
refreshedList.Add(updatedItem);
|
||||
|
||||
// Reorder
|
||||
base.Items = this.SortFunction(refreshedList).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (unsubscribeToken != null)
|
||||
{
|
||||
unsubscribeToken.Dispose();
|
||||
unsubscribeToken = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Disco.Models.BI.Job;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Services.Jobs.JobLists;
|
||||
using Disco.Services;
|
||||
using System.Linq;
|
||||
|
||||
namespace Disco.BI.JobBI
|
||||
{
|
||||
|
||||
@@ -40,6 +40,34 @@ namespace Disco.BI.JobBI
|
||||
|
||||
Database.Jobs.Add(j);
|
||||
|
||||
// Job Queues
|
||||
var queues = from st in subTypes
|
||||
from jq in st.JobQueues
|
||||
group st by jq into g
|
||||
select new { queue = g.Key, subTypes = g };
|
||||
foreach (var queue in queues)
|
||||
{
|
||||
var commentBuilder = new StringBuilder("Automatically added by:");
|
||||
foreach (var subType in queue.subTypes)
|
||||
{
|
||||
commentBuilder.AppendLine();
|
||||
commentBuilder.Append(subType.Description);
|
||||
}
|
||||
|
||||
var jqj = new JobQueueJob()
|
||||
{
|
||||
JobQueueId = queue.queue.Id,
|
||||
Job = j,
|
||||
AddedDate = DateTime.Now,
|
||||
AddedUserId = initialTech.Id,
|
||||
AddedComment = commentBuilder.ToString(),
|
||||
SLAExpiresDate = queue.queue.DefaultSLAExpiry.HasValue ? (DateTime?)DateTime.Now.AddMinutes(queue.queue.DefaultSLAExpiry.Value) : null,
|
||||
Priority = JobQueuePriority.Normal
|
||||
};
|
||||
|
||||
Database.JobQueueJobs.Add(jqj);
|
||||
}
|
||||
|
||||
switch (type.Id)
|
||||
{
|
||||
case JobType.JobTypeIds.HWar:
|
||||
@@ -89,83 +117,5 @@ namespace Disco.BI.JobBI
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
public static string JobStatusDescription(string StatusId, Job j = null)
|
||||
{
|
||||
switch (StatusId)
|
||||
{
|
||||
case Job.JobStatusIds.Open:
|
||||
return "Open";
|
||||
case Job.JobStatusIds.Closed:
|
||||
return "Closed";
|
||||
case Job.JobStatusIds.AwaitingWarrantyRepair:
|
||||
if (j == null)
|
||||
return "Awaiting Warranty Repair";
|
||||
else
|
||||
if (j.DeviceHeld.HasValue)
|
||||
return string.Format("Awaiting Warranty Repair ({0})", j.JobMetaWarranty.ExternalName);
|
||||
else
|
||||
return string.Format("Awaiting Warranty Repair - Not Held ({0})", j.JobMetaWarranty.ExternalName);
|
||||
case Job.JobStatusIds.AwaitingRepairs:
|
||||
if (j == null)
|
||||
return "Awaiting Repairs";
|
||||
else
|
||||
if (j.DeviceHeld.HasValue)
|
||||
return string.Format("Awaiting Repairs ({0})", j.JobMetaNonWarranty.RepairerName);
|
||||
else
|
||||
return string.Format("Awaiting Repairs - Not Held ({0})", j.JobMetaNonWarranty.RepairerName);
|
||||
case Job.JobStatusIds.AwaitingDeviceReturn:
|
||||
return "Awaiting Device Return";
|
||||
case Job.JobStatusIds.AwaitingUserAction:
|
||||
return "Awaiting User Action";
|
||||
case Job.JobStatusIds.AwaitingAccountingPayment:
|
||||
return "Awaiting Accounting Payment";
|
||||
case Job.JobStatusIds.AwaitingAccountingCharge:
|
||||
return "Awaiting Accounting Charge";
|
||||
case Job.JobStatusIds.AwaitingInsuranceProcessing:
|
||||
return "Awaiting Insurance Processing";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
public static string JobStatusDescription(string StatusId, JobTableModel.JobTableItemModelIncludeStatus j = null)
|
||||
{
|
||||
switch (StatusId)
|
||||
{
|
||||
case Job.JobStatusIds.Open:
|
||||
return "Open";
|
||||
case Job.JobStatusIds.Closed:
|
||||
return "Closed";
|
||||
case Job.JobStatusIds.AwaitingWarrantyRepair:
|
||||
if (j == null)
|
||||
return "Awaiting Warranty Repair";
|
||||
else
|
||||
if (j.DeviceHeld.HasValue)
|
||||
return string.Format("Awaiting Warranty Repair ({0})", j.JobMetaWarranty_ExternalName);
|
||||
else
|
||||
return string.Format("Awaiting Warranty Repair - Not Held ({0})", j.JobMetaWarranty_ExternalName);
|
||||
case Job.JobStatusIds.AwaitingRepairs:
|
||||
if (j == null)
|
||||
return "Awaiting Repairs";
|
||||
else
|
||||
if (j.DeviceHeld.HasValue)
|
||||
return string.Format("Awaiting Repairs ({0})", j.JobMetaNonWarranty_RepairerName);
|
||||
else
|
||||
return string.Format("Awaiting Repairs - Not Held ({0})", j.JobMetaNonWarranty_RepairerName);
|
||||
case Job.JobStatusIds.AwaitingDeviceReturn:
|
||||
return "Awaiting Device Return";
|
||||
case Job.JobStatusIds.AwaitingUserAction:
|
||||
return "Awaiting User Action";
|
||||
case Job.JobStatusIds.AwaitingAccountingPayment:
|
||||
return "Awaiting Accounting Payment";
|
||||
case Job.JobStatusIds.AwaitingAccountingCharge:
|
||||
return "Awaiting Accounting Charge";
|
||||
case Job.JobStatusIds.AwaitingInsuranceProcessing:
|
||||
return "Awaiting Insurance Processing";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user