diff --git a/WebHandler/ServiceTrackerWebHandler.cs b/WebHandler/ServiceTrackerWebHandler.cs index 3f2b664..b5e3a0f 100644 --- a/WebHandler/ServiceTrackerWebHandler.cs +++ b/WebHandler/ServiceTrackerWebHandler.cs @@ -16,7 +16,6 @@ namespace Disco.Plugins.ServiceTracker.WebHandler var dataPath = PluginConfigurationHandler.GetPluginDataDirectory( HostController.HttpContext.Application["Disco.Plugins.ServiceTracker"] as Plugin ?? new ServiceTrackerPlugin()); - // Fallback: use AppData path if (string.IsNullOrEmpty(dataPath)) { dataPath = System.IO.Path.Combine( @@ -51,13 +50,11 @@ namespace Disco.Plugins.ServiceTracker.WebHandler { var dataStore = GetDataStore(); var service = new ServiceTrackerService(Database, dataStore); - var filterPriority = HostController.Request.QueryString["priority"]; var filterLocation = HostController.Request.QueryString["location"]; var filterStatus = HostController.Request.QueryString["status"]; var filterTech = HostController.Request.QueryString["tech"]; var sortBy = HostController.Request.QueryString["sort"] ?? "due"; - var model = service.BuildDashboard(filterPriority, filterLocation, filterStatus, filterTech, sortBy); return HtmlResult(BuildDashboardPage(model)); } @@ -66,14 +63,11 @@ namespace Disco.Plugins.ServiceTracker.WebHandler { if (HostController.Request.HttpMethod != "POST") return new HttpStatusCodeResult(405); - var dataStore = GetDataStore(); var service = new ServiceTrackerService(Database, dataStore); - int jobId; if (!int.TryParse(HostController.Request.Form["jobId"], out jobId)) return new HttpStatusCodeResult(400); - var priorityId = HostController.Request.Form["priority"]; var locationId = HostController.Request.Form["location"]; var techId = HostController.Request.Form["tech"]; @@ -83,10 +77,8 @@ namespace Disco.Plugins.ServiceTracker.WebHandler DateTime etaParsed; if (DateTime.TryParse(HostController.Request.Form["eta"], out etaParsed)) eta = etaParsed; - var currentUser = HostController.HttpContext.User?.Identity?.Name ?? "system"; service.UpdateTicket(jobId, priorityId, locationId, techId, eta, status, summary, currentUser); - return new RedirectResult("/Plugin/Disco.Plugins.ServiceTracker/Dashboard"); } @@ -94,20 +86,15 @@ namespace Disco.Plugins.ServiceTracker.WebHandler { if (HostController.Request.HttpMethod != "POST") return new HttpStatusCodeResult(405); - var dataStore = GetDataStore(); var service = new ServiceTrackerService(Database, dataStore); - int jobId; if (!int.TryParse(HostController.Request.Form["jobId"], out jobId)) return new HttpStatusCodeResult(400); - var content = HostController.Request.Form["note"]; var noteType = HostController.Request.Form["noteType"] ?? "general"; var currentUser = HostController.HttpContext.User?.Identity?.Name ?? "system"; - var userName = currentUser; // Could resolve display name from DB - - service.AddNote(jobId, currentUser, userName, content, noteType); + service.AddNote(jobId, currentUser, currentUser, content, noteType); return new RedirectResult("/Plugin/Disco.Plugins.ServiceTracker/Detail?id=" + jobId); } @@ -116,22 +103,17 @@ namespace Disco.Plugins.ServiceTracker.WebHandler int jobId; if (!int.TryParse(HostController.Request.QueryString["id"], out jobId)) return new HttpStatusCodeResult(400); - var dataStore = GetDataStore(); var service = new ServiceTrackerService(Database, dataStore); var config = dataStore.LoadConfig(); - - // Get the job var job = Database.Jobs .Include("Device").Include("Device.DeviceModel") .Include("User").Include("OpenedTechUser") .Include("JobType").Include("JobSubTypes") .Include("JobLogs") .FirstOrDefault(j => j.Id == jobId); - if (job == null) return new HttpNotFoundResult(); - var ticket = service.GetTicketDetail(jobId); return HtmlResult(BuildDetailPage(job, ticket, config)); } @@ -141,7 +123,6 @@ namespace Disco.Plugins.ServiceTracker.WebHandler var dataStore = GetDataStore(); var service = new ServiceTrackerService(Database, dataStore); var model = service.BuildDashboard(); - var sb = new StringBuilder(); sb.AppendLine("JobId,Device,User,Priority,Location,Status,AssignedTech,OpenedDate,ETA,SlaDeadline,SlaBreached,AgeDays,Summary,NoteCount"); foreach (var t in model.Tiles) @@ -154,24 +135,15 @@ namespace Disco.Plugins.ServiceTracker.WebHandler t.SlaDeadline?.ToString("yyyy-MM-dd HH:mm") ?? "", t.IsSlaBreached, t.AgeDays, Csv(t.Summary), t.NoteCount)); } - var fileName = "ServiceTracker_Export_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv"; HostController.Response.Headers.Add("Content-Disposition", "attachment; filename=\"" + fileName + "\""); - return new ContentResult - { - Content = sb.ToString(), - ContentType = "text/csv", - ContentEncoding = Encoding.UTF8 - }; + return new ContentResult { Content = sb.ToString(), ContentType = "text/csv", ContentEncoding = Encoding.UTF8 }; } - // --- HTML Builders --- - private ActionResult HtmlResult(string html) { return new ContentResult { Content = html, ContentType = "text/html", ContentEncoding = Encoding.UTF8 }; } - private string Csv(string v) { return "\"" + (v ?? "").Replace("\"", "\"\"") + "\""; } private string H(string v) { return string.IsNullOrEmpty(v) ? "" : HttpUtility.HtmlEncode(v); } @@ -179,97 +151,65 @@ namespace Disco.Plugins.ServiceTracker.WebHandler { var pluginUrl = "/Plugin/Disco.Plugins.ServiceTracker"; var sb = new StringBuilder(); - - // --- Head --- sb.Append("
"); sb.Append("