Kanban.cs 7.3 KB

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