|
@@ -4,9 +4,7 @@ using InABox.Core;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
-using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
-using XF.Material.Forms.UI.Dialogs;
|
|
|
using IDigitalFormInstance = InABox.Core.IDigitalFormInstance;
|
|
|
|
|
|
namespace PRS.Mobile
|
|
@@ -23,10 +21,7 @@ namespace PRS.Mobile
|
|
|
public Entity Entity { get; set; }
|
|
|
public bool ReadOnly { get; set; }
|
|
|
public bool NewForm { get; set; }
|
|
|
-
|
|
|
- public event OnDigitalFormHostModelSaved OnDigitalFormHostModelSaved;
|
|
|
- public event OnDigitalFormHostModelBeforeSave OnDigitalFormHostModelBeforeSave;
|
|
|
-
|
|
|
+
|
|
|
public DigitalFormHostModel()
|
|
|
{
|
|
|
DFLayout = new DFLayout();
|
|
@@ -70,23 +65,49 @@ namespace PRS.Mobile
|
|
|
|
|
|
if (DigitalFormDataModel.Instance.FormCompleted != DateTime.MinValue)
|
|
|
ReadOnly = true;
|
|
|
-
|
|
|
- DigitalFormDataModel.BeforeModelSaved += (m) =>
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void LoadItems(TEntity parent, Guid formid, TInstance instance, DigitalFormLayout? layout = null)
|
|
|
+ {
|
|
|
+ List<DigitalFormVariable> variables = new List<DigitalFormVariable>();
|
|
|
+
|
|
|
+ var loadLayout = Task.Run(() =>
|
|
|
{
|
|
|
- OnDigitalFormHostModelBeforeSave?.Invoke();
|
|
|
- DigitalFormDataModel.Entity = Entity;
|
|
|
- CheckEntity(SaveType.BeforeSave);
|
|
|
- };
|
|
|
-
|
|
|
- DigitalFormDataModel.OnModelSaved += async (m) =>
|
|
|
+ DigitalFormLayout = layout ?? QueryDigitalFormLayout(formid);
|
|
|
+ });
|
|
|
+
|
|
|
+ var getVariables = Task.Run(() =>
|
|
|
+ {
|
|
|
+ variables = QueryVariables(formid);
|
|
|
+ });
|
|
|
+
|
|
|
+ var loadDFDataModel = Task.Run(() =>
|
|
|
{
|
|
|
- var userResponseRequest = CheckEntity(SaveType.AfterSave);
|
|
|
- var response = await OnDigitalFormHostModelSaved?.Invoke(userResponseRequest);
|
|
|
- if (response == DigitalFormHostUserResponse.Yes)
|
|
|
- DoResponseActions(userResponseRequest);
|
|
|
- };
|
|
|
+ DigitalFormDataModel = new DigitalFormDataModel<TEntity, TEntityLink, TInstance>(parent, instance);
|
|
|
+ DigitalFormDataModel.Load(null);
|
|
|
+ Entity = DigitalFormDataModel.Entity;
|
|
|
+ });
|
|
|
+
|
|
|
+ Task.WaitAll(loadLayout, getVariables, loadDFDataModel);
|
|
|
+
|
|
|
+ DFLayout.LoadLayout(DigitalFormLayout.Layout);
|
|
|
+
|
|
|
+ DFLayout.LoadVariables(variables);
|
|
|
+
|
|
|
+ DigitalFormDataModel.Instance.Form.ID = DigitalFormLayout.Form.ID;
|
|
|
+
|
|
|
+ DigitalFormDataModel.Variables = variables.ToArray();
|
|
|
+
|
|
|
+ if (!string.IsNullOrWhiteSpace(DigitalFormDataModel.Instance.FormData))
|
|
|
+ NewForm = false;
|
|
|
+
|
|
|
+ if (DigitalFormDataModel.Instance.FormCompleted != DateTime.MinValue)
|
|
|
+ ReadOnly = true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private IDigitalFormInstance GetInstance(Guid iD)
|
|
|
{
|
|
|
return new Client<TInstance>().Query(
|
|
@@ -228,74 +249,8 @@ namespace PRS.Mobile
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- private void DoResponseActions(DigitalFormHostResponseRequest userResponseRequest)
|
|
|
- {
|
|
|
- if (userResponseRequest == DigitalFormHostResponseRequest.CloseKanban)
|
|
|
- {
|
|
|
- var kanban = Entity as Kanban;
|
|
|
- kanban.Category = "Complete";
|
|
|
- Task.Run(() => { new Client<Kanban>().Save(kanban, "Completed after completing all forms for task"); });
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private DigitalFormHostResponseRequest CheckEntity(SaveType saveType)
|
|
|
- {
|
|
|
- if (Entity.GetType() == typeof(Kanban))
|
|
|
- return DoKanbanActions(saveType);
|
|
|
- else if (Entity.GetType() == typeof(LeaveRequest))
|
|
|
- (Entity as LeaveRequest).EmployeeLink.ID = App.Data.Me.ID;
|
|
|
- return DigitalFormHostResponseRequest.None;
|
|
|
- }
|
|
|
-
|
|
|
- private DigitalFormHostResponseRequest DoKanbanActions(SaveType saveType)
|
|
|
- {
|
|
|
- if (saveType == SaveType.BeforeSave)
|
|
|
- CheckAndCreateKanban();
|
|
|
- else if (saveType == SaveType.AfterSave)
|
|
|
- {
|
|
|
- CheckSubscriber();
|
|
|
- return CheckKanbanForms();
|
|
|
- }
|
|
|
- return DigitalFormHostResponseRequest.None;
|
|
|
- }
|
|
|
-
|
|
|
- private DigitalFormHostResponseRequest CheckKanbanForms()
|
|
|
- {
|
|
|
- if (Entity.ID != Guid.Empty)
|
|
|
- {
|
|
|
- CoreTable table = new Client<KanbanForm>().Query(new Filter<KanbanForm>(x => x.Parent.ID).IsEqualTo(Entity.ID),
|
|
|
- new Columns<KanbanForm>(x => x.FormCompleted));
|
|
|
- if (table.Rows.Any())
|
|
|
- {
|
|
|
- List<DateTime> dates = new List<DateTime>();
|
|
|
- foreach (CoreRow row in table.Rows)
|
|
|
- {
|
|
|
- dates.Add(row.Get<KanbanForm, DateTime>(x => x.FormCompleted));
|
|
|
- }
|
|
|
- var incompletedates = dates.Where(x => x.Equals(DateTime.MinValue));
|
|
|
- if (!incompletedates.Any())
|
|
|
- {
|
|
|
- return DigitalFormHostResponseRequest.CloseKanban;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return DigitalFormHostResponseRequest.None;
|
|
|
- }
|
|
|
|
|
|
- private void CheckAndCreateKanban()
|
|
|
- {
|
|
|
- if (Entity.ID == Guid.Empty)
|
|
|
- {
|
|
|
- Kanban kanban = Entity as Kanban;
|
|
|
- kanban.EmployeeLink.ID = App.Data.Me.ID;
|
|
|
- kanban.DueDate = DateTime.Today;
|
|
|
- kanban.Title = "Form - " + DigitalFormLayout.Form.Description;
|
|
|
- kanban.Notes = new string[] { "Created by Forms App" };
|
|
|
- kanban.Category = "In Progress";
|
|
|
-
|
|
|
- Entity = kanban;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
private void CheckSubscriber()
|
|
|
{
|