Kanban.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class KanbanDocumentCount : CoreAggregate<Kanban, KanbanDocument, Guid>
  8. {
  9. public override Expression<Func<KanbanDocument, Guid>> Aggregate => x => x.ID;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  11. public override Dictionary<Expression<Func<KanbanDocument, object>>, Expression<Func<Kanban, object>>> Links =>
  12. new Dictionary<Expression<Func<KanbanDocument, object>>, Expression<Func<Kanban, object>>> ()
  13. {
  14. { KanbanDocument => KanbanDocument.EntityLink.ID, Kanban => Kanban.ID }
  15. };
  16. }
  17. public class KanbaAssignmentDuration : CoreAggregate<Kanban, Assignment, TimeSpan>
  18. {
  19. public override Expression<Func<Assignment, TimeSpan>> Aggregate => x => x.Actual.Duration;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Sum;
  21. public override Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Kanban, object>>> Links =>
  22. new Dictionary<Expression<Func<Assignment, object>>, Expression<Func<Kanban, object>>>()
  23. {
  24. { Assignment => Assignment.Task.ID, Kanban => Kanban.ID }
  25. };
  26. }
  27. public enum KanbanCategory
  28. {
  29. Open,
  30. InProgress,
  31. Waiting,
  32. Complete
  33. }
  34. [UserTracking("Task Management")]
  35. [Caption("Tasks")]
  36. public class Kanban : Entity, IPersistent, IRemotable, IKanban, IScheduleAction, IOneToMany<Schedule>, INumericAutoIncrement<Kanban>,
  37. IOneToMany<Equipment>, ILicense<TaskManagementLicense>, IExportable, IImportable, IJobScopedItem
  38. {
  39. public static String OPEN => "Open";
  40. public static String INPROGRESS => "In Progress";
  41. public static String WAITING => "Waiting";
  42. public static String COMPLETE => "Complete";
  43. public static String[] ALL = new String[] { Kanban.OPEN, Kanban.INPROGRESS, Kanban.WAITING, Kanban.COMPLETE };
  44. private bool bChanging;
  45. [NullEditor]
  46. public DeliveryLink Delivery { get; set; }
  47. [IntegerEditor(Editable = Editable.Disabled)]
  48. [EditorSequence(-1)]
  49. public int Number { get; set; }
  50. [TextBoxEditor]
  51. [EditorSequence(0)]
  52. public string Title { get; set; }
  53. [EditorSequence(1)]
  54. public JobLink JobLink { get; set; }
  55. [EditorSequence(2)]
  56. public JobScopeLink JobScope { get; set; }
  57. [RichTextEditor]
  58. [EditorSequence(3)]
  59. public string Description { get; set; }
  60. [NotesEditor]
  61. [EditorSequence(4)]
  62. public string[] Notes { get; set; } = Array.Empty<string>();
  63. [MemoEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  64. [EditorSequence(5)]
  65. public string Summary { get; set; }
  66. [EditorSequence(6)]
  67. [Caption("Task Type")]
  68. public KanbanTypeLink Type { get; set; }
  69. [DateEditor]
  70. [EditorSequence(7)]
  71. public DateTime DueDate { get; set; } = DateTime.Today;
  72. [EditorSequence(8)]
  73. [Caption("Assigned To")]
  74. public EmployeeLink EmployeeLink { get; set; }
  75. [EditorSequence(9)]
  76. [Caption("Allocated By")]
  77. public EmployeeLink ManagerLink { get; set; }
  78. [DateTimeEditor(Editable = Editable.Hidden)]
  79. [EditorSequence(10)]
  80. public DateTime Completed { get; set; } = DateTime.MinValue;
  81. [EditorSequence("Other", 1)]
  82. [Caption("Equipment Item")]
  83. public EquipmentLink Equipment { get; set; }
  84. [DateEditor]
  85. [EditorSequence("Other", 2)]
  86. public DateTime StartDate { get; set; } = DateTime.Today;
  87. [DurationEditor]
  88. [EditorSequence("Other", 3)]
  89. public TimeSpan EstimatedTime { get; set; } = TimeSpan.FromHours(1);
  90. [Aggregate(typeof(KanbaAssignmentDuration))]
  91. [EditorSequence("Other", 4)]
  92. public TimeSpan ActualTime { get; set; }
  93. [CheckBoxEditor]
  94. [EditorSequence("Other", 5)]
  95. public bool Private { get; set; }
  96. [EditorSequence("Other", 6)]
  97. [CheckBoxEditor]
  98. public bool Locked { get; set; }
  99. [ComboLookupEditor(typeof(KanbanCategoryLookups))]
  100. [EditorSequence("Other", 7)]
  101. [LoggableProperty]
  102. public string Category { get; set; }
  103. [SecondaryIndex]
  104. [NullEditor]
  105. public DateTime Closed { get; set; } = DateTime.MinValue;
  106. [NullEditor]
  107. [Aggregate(typeof(KanbanDocumentCount))]
  108. public int Attachments { get; set; }
  109. public Expression<Func<Kanban, int>> AutoIncrementField()
  110. {
  111. return x => x.Number;
  112. }
  113. public Filter<Kanban>? AutoIncrementFilter()
  114. {
  115. return null;
  116. }
  117. [NullEditor]
  118. public ScheduleLink ScheduleLink { get; set; }
  119. public static KanbanCategory StringToCategory(string category)
  120. {
  121. return string.Equals(category, "Complete")
  122. ? KanbanCategory.Complete
  123. : string.Equals(category, "Waiting")
  124. ? KanbanCategory.Waiting
  125. : string.Equals(category, "In Progress")
  126. ? KanbanCategory.InProgress
  127. : KanbanCategory.Open;
  128. }
  129. public static string CategoryToString(KanbanCategory category)
  130. {
  131. return category.Equals(KanbanCategory.Complete)
  132. ? "Complete"
  133. : category.Equals(KanbanCategory.Waiting)
  134. ? "Waiting"
  135. : category.Equals(KanbanCategory.InProgress)
  136. ? "In Progress"
  137. : "Open";
  138. }
  139. private bool IsCompleted(object? value)
  140. {
  141. if (value == null)
  142. return false;
  143. if (value is DateTime dateTime)
  144. return !dateTime.IsEmpty();
  145. return value.Equals("Complete") || value.Equals("Completed");
  146. }
  147. protected override void DoPropertyChanged(string name, object? before, object? after)
  148. {
  149. base.DoPropertyChanged(name, before, after);
  150. if (bChanging)
  151. return;
  152. bChanging = true;
  153. if (name.Equals("Completed")) // set the completed date
  154. {
  155. Category = IsCompleted(after) ? "Complete" : IsCompleted(Category) ? "In Progress" : Category;
  156. }
  157. else if (name.Equals("Category")) // set the completed date
  158. {
  159. Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;
  160. }
  161. else if (name.Equals("Description"))
  162. {
  163. var summary = after as string;
  164. Summary = CoreUtils.StripHTML(summary);
  165. }
  166. bChanging = false;
  167. }
  168. static Kanban()
  169. {
  170. Classes.JobScope.LinkScopeProperties<Kanban>();
  171. }
  172. private class KanbanCategoryLookups : LookupGenerator<object>
  173. {
  174. public KanbanCategoryLookups(object[] items) : base(items)
  175. {
  176. AddValue(Kanban.OPEN, "To Do");
  177. AddValue(Kanban.INPROGRESS, "In Progress");
  178. AddValue(Kanban.WAITING, "Waiting For Others");
  179. AddValue(Kanban.COMPLETE, "Completed");
  180. }
  181. }
  182. }
  183. }