Feature #37: Stale Jobs

Stale Jobs replaces Long-Running Jobs on the homepage. Last Activity is
added to the job table.
This commit is contained in:
Gary Sharp
2014-02-13 22:17:49 +11:00
parent 2ac3a9bdd3
commit 68256d7abd
30 changed files with 881 additions and 330 deletions
+9 -1
View File
@@ -89,6 +89,7 @@ namespace Disco.Services.Authorization
{ "Job.Lists.MyJobs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.MyJobs, (c, v) => c.Job.Lists.MyJobs = v, "My Jobs List", "Can show list", false) },
{ "Job.Lists.MyJobsOrphaned", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.MyJobsOrphaned, (c, v) => c.Job.Lists.MyJobsOrphaned = v, "My Jobs List (Includes No Queue)", "Can show list", false) },
{ "Job.Lists.RecentlyClosed", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.RecentlyClosed, (c, v) => c.Job.Lists.RecentlyClosed = v, "Recently Closed List", "Can show list", false) },
{ "Job.Lists.StaleJobs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Lists.StaleJobs, (c, v) => c.Job.Lists.StaleJobs = v, "Stale Jobs List", "Can show list", false) },
{ "Job.Actions.AddAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.AddAttachments, (c, v) => c.Job.Actions.AddAttachments = v, "Add Attachments", "Can add attachments to jobs", false) },
{ "Job.Actions.AddLogs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.AddLogs, (c, v) => c.Job.Actions.AddLogs = v, "Add Logs", "Can add job logs", false) },
{ "Job.Actions.AddAnyQueues", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.AddAnyQueues, (c, v) => c.Job.Actions.AddAnyQueues = v, "Add to Any Queues", "Can add to any job queues", false) },
@@ -373,7 +374,8 @@ namespace Disco.Services.Authorization
new ClaimNavigatorItem("Job.Lists.LongRunningJobs", false),
new ClaimNavigatorItem("Job.Lists.MyJobs", false),
new ClaimNavigatorItem("Job.Lists.MyJobsOrphaned", false),
new ClaimNavigatorItem("Job.Lists.RecentlyClosed", false)
new ClaimNavigatorItem("Job.Lists.RecentlyClosed", false),
new ClaimNavigatorItem("Job.Lists.StaleJobs", false)
}),
new ClaimNavigatorItem("Job.Types", "Types", "Permissions related to Job Types", false, new List<IClaimNavigatorItem>() {
new ClaimNavigatorItem("Job.Types.CreateHMisc", false),
@@ -579,6 +581,7 @@ namespace Disco.Services.Authorization
c.Job.Lists.MyJobs = true;
c.Job.Lists.MyJobsOrphaned = true;
c.Job.Lists.RecentlyClosed = true;
c.Job.Lists.StaleJobs = true;
c.Job.Actions.AddAttachments = true;
c.Job.Actions.AddLogs = true;
c.Job.Actions.AddAnyQueues = true;
@@ -1137,6 +1140,11 @@ namespace Disco.Services.Authorization
/// <para>Can show list</para>
/// </summary>
public const string RecentlyClosed = "Job.Lists.RecentlyClosed";
/// <summary>Stale Jobs List
/// <para>Can show list</para>
/// </summary>
public const string StaleJobs = "Job.Lists.StaleJobs";
}
/// <summary>Actions
@@ -21,6 +21,8 @@ namespace Disco.Services.Authorization.Roles.ClaimGroups.Job
public bool AwaitingTechnicianAction { get; set; }
[ClaimDetails("Long Running Jobs List", "Can show list")]
public bool LongRunningJobs { get; set; }
[ClaimDetails("Stale Jobs List", "Can show list")]
public bool StaleJobs { get; set; }
[ClaimDetails("All Open List", "Can show list")]
public bool AllOpen { get; set; }
@@ -26,6 +26,7 @@ namespace Disco.Services
ShowTechnician = Model.ShowTechnician,
ShowLocation = Model.ShowLocation,
ShowStatus = Model.ShowStatus,
ShowLastActivityDate = Model.ShowLastActivityDate,
IsSmallTable = Model.IsSmallTable,
HideClosedJobs = Model.HideClosedJobs,
EnablePaging = Model.EnablePaging,
@@ -115,7 +116,7 @@ namespace Disco.Services
if (FilterAuthorization)
Jobs = model.FilterPermissions(Jobs, UserService.CurrentAuthorization);
if (model.ShowStatus)
if (model.ShowStatus || model.ShowLastActivityDate)
{
var jobItems = Jobs.Select(j => new JobTableStatusItemModel()
@@ -147,6 +148,12 @@ namespace Disco.Services
JobMetaNonWarranty_AccountingChargeRequiredDate = j.JobMetaNonWarranty.AccountingChargeRequiredDate,
JobMetaNonWarranty_IsInsuranceClaim = j.JobMetaNonWarranty.IsInsuranceClaim,
JobMetaInsurance_ClaimFormSentDate = j.JobMetaInsurance.ClaimFormSentDate,
JobMetaNonWarranty_InvoiceReceivedDate = j.JobMetaNonWarranty.InvoiceReceivedDate,
JobMetaNonWarranty_PurchaseOrderRaisedDate = j.JobMetaNonWarranty.PurchaseOrderRaisedDate,
JobMetaNonWarranty_PurchaseOrderSentDate = j.JobMetaNonWarranty.PurchaseOrderSentDate,
RecentAttachmentDate = j.JobAttachments.Max(ja => ja.Timestamp),
RecentLogDate = j.JobLogs.Max(jl => jl.Timestamp),
WaitingForUserAction = j.WaitingForUserAction,
DeviceReadyForReturn = j.DeviceReadyForReturn,
@@ -170,6 +177,31 @@ namespace Disco.Services
j.StatusId = j.CalculateStatusId();
j.StatusDescription = JobExtensions.JobStatusDescription(j.StatusId, j);
var activityDates = new DateTime?[] {
j.ActiveJobQueues.Max<JobTableStatusQueueItemModel, DateTime?>(jq => jq.AddedDate),
j.ClosedDate,
j.DeviceHeld,
j.DeviceReadyForReturn,
j.DeviceReturnedDate,
j.JobMetaInsurance_ClaimFormSentDate,
j.JobMetaNonWarranty_AccountingChargeAddedDate,
j.JobMetaNonWarranty_AccountingChargePaidDate,
j.JobMetaNonWarranty_AccountingChargeRequiredDate,
j.JobMetaNonWarranty_InvoiceReceivedDate,
j.JobMetaNonWarranty_PurchaseOrderRaisedDate,
j.JobMetaNonWarranty_PurchaseOrderSentDate,
j.JobMetaNonWarranty_RepairerCompletedDate,
j.JobMetaNonWarranty_RepairerLoggedDate,
j.JobMetaWarranty_ExternalCompletedDate,
j.JobMetaWarranty_ExternalLoggedDate,
j.OpenedDate,
j.RecentAttachmentDate,
j.RecentLogDate,
j.WaitingForUserAction
};
j.LastActivityDate = activityDates.Max().Value;
items.Add(j);
}
}
@@ -132,6 +132,8 @@ using Disco.Services.Authorization;
// - Device's Profile or Model Changes
unsubscribeToken = RepositoryMonitor.StreamAfterCommit
.Where(n => n.EntityType == typeof(Job) ||
n.EntityType == typeof(JobLog) ||
n.EntityType == typeof(JobAttachment) ||
n.EntityType == typeof(JobQueueJob) ||
n.EntityType == typeof(JobMetaWarranty) ||
n.EntityType == typeof(JobMetaNonWarranty) ||
@@ -186,6 +188,32 @@ using Disco.Services.Authorization;
if (e.EntityType == typeof(Job))
jobIds = new List<int>() { ((Job)e.Entity).Id };
else if (e.EntityType == typeof(JobLog))
{
if (e.EventType == RepositoryMonitorEventType.Added)
{
var jobLog = ((JobLog)e.Entity);
var job = base.Items.FirstOrDefault(i => i.JobId == jobLog.JobId);
if (job != null && job.LastActivityDate < jobLog.Timestamp)
job.LastActivityDate = jobLog.Timestamp;
return;
}
else
jobIds = new List<int>() { ((JobLog)e.Entity).JobId };
}
else if (e.EntityType == typeof(JobAttachment))
{
if (e.EventType == RepositoryMonitorEventType.Added)
{
var jobAttachment = ((JobAttachment)e.Entity);
var job = base.Items.FirstOrDefault(i => i.JobId == jobAttachment.JobId);
if (job != null && job.LastActivityDate < jobAttachment.Timestamp)
job.LastActivityDate = jobAttachment.Timestamp;
return;
}
else
jobIds = new List<int>() { ((JobAttachment)e.Entity).JobId };
}
else if (e.EntityType == typeof(JobQueueJob))
jobIds = new List<int>() { ((JobQueueJob)e.Entity).JobId };
else if (e.EntityType == typeof(JobMetaWarranty))