Browse Source

wpf: StagingSetouts now populate multi-images if the variable type is MultiImage

Kenric Nugteren 4 days ago
parent
commit
cb9a8b852a
1 changed files with 41 additions and 9 deletions
  1. 41 9
      prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

+ 41 - 9
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -395,6 +395,13 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
         var variable = PanelSettings.FormVariable;
         if (string.IsNullOrEmpty(variable)) return;
 
+        var fieldType = Client.Query(
+            Filter<DigitalFormVariable>.Where(x => x.Form.ID).IsEqualTo(form.Form.ID)
+                .And(x => x.Code).IsEqualTo(variable),
+            Columns.None<DigitalFormVariable>().Add(x => x.VariableType))
+            .ToObjects<DigitalFormVariable>().FirstOrDefault()?.FieldType();
+        if (fieldType is null) return;
+
         var doc = Client.Query(
             Filter<Document>.Where(x => x.ID).InQuery(
                 Filter<StagingSetoutDocument>.Where(x => x.EntityLink.ID).IsEqualTo(setout.ID),
@@ -404,18 +411,43 @@ public class StagingSetoutGrid : DynamicDataGrid<StagingSetout>
             .ToObjects<Document>().FirstOrDefault();
         if (doc?.Data is null || doc.Data.Length == 0) return;
 
-        var bytes = ImageUtils.PDFToBitmap(doc.Data, 0);
-
         var storage = DigitalForm.DeserializeFormSaveData(form) ?? new();
 
-        var value = new DFLayoutEmbeddedMediaValue
+        if(fieldType == typeof(DFLayoutEmbeddedImage))
         {
-            Data = bytes,
-            ID = DigitalFormDocumentFactory.SaveDocument(bytes),
-            Thumbnail = ImageUtils.GetPDFThumbnail(doc.Data, 200, 200)
-        };
-        var entry = storage.GetEntry(variable);
-        value.Serialize(entry);
+            var bytes = ImageUtils.PDFToBitmap(doc.Data, 0);
+
+            var value = new DFLayoutEmbeddedMediaValue
+            {
+                Data = bytes,
+                ID = DigitalFormDocumentFactory.SaveDocument(bytes),
+                Thumbnail = ImageUtils.GetPDFThumbnail(doc.Data, 200, 200)
+            };
+            var entry = storage.GetEntry(variable);
+            value.Serialize(entry);
+        }
+        else if(fieldType == typeof(DFLayoutMultiImage))
+        {
+            var values = new DFLayoutEmbeddedMediaValues();
+            var images = ImageUtils.PDFToByteArrays(doc.Data);
+            var thumbnails = ImageUtils.GetPDFThumbnails(doc.Data, 200, 200);
+            var i = 0;
+            foreach(var image in images)
+            {
+                var thumbnail = i < thumbnails.Length ? thumbnails[i] : null;
+                var value = new DFLayoutEmbeddedMediaValue
+                {
+                    Data = image,
+                    ID = DigitalFormDocumentFactory.SaveDocument(image),
+                    Thumbnail = thumbnail
+                };
+                values.Add(value);
+
+                ++i;
+            }
+            var entry = storage.GetEntry(variable);
+            values.Serialize(entry);
+        }
 
         DigitalForm.SerializeFormData(form, storage);
     }