|
|
@@ -11,6 +11,9 @@ using System.ComponentModel;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using InABox.Avalonia.Dialogs;
|
|
|
+using Avalonia;
|
|
|
+using DynamicData.Binding;
|
|
|
+using ReactiveUI;
|
|
|
|
|
|
namespace PRS.Avalonia.DigitalForms;
|
|
|
|
|
|
@@ -50,6 +53,8 @@ public interface IDigitalFormsHostViewModel : INotifyPropertyChanged
|
|
|
|
|
|
bool HasDocuments { get; }
|
|
|
|
|
|
+ DigitalFormViewer Viewer { get; }
|
|
|
+
|
|
|
DigitalFormDocumentModel Documents { get; }
|
|
|
|
|
|
Action<DFLoadStorage> LoadValues { set; }
|
|
|
@@ -136,6 +141,11 @@ public partial class DigitalFormsHostViewModel<TModel, TShell, TParent, TParentL
|
|
|
|
|
|
private bool _isChanged = false;
|
|
|
|
|
|
+ private bool _loaded = false;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DigitalFormViewer _viewer;
|
|
|
+
|
|
|
public DigitalFormsHostViewModel()
|
|
|
{
|
|
|
PrimaryMenu.Add(new(Images.save, SaveForm));
|
|
|
@@ -189,6 +199,8 @@ public partial class DigitalFormsHostViewModel<TModel, TShell, TParent, TParentL
|
|
|
|
|
|
protected override async Task<TimeSpan> OnRefresh()
|
|
|
{
|
|
|
+ if (_loaded) return TimeSpan.Zero;
|
|
|
+
|
|
|
await Task.WhenAll(
|
|
|
Model.RefreshAsync(DataAccess.Status == ConnectionStatus.Connected),
|
|
|
Documents.RefreshAsync(DataAccess.Status == ConnectionStatus.Connected));
|
|
|
@@ -259,18 +271,41 @@ public partial class DigitalFormsHostViewModel<TModel, TShell, TParent, TParentL
|
|
|
layout.LoadLayout(DigitalFormLayout.Layout);
|
|
|
layout.LoadVariables(Variables);
|
|
|
|
|
|
-
|
|
|
Dispatcher.UIThread.Invoke(() =>
|
|
|
{
|
|
|
- Layout = layout;
|
|
|
+ Viewer = new DigitalFormViewer
|
|
|
+ {
|
|
|
+ ReadOnly = ReadOnly
|
|
|
+ };
|
|
|
+ Viewer.Bind(DigitalFormViewer.EntityProperty, this.WhenChanged(x => x.Parent, (x, v) => v));
|
|
|
+ Viewer.Bind(DigitalFormViewer.FormProperty, this.WhenChanged(x => x.Form, (x, v) => v));
|
|
|
+ Viewer.FieldChanged += FieldChanged;
|
|
|
+ Viewer.Layout = layout;
|
|
|
+ SaveValues = Viewer.SaveValues;
|
|
|
+ LoadValues = Viewer.LoadValues;
|
|
|
+ Validate = () =>
|
|
|
+ {
|
|
|
+ if (Viewer.Validate(out var errors))
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return errors;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
LoadValues(DigitalForm.DeserializeFormData(Form) ?? new());
|
|
|
});
|
|
|
|
|
|
_isChanged = NewForm;
|
|
|
+ _loaded = true;
|
|
|
|
|
|
TimeStarted = DateTime.Now;
|
|
|
|
|
|
ProgressVisible = false;
|
|
|
+
|
|
|
return TimeSpan.Zero;
|
|
|
}
|
|
|
|