|
@@ -8,206 +8,201 @@ using InABox.Core;
|
|
|
using InABox.Database;
|
|
|
using System;
|
|
|
|
|
|
-namespace Comal.Stores
|
|
|
+namespace Comal.Stores;
|
|
|
+
|
|
|
+public class ServerKanbanSubscriberSet(IEnumerable<Guid> kanbanids, IProvider provider) : BaseKanbanSubscriberSet(kanbanids)
|
|
|
{
|
|
|
- public class ServerKanbanSubscriberSet : BaseKanbanSubscriberSet
|
|
|
- {
|
|
|
- public ServerKanbanSubscriberSet(IEnumerable<Guid> kanbanids) : base(kanbanids)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- protected override void DoSave(IEnumerable<KanbanSubscriber> updates)
|
|
|
- => DbFactory.NewProvider(Logger.Main).Save(updates);
|
|
|
+ protected override void DoSave(IEnumerable<KanbanSubscriber> updates)
|
|
|
+ => provider.Save(updates);
|
|
|
|
|
|
- protected override void DoDelete(KanbanSubscriber[] deletes)
|
|
|
- => DbFactory.NewProvider(Logger.Main).Delete(deletes,"");
|
|
|
+ protected override void DoDelete(KanbanSubscriber[] deletes)
|
|
|
+ => provider.Delete(deletes,"");
|
|
|
|
|
|
- protected override CoreTable DoQuery(Filter<KanbanSubscriber> filter, Columns<KanbanSubscriber> columns)
|
|
|
- => DbFactory.NewProvider(Logger.Main).Query(filter, columns);
|
|
|
-
|
|
|
- }
|
|
|
+ protected override CoreTable DoQuery(Filter<KanbanSubscriber> filter, Columns<KanbanSubscriber> columns)
|
|
|
+ => provider.Query(filter, columns);
|
|
|
|
|
|
- internal class KanbanStore : ScheduleActionStore<Kanban>
|
|
|
+}
|
|
|
+
|
|
|
+internal class KanbanStore : ScheduleActionStore<Kanban>
|
|
|
+{
|
|
|
+ private void CheckNotifications(Kanban entity)
|
|
|
{
|
|
|
- private void CheckNotifications(Kanban entity)
|
|
|
+ if (entity.HasOriginalValue(x => x.Completed) && !entity.Completed.IsEmpty())
|
|
|
{
|
|
|
- if (entity.HasOriginalValue(x => x.Completed) && !entity.Completed.IsEmpty())
|
|
|
- {
|
|
|
- // Find all notifications linked to this task
|
|
|
- var notifications = Provider.Query(
|
|
|
- new Filter<Notification>(x => x.EntityType).IsEqualTo(typeof(Kanban).EntityName()).And(x => x.EntityID).IsEqualTo(entity.ID)
|
|
|
- .And(x => x.Closed).IsEqualTo(DateTime.MinValue),
|
|
|
- Columns.None<Notification>().Add(x => x.ID)
|
|
|
- ).Rows.Select(x => x.ToObject<Notification>()).ToArray();
|
|
|
- foreach (var notification in notifications)
|
|
|
- notification.Closed = entity.Completed;
|
|
|
- if (notifications.Any())
|
|
|
- FindSubStore<Notification>().Save(notifications, "");
|
|
|
- }
|
|
|
+ // Find all notifications linked to this task
|
|
|
+ var notifications = Provider.Query(
|
|
|
+ new Filter<Notification>(x => x.EntityType).IsEqualTo(typeof(Kanban).EntityName())
|
|
|
+ .And(x => x.EntityID).IsEqualTo(entity.ID)
|
|
|
+ .And(x => x.Closed).IsEqualTo(DateTime.MinValue),
|
|
|
+ Columns.None<Notification>().Add(x => x.ID)
|
|
|
+ ).ToArray<Notification>();
|
|
|
+ foreach (var notification in notifications)
|
|
|
+ notification.Closed = entity.Completed;
|
|
|
+ if (notifications.Any())
|
|
|
+ FindSubStore<Notification>().Save(notifications, "");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void NotifyUsers(Kanban entity)
|
|
|
+ private void NotifyUsers(Kanban entity)
|
|
|
+ {
|
|
|
+ var Subject = $"Updated Task: {entity.Title} (Due: {entity.DueDate:dd MMM yy})";
|
|
|
+ var emps = Provider.Query(
|
|
|
+ new Filter<KanbanSubscriber>(x => x.Kanban.ID).IsEqualTo(entity.ID),
|
|
|
+ Columns.None<KanbanSubscriber>().Add(x => x.Employee.ID, x => x.Employee.UserLink.ID));
|
|
|
+ var senderrow = emps.Rows.FirstOrDefault(r => r.Get<KanbanSubscriber, Guid>(c => c.Employee.UserLink.ID).Equals(UserGuid));
|
|
|
+ var senderid = senderrow?.Get<KanbanSubscriber, Guid>(c => c.Employee.ID) ?? Guid.Empty;
|
|
|
+ var notifications = new List<Notification>();
|
|
|
+ foreach (var row in emps.Rows)
|
|
|
{
|
|
|
- var Subject = $"Updated Task: {entity.Title} (Due: {entity.DueDate:dd MMM yy})";
|
|
|
- var emps = Provider.Query(
|
|
|
- new Filter<KanbanSubscriber>(x => x.Kanban.ID).IsEqualTo(entity.ID),
|
|
|
- Columns.None<KanbanSubscriber>().Add(x => x.Employee.ID, x => x.Employee.UserLink.ID));
|
|
|
- var senderrow = emps.Rows.FirstOrDefault(r => r.Get<KanbanSubscriber, Guid>(c => c.Employee.UserLink.ID).Equals(UserGuid));
|
|
|
- var senderid = senderrow?.Get<KanbanSubscriber, Guid>(c => c.Employee.ID) ?? Guid.Empty;
|
|
|
- var notifications = new List<Notification>();
|
|
|
- foreach (var row in emps.Rows)
|
|
|
+ var userid = row.Get<KanbanSubscriber, Guid>(c => c.Employee.UserLink.ID);
|
|
|
+ if (userid != UserGuid)
|
|
|
{
|
|
|
- var userid = row.Get<KanbanSubscriber, Guid>(c => c.Employee.UserLink.ID);
|
|
|
- if (userid != UserGuid)
|
|
|
- {
|
|
|
- var notification = new Notification();
|
|
|
- notification.Employee.ID = row.Get<KanbanSubscriber, Guid>(c => c.Employee.ID);
|
|
|
- notification.Sender.ID = senderid;
|
|
|
- notification.Title = Subject;
|
|
|
- notification.EntityType = typeof(Kanban).EntityName();
|
|
|
- notification.EntityID = entity.ID;
|
|
|
- notification.Description = BuildDescription(entity);
|
|
|
- notifications.Add(notification);
|
|
|
- }
|
|
|
+ var notification = new Notification();
|
|
|
+ notification.Employee.ID = row.Get<KanbanSubscriber, Guid>(c => c.Employee.ID);
|
|
|
+ notification.Sender.ID = senderid;
|
|
|
+ notification.Title = Subject;
|
|
|
+ notification.EntityType = typeof(Kanban).EntityName();
|
|
|
+ notification.EntityID = entity.ID;
|
|
|
+ notification.Description = BuildDescription(entity);
|
|
|
+ notifications.Add(notification);
|
|
|
}
|
|
|
- if (emps.Rows.Count == 0)
|
|
|
+ }
|
|
|
+ if (emps.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ var userID = Provider.Query(
|
|
|
+ new Filter<Employee>(x => x.ID).IsEqualTo(entity.EmployeeLink.ID),
|
|
|
+ Columns.None<Employee>().Add(x => x.UserLink.ID)
|
|
|
+ ).Rows.FirstOrDefault()?.Get<Employee, Guid>(x => x.UserLink.ID);
|
|
|
+ if(userID != UserGuid)
|
|
|
{
|
|
|
- var userID = Provider.Query(
|
|
|
- new Filter<Employee>(x => x.ID).IsEqualTo(entity.EmployeeLink.ID),
|
|
|
- Columns.None<Employee>().Add(x => x.UserLink.ID)
|
|
|
- ).Rows.FirstOrDefault()?.Get<Employee, Guid>(x => x.UserLink.ID);
|
|
|
- if(userID != UserGuid)
|
|
|
- {
|
|
|
- Notification notification = new Notification();
|
|
|
- notification.Employee.ID = entity.EmployeeLink.ID;
|
|
|
- notification.Sender.ID = entity.ManagerLink.ID;
|
|
|
- notification.Title = Subject;
|
|
|
- notification.EntityType = typeof(Kanban).EntityName();
|
|
|
- notification.EntityID = entity.ID;
|
|
|
- notification.Description = BuildDescription(entity);
|
|
|
- notifications.Add(notification);
|
|
|
- }
|
|
|
+ Notification notification = new Notification();
|
|
|
+ notification.Employee.ID = entity.EmployeeLink.ID;
|
|
|
+ notification.Sender.ID = entity.ManagerLink.ID;
|
|
|
+ notification.Title = Subject;
|
|
|
+ notification.EntityType = typeof(Kanban).EntityName();
|
|
|
+ notification.EntityID = entity.ID;
|
|
|
+ notification.Description = BuildDescription(entity);
|
|
|
+ notifications.Add(notification);
|
|
|
}
|
|
|
- if (notifications.Any())
|
|
|
- FindSubStore<Notification>().Save(notifications, "");
|
|
|
}
|
|
|
+ if (notifications.Any())
|
|
|
+ FindSubStore<Notification>().Save(notifications, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ private string BuildDescription(Kanban entity)
|
|
|
+ {
|
|
|
+ var notes = string.Join("\r\n", entity.Notes)
|
|
|
+ .Split(new[] { "===================================\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var summary = notes.LastOrDefault();
|
|
|
+ if (string.IsNullOrEmpty(summary))
|
|
|
+ summary = entity.Summary;
|
|
|
+ if (string.IsNullOrEmpty(summary))
|
|
|
+ summary = "";
|
|
|
+ summary = Regex.Replace(summary.Replace("\r", "\n"), @"( |\r?\n|\r|\n)\1+", "$1");
|
|
|
+
|
|
|
+ var sb = new StringBuilder();
|
|
|
+ if (entity.EmployeeLink.HasOriginalValue(x => x.ID))
|
|
|
+ sb.AppendLine("The above task has been assigned to you. Please check the relevant details, and action as required.");
|
|
|
+ else
|
|
|
+ sb.AppendLine("The above task has been changed. Please check the relevant details, and action as required.");
|
|
|
|
|
|
- private string BuildDescription(Kanban entity)
|
|
|
+ if (entity.HasOriginalValue(x => x.Status))
|
|
|
{
|
|
|
- var notes = string.Join("\r\n", entity.Notes)
|
|
|
- .Split(new[] { "===================================\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
- var summary = notes.LastOrDefault();
|
|
|
- if (string.IsNullOrEmpty(summary))
|
|
|
- summary = entity.Summary;
|
|
|
- if (string.IsNullOrEmpty(summary))
|
|
|
- summary = "";
|
|
|
- summary = Regex.Replace(summary.Replace("\r", "\n"), @"( |\r?\n|\r|\n)\1+", "$1");
|
|
|
-
|
|
|
- var sb = new StringBuilder();
|
|
|
- if (entity.EmployeeLink.HasOriginalValue(x => x.ID))
|
|
|
- sb.AppendLine("The above task has been assigned to you. Please check the relevant details, and action as required.");
|
|
|
- else
|
|
|
- sb.AppendLine("The above task has been changed. Please check the relevant details, and action as required.");
|
|
|
-
|
|
|
- if (entity.HasOriginalValue(x => x.Status))
|
|
|
- {
|
|
|
- sb.AppendLine();
|
|
|
- sb.AppendLine(string.Format("- The task has progressed from {0} to {1}.", entity.GetOriginalValue(x => x.Status),
|
|
|
- entity.Status));
|
|
|
- }
|
|
|
- if (entity.HasOriginalValue(x => x.DueDate) && entity.GetOriginalValue(x => x.DueDate) != DateTime.MinValue)
|
|
|
- {
|
|
|
- sb.AppendLine();
|
|
|
- sb.AppendLine(string.Format("- The due date for the task has been changed from {0} to {1}.",
|
|
|
- entity.OriginalValueList["DueDate"],
|
|
|
- entity.DueDate));
|
|
|
- }
|
|
|
- if (entity.HasOriginalValue(x => x.Notes) && entity.Notes.Count() > 1)
|
|
|
- {
|
|
|
- sb.AppendLine("- The notes for the task have been updated as follows:");
|
|
|
- foreach (var line in summary.Split('\n'))
|
|
|
- sb.AppendLine(" " + line);
|
|
|
- }
|
|
|
- return sb.ToString();
|
|
|
+ sb.AppendLine();
|
|
|
+ sb.AppendLine(string.Format("- The task has progressed from {0} to {1}.", entity.GetOriginalValue(x => x.Status),
|
|
|
+ entity.Status));
|
|
|
}
|
|
|
+ if (entity.HasOriginalValue(x => x.DueDate) && entity.GetOriginalValue(x => x.DueDate) != DateTime.MinValue)
|
|
|
+ {
|
|
|
+ sb.AppendLine();
|
|
|
+ sb.AppendLine(string.Format("- The due date for the task has been changed from {0} to {1}.",
|
|
|
+ entity.OriginalValueList["DueDate"],
|
|
|
+ entity.DueDate));
|
|
|
+ }
|
|
|
+ if (entity.HasOriginalValue(x => x.Notes) && entity.Notes.Count() > 1)
|
|
|
+ {
|
|
|
+ sb.AppendLine("- The notes for the task have been updated as follows:");
|
|
|
+ foreach (var line in summary.Split('\n'))
|
|
|
+ sb.AppendLine(" " + line);
|
|
|
+ }
|
|
|
+ return sb.ToString();
|
|
|
+ }
|
|
|
|
|
|
- private void CheckNotificationRequired(Kanban entity)
|
|
|
+ private void CheckNotificationRequired(Kanban entity)
|
|
|
+ {
|
|
|
+ if (entity.EmployeeLink.HasOriginalValue(x => x.ID) || entity.HasOriginalValue(x => x.Notes) ||
|
|
|
+ entity.HasOriginalValue(x => x.Status) ||
|
|
|
+ entity.HasOriginalValue(x => x.Summary) || entity.HasOriginalValue(x => x.DueDate))
|
|
|
{
|
|
|
- if (entity.EmployeeLink.HasOriginalValue(x => x.ID) || entity.HasOriginalValue(x => x.Notes) ||
|
|
|
- entity.HasOriginalValue(x => x.Status) ||
|
|
|
- entity.HasOriginalValue(x => x.Summary) || entity.HasOriginalValue(x => x.DueDate))
|
|
|
+ NotifyUsers(entity);
|
|
|
+ }
|
|
|
+ else if (entity.ID != Guid.Empty && entity.HasOriginalValue(x => x.ID))
|
|
|
+ {
|
|
|
+ if (entity.GetOriginalValue<Kanban, Guid>("ID") == Guid.Empty)
|
|
|
{
|
|
|
NotifyUsers(entity);
|
|
|
}
|
|
|
- else if (entity.ID != Guid.Empty && entity.HasOriginalValue(x => x.ID))
|
|
|
- {
|
|
|
- if (entity.GetOriginalValue<Kanban, Guid>("ID") == Guid.Empty)
|
|
|
- {
|
|
|
- NotifyUsers(entity);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- protected override void BeforeSave(Kanban entity)
|
|
|
- {
|
|
|
- base.BeforeSave(entity);
|
|
|
- if (entity.Completed.IsEmpty())
|
|
|
- entity.Closed = DateTime.MinValue;
|
|
|
- }
|
|
|
+ protected override void BeforeSave(Kanban entity)
|
|
|
+ {
|
|
|
+ base.BeforeSave(entity);
|
|
|
+ if (entity.Completed.IsEmpty())
|
|
|
+ entity.Closed = DateTime.MinValue;
|
|
|
+ }
|
|
|
|
|
|
- private void CheckKanbanTypeForms(Kanban kanban)
|
|
|
+ private void CheckKanbanTypeForms(Kanban kanban)
|
|
|
+ {
|
|
|
+ if(!kanban.Type.HasOriginalValue(x => x.ID))
|
|
|
{
|
|
|
- if(!kanban.Type.HasOriginalValue(x => x.ID))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var kanbanForms = Provider.Query(
|
|
|
- new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(kanban.ID)).Rows.Select(x => x.ToObject<KanbanForm>()).ToArray();
|
|
|
- var toDelete = kanbanForms.Where(x => string.IsNullOrWhiteSpace(x.FormData)).ToArray();
|
|
|
- Provider.Delete(toDelete, UserID);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var kanbanForms = Provider.Query(
|
|
|
+ new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(kanban.ID)).Rows.Select(x => x.ToObject<KanbanForm>()).ToArray();
|
|
|
+ var toDelete = kanbanForms.Where(x => string.IsNullOrWhiteSpace(x.FormData)).ToArray();
|
|
|
+ Provider.Delete(toDelete, UserID);
|
|
|
|
|
|
- var kanbanTypeForms = Provider.Query(
|
|
|
- new Filter<KanbanTypeForm>(x => x.Type.ID).IsEqualTo(kanban.Type.ID)
|
|
|
- .And(x => x.Form.AppliesTo).IsEqualTo(nameof(Kanban)));
|
|
|
+ var kanbanTypeForms = Provider.Query(
|
|
|
+ new Filter<KanbanTypeForm>(x => x.Type.ID).IsEqualTo(kanban.Type.ID)
|
|
|
+ .And(x => x.Form.AppliesTo).IsEqualTo(nameof(Kanban)));
|
|
|
|
|
|
- var newForms = new List<KanbanForm>();
|
|
|
- foreach(var row in kanbanTypeForms.Rows)
|
|
|
+ var newForms = new List<KanbanForm>();
|
|
|
+ foreach(var row in kanbanTypeForms.Rows)
|
|
|
+ {
|
|
|
+ var formID = row.Get<KanbanTypeForm, Guid>(x => x.Form.ID);
|
|
|
+ if (!(kanbanForms.Any(x => x.Form.ID == formID) && toDelete.All(x => x.Form.ID != formID)))
|
|
|
{
|
|
|
- var formID = row.Get<KanbanTypeForm, Guid>(x => x.Form.ID);
|
|
|
- if (!(kanbanForms.Any(x => x.Form.ID == formID) && toDelete.All(x => x.Form.ID != formID)))
|
|
|
- {
|
|
|
- var kanbanForm = new KanbanForm();
|
|
|
- kanbanForm.Form.ID = formID;
|
|
|
- kanbanForm.Parent.ID = kanban.ID;
|
|
|
- newForms.Add(kanbanForm);
|
|
|
- }
|
|
|
+ var kanbanForm = new KanbanForm();
|
|
|
+ kanbanForm.Form.ID = formID;
|
|
|
+ kanbanForm.Parent.ID = kanban.ID;
|
|
|
+ newForms.Add(kanbanForm);
|
|
|
}
|
|
|
- Provider.Save(newForms);
|
|
|
}
|
|
|
+ Provider.Save(newForms);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void AfterSave(Kanban entity)
|
|
|
+ {
|
|
|
+ base.AfterSave(entity);
|
|
|
+ CheckNotifications(entity);
|
|
|
+ CheckNotificationRequired(entity);
|
|
|
+ CheckKanbanTypeForms(entity);
|
|
|
+ CheckSubscribers(entity);
|
|
|
+ }
|
|
|
|
|
|
- protected override void AfterSave(Kanban entity)
|
|
|
+ private void CheckSubscribers(Kanban entity)
|
|
|
+ {
|
|
|
+ var changedEmployee = entity.HasOriginalValue(x => x.EmployeeLink.ID);
|
|
|
+ var changedManager = entity.HasOriginalValue(x => x.ManagerLink.ID);
|
|
|
+ if (changedEmployee || changedManager)
|
|
|
{
|
|
|
- base.AfterSave(entity);
|
|
|
- CheckNotifications(entity);
|
|
|
- CheckNotificationRequired(entity);
|
|
|
- CheckKanbanTypeForms(entity);
|
|
|
- //CheckSubscribers(entity);
|
|
|
+ var set = new ServerKanbanSubscriberSet([entity.ID], Provider);
|
|
|
+ if (changedEmployee)
|
|
|
+ set.EnsureAssignee(entity.ID, entity.EmployeeLink.ID);
|
|
|
+ if (changedManager)
|
|
|
+ set.EnsureManager(entity.ID, entity.ManagerLink.ID);
|
|
|
+ set.Save();
|
|
|
}
|
|
|
-
|
|
|
- // private void CheckSubscribers(Kanban entity)
|
|
|
- // {
|
|
|
- // if (entity.EmployeeLink.HasOriginalValue(x => x.ID) || (entity.ManagerLink.HasOriginalValue(x => x.ID)))
|
|
|
- // {
|
|
|
- // var set = new ServerKanbanSubscriberSet(new Guid[] { entity.ID });
|
|
|
- // if (entity.EmployeeLink.HasOriginalValue(x => x.ID))
|
|
|
- // set.EnsureAssignee(entity.ID,entity.EmployeeLink.ID);
|
|
|
- // if (entity.ManagerLink.HasOriginalValue(x => x.ID))
|
|
|
- // set.EnsureManager(entity.ID,entity.ManagerLink.ID);
|
|
|
- // set.Save();
|
|
|
- //
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
}
|
|
|
}
|