From 3ec2ea7d37171ea5d3fcaa52b837869c2c8f50da Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Fri, 3 Nov 2023 15:50:01 +1100 Subject: [PATCH] add job log when re-opening --- Disco.BI/BI/Interop/Pdf/PdfGenerator.cs | 2 -- Disco.Services/Interop/MimeTypes.cs | 2 ++ Disco.Services/Jobs/JobActionExtensions.cs | 17 +++++++++++++++-- .../Areas/API/Controllers/JobController.cs | 13 ++++++------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs b/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs index 80bf7e06..6550219a 100644 --- a/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs +++ b/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs @@ -268,8 +268,6 @@ namespace Disco.BI.Interop.Pdf var pageUniqueIdBytes = pageUniqueId.ToQRCodeBytes(); // Encode to QRCode byte array - var pageUniqueIdWidth = (int)pdfFieldPosition.position.Width; - var pageUniqueIdHeight = (int)pdfFieldPosition.position.Height; var pageUniqueIdEncoded = QRCodeBinaryEncoder.Encode(pageUniqueIdBytes, out var qrWidth, out var qrHeight); // Encode byte array to Image diff --git a/Disco.Services/Interop/MimeTypes.cs b/Disco.Services/Interop/MimeTypes.cs index 22025dd8..84ed6004 100644 --- a/Disco.Services/Interop/MimeTypes.cs +++ b/Disco.Services/Interop/MimeTypes.cs @@ -54,6 +54,8 @@ namespace Disco.Services.Interop return "video/x-ms-wmv"; case "mov": return "video/quicktime"; + case "js": + return "application/javascript"; } // Check System Registry diff --git a/Disco.Services/Jobs/JobActionExtensions.cs b/Disco.Services/Jobs/JobActionExtensions.cs index a19be51b..72eaae5d 100644 --- a/Disco.Services/Jobs/JobActionExtensions.cs +++ b/Disco.Services/Jobs/JobActionExtensions.cs @@ -661,7 +661,9 @@ namespace Disco.Services JobId = j.Id, TechUserId = Technician.UserId, Timestamp = DateTime.Now, - Comments = string.Format("# Job Forcibly Closed\r\n{0}", string.IsNullOrWhiteSpace(Reason) ? "" : Reason) + Comments = $@"## Job Forcibly Closed + +{(string.IsNullOrWhiteSpace(Reason) ? "" : Reason)}" }; Database.JobLogs.Add(jobLog); @@ -700,11 +702,22 @@ namespace Disco.Services return j.ClosedDate.HasValue; } - public static void OnReopen(this Job j) + public static void OnReopen(this Job j, DiscoDataContext database, User technician) { if (!j.CanReopen()) throw new InvalidOperationException("Reopen was Denied"); + var log = new JobLog() + { + JobId = j.Id, + TechUserId = technician.UserId, + Timestamp = DateTime.Now, + Comments = $@"## Job Re-Opened + +Previously Closed by {j.ClosedTechUser.DisplayName} [`@{j.ClosedTechUser.FriendlyId()}`] at `{j.ClosedDate:yyyy-MM-dd HH:mm}`.", + }; + database.JobLogs.Add(log); + j.ClosedDate = null; j.ClosedTechUserId = null; } diff --git a/Disco.Web/Areas/API/Controllers/JobController.cs b/Disco.Web/Areas/API/Controllers/JobController.cs index 679b3434..756d14cf 100644 --- a/Disco.Web/Areas/API/Controllers/JobController.cs +++ b/Disco.Web/Areas/API/Controllers/JobController.cs @@ -1,19 +1,16 @@ -using Disco.BI.Extensions; -using Disco.Models.Repository; -using Disco.Models.Services.Documents; +using Disco.Models.Repository; using Disco.Models.Services.Job; using Disco.Models.Services.Jobs.JobLists; using Disco.Services; using Disco.Services.Authorization; -using Disco.Services.Documents; using Disco.Services.Interop; using Disco.Services.Jobs.JobLists; using Disco.Services.Jobs.Statistics; using Disco.Services.Users; using Disco.Services.Web; -using Disco.Web.Extensions; using System; using System.Collections.Generic; +using System.Data.Entity; using System.IO; using System.Linq; using System.Web.Mvc; @@ -1729,12 +1726,14 @@ namespace Disco.Web.Areas.API.Controllers [DiscoAuthorize(Claims.Job.Actions.Reopen)] public virtual ActionResult Reopen(int id, bool redirect) { - var j = Database.Jobs.Find(id); + var j = Database.Jobs + .Include(x => x.ClosedTechUser) + .FirstOrDefault(x => x.Id == id); if (j != null) { if (j.CanReopen()) { - j.OnReopen(); + j.OnReopen(Database, CurrentUser); Database.SaveChanges(); if (redirect)