Kanban.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. [EditorSequence(2)]
  51. public JobScopeLink JobScope { get; set; }
  52. [RichTextEditor]
  53. [EditorSequence(3)]
  54. public string Description { get; set; }
  55. [NotesEditor]
  56. [EditorSequence(4)]
  57. public string[] Notes { get; set; } = Array.Empty<string>();
  58. [MemoEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  59. [EditorSequence(5)]
  60. public string Summary { get; set; }
  61. [EditorSequence(6)]
  62. [Caption("Task Type")]
  63. public KanbanTypeLink Type { get; set; }
  64. [DateEditor]
  65. [EditorSequence(7)]
  66. public DateTime DueDate { get; set; } = DateTime.Today;
  67. [EditorSequence(8)]
  68. [Caption("Assigned To")]
  69. public EmployeeLink EmployeeLink { get; set; }
  70. [EditorSequence(9)]
  71. [Caption("Allocated By")]
  72. public EmployeeLink ManagerLink { get; set; }
  73. [DateTimeEditor(Editable = Editable.Hidden)]
  74. [EditorSequence(10)]
  75. public DateTime Completed { get; set; } = DateTime.MinValue;
  76. [EditorSequence("Other", 1)]
  77. [Caption("Equipment Item")]
  78. public EquipmentLink Equipment { get; set; }
  79. [DateEditor]
  80. [EditorSequence("Other", 2)]
  81. public DateTime StartDate { get; set; } = DateTime.Today;
  82. [DurationEditor]
  83. [EditorSequence("Other", 3)]
  84. public TimeSpan EstimatedTime { get; set; } = TimeSpan.FromHours(1);
  85. [Aggregate(typeof(KanbaAssignmentDuration))]
  86. [EditorSequence("Other", 4)]
  87. public TimeSpan ActualTime { get; set; }
  88. [CheckBoxEditor]
  89. [EditorSequence("Other", 5)]
  90. public bool Private { get; set; }
  91. [EditorSequence("Other", 6)]
  92. [CheckBoxEditor]
  93. public bool Locked { get; set; }
  94. [EditorSequence("Other", 7)]
  95. [LoggableProperty]
  96. [EnumLookupEditor(typeof(KanbanStatus))]
  97. public KanbanStatus Status { get; set; }
  98. [SecondaryIndex]
  99. [NullEditor]
  100. public DateTime Closed { get; set; } = DateTime.MinValue;
  101. [NullEditor]
  102. [Aggregate(typeof(KanbanDocumentCount))]
  103. public int Attachments { get; set; }
  104. [NullEditor]
  105. [Obsolete("Replaced with Status",true)]
  106. public string Category { get; set; }
  107. public Expression<Func<Kanban, int>> AutoIncrementField()
  108. {
  109. return x => x.Number;
  110. }
  111. public Filter<Kanban>? AutoIncrementFilter()
  112. {
  113. return null;
  114. }
  115. [NullEditor]
  116. public ScheduleLink ScheduleLink { get; set; }
  117. private bool IsCompleted(object? value)
  118. {
  119. if (value == null)
  120. return false;
  121. if (value is DateTime dateTime)
  122. return !dateTime.IsEmpty();
  123. if (value is KanbanStatus category)
  124. return category == KanbanStatus.Complete;
  125. return false;
  126. }
  127. protected override void DoPropertyChanged(string name, object? before, object? after)
  128. {
  129. base.DoPropertyChanged(name, before, after);
  130. if (bChanging)
  131. return;
  132. bChanging = true;
  133. if (name.Equals(nameof(Completed))) // set the completed date
  134. {
  135. Status = IsCompleted(after) ? KanbanStatus.Complete : IsCompleted(Status) ? KanbanStatus.InProgress : Status;
  136. }
  137. else if (name.Equals(nameof(Status))) // set the completed date
  138. {
  139. Completed = IsCompleted(after) ? IsCompleted(Completed) ? Completed : DateTime.Now : DateTime.MinValue;
  140. }
  141. else if (name.Equals(nameof(Description)))
  142. {
  143. var summary = after as string;
  144. Summary = CoreUtils.StripHTML(summary);
  145. }
  146. bChanging = false;
  147. }
  148. static Kanban()
  149. {
  150. Classes.JobScope.LinkScopeProperties<Kanban>();
  151. }
  152. }
  153. }