resolves #179: filter noticeboard by job queue

This commit is contained in:
Gary Sharp
2025-10-31 17:45:04 +11:00
parent 8424a9a9a2
commit 529bba5c72
17 changed files with 582 additions and 236 deletions
@@ -16,20 +16,22 @@ namespace Disco.Services.Jobs.Noticeboards
public string DeviceSerialNumber { get; set; }
public string DeviceComputerNameFriendly
{
get
{
return DeviceComputerName == null ? null : ActiveDirectory.FriendlyAccountId(DeviceComputerName);
}
get => DeviceComputerName == null ? null : ActiveDirectory.FriendlyAccountId(DeviceComputerName);
set { } // for XML Serialization
}
public string DeviceComputerName { get; set; }
public string DeviceName
{
get => DeviceComputerNameFriendly ?? DeviceSerialNumber;
set { }
}
public string DeviceLocation { get; set; }
public string DeviceDescription
{
get
{
StringBuilder sb = new StringBuilder(DeviceComputerNameFriendly);
StringBuilder sb = new StringBuilder(DeviceName);
if (UserId != null)
sb.Append(" - ").Append(UserDisplayName).Append(" (").Append(UserIdFriendly).Append(")");
@@ -60,6 +62,7 @@ namespace Disco.Services.Jobs.Noticeboards
}
set { } // for XML Serialization
}
public IEnumerable<int> JobQueueIds { get; set; }
public string UserId { get; set; }
public string UserIdFriendly
@@ -130,6 +133,7 @@ namespace Disco.Services.Jobs.Noticeboards
DeviceLocation = j.Device.Location,
DeviceProfileId = j.Device.DeviceProfileId,
DeviceAddressId = j.Device.DeviceProfile.DefaultOrganisationAddress,
JobQueueIds = j.JobQueues.Where(q => q.RemovedDate == null).Select(q => q.JobQueueId),
UserId = j.Device.AssignedUserId,
UserDisplayName = j.Device.AssignedUser.DisplayName,
WaitingForUserAction = j.WaitingForUserAction.HasValue || ((j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue || j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue),
@@ -15,7 +15,7 @@ namespace Disco.Services.Jobs.Noticeboards
{
public const string Name = "HeldDevices";
private readonly static List<string> MonitorJobProperties = new List<string>() {
private static readonly List<string> MonitorJobProperties = new List<string>() {
"DeviceSerialNumber",
"UserId",
"ExpectedClosedDate",
@@ -25,25 +25,25 @@ namespace Disco.Services.Jobs.Noticeboards
"DeviceReadyForReturn",
"DeviceReturnedDate"
};
private readonly static List<string> MonitorJobMetaNonWarrantyProperties = new List<string>(){
private static readonly List<string> MonitorJobMetaNonWarrantyProperties = new List<string>(){
"AccountingChargeRequiredDate",
"AccountingChargeAddedDate",
"AccountingChargePaidDate"
};
private readonly static List<string> MonitorDeviceProperties = new List<string>(){
private static readonly List<string> MonitorDeviceProperties = new List<string>(){
"Location",
"DeviceProfileId",
"DeviceDomainId",
"AssignedUserId",
};
private readonly static List<string> MonitorDeviceProfileProperties = new List<string>(){
private static readonly List<string> MonitorDeviceProfileProperties = new List<string>(){
"DefaultOrganisationAddress"
};
private readonly static List<string> MonitorUserProperties = new List<string>(){
private static readonly List<string> MonitorUserProperties = new List<string>(){
"DisplayName"
};
private static Subject<Tuple<List<string>, List<string>>> BufferedUpdateStream;
private static readonly Subject<Tuple<List<string>, List<string>>> BufferedUpdateStream;
static HeldDevices()
{
@@ -74,7 +74,9 @@ namespace Disco.Services.Jobs.Noticeboards
) ||
(e.EntityType == typeof(User) &&
(e.EventType == RepositoryMonitorEventType.Modified && e.ModifiedProperties.Any(p => MonitorUserProperties.Contains(p)))
)
) ||
(e.EntityType == typeof(JobQueueJob) &&
(e.EventType == RepositoryMonitorEventType.Added || e.EventType == RepositoryMonitorEventType.Modified))
)
.Subscribe(RepositoryEvent);
}
@@ -147,6 +149,15 @@ namespace Disco.Services.Jobs.Noticeboards
.Select(j => j.DeviceSerialNumber)
);
}
else if (i.EntityType == typeof(JobQueueJob))
{
var jqj = (JobQueueJob)i.Entity;
var j = i.Database.Jobs.Find(jqj.JobId);
if (j != null && j.DeviceSerialNumber != null)
{
deviceSerialNumbers.Add(j.DeviceSerialNumber);
}
}
if (deviceSerialNumbers.Count > 0 || userIds.Count > 0)
{