Kanban.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. [SecondaryIndex]
  126. [NullEditor]
  127. public DateTime Closed { get; set; } = DateTime.MinValue;
  128. [NullEditor]
  129. [Aggregate(typeof(KanbanDocumentCount))]
  130. public int Attachments { get; set; }
  131. [NullEditor]
  132. [Obsolete("Replaced with Status",true)]
  133. public string Category { get; set; }
  134. [TextBoxEditor(Editable = Editable.Hidden)]
  135. public override string CreatedBy
  136. {
  137. get => base.CreatedBy;
  138. set => base.CreatedBy = value;
  139. }
  140. public Expression<Func<Kanban, int>> AutoIncrementField()
  141. {
  142. return x => x.Number;
  143. }
  144. public Filter<Kanban>? AutoIncrementFilter()
  145. {
  146. return null;
  147. }
  148. [NullEditor]
  149. public ScheduleLink ScheduleLink { get; set; }
  150. private bool IsCompleted(object? value)
  151. {
  152. if (value == null)
  153. return false;
  154. if (value is DateTime dateTime)
  155. return !dateTime.IsEmpty();
  156. if (value is KanbanStatus category)
  157. return category == KanbanStatus.Complete;
  158. return false;
  159. }
  160. protected override void DoPropertyChanged(string name, object? before, object? after)
  161. {
  162. base.DoPropertyChanged(name, before, after);
  163. if (bChanging)
  164. return;
  165. bChanging = true;
  166. if (name.Equals(nameof(Completed))) // set the completed date
  167. {
  168. Status = IsCompleted(after) ? KanbanStatus.Complete : IsCompleted(Status) ? KanbanStatus.InProgress : Status;
  169. }
  170. else if (name.Equals(nameof(Status))) // set the completed date
  171. {
  172. Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;
  173. }
  174. else if (name.Equals(nameof(Description)))
  175. {
  176. var summary = after as string;
  177. Summary = CoreUtils.StripHTML(summary);
  178. }
  179. bChanging = false;
  180. }
  181. static Kanban()
  182. {
  183. Classes.JobScope.LinkScopeProperties<Kanban>();
  184. }
  185. }
  186. }