Esempio n. 1
0
 /// <summary>
 /// View Model for showing a single form or page.
 /// </summary>
 public FormViewModel(StandAloneFormSessionInfo formInfo, FlowExecutionStateInstruction instruction, bool canRunOffline = false, string serviceCategoryId = "")
 {
     FormInfo          = formInfo;
     Title             = instruction.FormTitle ?? instruction.StepName;
     FlowTrackingId    = instruction.FlowTrackingId;
     StepTrackingId    = instruction.StepTrackingId;
     FlowId            = instruction.FlowId;
     CanRunOffline     = canRunOffline;
     ServiceCategoryId = serviceCategoryId;
 }
Esempio n. 2
0
        private async void ShowNextForm(FlowExecutionStateInstruction instruction)
        {
            // get the form JSON
            StandAloneFormSessionInfo formModel = await FormService.GetFormSessionSurfaceJson(instruction, useNamedSession);

            FormViewModel formViewModel = new FormViewModel(formModel, instruction);

            if (formModel == null)
            {
                await DisplayAlert("Error", "Problem loading form data.", "OK");

                return;
            }
            InitModel(formViewModel);
            RenderForm(formModel);
        }
        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);
        }
 public static bool IsShowFormType(FlowExecutionStateInstruction instruction)
 {
     return(!String.IsNullOrEmpty(instruction.FormId));
 }
Esempio n. 5
0
        // TODO dry these methods up with a good generic...

        public static async Task <StandAloneFormSessionInfo> GetFormSessionSurfaceJson(FlowExecutionStateInstruction instruction, bool useNamedSession = false)
        {
            Uri uri = await RestConstants.GetUriAsync(SERVICE_URL, "GetFormSessionSurfaceJson");

            try
            {
                FormServiceRequestBody requestBody = new FormServiceRequestBody
                {
                    UserContext       = useNamedSession ? new UserContext(RestConstants.NamedSessionId) : await AuthService.Instance.GetUserContextAsync(),
                    FormSessionInfoId = instruction.FormSessionId
                };

                var        serializedBody = RestConstants.SerializeBody(requestBody);
                HttpClient httpClient     = new HttpClient();
                var        response       = await httpClient.PostAsync(uri, serializedBody);

                if (response.IsSuccessStatusCode)
                {
                    var responseBody = await response.Content.ReadAsStringAsync();

                    var resultWrapper = JsonConvert.DeserializeObject <GetFormSessionSurfaceJsonResponse>(responseBody);
                    // we need $type field to specify component type in form data
                    // NewtonJson can't deserialize field which starts with '$', so we needed to replace it to get correct deserialization.
                    resultWrapper.GetFormSessionSurfaceJsonResult = resultWrapper.GetFormSessionSurfaceJsonResult.Replace("$type", "__type");
                    StandAloneFormSessionInfo info = JsonConvert.DeserializeObject <StandAloneFormSessionInfo>(
                        resultWrapper.GetFormSessionSurfaceJsonResult);

                    return(info);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"             ERROR {0}", ex.Message);
            }
            return(null);
        }
Esempio n. 6
0
        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));
            }
        }