Browse Source

Fixed global jobdocumentsettags not being loaded

Kenric Nugteren 1 year ago
parent
commit
78bd5c8c4d

+ 3 - 1
prs.classes/Entities/Job/DocumentSet/JobDocumentSetTag.cs

@@ -17,7 +17,9 @@ namespace Comal.Classes
     [Caption("Document Tags")]
     public class JobDocumentSetTag : Entity, IRemotable, IPersistent, ILicense<ProjectManagementLicense>, IOneToMany<Job>
     {
-        
+        /// <summary>
+        /// The job that this tag is specifically linked to; if it is <see cref="Guid.Empty"/>, this is a global tag, across all jobs.
+        /// </summary>
         [NullEditor]
         public JobLink Job { get; set; }
         

+ 28 - 21
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetPanel.xaml.cs

@@ -36,7 +36,7 @@ namespace PRSDesktop
 
         private JobDocumentSetSettings _settings = new();
 
-        public Job Master { get; set; }
+        public Job? Master { get; set; }
         
         public JobDocumentSetPanel()
         {
@@ -54,7 +54,7 @@ namespace PRSDesktop
 
         public event DataModelUpdateEvent? OnUpdateDataModel;
         
-        private bool GetAreas(CoreTable areas, ComboBox target) //, RowDefinition row)
+        private static bool GetAreas(CoreTable areas, ComboBox target) //, RowDefinition row)
         {
             using (new EventSuppressor(Suppress.This))
             {
@@ -76,13 +76,13 @@ namespace PRSDesktop
             }
         }
 
-        private bool GetTags(CoreTable tags, JobDocumentSetTagType type, ComboBox target) //, RowDefinition row)
+        private static bool GetTags(CoreTable tags, JobDocumentSetTagType type, ComboBox target) //, RowDefinition row)
         {
             using (new EventSuppressor(Suppress.This))
             {
-                Dictionary<Guid, String> result = new Dictionary<Guid, String>()
+                var result = new Dictionary<Guid, String>()
                 {
-                    { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" }
+                    { Guid.Empty, "" }
                 };
                 foreach (var tag in tags.Rows.Where(x => x.Get<JobDocumentSetTag, JobDocumentSetTagType>(x => x.Type).Equals(type)))
                     result[tag.Get<JobDocumentSetTag, Guid>(c => c.ID)] = tag.Get<JobDocumentSetTag, String>(c => c.Description);
@@ -123,20 +123,27 @@ namespace PRSDesktop
 
         private void LoadDocumentTags()
         {
-            MultiQuery query = new MultiQuery();
-            query.Add<JobDocumentSetTag>(
-                new Filter<JobDocumentSetTag>(x => x.Job.ID).IsEqualTo(Master?.ID ?? Guid.Empty),
-                null,
-                new SortOrder<JobDocumentSetTag>(x => x.Description)
-            );
-            query.Add<JobITP>(
-                new Filter<JobITP>(x => x.Job.ID).IsEqualTo(Master?.ID ?? Guid.Empty),
-                new Columns<JobITP>(x => x.ID).Add(x => x.Code).Add(x => x.Description),
-                new SortOrder<JobITP>(x => x.Code)
-            );
-            query.Query();
-
-            var tags = query.Get<JobDocumentSetTag>();
+            // Global tags
+            var tagFilter = new Filter<JobDocumentSetTag>(x => x.Job.ID).IsEqualTo(Guid.Empty);
+            if(Master is not null && Master.ID != Guid.Empty)
+            {
+                tagFilter = tagFilter.Or(x => x.Job.ID).IsEqualTo(Master.ID);
+            }
+
+            var results = Client.QueryMultiple(
+                new KeyedQueryDef<JobDocumentSetTag>(
+                    tagFilter,
+                    new Columns<JobDocumentSetTag>(x => x.ID)
+                        .Add(x => x.Type)
+                        .Add(x => x.Description),
+                    new SortOrder<JobDocumentSetTag>(x => x.Description)
+                    ),
+                new KeyedQueryDef<JobITP>(
+                    new Filter<JobITP>(x => x.Job.ID).IsEqualTo(Master?.ID ?? Guid.Empty),
+                    new Columns<JobITP>(x => x.ID).Add(x => x.Code).Add(x => x.Description),
+                    new SortOrder<JobITP>(x => x.Code)));
+
+            var tags = results.Get<JobDocumentSetTag>();
             /* Documents.DisciplineVisible = */
             GetTags(tags, JobDocumentSetTagType.Discipline, Discipline); //, DisciplineRow);
             /* Documents.TypeVisible = */
@@ -144,7 +151,7 @@ namespace PRSDesktop
             /* Documents.CategoryVisible = */
             GetTags(tags, JobDocumentSetTagType.Category, Category); //, CategoryRow);
             /* Documents.AreaVisible = */
-            GetAreas(query.Get<JobITP>(), Area); //, AreaRow);
+            GetAreas(results.Get<JobITP>(), Area); //, AreaRow);
         }
 
         public bool IsReady { get; set; }
@@ -271,7 +278,7 @@ namespace PRSDesktop
             };
             editor.Refresh(true, true);
             var window = new DynamicContentDialog(editor, false);
-            window.Title = $"{tagtype.ToString()} Document Tags";
+            window.Title = $"{tagtype} Document Tags";
             window.ShowDialog();
             LoadDocumentTags();
         }

+ 2 - 1
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTagEditor.cs

@@ -13,7 +13,8 @@ namespace PRSDesktop
 
         private Guid _jobid;
         public Guid JobID 
-        { get => _jobid;
+        {
+            get => _jobid;
             set
             {
                 _jobid = value;