private async void CreateAccount_Clicked(object sender, EventArgs e) { _viewModel.SetIsBusy(true); btnCreateAccount.IsEnabled = false; FlowExecutionStateInstruction instruction = await FlowExecutionService.StartFlowWithData(RestConstants.CreateAccountFlowId, new DataPair[0], true); if (instruction == null) { _viewModel.SetIsBusy(false); btnCreateAccount.IsEnabled = true; Debug.WriteLine("Flow Execution Instruction was null"); return; } if (FlowExecutionService.IsShowFormType(instruction)) { // get the form JSON StandAloneFormSessionInfo formModel = await FormService.GetFormSessionSurfaceJson(instruction, true); // launch the view to render the form: FormViewModel formViewModel; formViewModel = new FormViewModel(formModel, instruction); if (formModel == null) { _viewModel.SetIsBusy(false); btnCreateAccount.IsEnabled = true; await DisplayAlert("Error", "Problem loading form data.", "OK"); return; } await Navigation.PushAsync(new FormPage(formViewModel, true)); } else { // throw a modal that the flow has been started await DisplayAlert("Workflow", $"Flow for Account creation has been started", "OK"); } btnCreateAccount.IsEnabled = true; _viewModel.SetIsBusy(false); }
private async void OnButtonClick(Button button, ChildElement elementData) { button.IsEnabled = false; IsBusy = true; try { string outcomePathName = elementData.Child.OutcomePathName; string validationMessage = ""; if (!FormService.Validate(controls, outcomePathName, out validationMessage)) { await DisplayAlert("Validation Issues", validationMessage, "OK"); return; } var data = FormUtils.CollectData(controls); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { DecisionsFormInfoEvent e = await FormService.SelectPath(viewModel.FormInfo.FormSessionInfoId, outcomePathName, data, useNamedSession); Debug.Write(e); if (e == null) { await DisplayAlert("Error", "Problem with next form instruction.", "OK"); return; } var validationMessages = e.GetValidationMessages(); if (validationMessages.Length > 0) { string message = ""; Array.ForEach(validationMessages, msg => message += $"{msg}.\n\n"); await DisplayAlert("Validation Issues", message, "OK"); // TODO highlight the offending components Array.ForEach(e.CurrentValidations, validation => { FormControlWrapper control; controls.TryGetValue(validation.ComponentID, out control); // just show breaking issues for cut 1: var breakingIssue = Array.Find(validation.ValidationIssues, issue => issue.BreakLevel == BreakLevel.Fatal); if (control != null && breakingIssue != null) { control.SetValidation(breakingIssue.BreakLevel); } }); } // if there were no validations to show, there should be next instructions if (e.IsFlowCompletedInstructionEvent()) { // Close this page. The flow's forms are done. viewModel.Submitted = true; await Navigation.PopAsync(); DependencyService.Get <ISnackbar>().ShortAlert("Form submitted successfully."); } else if (!String.IsNullOrEmpty(e.FlowTrackingId) && !String.IsNullOrEmpty(e.StepTrackingId)) { var flowInstr = await FlowExecutionService.GetInstructionsForStep(e.FlowTrackingId, e.StepTrackingId, useNamedSession); if (FlowExecutionService.IsShowFormType(flowInstr)) { // render the next form in this page. ShowNextForm(flowInstr); } else { // close this page? Not sure how we'd get here... Console.WriteLine("Found Next Instruction was not a form instruction!"); viewModel.Submitted = true; await Navigation.PopAsync(); DependencyService.Get <ISnackbar>().ShortAlert("Form submitted successfully."); if (useNamedSession) { MessagingCenter.Send(this, Message.ACCOUNT_CREATED); } } } else { // did I missunderstand the structure? Debug.WriteLine(e); } } else { if (viewModel.CanRunOffline) { var ret = await OfflineService.Instance.SaveOfflineFormSubmission(viewModel.ServiceCategoryId, data, outcomePathName, viewModel.FormInfo.FormRules); viewModel.Submitted = true; await Navigation.PopAsync(); DependencyService.Get <ISnackbar>().ShortAlert("Form saved, and will submit when online."); } else { await DisplayAlert("Error", "Connection lost. Please, try again later.", "OK"); } } } catch (Exception ex) { Debug.WriteLine("FormPage Submit---", ex.Message); await DisplayAlert("Error", "Something went wrong! Please try again later.", "OK"); } finally { IsBusy = false; button.IsEnabled = true; } }
async void OnItemSelected(object sender, SelectedItemChangedEventArgs args) { if (!(args.SelectedItem is Models.Workflow workflow)) { return; } viewModel.SetIsBusy(true); // show loader in case fetching action takes time if (Connectivity.NetworkAccess == NetworkAccess.Internet) { WorkFlowAction action = await(viewModel.DataStore as WorkflowStore).GetWorkflowActionAsync(workflow); Debug.WriteLine(action); // see if it's a flow we can run: if (action?.RunFlowId != null) { FlowExecutionStateInstruction instruction = await FlowExecutionService.StartFlowWithData(action.RunFlowId, new DataPair[0]); if (instruction == null) { Debug.WriteLine("Flow Execution Instruction was null"); DoneLaunching(); return; } if (FlowExecutionService.IsShowFormType(instruction)) { // get the form JSON StandAloneFormSessionInfo formModel = await FormService.GetFormSessionSurfaceJson(instruction); // launch the view to render the form: FormViewModel formViewModel; if (workflow.CanRunOffline) { formViewModel = new FormViewModel(formModel, instruction, true, workflow.ServiceCatalogId); } else { formViewModel = new FormViewModel(formModel, instruction); } if (formModel == null) { await DisplayAlert("Error", "Problem loading form data.", "OK"); DoneLaunching(); return; } DoneLaunching(); await Navigation.PushAsync(new FormPage(formViewModel)); } else { // throw a modal that the flow has been started DoneLaunching(); await DisplayAlert("Workflow", $"Flow for {workflow.EntityName} has been started", "OK"); } return; } // Otherwise, try to embed the result in a web-view var actionuUrl = action.WebViewUrl; viewModel.SetIsBusy(false); if (string.IsNullOrEmpty(actionuUrl)) { await DisplayAlert("Alert", "No valid action was found for this item", "OK"); return; } // Manually deselect item. WorkflowListView.SelectedItem = null; await Navigation.PushAsync(new DoWorkflowPage(workflow, actionuUrl)); } else { // get the form JSON var formInfos = await OfflineService.Instance.GetStandAloneFormSessionInfoAsync(workflow.ServiceCatalogId); if (formInfos == null || formInfos.Count <= 0) { await DisplayAlert("Error", "Problem loading form data.", "OK"); DoneLaunching(); return; } StandAloneFormSessionInfo formModel = formInfos[0]; FlowExecutionStateInstruction instruction = new FlowExecutionStateInstruction { FormTitle = workflow.EntityName }; FormViewModel formViewModel; if (workflow.CanRunOffline) { formViewModel = new FormViewModel(formModel, instruction, true, workflow.ServiceCatalogId); } else { formViewModel = new FormViewModel(formModel, instruction); } DoneLaunching(); await Navigation.PushAsync(new FormPage(formViewModel)); } }