|
@@ -13,6 +13,7 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
+using System.Windows.Media;
|
|
|
|
|
|
namespace PRSDesktop.Forms.Issues;
|
|
|
|
|
@@ -22,24 +23,34 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
|
|
|
public IQueryProviderFactory ClientFactory { get; set; }
|
|
|
|
|
|
- private IQueryProvider<Kanban> _client;
|
|
|
- private IQueryProvider<Kanban> Client
|
|
|
+ private IQueryProvider<Kanban>? _kanbanClient;
|
|
|
+ private IQueryProvider<Kanban> KanbanClient
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- _client ??= ClientFactory.Create<Kanban>();
|
|
|
- return _client;
|
|
|
+ _kanbanClient ??= ClientFactory.Create<Kanban>();
|
|
|
+ return _kanbanClient;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private IQueryProvider<Job>? _jobClient;
|
|
|
+ private IQueryProvider<Job> JobClient
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ _jobClient ??= ClientFactory.Create<Job>();
|
|
|
+ return _jobClient;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Guid CustomerID { get; set; }
|
|
|
|
|
|
- public static CustomProperty CustomerProperty = new CustomProperty
|
|
|
- {
|
|
|
- Name = "CustomerID",
|
|
|
- PropertyType = typeof(string),
|
|
|
- ClassType = typeof(Kanban)
|
|
|
- };
|
|
|
+ // public static CustomProperty CustomerProperty = new CustomProperty
|
|
|
+ // {
|
|
|
+ // Name = "CustomerID",
|
|
|
+ // PropertyType = typeof(string),
|
|
|
+ // ClassType = typeof(Kanban)
|
|
|
+ // };
|
|
|
|
|
|
public IssuesGrid() : base()
|
|
|
{
|
|
@@ -53,6 +64,38 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
|
|
|
ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.End });
|
|
|
}
|
|
|
+
|
|
|
+ private class UIComponent : DynamicGridGridUIComponent<Kanban>
|
|
|
+ {
|
|
|
+ private IssuesGrid Grid;
|
|
|
+
|
|
|
+ public UIComponent(IssuesGrid grid)
|
|
|
+ {
|
|
|
+ Grid = grid;
|
|
|
+ Parent = grid;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override Brush? GetCellBackground(CoreRow row, DynamicColumnBase column)
|
|
|
+ {
|
|
|
+ var status = row.Get<Kanban, KanbanStatus>(x => x.Status);
|
|
|
+ var color = status == KanbanStatus.Open
|
|
|
+ ? Colors.Orange
|
|
|
+ : status == KanbanStatus.InProgress
|
|
|
+ ? Colors.Plum
|
|
|
+ : status == KanbanStatus.Waiting
|
|
|
+ ? Colors.LightGreen
|
|
|
+ : Colors.Silver;
|
|
|
+ return color.ToBrush(0.5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ protected override IDynamicGridUIComponent<Kanban> CreateUIComponent()
|
|
|
+ {
|
|
|
+ return new UIComponent(this);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
protected override void Init()
|
|
|
{
|
|
@@ -63,6 +106,8 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
options.Clear();
|
|
|
options.AddRows = true;
|
|
|
options.EditRows = true;
|
|
|
+ options.FilterRows = true;
|
|
|
+ options.HideDatabaseFilters = true;
|
|
|
}
|
|
|
|
|
|
private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
@@ -99,7 +144,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
var item = base.CreateItem();
|
|
|
item.UserProperties["CustomerID"] = CustomerID.ToString();
|
|
|
item.Notes = [
|
|
|
- $"Created on PRS {CoreUtils.GetVersion()}"
|
|
|
+ $"Created on PRS {CoreUtils.GetVersion()} by {App.EmployeeName} ({App.EmployeeEmail})"
|
|
|
];
|
|
|
// item.Status = KanbanStatus.Open;
|
|
|
return item;
|
|
@@ -226,8 +271,12 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
protected override DynamicGridColumns LoadColumns()
|
|
|
{
|
|
|
var columns = new DynamicGridColumns<Kanban>();
|
|
|
- columns.Add(x => x.Number);
|
|
|
+ columns.Add(x => x.Number, caption: "Ticket", width: 60, alignment: Alignment.MiddleCenter);
|
|
|
columns.Add(x => x.Title);
|
|
|
+ columns.Add(x => x.CreatedBy, caption: "Created By", width: 150);
|
|
|
+ columns.Add(x => x.EmployeeLink.Name, caption: "Assigned To", width: 150);
|
|
|
+ columns.Add(x => x.Type.Description, caption: "Type", width: 100, alignment: Alignment.MiddleCenter);
|
|
|
+ columns.Add(x => x.Status, caption: "Status", width: 80, alignment: Alignment.MiddleCenter);
|
|
|
return columns;
|
|
|
}
|
|
|
|
|
@@ -245,7 +294,11 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
CancellationToken token, Action<CoreTable?, Exception?> action)
|
|
|
{
|
|
|
criteria.Add(new Filter<Kanban>(x => x.Closed).IsEqualTo(Guid.Empty));
|
|
|
- criteria.Add(new Filter<Kanban>(CustomerProperty).IsEqualTo(CustomerID.ToString()));
|
|
|
+ criteria.Add(new Filter<Kanban>(x => x.Status).IsNotEqualTo(KanbanStatus.Complete));
|
|
|
+ criteria.Add(new Filter<Kanban>(x => x.JobLink.Customer.ID).IsEqualTo(CustomerID));
|
|
|
+
|
|
|
+ //criteria.Add(new Filter<Kanban>(CustomerProperty).IsEqualTo(CustomerID.ToString()));
|
|
|
+
|
|
|
if(Options.PageSize > 0)
|
|
|
{
|
|
|
var inSort = sort;
|
|
@@ -260,7 +313,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var data = Client.Query(filter, columns, inSort, page);
|
|
|
+ var data = KanbanClient.Query(filter, columns, inSort, page);
|
|
|
data.Offset = page.Offset;
|
|
|
IsPaging = data.Rows.Count == page.Limit;
|
|
|
|
|
@@ -288,7 +341,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Client.Query(criteria.Combine(), columns, sort, null, action);
|
|
|
+ KanbanClient.Query(criteria.Combine(), columns, sort, null, action);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -301,7 +354,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
var filter = new Filter<Kanban>(x => x.ID).InList(chunk.Select(x => x.Get<Kanban, Guid>(x => x.ID)).ToArray());
|
|
|
|
|
|
var columns = DynamicGridUtils.LoadEditorColumns(Columns.None<Kanban>());
|
|
|
- var data = Client.Query(filter, columns);
|
|
|
+ var data = KanbanClient.Query(filter, columns);
|
|
|
results.AddRange(data.ToObjects<Kanban>());
|
|
|
}
|
|
|
|
|
@@ -311,7 +364,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
public override Kanban LoadItem(CoreRow row)
|
|
|
{
|
|
|
var id = row.Get<Kanban, Guid>(x => x.ID);
|
|
|
- return Client.Query(
|
|
|
+ return KanbanClient.Query(
|
|
|
new Filter<Kanban>(x => x.ID).IsEqualTo(id),
|
|
|
DynamicGridUtils.LoadEditorColumns(Columns.None<Kanban>())).ToObjects<Kanban>().FirstOrDefault()
|
|
|
?? throw new Exception($"No Kanban with ID {id}");
|
|
@@ -319,12 +372,50 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
|
|
|
public override void SaveItem(Kanban item)
|
|
|
{
|
|
|
- Client.Save(item, "Edited by User");
|
|
|
+ CheckJob(item);
|
|
|
+ KanbanClient.Save(item, "Edited by User");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CheckJob(Kanban item)
|
|
|
+ {
|
|
|
+ if (item.ID == Guid.Empty)
|
|
|
+ {
|
|
|
+ item.CreatedBy = App.EmployeeName;
|
|
|
+
|
|
|
+ // Check if there is an open Project Job (ie installation or periodic billing) for this Client
|
|
|
+ var job = JobClient.Query(
|
|
|
+ new Filter<Job>(x => x.Customer.ID).IsEqualTo(CustomerID)
|
|
|
+ .And(x => x.JobType).IsEqualTo(JobType.Project)
|
|
|
+ .And(x => x.JobStatus.Active).IsEqualTo(true),
|
|
|
+ Columns.None<Job>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x=>x.DefaultScope.ID)
|
|
|
+ ).ToObjects<Job>().FirstOrDefault();
|
|
|
+
|
|
|
+ // No Job ? Create a service job for this ticket
|
|
|
+ if (job == null)
|
|
|
+ {
|
|
|
+ job = new Job();
|
|
|
+ job.Name = item.Title;
|
|
|
+ job.Customer.ID = CustomerID;
|
|
|
+ job.JobType = JobType.Service;
|
|
|
+ job.Notes = item.Notes?.ToList().ToArray() ?? [];
|
|
|
+ job.UserProperties.Clear();
|
|
|
+ JobClient.Save(job, "Created by Client Issues Screen");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Created Tickets should always have a job #!
|
|
|
+ item.JobLink.ID = job.ID;
|
|
|
+ item.JobScope.ID = job.DefaultScope.ID;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public override void SaveItems(IEnumerable<Kanban> items)
|
|
|
{
|
|
|
- Client.Save(items, "Edited by User");
|
|
|
+ var list = items.ToArray();
|
|
|
+ foreach (var item in list)
|
|
|
+ CheckJob(item);
|
|
|
+ KanbanClient.Save(list, "Edited by User");
|
|
|
}
|
|
|
|
|
|
public override void DeleteItems(params CoreRow[] rows)
|
|
@@ -340,7 +431,7 @@ public class IssuesGrid : DynamicGrid<Kanban>, ISpecificGrid
|
|
|
deletes.Add(delete);
|
|
|
}
|
|
|
|
|
|
- Client.Delete(deletes, "Deleted on User Request");
|
|
|
+ KanbanClient.Delete(deletes, "Deleted on User Request");
|
|
|
}
|
|
|
|
|
|
#endregion
|