private static T GetControlData <T>(ComponentContainer child, StandAloneFormSessionInfo info) { string name = child.DataName ?? child.ComponentId; return((T)Array.Find(info.InitialControlsData, data => data.Name.Equals(name))?.OutputValue); }
private Grid RenderGrid(ComponentContainer decisionsGrid, StandAloneFormSessionInfo info) { Grid grid = new Grid { Margin = decisionsGrid.MarginTop, RowSpacing = decisionsGrid.RowGap, ColumnSpacing = decisionsGrid.ColumnGap }; foreach (GridLayoutPart row in decisionsGrid.Rows) { grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(row.RequestedSize, FormUtils.GetGridUnitType(row.LayoutType)) }); } foreach (GridLayoutPart col in decisionsGrid.Columns) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(col.RequestedSize, FormUtils.GetGridUnitType(col.LayoutType)) }); } foreach (ChildElement element in decisionsGrid.Children) { View view = null; if (element.Child.ServerType.Contains("GridLayout") || element.Child.ServerType.Contains("SilverVerticalStack") || element.Child.ServerType.Contains("SilverHorizontalStack")) { view = RenderLayout(element.Child, info); } else { FormControlWrapper control = FormUtils.GetComponentView(element, info); view = control.View; // track elements by id: controls.Add(element.Child.ComponentId, control); // add any button handlers also during this iteration: if (control.GetType().Equals(typeof(ButtonControl))) { AddButtonHandler((ButtonControl)control); } else if (control.GetType().Equals(typeof(ImageButtonControl))) { AddImageButtonHandler((ImageButtonControl)control); } } grid.Children.Add(view, element.Column, element.Row); Grid.SetColumnSpan(view, element.ColumnSpan); Grid.SetRowSpan(view, element.RowSpan); } return(grid); }
private static bool GetRadioData <T>(ComponentContainer child, StandAloneFormSessionInfo info) { string name = child.ComponentId ?? child.DataName; //return (T)Array.Find(info.InitialControlsData, //data => data.Name.Equals(name)).OutputValue; return(true); }
public static TimePicker GetTimePicker(ComponentContainer child, StandAloneFormSessionInfo info) { TimePicker timePicker = new TimePicker(); string timeString = GetControlData <string>(child, info); var span = ParseTime(timeString); timePicker.Time = span; return(timePicker); }
public static Entry GetEntry(ComponentContainer child, StandAloneFormSessionInfo info) { string text = string.Empty, placeholder = string.Empty; Keyboard keyboard = Keyboard.Default; if (child.ServerType.Contains("SilverNumberBox")) { keyboard = Keyboard.Numeric; object t = GetControlData <object>(child, info); if (t != null) { if (child.OutputType == (byte)NumberBoxOutputType.Int) { int val = Convert.ToInt32(t); if (val != 0) { placeholder = text = val.ToString(); } else { placeholder = "0"; } } else { double val = Convert.ToDouble(t); if (val != 0) { placeholder = text = val.ToString(); } else { placeholder = "0"; } } } } else { text = GetControlData <string>(child, info); } Entry entry = new Entry() { // Text = child.Text, Text = text, Placeholder = placeholder, Keyboard = keyboard, IsPassword = child.ServerType.Contains("SilverPasswordBox") //TextColor = GetColor(silverLabel.Attributes.LabelColor), }; return(entry); }
public static CheckBoxView GetCheckBox(ComponentContainer child, StandAloneFormSessionInfo info) { CheckBoxView checkBox = new CheckBoxView() { IsChecked = GetControlData <bool>(child, info), Text = child.DataName }; return(checkBox); }
public static RadioButton GetRadioButton(ComponentContainer child, StandAloneFormSessionInfo info) { RadioButton radioButton = new RadioButton() { IsChecked = GetRadioData <bool>(child, info) //BackgroundColor silverButton. }; return(radioButton); }
public static Button GetImageButton(ComponentContainer child, StandAloneFormSessionInfo info) { Button imagebtn = new Button() { ImageSource = ImageSource.FromUri(new Uri(GetImageButtonData(child, info))), BackgroundColor = Color.Transparent }; return(imagebtn); }
public static Image GetImage(ComponentContainer child, StandAloneFormSessionInfo info) { Image image = new Image() { Source = GetImageData <string>(child, info), //BackgroundColor silverButton. }; return(image); }
/// <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; }
public static DataPair GetSelectedPickerOption(ComponentContainer child, StandAloneFormSessionInfo info, DataPair[] options) { var pair = Array.Find(info.InitialControlsData, data => data.Name.Equals(child.SelectedItemDataNameKey)); JArray outputValue = (JArray)pair.OutputValue; var tokens = outputValue.ToArray(); var selectedId = tokens.Length > 0 ? tokens.First().ToString() : ""; return(Array.Find(options, option => option.Name.Equals(selectedId))); }
public static Editor GetEditor(ComponentContainer child, StandAloneFormSessionInfo info) { Editor editor = new Editor() { Text = GetControlData <string>(child, info), //TextColor = GetColor(silverLabel.Attributes.LabelColor), }; return(editor); }
public static Label GetLabel(ComponentContainer child, StandAloneFormSessionInfo info) { Label label = new Label() { Text = child.Text, HorizontalTextAlignment = GetLabelHorizontalAlign(child.LabelAlignment), VerticalTextAlignment = GetLabelVerticalAlign(child.LabelVerticalAlignment), //TextColor = GetColor(silverLabel.Attributes.LabelColor), }; return(label); }
public static Slider GetSlider(ComponentContainer child, StandAloneFormSessionInfo info) { Slider slider = new Slider() { Minimum = child.Min ?? 0, Maximum = child.Max ?? 1, Value = GetControlData <double>(child, info), MaximumTrackColor = (Color)Application.Current.Resources["LightTextColor"] }; return(slider); }
public static Xamarin.Forms.Switch GetToggle(ComponentContainer child, StandAloneFormSessionInfo info) { Xamarin.Forms.Switch Switch = new Xamarin.Forms.Switch() { IsToggled = GetToggleData <bool>(child, info) // Text = child.Text,m // Text = GetControlData<string>(child, info) //TextColor = GetColor(silverLabel.Attributes.LabelColor), }; return(Switch); }
public static DatePicker GetDatePicker(ComponentContainer child, StandAloneFormSessionInfo info) { DatePicker datePicker = new DatePicker(); string dateString = GetControlData <string>(child, info); if (DateTime.TryParse(dateString, out DateTime date)) { datePicker.Date = date; } else { Console.Write($"Unable to parse date-string for control {child.DataName}"); } return(datePicker); }
private static string GetImageData <T>(ComponentContainer child, StandAloneFormSessionInfo info) { string name = child.ComponentId ?? child.ComponentName; string sessionid = info.FormSessionInfoId; string gen = Array.Find(info.InitialControlsData, data => data.Name.Equals(name)).OutputValue.ToString(); var uriTask = RestConstants.GetUriAsync("FormService", "GetFileStream?"); uriTask.Wait(); string url = uriTask.Result.AbsoluteUri + $"formSessionInfoId={sessionid}&componentId={name}&fileId=silverimagefile&downloadFile=true&gen={gen}"; return(url); }
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); }
// holdover from initial "offline" proof of concept, for reference. //private StandAloneFormSessionInfo LoadForm() //{ // // testing this as synchronous... because aysnc was swallowing errors... // StandAloneFormSessionInfo formList = ((FormsDataStore)viewModel.DataStore).GetGridSample() as StandAloneFormSessionInfo; // StandAloneFormSessionInfo info = formList; // derrrrrpp // RenderForm(info); // return info; //} private void RenderForm(StandAloneFormSessionInfo info) { // initialize collection: controls = new Dictionary <string, FormControlWrapper>(); // root container: ComponentContainer container = info.FormSurface.RootContainer; if (container.ServerType.Contains("SilverHorizontalStack")) { ((ScrollView)Content).HorizontalOptions = LayoutOptions.Fill; ((ScrollView)Content).Orientation = ScrollOrientation.Horizontal; } ((ScrollView)Content).Content = RenderLayout(container, info); // tell the sever we're done loading the form; _ = FormService.FormLoadComplete(info.FormSessionInfoId); }
public static DataPair[] GetRadioButtonListOptions(ComponentContainer child, StandAloneFormSessionInfo info) { child.DataName = null; var obj = GetControlData <object>(child, info); var arrayOfObject = ((IEnumerable)obj).Cast <object>().ToArray(); var dict = new Dictionary <string, string>(); DataPair[] options = new DataPair[arrayOfObject.Length]; // it's giving me such casting trouble here, because // these are still NewtonSoft Json objects, so we need to re-deserilze them for (int i = 0; i < arrayOfObject.Length; i++) { var stringObj = JsonConvert.SerializeObject(arrayOfObject[i]); options[i] = JsonConvert.DeserializeObject <DataPair>(stringObj); } return(options); }
private StackLayout RenderStackLayout(ComponentContainer decisionsLayout, StandAloneFormSessionInfo info, StackOrientation orientation) { StackLayout layout = new StackLayout { Orientation = orientation, }; foreach (var element in decisionsLayout.Children) { View view = null; if (element.Child.ServerType.Contains("GridLayout") || element.Child.ServerType.Contains("SilverVerticalStack") || element.Child.ServerType.Contains("SilverHorizontalStack")) { view = RenderLayout(element.Child, info); } else { FormControlWrapper control = FormUtils.GetComponentView(element, info); view = control.View; // track elements by id: controls.Add(element.Child.ComponentId, control); // add any button handlers also during this iteration: if (control.GetType().Equals(typeof(ButtonControl))) { AddButtonHandler((ButtonControl)control); } else if (control.GetType().Equals(typeof(ImageButtonControl))) { AddImageButtonHandler((ImageButtonControl)control); } } if (orientation == StackOrientation.Horizontal) { view.VerticalOptions = LayoutOptions.Start; } layout.Children.Add(view); } return(layout); }
private View RenderLayout(ComponentContainer container, StandAloneFormSessionInfo info) { if (container.ServerType.Contains("GridLayout")) { return(RenderGrid(container, info)); } else if (container.ServerType.Contains("SilverHorizontalStack")) { return(RenderStackLayout(container, info, StackOrientation.Horizontal)); } else if (container.ServerType.Contains("SilverVerticalStack")) { return(RenderStackLayout(container, info, StackOrientation.Vertical)); } else { return(new Grid()); } }
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); }
// 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); }
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)); } }
// TODO fix these Child -> ChildChild names... public static FormControlWrapper GetComponentView(ChildElement element, StandAloneFormSessionInfo info) { ComponentContainer child = element.Child; if (child.ServerType.Contains("SilverImage")) { switch (child.ComponentName) { case "Image": return(new ImageControl(element, GetImage(child, info))); case "Image Button": return(new ImageButtonControl(element, GetImageButton(child, info))); } // Textbox maps to Image https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.Image } if (child.ServerType.Contains("SilverToggleButton")) { // https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/checkbox return(new ToggleControl(element, GetToggle(child, info))); } /* * if (child.ComponentName.Contains("RadioButton")) * { * // Textbox maps to RadioButton https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.RadioButton * return new RadioButtonControl(element, GetRadioButton(child, info)); * } */ if (child.ServerType.Contains("SilverRadioButtonList")) { var options = GetRadioButtonListOptions(child, info); var selectedOption = GetSelectedRadioButtonListOption(child, info, options); var control = new RadioListControl(element, GetRadioButtonListView(child, options), options); if (selectedOption != null) { control.SetSelected(selectedOption); } return(control); } if (child.ServerType.Contains("SilverButton")) { // Button maps to Button https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/button return(new ButtonControl(element, GetButton(child))); } if (child.ServerType.Contains("SilverLabel")) { // Label maps to Label https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/label return(new LabelControl(element, GetLabel(child, info))); } if (child.ServerType.Contains("SilverTextArea,")) { // Text Area gets mapped to Editor https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/editor return(new TextAreaControl(element, GetEditor(child, info))); } if (child.ServerType.Contains("SilverDatePicker")) { // Datepicker https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.datepicker return(new DateControl(element, GetDatePicker(child, info))); } if (child.ServerType.Contains("SilverTimePicker")) { // TimePicker https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.timepicker return(new TimePickerControl(element, GetTimePicker(child, info))); } if (child.ServerType.Contains("SilverTextBox")) { // Textbox maps to Entry https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.entry return(new TextBoxControl(element, GetEntry(child, info))); } if (child.ServerType.Contains("SilverNumberBox")) { return(new TextBoxControl(element, GetEntry(child, info))); } if (child.ServerType.Contains("SilverCheckBox")) { // Textbox maps to Checkbox https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.Checkbox return(new CheckBoxControl(element, GetCheckBox(child, info))); } //if (child.ComponentName.Replace(" ", string.Empty) == "ImageButton") //{ // return new ImageButtonControl(element, GetImageButton(child, info)); //} if (child.ServerType.Contains("SilverCombo")) { // Dropdown maps to https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.picker var options = GetPickerOptions(child, info); var selectedOption = GetSelectedPickerOption(child, info, options); var control = new ComboControl(element, GetPicker(child, options), options); if (selectedOption != null) { control.SetSelected(selectedOption); } return(control); } if (child.ServerType.Contains("SilverSlider")) { return(new SliderControl(element, GetSlider(child, info))); } // Slider https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.slider // Checkbox maps to Checkbox https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/checkbox if (child.ServerType.Contains("SilverPasswordBox")) { return(new TextBoxControl(element, GetEntry(child, info))); } return(new LabelControl(element, new Label() { Text = "Not yet implemented." } )); }
private static string GetImageButtonData(ComponentContainer child, StandAloneFormSessionInfo info) { return(ImageHelper.GetImageInfoUrl(child.ImageInfo)); }