From cacedf68b87486e0855ef9e4a0870d2359d57eb2 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 6 Oct 2021 00:10:53 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- .../AyaNova/Controllers/ScheduleController.cs | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 976f60e9..f92c39ec 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -52,7 +52,7 @@ "AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles", "AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles", "AYANOVA_FOLDER_TEMPORARY_SERVER_FILES": "c:\\temp\\RavenTestData\\tempfiles", - "AYANOVA_SERVER_TEST_MODE": "true", + "AYANOVA_SERVER_TEST_MODE": "false", "AYANOVA_SERVER_TEST_MODE_SEEDLEVEL": "small", "AYANOVA_SERVER_TEST_MODE_TZ_OFFSET": "-7", "AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_13\\bin\\" diff --git a/server/AyaNova/Controllers/ScheduleController.cs b/server/AyaNova/Controllers/ScheduleController.cs index 2967b600..96f1501d 100644 --- a/server/AyaNova/Controllers/ScheduleController.cs +++ b/server/AyaNova/Controllers/ScheduleController.cs @@ -91,10 +91,31 @@ namespace AyaNova.Api.Controllers ViewEnd = p.End.AddDays(6); } + + //Tags to Users + List Users = null; + + if (p.Tags.Count == 0) + Users = await ct.User.AsNoTracking().Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service).OrderBy(x => x.Name).Select(x => x.Id).ToListAsync(); + else + { + Users = new List(); + //add users that match any of the tags, to match they must have at least one of the tags + //iterate available users + var availableUsers = await ct.User.AsNoTracking().Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service).OrderBy(x => x.Name).Select(x => new { x.Id, x.Tags }).ToListAsync(); + //if user has any of the tags in the list then include them + foreach (var u in availableUsers) + { + //any of the inclusive tags in contact tags? + if (p.Tags.Intersect(u.Tags).Any()) + Users.Add(u.Id); + } + + } //WORKORDERS { //Note: query for *overlapping* ranges, not *contained* entirely in view range - r.AddRange(await ct.ViewScheduleWorkOrder.Where(x => p.Users.Contains(x.SchedUserId) && ViewStart <= x.StopDate && x.StartDate <= ViewEnd) + r.AddRange(await ct.ViewScheduleWorkOrder.Where(x => Users.Contains(x.SchedUserId) && ViewStart <= x.StopDate && x.StartDate <= ViewEnd) .Select(x => MakeServiceWOSchedItem(x, p)) .ToListAsync()); } @@ -111,8 +132,10 @@ namespace AyaNova.Api.Controllers public DateTime End { get; set; } [Required] public ScheduleWorkOrderColorSource WisuColorSource { get; set; } + // [Required] + // public List Users { get; set; }//user id's to display and in order to display [Required] - public List Users { get; set; }//user id's to display and in order to display + public List Tags { get; set; } [Required] public bool Dark { get; set; }//indicate if Client is set to dark mode or not, used for colorless types to display as black or white } @@ -259,7 +282,7 @@ namespace AyaNova.Api.Controllers s.Type = AyaType.WorkOrderItemScheduledUser; s.Name = NameFromWOItem(v); s.Editable = v.WorkOrderStatusCompleted != true && v.WorkOrderStatusLocked != true;//could be null as well which we'll consider open as it's no status set - s.UserId=v.SchedUserId; + s.UserId = v.SchedUserId; return s; } @@ -407,7 +430,7 @@ namespace AyaNova.Api.Controllers //user can simply filter a data table by null dates to see them //we shouldn't have allowed null dates in the first place in v7 but here we are :) public DateTime Start { get; set; } - public DateTime End { get; set; } + public DateTime End { get; set; } public string Name { get; set; } public string Color { get; set; } public string TextColor { get; set; }