Ejemplo n.º 1
0
        public static FrameworkElement Render(AdaptiveTimeInput input, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity)
            {
                AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;

                return(context.Render(textBlock));
            }

            TimePicker timePicker = new TimePicker
            {
                DataContext = input,
                ToolTip     = input.Placeholder,
                Style       = context.GetStyle("Adaptive.Input.Time"),
                Is24Hours   = true
            };

            if (DateTime.TryParse(input.Value, out DateTime value))
            {
                timePicker.SelectedTime = value;
            }

            context.InputBindings.Add(input.Id, () => timePicker.SelectedTime?.ToString("HH:mm") ?? "");

            return(timePicker);
        }
        public static void Create(AdaptiveOpenUrlAction action, HtmlTag tag, AdaptiveRenderContext renderContext)
        {
            tag.Attr("id", AdaptiveCardRenderer.GenerateRandomId());
            tag.Attr("data-ac-url", action.Url);

            tag.Attributes.Add("onclick", "window.blazorAdaptiveCards.openUrl(this.getAttribute('data-ac-url'), this)");
        }
Ejemplo n.º 3
0
            public UIElement Render(IAdaptiveActionElement action, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
            {
                RadioButton customActionRadioButton = new RadioButton();

                customActionRadioButton.Name = "CustomActionRadioButton";
                return(customActionRadioButton);
            }
Ejemplo n.º 4
0
            public UIElement Render(IAdaptiveActionElement action, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
            {
                RadioButton submitActionRadioButton = new RadioButton();

                submitActionRadioButton.Name = "SubmitActionRadioButton";
                return(submitActionRadioButton);
            }
Ejemplo n.º 5
0
        public static FrameworkElement Render(MyCustomInput input, AdaptiveRenderContext context)
        {
            var textBox = new TextBox();

            textBox.Text = input.Value;
            context.InputBindings.Add(input.Id, () => textBox.Text);

            return(textBox);
        }
Ejemplo n.º 6
0
        public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
        {
            UIElement renderedOriginalInput = m_originalRenderer.Render(element, context, renderArgs);

            if (renderedOriginalInput != null)
            {
                try
                {
                    var input = element as AdaptiveTextInput;
                    if (input != null)
                    {
                        JsonObject inlineAction = input.AdditionalProperties.GetNamedObject("inlineAction");
                        if (inlineAction != null)
                        {
                            string icon = inlineAction.GetNamedString("iconUrl");
                            if (icon != null)
                            {
                                var renderedIcon = new Image()
                                {
                                    Source  = new BitmapImage(new Uri(icon)),
                                    Width   = 30,
                                    Height  = 30,
                                    Stretch = Windows.UI.Xaml.Media.Stretch.Uniform,
                                    Margin  = new Thickness(12, 0, 0, 0)
                                };
                                Grid.SetColumn(renderedIcon, 1);

                                return(new Grid()
                                {
                                    ColumnDefinitions =
                                    {
                                        new ColumnDefinition()
                                        {
                                            Width = new GridLength(1, GridUnitType.Star)
                                        },
                                        new ColumnDefinition()
                                        {
                                            Width = GridLength.Auto
                                        }
                                    },
                                    Children =
                                    {
                                        renderedOriginalInput,
                                        renderedIcon
                                    }
                                });
                            }
                        }
                    }
                }
                catch { }
            }

            return(renderedOriginalInput);
        }
Ejemplo n.º 7
0
        public static void Create(AdaptiveShowCardAction action, HtmlTag tag, AdaptiveRenderContext renderContext)
        {
            tag.Attr("id", AdaptiveCardRenderer.GenerateRandomId());

            var targetId = AdaptiveCardRenderer.GenerateRandomId();

            tag.Attr("data-ac-showCardId", targetId);

            tag.Attributes.Add("onclick",
                               $"document.getElementById('{targetId}').style.display === 'none' ? document.getElementById('{targetId}').style.display = '' : document.getElementById('{targetId}').style.display = 'none';");
        }
Ejemplo n.º 8
0
        public void BleedProperty()
        {
            var renderContext = new AdaptiveRenderContext(
                new AdaptiveHostConfig(),
                new AdaptiveElementRenderers <HtmlTag, AdaptiveRenderContext>());

            renderContext.ElementRenderers.Set <AdaptiveContainer>(TestHtmlRenderer.CallContainerRender);
            renderContext.RenderArgs.ParentStyle = AdaptiveContainerStyle.Default;

            var containerWithWorkingBleed = new AdaptiveContainer
            {
                Style = AdaptiveContainerStyle.Default,
                Items = new System.Collections.Generic.List <AdaptiveElement>
                {
                    new AdaptiveContainer()
                    {
                        Style = AdaptiveContainerStyle.Emphasis,
                        Bleed = true,
                        Items = new System.Collections.Generic.List <AdaptiveElement>()
                    }
                }
            };

            renderContext.RenderArgs.ParentStyle = AdaptiveContainerStyle.Default;

            var containerWithoutWorkingBleed = new AdaptiveContainer
            {
                Style = AdaptiveContainerStyle.Default,
                Items = new System.Collections.Generic.List <AdaptiveElement>
                {
                    new AdaptiveContainer()
                    {
                        Style = AdaptiveContainerStyle.Default,
                        Bleed = true,
                        Items = new System.Collections.Generic.List <AdaptiveElement>()
                    }
                }
            };

            var workingBleedHtml    = TestHtmlRenderer.CallContainerRender(containerWithWorkingBleed, renderContext).ToString();
            var notWorkingBleedHtml = TestHtmlRenderer.CallContainerRender(containerWithoutWorkingBleed, renderContext).ToString();

            // Generated HTML should have an additional disabled and hidden option which is selected.
            Assert.AreEqual(
                "<div class='ac-container' style='background-color: rgba(255, 255, 255, 1.00);justify-content: flex-start;'><div class='ac-container' style='padding-right: 15px;padding-left: 15px;padding-top: 15px;padding-bottom: 15px;margin-right: -15px;margin-left: -15px;background-color: rgba(0, 0, 0, 0.03);justify-content: flex-start;'></div></div>",
                workingBleedHtml);

            Assert.AreEqual(
                "<div class='ac-container' style='background-color: rgba(255, 255, 255, 1.00);justify-content: flex-start;'><div class='ac-container' style='background-color: rgba(255, 255, 255, 1.00);justify-content: flex-start;'></div></div>",
                notWorkingBleedHtml);
        }
Ejemplo n.º 9
0
 public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
 {
     try
     {
         var json = element.ToJson();
         var obj  = json.GetNamedObject("-ms-action");
         return(new TextBlock()
         {
             Text = "-ms-action"
         });
     }
     catch { }
     return(_originalRenderer.Render(element, context, renderArgs));
 }
Ejemplo n.º 10
0
        public static FrameworkElement Render(MyCustomRating rating, AdaptiveRenderContext context)
        {
            var textBlock = new AdaptiveTextBlock
            {
                Size  = rating.Size,
                Color = rating.Color
            };

            for (int i = 0; i < rating.Rating; i++)
            {
                textBlock.Text += "\u2605";
            }
            textBlock.Text += $" ({rating.Rating})";
            return(context.Render(textBlock));
        }
        /// <summary>
        /// Creates the specified submit action.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="renderContext">The render context.</param>
        public static void Create(AdaptiveSubmitAction action, HtmlTag tag, AdaptiveRenderContext renderContext)
        {
            var id = AdaptiveCardRenderer.GenerateRandomId();

            tag.Attr("id", id);
            tag.Attr("data-ac-submitData", JsonConvert.SerializeObject(action.Data, Formatting.None));

            if (action.AdditionalProperties.ContainsKey("name"))
            {
                tag.Attributes.Add("data-name", action.AdditionalProperties["name"].ToString());
            }
            else
            {
                tag.Attributes.Add("data-name", "Submit");
            }

            tag.Attributes.Add("onclick", "window.blazorAdaptiveCards.submitData(this, id)");
        }
Ejemplo n.º 12
0
        public UIElement Render(IAdaptiveCardElement element, AdaptiveRenderContext context, AdaptiveRenderArgs renderArgs)
        {
            var card = new AdaptiveCard();

            foreach (var a in (element as AdaptiveActionSet).Actions)
            {
                card.Actions.Add(a);
            }

            var originalPadding = m_cardRenderer.HostConfig.Spacing.Padding;

            m_cardRenderer.HostConfig.Spacing.Padding = 0;
            var result = m_cardRenderer.RenderAdaptiveCard(card).FrameworkElement;

            m_cardRenderer.HostConfig.Spacing.Padding = originalPadding;

            return(result);
        }
Ejemplo n.º 13
0
        public void TextBlockRender_ParagraphElementStylesAdded()
        {
            var renderContext = new AdaptiveRenderContext(
                new AdaptiveHostConfig(),
                new AdaptiveElementRenderers <HtmlTag, AdaptiveRenderContext>());

            var textBlock = new AdaptiveTextBlock
            {
                Text = "first line\n\nsecond line",
            };

            var generatedHtml = TestHtmlRenderer.CallTextBlockRender(textBlock, renderContext).ToString();

            // From String

            // Generated HTML should have two <p> tags, with appropriate styles set.
            Assert.AreEqual(
                "<div class='ac-textblock' style='box-sizing: border-box;text-align: left;color: rgba(0, 0, 0, 1.00);line-height: 18.62px;font-size: 14px;font-weight: 400;white-space: nowrap;'><p style='margin-top: 0px;margin-bottom: 0px;width: 100%;text-overflow: ellipsis;overflow: hidden;'>first line</p><p style='margin-top: 0px;margin-bottom: 0px;width: 100%;text-overflow: ellipsis;overflow: hidden;'>second line</p></div>",
                generatedHtml);
        }
Ejemplo n.º 14
0
        public void ChoiceSetInput()
        {
            var renderContext = new AdaptiveRenderContext(
                new AdaptiveHostConfig(),
                new AdaptiveElementRenderers <HtmlTag, AdaptiveRenderContext>());

            var dropdownList = new AdaptiveChoiceSetInput()
            {
                Id      = "1",
                Value   = "1,3",
                Style   = AdaptiveChoiceInputStyle.Compact,
                Choices =
                {
                    new AdaptiveChoice()
                    {
                        Title = "Value 1",
                        Value = "1"
                    },
                    new AdaptiveChoice()
                    {
                        Title = "Value 2",
                        Value = "2"
                    },
                    new AdaptiveChoice()
                    {
                        Title = "Value 3",
                        Value = "3"
                    }
                }
            };

            var dropdownGeneratedHtml = TestHtmlRenderer.CallChoiceSetInputRender(dropdownList, renderContext).ToString();

            // Generated HTML should have an additional disabled and hidden option which is selected.
            Assert.AreEqual(
                "<select class='ac-input ac-multichoiceInput' name='1' style='width: 100%;'><option disabled='' hidden='' selected=''/><option value='1'>Value 1</option><option value='2'>Value 2</option><option value='3'>Value 3</option></select>",
                dropdownGeneratedHtml);
        }
Ejemplo n.º 15
0
        public static FrameworkElement Render(AdaptiveDateInput input, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity)
            {
                AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;

                return(context.Render(textBlock));
            }

            DatePicker datePicker = new DatePicker
            {
                DataContext = input,
                ToolTip     = input.Placeholder,
                Style       = context.GetStyle("Adaptive.Input.Date")
            };


            if (DateTime.TryParse(input.Value, out DateTime value))
            {
                datePicker.SelectedDate = value;
            }

            if (DateTime.TryParse(input.Min, out DateTime minValue))
            {
                datePicker.DisplayDateStart = minValue;
            }

            if (DateTime.TryParse(input.Max, out DateTime maxValue))
            {
                datePicker.DisplayDateEnd = maxValue;
            }

            context.InputBindings.Add(input.Id, () => datePicker.SelectedDate?.ToString("yyyy-MM-dd") ?? "");

            return(datePicker);
        }
Ejemplo n.º 16
0
 public static HtmlTag CallTextBlockRender(AdaptiveTextBlock element, AdaptiveRenderContext context)
 {
     return(TextBlockRender(element, context));
 }
Ejemplo n.º 17
0
        public static void Create(AdaptiveToggleVisibilityAction action, HtmlTag tag, AdaptiveRenderContext renderContext)
        {
            var targetElements = string.Empty;

            if (action.TargetElements?.Any() != true)
            {
                return;
            }

            foreach (var targetElement in action.TargetElements)
            {
                if (!string.IsNullOrWhiteSpace(targetElements))
                {
                    targetElements += ",";
                }

                string targetElementId           = null;
                var    targetElementToggleAction = "Toggle";

                if (targetElement != null)
                {
                    targetElementId = targetElement.ElementId;

                    if (targetElement.IsVisible.HasValue)
                    {
                        targetElementToggleAction = targetElement.IsVisible.Value.ToString();
                    }
                }

                targetElements += targetElementId + ":" + targetElementToggleAction;
            }

            tag.Attr("data-ac-targetelements", targetElements);
            var toggleId = AdaptiveCardRenderer.GenerateRandomId();

            tag.Attr("id", toggleId);
            tag.Attributes.Add("onclick",
                               $"blazorAdaptiveCards.toggleVisibility('{toggleId}')");
        }
Ejemplo n.º 18
0
 public static HtmlTag CallContainerRender(AdaptiveContainer element, AdaptiveRenderContext context)
 {
     return(ContainerRender(element, context));
 }
Ejemplo n.º 19
0
 public static HtmlTag CallChoiceSetInputRender(AdaptiveChoiceSetInput element, AdaptiveRenderContext context)
 {
     return(ChoiceSetRender(element, context));
 }