Kanban.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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
  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. [Caption("Attached to")]
  55. public JobLink JobLink { get; set; }
  56. [RichTextEditor]
  57. [EditorSequence(2)]
  58. public string Description { get; set; }
  59. [NotesEditor]
  60. [EditorSequence(3)]
  61. public string[] Notes { get; set; } = Array.Empty<string>();
  62. [MemoEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  63. [EditorSequence(4)]
  64. public string Summary { get; set; }
  65. [EditorSequence(5)]
  66. [Caption("Task Type")]
  67. public KanbanTypeLink Type { get; set; }
  68. [DateEditor]
  69. [EditorSequence(6)]
  70. public DateTime DueDate { get; set; } = DateTime.Today;
  71. [EditorSequence(7)]
  72. [Caption("Assigned To")]
  73. public EmployeeLink EmployeeLink { get; set; }
  74. [EditorSequence(8)]
  75. [Caption("Allocated By")]
  76. public EmployeeLink ManagerLink { get; set; }
  77. [DateTimeEditor(Editable = Editable.Hidden)]
  78. [EditorSequence(9)]
  79. public DateTime Completed { get; set; } = DateTime.MinValue;
  80. [EditorSequence("Other", 1)]
  81. [Caption("Equipment Item")]
  82. public EquipmentLink Equipment { get; set; }
  83. [DateEditor]
  84. [EditorSequence("Other", 2)]
  85. public DateTime StartDate { get; set; } = DateTime.Today;
  86. [DurationEditor]
  87. [EditorSequence("Other", 3)]
  88. public TimeSpan EstimatedTime { get; set; } = TimeSpan.FromHours(1);
  89. [Aggregate(typeof(KanbaAssignmentDuration))]
  90. [EditorSequence("Other", 4)]
  91. public TimeSpan ActualTime { get; set; }
  92. [CheckBoxEditor]
  93. [EditorSequence("Other", 5)]
  94. public bool Private { get; set; }
  95. [EditorSequence("Other", 6)]
  96. [CheckBoxEditor]
  97. public bool Locked { get; set; }
  98. [ComboLookupEditor(typeof(KanbanCategoryLookups))]
  99. [EditorSequence("Other", 7)]
  100. [LoggableProperty]
  101. public string Category { get; set; }
  102. [SecondaryIndex]
  103. [NullEditor]
  104. public DateTime Closed { get; set; } = DateTime.MinValue;
  105. [NullEditor]
  106. [Aggregate(typeof(KanbanDocumentCount))]
  107. public int Attachments { get; set; }
  108. public Expression<Func<Kanban, int>> AutoIncrementField()
  109. {
  110. return x => x.Number;
  111. }
  112. public Filter<Kanban>? AutoIncrementFilter()
  113. {
  114. return null;
  115. }
  116. [NullEditor]
  117. public ScheduleLink ScheduleLink { get; set; }
  118. public static KanbanCategory StringToCategory(string category)
  119. {
  120. return string.Equals(category, "Complete")
  121. ? KanbanCategory.Complete
  122. : string.Equals(category, "Waiting")
  123. ? KanbanCategory.Waiting
  124. : string.Equals(category, "In Progress")
  125. ? KanbanCategory.InProgress
  126. : KanbanCategory.Open;
  127. }
  128. public static string CategoryToString(KanbanCategory category)
  129. {
  130. return category.Equals(KanbanCategory.Complete)
  131. ? "Complete"
  132. : category.Equals(KanbanCategory.Waiting)
  133. ? "Waiting"
  134. : category.Equals(KanbanCategory.InProgress)
  135. ? "In Progress"
  136. : "Open";
  137. }
  138. private bool IsCompleted(object? value)
  139. {
  140. if (value == null)
  141. return false;
  142. if (value is DateTime dateTime)
  143. return !dateTime.IsEmpty();
  144. return value.Equals("Complete") || value.Equals("Completed");
  145. }
  146. protected override void DoPropertyChanged(string name, object? before, object? after)
  147. {
  148. base.DoPropertyChanged(name, before, after);
  149. if (bChanging)
  150. return;
  151. bChanging = true;
  152. if (name.Equals("Completed")) // set the completed date
  153. {
  154. Category = IsCompleted(after) ? "Complete" : IsCompleted(Category) ? "In Progress" : Category;
  155. }
  156. else if (name.Equals("Category")) // set the completed date
  157. {
  158. Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;
  159. }
  160. else if (name.Equals("Description"))
  161. {
  162. var summary = after as string;
  163. Summary = CoreUtils.StripHTML(summary);
  164. }
  165. bChanging = false;
  166. }
  167. private class KanbanCategoryLookups : LookupGenerator<object>
  168. {
  169. public KanbanCategoryLookups(object[] items) : base(items)
  170. {
  171. AddValue(Kanban.OPEN, "To Do");
  172. AddValue(Kanban.INPROGRESS, "In Progress");
  173. AddValue(Kanban.WAITING, "Waiting For Others");
  174. AddValue(Kanban.COMPLETE, "Completed");
  175. }
  176. }
  177. }
  178. }