feat: add change tracking on ticket updates, plugin version constant
This commit is contained in:
@@ -9,6 +9,8 @@ namespace Disco.Plugins.ServiceTracker.Services
|
|||||||
{
|
{
|
||||||
public class ServiceTrackerService
|
public class ServiceTrackerService
|
||||||
{
|
{
|
||||||
|
public const string PluginVersion = "1.1.0";
|
||||||
|
|
||||||
private readonly DiscoDataContext _database;
|
private readonly DiscoDataContext _database;
|
||||||
private readonly ServiceTrackerDataStore _dataStore;
|
private readonly ServiceTrackerDataStore _dataStore;
|
||||||
private readonly ServiceTrackerConfig _config;
|
private readonly ServiceTrackerConfig _config;
|
||||||
@@ -118,7 +120,7 @@ namespace Disco.Plugins.ServiceTracker.Services
|
|||||||
else ageBadge = (ageDays / 30) + " mo" + (ageDays / 30 > 1 ? "s" : "");
|
else ageBadge = (ageDays / 30) + " mo" + (ageDays / 30 > 1 ? "s" : "");
|
||||||
|
|
||||||
var eta = (ticket != null ? ticket.EstimatedCompletion : null) ?? job.ExpectedClosedDate;
|
var eta = (ticket != null ? ticket.EstimatedCompletion : null) ?? job.ExpectedClosedDate;
|
||||||
string etaDisplay = "—";
|
string etaDisplay = "\u2014";
|
||||||
if (eta.HasValue)
|
if (eta.HasValue)
|
||||||
{
|
{
|
||||||
var etaDays = (int)(eta.Value - now).TotalDays;
|
var etaDays = (int)(eta.Value - now).TotalDays;
|
||||||
@@ -152,7 +154,7 @@ namespace Disco.Plugins.ServiceTracker.Services
|
|||||||
{
|
{
|
||||||
JobId = job.Id,
|
JobId = job.Id,
|
||||||
JobTypeDescription = job.JobType != null ? job.JobType.Description : job.JobTypeId,
|
JobTypeDescription = job.JobType != null ? job.JobType.Description : job.JobTypeId,
|
||||||
DeviceSerialNumber = job.DeviceSerialNumber ?? "—",
|
DeviceSerialNumber = job.DeviceSerialNumber ?? "\u2014",
|
||||||
DeviceModelDescription = job.Device != null && job.Device.DeviceModel != null ? job.Device.DeviceModel.Description : null,
|
DeviceModelDescription = job.Device != null && job.Device.DeviceModel != null ? job.Device.DeviceModel.Description : null,
|
||||||
DeviceComputerName = job.Device != null ? job.Device.DeviceDomainId : null,
|
DeviceComputerName = job.Device != null ? job.Device.DeviceDomainId : null,
|
||||||
UserId = job.UserId,
|
UserId = job.UserId,
|
||||||
@@ -198,15 +200,13 @@ namespace Disco.Plugins.ServiceTracker.Services
|
|||||||
AvgAgeDays = tiles.Count > 0 ? Math.Round(tiles.Average(t => (double)t.AgeDays), 1) : 0,
|
AvgAgeDays = tiles.Count > 0 ? Math.Round(tiles.Average(t => (double)t.AgeDays), 1) : 0,
|
||||||
OldestJobDays = tiles.Count > 0 ? tiles.Max(t => t.AgeDays) : 0
|
OldestJobDays = tiles.Count > 0 ? tiles.Max(t => t.AgeDays) : 0
|
||||||
};
|
};
|
||||||
foreach (var p in _config.Priorities)
|
foreach (var p in _config.Priorities) stats.ByPriority[p.Id] = tiles.Count(t => t.PriorityId == p.Id);
|
||||||
stats.ByPriority[p.Id] = tiles.Count(t => t.PriorityId == p.Id);
|
|
||||||
stats.Critical = tiles.Count(t => t.PriorityId == "critical");
|
stats.Critical = tiles.Count(t => t.PriorityId == "critical");
|
||||||
stats.High = tiles.Count(t => t.PriorityId == "high");
|
stats.High = tiles.Count(t => t.PriorityId == "high");
|
||||||
stats.Medium = tiles.Count(t => t.PriorityId == "medium");
|
stats.Medium = tiles.Count(t => t.PriorityId == "medium");
|
||||||
stats.Low = tiles.Count(t => t.PriorityId == "low");
|
stats.Low = tiles.Count(t => t.PriorityId == "low");
|
||||||
stats.Scheduled = tiles.Count(t => t.PriorityId == "scheduled");
|
stats.Scheduled = tiles.Count(t => t.PriorityId == "scheduled");
|
||||||
foreach (var l in _config.Locations)
|
foreach (var l in _config.Locations) stats.ByLocation[l.Id] = tiles.Count(t => t.LocationId == l.Id);
|
||||||
stats.ByLocation[l.Id] = tiles.Count(t => t.LocationId == l.Id);
|
|
||||||
stats.InItOffice = tiles.Count(t => t.LocationId == "it-office");
|
stats.InItOffice = tiles.Count(t => t.LocationId == "it-office");
|
||||||
stats.WithUser = tiles.Count(t => t.LocationId == "with-user");
|
stats.WithUser = tiles.Count(t => t.LocationId == "with-user");
|
||||||
stats.AtRepairer = tiles.Count(t => t.LocationId == "at-repairer");
|
stats.AtRepairer = tiles.Count(t => t.LocationId == "at-repairer");
|
||||||
@@ -262,13 +262,48 @@ namespace Disco.Plugins.ServiceTracker.Services
|
|||||||
{
|
{
|
||||||
var ticket = _dataStore.GetTicket(jobId);
|
var ticket = _dataStore.GetTicket(jobId);
|
||||||
if (ticket == null) ticket = new ServiceTicket { JobId = jobId };
|
if (ticket == null) ticket = new ServiceTicket { JobId = jobId };
|
||||||
if (priorityId != null) ticket.PriorityId = priorityId;
|
if (ticket.ChangeLog == null) ticket.ChangeLog = new List<ChangeEntry>();
|
||||||
if (locationId != null) ticket.LocationId = locationId;
|
|
||||||
if (assignedTechId != null) ticket.AssignedTechId = assignedTechId;
|
// Track changes
|
||||||
if (eta.HasValue) ticket.EstimatedCompletion = eta;
|
if (priorityId != null && priorityId != ticket.PriorityId)
|
||||||
if (status != null) ticket.StatusOverride = status;
|
{
|
||||||
if (summary != null) ticket.Summary = summary;
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "Priority", OldValue = ticket.PriorityId, NewValue = priorityId });
|
||||||
|
ticket.PriorityId = priorityId;
|
||||||
|
}
|
||||||
|
if (locationId != null && locationId != ticket.LocationId)
|
||||||
|
{
|
||||||
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "Location", OldValue = ticket.LocationId, NewValue = locationId });
|
||||||
|
ticket.LocationId = locationId;
|
||||||
|
}
|
||||||
|
if (assignedTechId != null && assignedTechId != ticket.AssignedTechId)
|
||||||
|
{
|
||||||
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "Assigned Tech", OldValue = ticket.AssignedTechId, NewValue = assignedTechId });
|
||||||
|
ticket.AssignedTechId = assignedTechId;
|
||||||
|
}
|
||||||
|
if (eta.HasValue)
|
||||||
|
{
|
||||||
|
var oldEta = ticket.EstimatedCompletion.HasValue ? ticket.EstimatedCompletion.Value.ToString("dd MMM yyyy") : "none";
|
||||||
|
var newEta = eta.Value.ToString("dd MMM yyyy");
|
||||||
|
if (oldEta != newEta)
|
||||||
|
{
|
||||||
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "ETA", OldValue = oldEta, NewValue = newEta });
|
||||||
|
ticket.EstimatedCompletion = eta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status != null && status != ticket.StatusOverride)
|
||||||
|
{
|
||||||
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "Status", OldValue = ticket.StatusOverride ?? "(Disco default)", NewValue = string.IsNullOrEmpty(status) ? "(Disco default)" : status });
|
||||||
|
ticket.StatusOverride = status;
|
||||||
|
}
|
||||||
|
if (summary != null && summary != ticket.Summary)
|
||||||
|
{
|
||||||
|
ticket.ChangeLog.Add(new ChangeEntry { UserId = modifiedBy, Field = "Summary", OldValue = null, NewValue = "(updated)" });
|
||||||
|
ticket.Summary = summary;
|
||||||
|
}
|
||||||
|
|
||||||
ticket.LastModifiedBy = modifiedBy;
|
ticket.LastModifiedBy = modifiedBy;
|
||||||
|
|
||||||
|
// Recalculate SLA if priority changed
|
||||||
if (priorityId != null)
|
if (priorityId != null)
|
||||||
{
|
{
|
||||||
var priority = _config.Priorities.FirstOrDefault(p => p.Id == priorityId);
|
var priority = _config.Priorities.FirstOrDefault(p => p.Id == priorityId);
|
||||||
|
|||||||
Reference in New Issue
Block a user