diff --git a/server/AyaNova/Controllers/ScheduleController.cs b/server/AyaNova/Controllers/ScheduleController.cs index ddf95ef6..f13ed074 100644 --- a/server/AyaNova/Controllers/ScheduleController.cs +++ b/server/AyaNova/Controllers/ScheduleController.cs @@ -10,6 +10,7 @@ using AyaNova.Biz; using Microsoft.EntityFrameworkCore; using System.Linq; using System.Collections.Generic; +using AyaNova.Util; namespace AyaNova.Api.Controllers { @@ -60,17 +61,29 @@ namespace AyaNova.Api.Controllers DateTime dtEnd = p.End.AddDays(6); - //WORKORDERS if (p.WorkOrders && (UType == UserType.Service || UType == UserType.ServiceContractor)) { r.AddRange(await ct.ViewSchedulePersonalWorkOrder.Where(x => x.SchedUserId == UserId && x.StartDate > dtStart && x.StopDate < dtEnd) - .Select(x => new PersonalScheduleListItem() { Id = x.WoItemSchedUserId, Color = ColorFromWOItem(x, p), Start = EpochSeconds(x.StartDate), End = EpochSeconds(x.StopDate), Type = AyaType.WorkOrderItemScheduledUser, Name = NameFromWOItem(x, p) }) + .Select(x => MakeWOSchedItem(x, p)) .ToListAsync()); } return Ok(ApiOkResponse.Response(r)); } + private static PersonalScheduleListItem MakeWOSchedItem(ViewSchedulePersonalWorkOrder v, PersonalScheduleParams p) + { + var s = new PersonalScheduleListItem(); + s.Id = v.WoItemSchedUserId; + s.Color = ColorFromWOItem(v, p); + s.TextColor = TextColor(s.Color); + s.Start = EpochSeconds(v.StartDate); + s.End = EpochSeconds(v.StopDate); + s.Type = AyaType.WorkOrderItemScheduledUser; + s.Name = NameFromWOItem(v, p); + return s; + } + private static long? EpochSeconds(DateTime? dt) { if (dt == null) return null; @@ -92,6 +105,17 @@ namespace AyaNova.Api.Controllers return string.Empty; } + private static string TextColor(string hexcolor) + { + if (string.IsNullOrWhiteSpace(hexcolor)) return "black"; + hexcolor = hexcolor.Replace("#", ""); + var r = StringUtil.HexToInt(hexcolor.Substring(0, 2)); + var g = StringUtil.HexToInt(hexcolor.Substring(2, 2)); + var b = StringUtil.HexToInt(hexcolor.Substring(4, 2)); + var yiq = (r * 299 + g * 587 + b * 114) / 1000; + return yiq >= 128 ? "black" : "white"; + } + private static string NameFromWOItem(ViewSchedulePersonalWorkOrder v, PersonalScheduleParams p) { // Name=[wonumber customername] @@ -105,11 +129,19 @@ namespace AyaNova.Api.Controllers WorkOrderStatus = 2, WorkOrderItemStatus = 3, WorkOrderItemPriority = 4 + } + public enum ScheduleView : int + { + Day = 1, + Week = 2, + Month = 3, + Day4 = 4 } public class PersonalScheduleParams { + public ScheduleView View {get;set;} public DateTime Start { get; set; } public DateTime End { get; set; } public PersonalScheduleWorkOrderColorSource ColorSource { get; set; } @@ -125,6 +157,7 @@ namespace AyaNova.Api.Controllers public bool Timed { get { return true; } } public string Name { get; set; } public string Color { get; set; } + public string TextColor { get; set; } public AyaType Type { get; set; } public long Id { get; set; } diff --git a/server/AyaNova/util/StringUtil.cs b/server/AyaNova/util/StringUtil.cs index 2e00c379..aa5882f5 100644 --- a/server/AyaNova/util/StringUtil.cs +++ b/server/AyaNova/util/StringUtil.cs @@ -130,6 +130,13 @@ namespace AyaNova.Util return result; } + public static int HexToInt(string h) + { + int r = 0; + int.TryParse(h, System.Globalization.NumberStyles.HexNumber, null, out r); + return r; + } + }//eoc