using System; using System.Linq; using Comal.Classes; using InABox.Core; using System.Diagnostics.CodeAnalysis; namespace comal.timesheets { public class JobDetailModel : DetailModel { public JobDetailModel(IModelHost host, Func> filter, bool transient = false) : base(host, filter, transient) { } public JobDetailModel(IModelHost host, Func> filter, [NotNull] string filename) : base(host, filter, filename) { } protected override void Initialize() { new JobDeliveryShell(); new JobEquipmentShell(); new JobITPShell(); new JobKanbanShell(); new JobDetailFormShell(); new JobDocumentShell(); base.Initialize(); Deliveries = new JobDeliveryShell[] { }; Equipment = new JobEquipmentShell[] { }; ITPs = new JobITPShell[] { }; Kanbans = new JobKanbanShell[] { }; Forms = new JobDetailFormShell[] { }; Documents = new JobDocumentShell[] { }; DocumentFolders = new DynamicTreeNodes(); } // public override Columns<(.+)> Columns => JobDetailShell.Columns.Columns; public JobDeliveryShell[] Deliveries { get; private set; } public JobEquipmentShell[] Equipment { get; private set; } public JobITPShell[] ITPs { get; private set; } public JobKanbanShell[] Kanbans { get; private set; } public JobDetailFormShell[] Forms { get; private set; } public JobDocumentShell[] Documents { get; private set; } public DynamicTreeNodes DocumentFolders { get; private set; } public override void BeforeLoad(MultiQuery query) { base.BeforeLoad(query); query.Add( new Filter(x=>x.Job.ID).InQuery(Filter(), x=>x.ID), JobDeliveryShell.Columns.Columns); query.Add( new Filter(x=>x.JobLink.ID).InQuery(Filter(), x=>x.ID), JobEquipmentShell.Columns.Columns); query.Add( new Filter(x=>x.Job.ID).InQuery(Filter(), x=>x.ID), JobITPShell.Columns.Columns); query.Add( new Filter(x=>x.JobLink.ID).InQuery(Filter(), x=>x.ID), JobKanbanShell.Columns.Columns); query.Add( new Filter(x=>x.Parent.ID).InQuery(Filter(), x=>x.ID), JobDetailFormShell.Columns.Columns); query.Add( new Filter(x=>x.EntityLink.DocumentSet.Job.ID).InQuery(Filter(), x=>x.ID), JobDocumentShell.Columns.Columns); query.Add( new Filter(x=>x.Job.ID).InQuery(Filter(), x=>x.ID), JobDocumentSetFolderShell.Columns.Columns); } public override void AfterLoad(MultiQuery query) { base.AfterLoad(query); Deliveries = query.Get() .Rows .Select(x => new JobDeliveryShell() { Row = x, Parent = this }) .ToArray(); Equipment = query.Get() .Rows .Select(x => new JobEquipmentShell() { Row = x, Parent = this }) .ToArray(); ITPs = query.Get() .Rows .Select(x => new JobITPShell() { Row = x, Parent = this }) .ToArray(); Kanbans = query.Get() .Rows .Select(x => new JobKanbanShell() { Row = x, Parent = this }) .ToArray(); Forms = query.Get() .Rows .Select(x => new JobDetailFormShell() { Row = x, Parent = this }) .ToArray(); Documents = query.Get() .Rows .Select(x => new JobDocumentShell() { Row = x, Parent = this }) .ToArray(); DocumentFolders.Load( query.Get(), x=>x.ID, x=>x.Parent.ID, x=>x.Name ); var roots = DocumentFolders.GetChilden(Guid.Empty); foreach (var root in roots) root.Parent = CoreUtils.FullGuid; DocumentFolders.Add(CoreUtils.FullGuid, Guid.Empty).Description = "All Folders"; } } }