Exemple #1
0
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            DateInput input = (DateInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var datePicker = new DatePicker();
                datePicker.ToolTip = input.Placeholder;
                DateTime value;
                if (DateTime.TryParse(input.Value, out value))
                {
                    datePicker.SelectedDate = value;
                }
                DateTime minValue;
                if (DateTime.TryParse(input.Min, out minValue))
                {
                    datePicker.DisplayDateStart = minValue;
                }
                DateTime maxValue;
                if (DateTime.TryParse(input.Max, out maxValue))
                {
                    datePicker.DisplayDateEnd = maxValue;
                }
                datePicker.Style       = context.GetStyle("Adaptive.Input.Date");
                datePicker.DataContext = input;
                context.InputBindings.Add(input.Id, () => datePicker.Text);
                return(datePicker);
            }
            else
            {
                var textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            TimeInput input = (TimeInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var      timePicker = new TimePicker();
                DateTime value;
                if (DateTime.TryParse(input.Value, out value))
                {
                    timePicker.Value = value;
                }
                TimeSpan minValue;
                if (TimeSpan.TryParse(input.Min, out minValue))
                {
                    timePicker.EndTime = minValue;
                }
                TimeSpan maxValue;
                if (TimeSpan.TryParse(input.Max, out maxValue))
                {
                    timePicker.EndTime = maxValue;
                }
                timePicker.Watermark   = input.Placeholder;
                timePicker.Style       = context.GetStyle("Adaptive.Input.Time");
                timePicker.DataContext = input;
                context.InputBindings.Add(input.Id, () => timePicker.Text);
                return(timePicker);
            }
            else
            {
                var textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            DateInput input = (DateInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var textBox = new TextBox()
                {
                    Text = input.Value
                };
                textBox.SetPlaceholder(input.Placeholder);
                textBox.Style = context.GetStyle($"Adaptive.Input.Text.Date");
                textBox.SetContext(input);
                context.InputBindings.Add(input.Id, () => textBox.Text);
                return(textBox);
            }
            else
            {
                Container container = TypedElementConverter.CreateElement <Container>();
                container.Separation = input.Separation;
                TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                container.Items.Add(textBlock);
                if (input.Value != null)
                {
                    textBlock       = TypedElementConverter.CreateElement <TextBlock>();
                    textBlock.Text  = input.Value;
                    textBlock.Color = TextColor.Accent;
                    textBlock.Wrap  = true;
                    container.Items.Add(textBlock);
                }
                return(context.Render(container));
            }
        }
 public static FrameworkElement Render(SubmitAction action, RenderContext context)
 {
     if (context.Config.SupportsInteractivity)
     {
         Button uiButton = XamlUtilities.CreateActionButton(action, context); // content
         uiButton.Click += (sender, e) =>
         {
             try
             {
                 dynamic data = (action.Data != null) ? ((JToken)action.Data).DeepClone() : new JObject();
                 data = context.MergeInputData(data);
                 context.Action(uiButton, new ActionEventArgs()
                 {
                     Action = action, Data = data
                 });
             }
             catch (MissingInputException err)
             {
                 context.MissingInput(action, new MissingInputEventArgs(err.Input, err.FrameworkElement));
             }
         };
         return(uiButton);
     }
     return(null);
 }
        public static FrameworkElement Render(NumberInput input, RenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                IntegerUpDown numberPicker = new IntegerUpDown();
                // numberPicker.ShowButtonSpinner = true;

                if (!Double.IsNaN(input.Value))
                {
                    numberPicker.Value = Convert.ToInt32(input.Value);
                }

                if (!Double.IsNaN(input.Min))
                {
                    numberPicker.Minimum = Convert.ToInt32(input.Min);
                }

                if (!Double.IsNaN(input.Max))
                {
                    numberPicker.Minimum = Convert.ToInt32(input.Max);
                }

                numberPicker.Watermark   = input.Placeholder;
                numberPicker.Style       = context.GetStyle("Adaptive.Input.Number");
                numberPicker.DataContext = input;
                context.InputBindings.Add(input.Id, () => numberPicker.Value?.ToString());
                return(numberPicker);
            }
            else
            {
                var textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
        public static FrameworkElement Render(TextInput input, RenderContext context)
        {
            if (context.Config.SupportsInteractivity)
            {
                var textBox = new WatermarkTextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
                    textBox.TextWrapping  = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                }
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }

                textBox.Watermark   = input.Placeholder;
                textBox.Style       = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.DataContext = input;
                context.InputBindings.Add(input.Id, () => textBox.Text);
                return(textBox);
            }
            else
            {
                var textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                return(context.Render(textBlock));
            }
        }
