public ConditionViewModel(QueryCondition conditionObject, string recordType, IRecordService recordService, IApplicationController controller)
            : base(FormController.CreateForObject(conditionObject, controller, recordService, optionSetLimitedvalues: new Dictionary<string, IEnumerable<string>> { { nameof(QueryCondition.FieldName), GetValidFields(recordType, recordService) } }))
        {
            _queryCondition = conditionObject;
            _queryConditionRecord = new ObjectRecord(conditionObject);

            var metadata = FormService.GetFormMetadata(GetRecord().Type, RecordService);
            var sections = metadata.FormSections;
            var firstSection = sections.First();
            var sectionViewModel = new FieldSectionViewModel(
                        (FormFieldSection)firstSection,
                        this
                        );
            FormFieldSection = sectionViewModel;
            OnLoad();
        }
Beispiel #2
0
        public virtual void LoadFormSections()
        {
            var verifyConnection = RecordService.VerifyConnection();

            if (!verifyConnection.IsValid)
            {
                ValidationPrompt                = $"This Form Could Not Be Loaded Due To A Connection Error\n\n{string.Join("\n" ,verifyConnection.InvalidReasons)}";
                LoadingViewModel.IsLoading      = false;
                BackButtonViewModel.IsVisible   = OnBack != null;
                CancelButtonViewModel.IsVisible = OnCancel != null;
                ApplicationController.LogEvent("Loading Form Connection Error", new Dictionary <string, string>
                {
                    { "Is Error", true.ToString() },
                    { "Record Type", GetRecordType() }
                });
            }
            else
            {
                //forcing enumeration up front
                var sections          = FormService.GetFormMetadata(RecordType, RecordService).FormSections.ToArray();
                var sectionViewModels = new List <SectionViewModelBase>();
                //Create the section view models

                foreach (var section in sections)
                {
                    if (section is FormFieldSection ffs)
                    {
                        var sectionVm = new FieldSectionViewModel(
                            ffs,
                            this
                            );
                        sectionVm.IsVisible = ffs.FormFields.Any(f => FormService.IsFieldInContext(f.FieldName, GetRecord()));
                        sectionViewModels.Add(sectionVm);
                    }
                }
                //now set the section view model property in the ui thread which will notify the ui with the sections
                DoOnMainThread(
                    () =>
                {
                    FormSectionsAsync = new ObservableCollection <SectionViewModelBase>(sectionViewModels);
                    OnSectionLoaded();
                });
            }
        }