resolves #179: filter noticeboard by job queue
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services.Jobs.Noticeboards;
|
||||
using Disco.Services.Web;
|
||||
using Disco.Web.Areas.Public.Models.UserHeldDevices;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
@@ -10,30 +10,53 @@ namespace Disco.Web.Areas.Public.Controllers
|
||||
{
|
||||
public partial class HeldDevicesController : DatabaseController
|
||||
{
|
||||
public virtual ActionResult Index(List<int?> DeviceProfileInclude, List<int?> DeviceProfileExclude, List<string> DeviceAddressInclude, List<string> DeviceAddressExclude)
|
||||
public virtual ActionResult Index(string DeviceProfileInclude, string DeviceProfileExclude, string DeviceAddressInclude, string DeviceAddressExclude, string JobQueueInclude, string JobQueueExclude)
|
||||
{
|
||||
IQueryable<Job> query = Database.Jobs;
|
||||
|
||||
if (DeviceProfileInclude != null)
|
||||
query = query.Where(j => DeviceProfileInclude.Contains(j.Device.DeviceProfileId));
|
||||
if (DeviceProfileExclude != null)
|
||||
query = query.Where(j => !DeviceProfileExclude.Contains(j.Device.DeviceProfileId));
|
||||
if (DeviceAddressInclude != null && DeviceAddressInclude.Count > 0)
|
||||
{
|
||||
var addressIds = Database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => DeviceAddressInclude.Contains(a.ShortName)).Select(a => a.Id).ToList();
|
||||
query = query.Where(j => addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
if (DeviceAddressExclude != null && DeviceAddressExclude.Count > 0)
|
||||
{
|
||||
var addressIds = Database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => DeviceAddressExclude.Contains(a.ShortName)).Select(a => (int?)a.Id).ToList();
|
||||
query = query.Where(j => j.Device.DeviceProfile.DefaultOrganisationAddress == null || !addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
var query = FilterJobs(Database.Jobs, Database, DeviceProfileInclude, DeviceProfileExclude, DeviceAddressInclude, DeviceAddressExclude, JobQueueInclude, JobQueueExclude);
|
||||
|
||||
var m = Disco.Services.Jobs.Noticeboards.HeldDevices.GetHeldDevices(query);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
|
||||
internal static IQueryable<Job> FilterJobs(IQueryable<Job> query, DiscoDataContext database, string deviceProfileInclude, string deviceProfileExclude, string deviceAddressInclude, string deviceAddressExclude, string jobQueueInclude, string jobQueueExclude)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(deviceProfileInclude))
|
||||
{
|
||||
var include = deviceProfileInclude.Split(',').Select(int.Parse).ToList();
|
||||
query = query.Where(j => include.Contains(j.Device.DeviceProfileId));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(deviceProfileExclude))
|
||||
{
|
||||
var exclude = deviceProfileExclude.Split(',').Select(int.Parse).ToList();
|
||||
query = query.Where(j => !exclude.Contains(j.Device.DeviceProfileId));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(deviceAddressInclude))
|
||||
{
|
||||
var include = deviceAddressInclude.Split(',');
|
||||
var addressIds = database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => include.Contains(a.ShortName)).Select(a => a.Id).ToList();
|
||||
query = query.Where(j => addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(deviceAddressExclude))
|
||||
{
|
||||
var exclude = deviceAddressExclude.Split(',');
|
||||
var addressIds = database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => exclude.Contains(a.ShortName)).Select(a => (int?)a.Id).ToList();
|
||||
query = query.Where(j => j.Device.DeviceProfile.DefaultOrganisationAddress == null || !addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
if (jobQueueInclude != null)
|
||||
{
|
||||
var include = jobQueueInclude.Split(',').Select(int.Parse).ToList();
|
||||
query = query.Where(j => j.JobQueues.Any(q => q.RemovedDate == null && include.Contains(q.JobQueueId)));
|
||||
}
|
||||
if (jobQueueExclude != null)
|
||||
{
|
||||
var exclude = jobQueueExclude.Split(',').Select(int.Parse).ToList();
|
||||
query = query.Where(j => !j.JobQueues.Any(q => q.RemovedDate == null && exclude.Contains(q.JobQueueId)));
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public virtual ActionResult ReadyForReturnXml()
|
||||
{
|
||||
var readyForReturn = Disco.Services.Jobs.Noticeboards.HeldDevices.GetHeldDevices(Database)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services.Jobs.Noticeboards;
|
||||
using Disco.Services.Jobs.Noticeboards;
|
||||
using Disco.Services.Web;
|
||||
using Disco.Web.Areas.Public.Models.UserHeldDevices;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
@@ -10,24 +8,9 @@ namespace Disco.Web.Areas.Public.Controllers
|
||||
{
|
||||
public partial class UserHeldDevicesController : DatabaseController
|
||||
{
|
||||
public virtual ActionResult Index(List<int?> DeviceProfileInclude, List<int?> DeviceProfileExclude, List<string> DeviceAddressInclude, List<string> DeviceAddressExclude)
|
||||
public virtual ActionResult Index(string DeviceProfileInclude, string DeviceProfileExclude, string DeviceAddressInclude, string DeviceAddressExclude, string JobQueueInclude, string JobQueueExclude)
|
||||
{
|
||||
IQueryable<Job> query = Database.Jobs;
|
||||
|
||||
if (DeviceProfileInclude != null)
|
||||
query = query.Where(j => DeviceProfileInclude.Contains(j.Device.DeviceProfileId));
|
||||
if (DeviceProfileExclude != null)
|
||||
query = query.Where(j => !DeviceProfileExclude.Contains(j.Device.DeviceProfileId));
|
||||
if (DeviceAddressInclude != null && DeviceAddressInclude.Count > 0)
|
||||
{
|
||||
var addressIds = Database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => DeviceAddressInclude.Contains(a.ShortName)).Select(a => a.Id).ToList();
|
||||
query = query.Where(j => addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
if (DeviceAddressExclude != null && DeviceAddressExclude.Count > 0)
|
||||
{
|
||||
var addressIds = Database.DiscoConfiguration.OrganisationAddresses.Addresses.Where(a => DeviceAddressExclude.Contains(a.ShortName)).Select(a => (int?)a.Id).ToList();
|
||||
query = query.Where(j => j.Device.DeviceProfile.DefaultOrganisationAddress == null || !addressIds.Contains(j.Device.DeviceProfile.DefaultOrganisationAddress));
|
||||
}
|
||||
var query = HeldDevicesController.FilterJobs(Database.Jobs, Database, DeviceProfileInclude, DeviceProfileExclude, DeviceAddressInclude, DeviceAddressExclude, JobQueueInclude, JobQueueExclude);
|
||||
|
||||
var m = HeldDevicesForUsers.GetHeldDevicesForUsers(query);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user