Exemple #7
0
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            TextInput input = (TextInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var textBox = new TextBox()
                {
                    Text = input.Value
                };
                if (input.IsMultiline == true)
                {
                    textBox.AcceptsReturn = true;
#if WPF
                    textBox.TextWrapping = TextWrapping.Wrap;
                    textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
#elif XAMARIN
                    // TODO
#endif
                }
#if WPF
                if (input.MaxLength > 0)
                {
                    textBox.MaxLength = input.MaxLength;
                }
#elif XAMARIN
                // TODO
#endif
                textBox.SetPlaceholder(input.Placeholder);
                textBox.Style = context.GetStyle($"Adaptive.Input.Text.{input.Style}");
                textBox.SetContext(input);
                context.InputBindings.Add(input.Id, () => textBox.Text);
                return(textBox);
            }
            else
            {
                Container container = TypedElementConverter.CreateElement <Container>();
                container.Separation = input.Separation;
                TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;
                container.Items.Add(textBlock);
                if (input.Value != null)
                {
                    textBlock       = TypedElementConverter.CreateElement <TextBlock>();
                    textBlock.Text  = input.Value;
                    textBlock.Color = TextColor.Accent;
                    textBlock.Wrap  = true;
                    container.Items.Add(textBlock);
                }
                return(context.Render(container));
            }
        }
 public static FrameworkElement Render(OpenUrlAction action, RenderContext context)
 {
     if (context.Config.SupportsInteractivity)
     {
         Button uiButton = XamlUtilities.CreateActionButton(action, context); // content);
         uiButton.Click += (sender, e) =>
         {
             context.Action(uiButton, new ActionEventArgs()
             {
                 Action = action
             });
         };
         return(uiButton);
     }
     return(null);
 }
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            ShowCardAction action = (ShowCardAction)element;

            if (context.Config.SupportsInteractivity)
            {
                Button uiButton = XamlUtilities.CreateActionButton(action, context);
                uiButton.Click += (sender, e) =>
                {
                    context.Action(uiButton, new ActionEventArgs()
                    {
                        Action = action, Data = null
                    });
                };
                return(uiButton);
            }
            return(null);
        }
Exemple #10
0
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            ToggleInput input = (ToggleInput)element;

            if (context.Config.SupportsInteractivity)
            {
                var uiToggle = new CheckBox();
#if WPF
                // TODO: Finish switch
                uiToggle.Content = input.Title;
#endif
                uiToggle.SetState(input.Value == (input.ValueOn ?? "true"));
                uiToggle.Style = context.GetStyle($"Adaptive.Input.Toggle");
                uiToggle.SetContext(input);
                context.InputBindings.Add(input.Id, () =>
                {
                    return(uiToggle.GetState() == true ? input.ValueOn ?? "true" : input.ValueOff ?? "false");
                });
                return(uiToggle);
            }
            else
            {
                Container container = TypedElementConverter.CreateElement <Container>();
                container.Separation = input.Separation;

                TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input);
                container.Items.Add(textBlock);
                if (input.Value != null)
                {
                    textBlock       = TypedElementConverter.CreateElement <TextBlock>();
                    textBlock.Text  = (input.Value == (input.ValueOn ?? "true")) ? input.ValueOn ?? "selected" : input.ValueOff ?? "not selected";
                    textBlock.Color = TextColor.Accent;
                    textBlock.Wrap  = true;
                    container.Items.Add(textBlock);
                }
                return(context.Render(container));
            }
        }
