Kanban.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 KanbanStatus
  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. 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. public JobLink JobLink { get; set; }
  50. private class JobScopeLookup : LookupDefinitionGenerator<JobScope, Kanban>
  51. {
  52. public override Filter<JobScope> DefineFilter(Kanban[] items)
  53. {
  54. var item = items?.Length == 1 ? items[0] : null;
  55. if (item != null)
  56. return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(item.JobLink.ID).And(x => x.Status.Approved).IsEqualTo(true);
  57. return new Filter<JobScope>(x => x.ID).None();
  58. }
  59. public override Columns<Kanban> DefineFilterColumns()
  60. => Columns.None<Kanban>().Add(x => x.JobLink.ID);
  61. }
  62. [LookupDefinition(typeof(JobScopeLookup))]
  63. [EditorSequence(2)]
  64. public JobScopeLink JobScope { get; set; }
  65. [RichTextEditor]
  66. [EditorSequence(3)]
  67. public string Description { get; set; }
  68. [NotesEditor]
  69. [EditorSequence(4)]
  70. public string[] Notes { get; set; } = Array.Empty<string>();
  71. [MemoEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  72. [EditorSequence(5)]
  73. public string Summary { get; set; }
  74. [EditorSequence(6)]
  75. [Caption("Task Type")]
  76. public KanbanTypeLink Type { get; set; }
  77. [DateEditor]
  78. [EditorSequence(7)]
  79. public DateTime DueDate { get; set; } = DateTime.Today;
  80. // Same lookup right now used for manager and employee.
  81. private class EmployeeLookup : LookupDefinitionGenerator<Employee, Kanban>
  82. {
  83. public override Filter<Employee> DefineFilter(Kanban[] items)
  84. {
  85. var result = LookupFactory.DefineFilter<Employee>();
  86. result.Ands.Add(new Filter<Employee>(x => x.CanAllocateTasks).IsEqualTo(true));
  87. return result;
  88. }
  89. public override Columns<Kanban> DefineFilterColumns()
  90. => Columns.None<Kanban>();
  91. }
  92. [LookupDefinition(typeof(EmployeeLookup))]
  93. [EditorSequence(8)]
  94. [Caption("Assigned To")]
  95. public EmployeeLink EmployeeLink { get; set; }
  96. [EditorSequence(9)]
  97. [Caption("Allocated By")]
  98. [LookupDefinition(typeof(EmployeeLookup))]
  99. public EmployeeLink ManagerLink { get; set; }
  100. [DateTimeEditor(Editable = Editable.Hidden)]
  101. [EditorSequence(10)]
  102. public DateTime Completed { get; set; } = DateTime.MinValue;
  103. [EditorSequence("Other", 1)]
  104. [Caption("Equipment Item")]
  105. public EquipmentLink Equipment { get; set; }
  106. [DateEditor]
  107. [EditorSequence("Other", 2)]
  108. public DateTime StartDate { get; set; } = DateTime.Today;
  109. [DurationEditor]
  110. [EditorSequence("Other", 3)]
  111. public TimeSpan EstimatedTime { get; set; } = TimeSpan.FromHours(1);
  112. [Aggregate(typeof(KanbaAssignmentDuration))]
  113. [EditorSequence("Other", 4)]
  114. public TimeSpan ActualTime { get; set; }
  115. [CheckBoxEditor]
  116. [EditorSequence("Other", 5)]
  117. public bool Private { get; set; }
  118. [EditorSequence("Other", 6)]
  119. [CheckBoxEditor]
  120. public bool Locked { get; set; }
  121. [EditorSequence("Other", 7)]
  122. [LoggableProperty]
  123. [EnumLookupEditor(typeof(KanbanStatus))]
  124. public KanbanStatus Status { get; set; }
  125. [EditorSequence("Other", 8)]
  126. [TagsEditor]
  127. public string Tags { get; set; } = "";
  128. [SecondaryIndex]
  129. [NullEditor]
  130. public DateTime Closed { get; set; } = DateTime.MinValue;
  131. [NullEditor]
  132. [Aggregate(typeof(KanbanDocumentCount))]
  133. public int Attachments { get; set; }
  134. [NullEditor]
  135. [Obsolete("Replaced with Status",true)]
  136. public string Category { get; set; }
  137. [TextBoxEditor(Editable = Editable.Hidden)]
  138. public override string CreatedBy
  139. {
  140. get => base.CreatedBy;
  141. set => base.CreatedBy = value;
  142. }
  143. public Expression<Func<Kanban, int>> AutoIncrementField()
  144. {
  145. return x => x.Number;
  146. }
  147. public Filter<Kanban>? AutoIncrementFilter()
  148. {
  149. return null;
  150. }
  151. [NullEditor]
  152. public ScheduleLink ScheduleLink { get; set; }
  153. private bool IsCompleted(object? value)
  154. {
  155. if (value == null)
  156. return false;
  157. if (value is DateTime dateTime)
  158. return !dateTime.IsEmpty();
  159. if (value is KanbanStatus category)
  160. return category == KanbanStatus.Complete;
  161. return false;
  162. }
  163. protected override void DoPropertyChanged(string name, object? before, object? after)
  164. {
  165. base.DoPropertyChanged(name, before, after);
  166. if (bChanging)
  167. return;
  168. bChanging = true;
  169. if (name.Equals(nameof(Completed))) // set the completed date
  170. {
  171. Status = IsCompleted(after) ? KanbanStatus.Complete : IsCompleted(Status) ? KanbanStatus.InProgress : Status;
  172. }
  173. else if (name.Equals(nameof(Status))) // set the completed date
  174. {
  175. Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;
  176. }
  177. else if (name.Equals(nameof(Description)))
  178. {
  179. var summary = after as string;
  180. Summary = CoreUtils.StripHTML(summary);
  181. }
  182. bChanging = false;
  183. }
  184. static Kanban()
  185. {
  186. Classes.JobScope.LinkScopeProperties<Kanban>();
  187. }
  188. }
  189. }