|
@@ -1,5 +1,7 @@
|
|
|
-using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
+using Comal.Classes;
|
|
|
+using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using InABox.Avalonia;
|
|
|
+using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using PRS.Avalonia.Modules;
|
|
|
using System;
|
|
@@ -10,12 +12,36 @@ using System.Threading.Tasks;
|
|
|
|
|
|
namespace PRS.Avalonia.DigitalForms;
|
|
|
|
|
|
-public partial class DigitalFormsHostViewModel : ModuleViewModel
|
|
|
+public class DigitalFormCacheModel<TParent, TParentLink, TForm> : ISerializeBinary
|
|
|
+ where TParent : Entity, IRemotable, IPersistent, new()
|
|
|
+ where TParentLink : EntityLink<TParent>, new()
|
|
|
+ where TForm : EntityForm<TParent, TParentLink, TForm>, IRemotable, IPersistent, IDigitalFormInstance<TParentLink>, new()
|
|
|
{
|
|
|
- public override string Title => "WIP";
|
|
|
+ public TParent Parent { get; set; }
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
- private Entity _parent;
|
|
|
+ public TForm Form { get; set; }
|
|
|
+
|
|
|
+ public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
+ {
|
|
|
+ Parent = reader.ReadObject<TParent>();
|
|
|
+ Form = reader.ReadObject<TForm>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
+ {
|
|
|
+ writer.WriteObject(Parent);
|
|
|
+ writer.WriteObject(Form);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public partial class DigitalFormsHostViewModel<TModel, TShell, TParent, TParentLink, TForm> : ModuleViewModel
|
|
|
+ where TModel : DigitalFormInstanceModel<TModel, TShell, TForm>
|
|
|
+ where TShell : DigitalFormInstanceShell<TModel, TParent, TParentLink, TForm>, new()
|
|
|
+ where TParent : Entity, IRemotable, IPersistent, new()
|
|
|
+ where TParentLink : EntityLink<TParent>, new()
|
|
|
+ where TForm : EntityForm<TParent, TParentLink, TForm>, IRemotable, IPersistent, IDigitalFormInstance<TParentLink>, new()
|
|
|
+{
|
|
|
+ public override string Title => "WIP";
|
|
|
|
|
|
[ObservableProperty]
|
|
|
private Guid _formID;
|
|
@@ -23,37 +49,129 @@ public partial class DigitalFormsHostViewModel : ModuleViewModel
|
|
|
[ObservableProperty]
|
|
|
private Guid _instanceID;
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
+ private DigitalFormLayout _digitalFormLayout;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DigitalFormVariable[] _variables;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DigitalFormModel _model;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DigitalFormDocumentModel _documents;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private TParent _parent;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private TForm _form;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private DFLayout _layout = new();
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _newForm;
|
|
|
+
|
|
|
+ [ObservableProperty]
|
|
|
+ private bool _readOnly;
|
|
|
+
|
|
|
public event Action? OnSaved;
|
|
|
|
|
|
- public void Configure(Entity parent, Guid formID, Guid instanceID)
|
|
|
+ private string CacheFileName => $"{typeof(TForm)}.{InstanceID}";
|
|
|
+
|
|
|
+ public DigitalFormsHostViewModel()
|
|
|
+ {
|
|
|
+ PrimaryMenu.Add(new(Images.save, SaveForm));
|
|
|
+
|
|
|
+ ProgressVisible = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Configure(TParent parent, Guid formID, Entity instance)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Configure(TParent parent, Guid formID, Guid instanceID)
|
|
|
{
|
|
|
Parent = parent;
|
|
|
FormID = formID;
|
|
|
InstanceID = instanceID;
|
|
|
|
|
|
- // TODO: LoadItems; show loading screen or progress ring while loading.
|
|
|
+ Model = DigitalFormModel.CreateModel(DataAccess, Parent.GetType().Name);
|
|
|
+ Documents = new DigitalFormDocumentModel(DataAccess,
|
|
|
+ () => new Filter<DigitalFormDocument>(x => x.EntityLink.ID).IsEqualTo(FormID),
|
|
|
+ () => $"{nameof(DigitalFormDocument)}.{FormID}");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override async Task<TimeSpan> OnRefresh()
|
|
|
+ {
|
|
|
+ await Model.RefreshAsync(false);
|
|
|
+
|
|
|
+ Variables = Model.Variables.Where(x => x.FormID == FormID).Select(x => x.Entity).ToArray();
|
|
|
+ DigitalFormLayout = Model.Layouts.First().Entity;
|
|
|
+
|
|
|
+ if(DataAccess.Status == ConnectionStatus.Connected)
|
|
|
+ {
|
|
|
+ Parent = Client.Query(
|
|
|
+ new Filter<TParent>(x => x.ID).IsEqualTo(Parent.ID),
|
|
|
+ DFUtils.EntityColumns<TParent>(Variables))
|
|
|
+ .ToObjects<TParent>()
|
|
|
+ .First();
|
|
|
+ Form = Client.Query(
|
|
|
+ new Filter<TForm>(x => x.ID).IsEqualTo(InstanceID),
|
|
|
+ Columns.None<TForm>()
|
|
|
+ .Add(
|
|
|
+ x => x.ID,
|
|
|
+ x => x.Number,
|
|
|
+ x => x.FormData,
|
|
|
+ x => x.Form.ID,
|
|
|
+ x => x.Form.Description,
|
|
|
+ x => x.Form.DescriptionExpression,
|
|
|
+ x => x.FormCompleted,
|
|
|
+ x => x.FormCompletedBy.ID,
|
|
|
+ x => x.Created,
|
|
|
+ x => x.FormOpen,
|
|
|
+ x => x.BlobData))
|
|
|
+ .ToObjects<TForm>()
|
|
|
+ .First();
|
|
|
+ CacheManager.SaveBinary<DigitalFormCacheModel<TParent, TParentLink, TForm>>(CacheFileName, new()
|
|
|
+ {
|
|
|
+ Parent = Parent,
|
|
|
+ Form = Form
|
|
|
+ }, DateTime.MaxValue);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(CacheManager.TryLoadBinary<DigitalFormCacheModel<TParent, TParentLink, TForm>>(CacheFileName, out var model, out var _))
|
|
|
+ {
|
|
|
+ Parent = model.Parent;
|
|
|
+ Form = model.Form;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Layout.LoadLayout(DigitalFormLayout.Layout);
|
|
|
+ Layout.LoadVariables(Variables);
|
|
|
+
|
|
|
+ NewForm = Form.FormData.IsNullOrWhiteSpace();
|
|
|
+ ReadOnly = Form.FormCompleted != DateTime.MinValue;
|
|
|
+
|
|
|
+ ProgressVisible = false;
|
|
|
+ return TimeSpan.Zero;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<bool> SaveForm()
|
|
|
+ {
|
|
|
+ throw new NotImplementedException();
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Edit a form.
|
|
|
- /// </summary>
|
|
|
- /// <typeparam name="TParent"></typeparam>
|
|
|
- /// <typeparam name="TParentLink"></typeparam>
|
|
|
- /// <typeparam name="TForm"></typeparam>
|
|
|
- /// <param name="shell"></param>
|
|
|
- /// <param name="parent"></param>
|
|
|
- /// <param name="model">A model to refresh on saving, or <see langword="null"/>.</param>
|
|
|
- public static void EditForm<TParent, TParentLink, TForm>(IDigitalFormInstanceShell shell, TParent parent, ICoreRepository? model = null)
|
|
|
- where TParent : Entity, IRemotable, IPersistent, new()
|
|
|
- where TParentLink : EntityLink<TParent>, new()
|
|
|
- where TForm : Entity, IRemotable, IPersistent, IDigitalFormInstance<TParentLink>, new()
|
|
|
+ public static void EditForm(TModel model, TShell shell, TParent parent)
|
|
|
{
|
|
|
- Navigation.Navigate<DigitalFormsHostViewModel>(x =>
|
|
|
+ Navigation.Navigate<DigitalFormsHostViewModel<TModel, TShell, TParent, TParentLink, TForm>>(x =>
|
|
|
{
|
|
|
x.Configure(parent, shell.FormID, shell.ID);
|
|
|
x.OnSaved += () =>
|
|
|
{
|
|
|
- model?.RefreshAsync(true).ContinueWith(task =>
|
|
|
+ model.RefreshAsync(true).ContinueWith(task =>
|
|
|
{
|
|
|
if(task.Exception is not null)
|
|
|
{
|