Exemple #11
0
        public static FrameworkElement Render(TypedElement element, RenderContext context)
        {
            HttpAction action = (HttpAction)element;

            if (context.Config.SupportsInteractivity)
            {
                Button uiButton = XamlUtilities.CreateActionButton(action, context);
                uiButton.Click += (sender, e) =>
                {
                    dynamic data = new JObject();
                    try
                    {
                        data = context.MergeInputData(data);

                        string body = (string)action.Body?.ToString() ?? String.Empty;

                        context.Action(uiButton, new ActionEventArgs()
                        {
                            Action = new HttpAction()
                            {
                                Title   = action.Title,
                                Method  = action.Method,
                                Url     = RendererUtilities.BindData(data, action.Url, url: true),
                                Headers = action.Headers,
                                Body    = RendererUtilities.BindData(data, body),
                            },
                            Data = data
                        });
                    }
                    catch (MissingInputException err)
                    {
                        context.MissingInput(action, new MissingInputEventArgs(err.Input, err.FrameworkElement));
                    }
                };
                return(uiButton);
            }
            return(null);
        }
        public static FrameworkElement Render(ChoiceSet choiceSet, RenderContext context)
        {
            var chosen = choiceSet.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

#if WPF
            if (context.Config.SupportsInteractivity)
            {
                var uiGrid = new Grid();
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                var uiComboBox = new ComboBox();
                uiComboBox.Style       = context.GetStyle("Adaptive.Input.ChoiceSet.ComboBox");
                uiComboBox.DataContext = choiceSet;

                var uiChoices = new ListBox();
                ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled);
                var itemsPanelTemplate = new ItemsPanelTemplate();
                var factory            = new FrameworkElementFactory(typeof(WrapPanel));
                itemsPanelTemplate.VisualTree = factory;
                uiChoices.ItemsPanel          = itemsPanelTemplate;
                uiChoices.DataContext         = choiceSet;
                uiChoices.Style = context.GetStyle("Adaptive.Input.ChoiceSet");

                foreach (var choice in choiceSet.Choices)
                {
                    if (choiceSet.IsMultiSelect == true)
                    {
                        var uiCheckbox = new CheckBox();
                        uiCheckbox.Content     = choice.Title;
                        uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                        uiCheckbox.DataContext = choice;
                        uiCheckbox.Style       = context.GetStyle("Adaptive.Input.ChoiceSet.CheckBox");
                        uiChoices.Items.Add(uiCheckbox);
                    }
                    else
                    {
                        if (choiceSet.Style == ChoiceInputStyle.Compact)
                        {
                            var uiComboItem = new ComboBoxItem();
                            uiComboItem.Style       = context.GetStyle("Adaptive.Input.ChoiceSet.ComboBoxItem");
                            uiComboItem.Content     = choice.Title;
                            uiComboItem.DataContext = choice;
                            uiComboBox.Items.Add(uiComboItem);
                            if (chosen.Contains(choice.Value))
                            {
                                uiComboBox.SelectedItem = uiComboItem;
                            }
                        }
                        else
                        {
                            var uiRadio = new RadioButton();
                            uiRadio.Content     = choice.Title;
                            uiRadio.IsChecked   = chosen.Contains(choice.Value);
                            uiRadio.GroupName   = choiceSet.Id;
                            uiRadio.DataContext = choice;
                            uiRadio.Style       = context.GetStyle("Adaptive.Input.ChoiceSet.Radio");
                            uiChoices.Items.Add(uiRadio);
                        }
                    }
                }
                context.InputBindings.Add(choiceSet.Id, () =>
                {
                    if (choiceSet.IsMultiSelect == true)
                    {
                        string values = string.Empty;
                        foreach (var item in uiChoices.Items)
                        {
                            CheckBox checkBox = (CheckBox)item;
                            Choice choice     = checkBox.DataContext as Choice;
                            if (checkBox.IsChecked == true)
                            {
                                values += (values == string.Empty ? "" : ",") + choice.Value;
                            }
                        }
                        return(values);
                    }
                    else
                    {
                        if (choiceSet.Style == ChoiceInputStyle.Compact)
                        {
                            ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                            if (item != null)
                            {
                                Choice choice = item.DataContext as Choice;
                                return(choice.Value);
                            }
                            return(null);
                        }
                        else
                        {
                            foreach (var item in uiChoices.Items)
                            {
                                RadioButton radioBox = (RadioButton)item;
                                Choice choice        = radioBox.DataContext as Choice;
                                if (radioBox.IsChecked == true)
                                {
                                    return(choice.Value);
                                }
                            }
                            return(null);
                        }
                    }
                });
                if (choiceSet.Style == ChoiceInputStyle.Compact)
                {
                    Grid.SetRow(uiComboBox, 1);
                    uiGrid.Children.Add(uiComboBox);
                    return(uiGrid);
                }
                else
                {
                    Grid.SetRow(uiChoices, 1);
                    uiGrid.Children.Add(uiChoices);
                    return(uiGrid);
                }
            }
#endif

            string choiceText = XamlUtilities.GetFallbackText(choiceSet);
            if (choiceText == null)
            {
                List <string> choices = choiceSet.Choices.Select(choice => choice.Title).ToList();
                if (choiceSet.Style == ChoiceInputStyle.Compact)
                {
                    if (choiceSet.IsMultiSelect)
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}";
                    }
                    else
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}";
                    }
                }
                else // if (choiceSet.Style == ChoiceInputStyle.Expanded)
                {
                    choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}";
                }
            }
            Container container = TypedElementConverter.CreateElement <Container>();
            container.Separation = choiceSet.Separation;
            TextBlock textBlock = TypedElementConverter.CreateElement <TextBlock>();
            textBlock.Text = choiceText;
            textBlock.Wrap = true;
            container.Items.Add(textBlock);

            textBlock       = TypedElementConverter.CreateElement <TextBlock>();
            textBlock.Text  = RendererUtilities.JoinString(choiceSet.Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and ");
            textBlock.Color = TextColor.Accent;
            textBlock.Wrap  = true;
            container.Items.Add(textBlock);
            return(context.Render(container));
        }