public void TestObjectModelActionSetElement() { AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion("1.2")); AdaptiveActionSet actionSet = new AdaptiveActionSet(); card.Body.Add(actionSet); AdaptiveSubmitAction submitAction = new AdaptiveSubmitAction { Title = "Action.Submit", DataJson = "{\"x\": 13}" }; actionSet.Actions.Add(submitAction); AdaptiveOpenUrlAction openUrlAction = new AdaptiveOpenUrlAction { Title = "OpenUrl", UrlString = "http://adaptivecards.io" }; actionSet.Actions.Add(openUrlAction); #pragma warning disable 0618 AdaptiveShowCardAction showCardAction = new AdaptiveShowCardAction { Title = "ShowCard", Card = new AdaptiveCard { Body = new List <AdaptiveElement> { new AdaptiveTextBlock { Text = "This is a show card" } } } }; #pragma warning restore 0618 actionSet.Actions.Add(showCardAction); AdaptiveToggleVisibilityAction toggleVisibilityAction = new AdaptiveToggleVisibilityAction { Title = "Toggle", TargetElements = new List <AdaptiveTargetElement> { "test" } }; actionSet.Actions.Add(toggleVisibilityAction); // This lines are not indented so the comparisson doesn't fail due to extra spaces var expectedJson = @"{ ""type"": ""AdaptiveCard"", ""version"": ""1.2"", ""body"": [ { ""type"": ""ActionSet"", ""actions"": [ { ""type"": ""Action.Submit"", ""data"": { ""x"": 13 }, ""title"": ""Action.Submit"" }, { ""type"": ""Action.OpenUrl"", ""url"": ""http://adaptivecards.io"", ""title"": ""OpenUrl"" }, { ""type"": ""Action.ShowCard"", ""card"": { ""type"": ""AdaptiveCard"", ""version"": ""1.0"", ""body"": [ { ""type"": ""TextBlock"", ""text"": ""This is a show card"" } ] }, ""title"": ""ShowCard"" }, { ""type"": ""Action.ToggleVisibility"", ""targetElements"": [ ""test"" ], ""title"": ""Toggle"" } ] } ] }"; var outputJson = card.ToJson(); Assert.AreEqual(outputJson, expectedJson); }
public static AdaptiveCard CreateCardCalendarEventInputs(CardDataModel cardModel) { // DateTime dueStartDate = new Date DateTime dueDateStart = DateTime.Now; DateTime dueDateEnd = dueDateStart.AddDays(1); var card = new AdaptiveCard(new AdaptiveSchemaVersion("1.2")) { Body = new List <AdaptiveElement> { new AdaptiveContainer() { Items = new List <AdaptiveElement>() { new AdaptiveTextBlock() { Id = "Header", Text = "Enter Calendar Event Details", Weight = AdaptiveTextWeight.Bolder }, } } }, }; card.Body.Add(new AdaptiveTextBlock() { Id = "LabelTitle", Text = "Event Title" }); card.Body.Add(new AdaptiveTextInput() { Id = "Title", Value = cardModel.TaskTitle, IsVisible = true }); card.Body.Add(new AdaptiveTextBlock() { Id = "LabelDetails", Text = "Event Details" }); card.Body.Add(new AdaptiveTextInput() { Id = "Details", Placeholder = "Enter Event Details", IsVisible = true }); // Row 2 var colSet = new AdaptiveColumnSet(); var col1 = new AdaptiveColumn(); col1.Width = "100"; col1.Items.Add(new AdaptiveTextBlock() { Id = "LabelStartDt", Text = "Start Date", IsVisible = true }); var col2 = new AdaptiveColumn(); col2.Width = "100"; col2.Items.Add(new AdaptiveDateInput() { Id = "StartDt", Placeholder = "Select Date", Value = dueDateStart.ToString() }); var col3 = new AdaptiveColumn(); col3.Width = "100"; col3.Items.Add(new AdaptiveTimeInput() { Id = "StartTime", Placeholder = "Select Time", }); colSet.Columns.Add(col1); colSet.Columns.Add(col2); colSet.Columns.Add(col3); card.Body.Add(colSet); // Row 3 var colSet2 = new AdaptiveColumnSet(); var col21 = new AdaptiveColumn(); col21.Width = "100"; col21.Items.Add(new AdaptiveTextBlock() { Id = "LabelDuration", Text = "Event Duration", IsVisible = true }); var col22 = new AdaptiveColumn(); col22.Width = "100"; col22.Items.Add(new AdaptiveChoiceSetInput { Id = "EventDuration", Style = AdaptiveChoiceInputStyle.Compact, Value = "EventDuration", IsMultiSelect = false, Choices = new List <AdaptiveChoice> { new AdaptiveChoice() { Title = "15 mins", Value = "15" }, new AdaptiveChoice() { Title = "30 mins", Value = "30" }, new AdaptiveChoice() { Title = "45 mins", Value = "45" }, new AdaptiveChoice() { Title = "1 hr", Value = "60" }, new AdaptiveChoice() { Title = "2 hr", Value = "120" }, new AdaptiveChoice() { Title = "3 hr", Value = "180" }, }, } ); var col23 = new AdaptiveColumn(); col23.Width = "100"; col23.Items.Add(new AdaptiveTextBlock() { Id = "LabelDummy2", Text = "", IsVisible = false }); colSet2.Columns.Add(col21); colSet2.Columns.Add(col22); colSet2.Columns.Add(col23); card.Body.Add(colSet2); var actionItem = new AdaptiveActionSet() { Id = "SubmitCalendarEvent", Actions = new List <AdaptiveAction> { new AdaptiveSubmitAction { Type = AdaptiveSubmitAction.TypeName, Title = "Create Calendar Event", Id = "SubmitCalendarEvent", Data = new JObject { { "Type", "CalendarEvent" } }, }, }, }; card.Body.Add(actionItem); return(card); }
/// <summary> /// 為AdaptiveActionSet加入一個AdaptiveAction /// </summary> /// <param name="set">要被加入AdaptiveAction的AdaptiveActionSet</param> /// <param name="action">要加入的AdaptiveAction</param> /// <returns>加入一個AdaptiveAction後的AdaptiveActionSet</returns> public static AdaptiveActionSet AddActionToSet(this AdaptiveActionSet set, AdaptiveAction action) { set.Actions.Add(action); return(set); }
/// <summary> /// 為AdaptiveCard新增一個AdaptiveActionSet /// </summary> /// <param name="card">要被掛上Set的AdaptiveCard</param> /// <param name="set">要掛上的AdaptiveActionSet</param> /// <returns>加入AdaptiveActionSet後的AdaptiveCard</returns> public static AdaptiveCard AddActionsSet(this AdaptiveCard card, AdaptiveActionSet set) { card.Body.Add(set); return(card); }
private List <AdaptiveElement> CreateActions(AdaptiveBlockContent block, AdaptiveBlockTransformContext context) { if (!block.Actions.Any() || !context.Transformer.Properties.AllowsInteractivity) { return(new List <AdaptiveElement>()); } var answer = new List <AdaptiveElement>(); var inputGroups = block.GetActionInputGroups().ToArray(); bool alreadyRenderedInputs = false; // If there's just one input group, render it inline if (inputGroups.Length == 1) { var inputs = inputGroups[0]; var simplifedActions = block.GetSimplifiedActions(); if (inputs.Count == 1 && simplifedActions.Count() == 1 && inputs.First() is AdaptiveBlocks.Inputs.AdaptiveTextInputBlock textInputBlock) { // Inline the action List <AdaptiveElement> cardTextInputElements = TextInputTransformer.Transform(textInputBlock); var cardTextInput = cardTextInputElements.OfType <AdaptiveTextInput>().FirstOrDefault(); if (cardTextInput != null) { var blockAction = simplifedActions.First(); cardTextInput.AdditionalProperties["inlineAction"] = new Dictionary <string, string>() { { "type", "Action.Submit" }, { "title", blockAction.Title }, { "iconUrl", blockAction.Icon?.GetIconForTheme(Attributes.AdaptiveThemes.Light)?.Url } }; answer.AddRange(cardTextInputElements); return(answer); } } answer.AddRange(context.Transformer.TransformInputsToElements(inputs, context)); alreadyRenderedInputs = true; } var actionSet = new AdaptiveActionSet(); if (alreadyRenderedInputs || inputGroups.Length == 0) { foreach (var a in block.GetSimplifiedActions()) { actionSet.Actions.Add(new AdaptiveSubmitAction() { Title = a.Title }); } } else { foreach (var a in block.GetSimplifiedActions()) { if (a.Inputs.Any()) { var card = new AdaptiveCard(); foreach (var el in context.Transformer.TransformInputsToElements(a.Inputs, context)) { card.Body.Add(el); } card.Actions.Add(new AdaptiveSubmitAction() { Title = a.Title }); // Note that constructing a ShowCard fails in UWP for some reason... actionSet.Actions.Add(new AdaptiveShowCardAction() { Title = a.Title, Card = card }); } else { actionSet.Actions.Add(new AdaptiveSubmitAction() { Title = a.Title }); } } } answer.Add(actionSet); return(answer); }
private AdaptiveColumnSet StoreItems(string Storename, Guid MenuId) { var ModifyData = new CardDataModel <ModifyData>() { Type = "CustomizedModification", Value = new ModifyData() { MenuId = MenuId.ToString() } }; var DeleteMenuDate = new Data() { msteams = new Msteams() { type = "invoke", value = new MsteamsValue() { MenuId = MenuId, Option = "DeleteMenu" } } }; var cardData = new CardDataModel <string>() { Type = "CreateMenuDetail", Value = MenuId.ToString() }; var MainColumnSet = new AdaptiveColumnSet(); var Column1 = new AdaptiveColumn(); MainColumnSet.Columns.Add(Column1); var StoreName = new AdaptiveTextBlock() { Text = Storename, Height = AdaptiveHeight.Stretch, Weight = AdaptiveTextWeight.Bolder }; Column1.Items.Add(StoreName); var Column2 = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto }; MainColumnSet.Columns.Add(Column2); var ChildColumnSet = new AdaptiveColumnSet(); Column2.Items.Add(ChildColumnSet); var CreateColumn = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto }; ChildColumnSet.Columns.Add(CreateColumn); var CreateActionSet = new AdaptiveActionSet(); CreateActionSet.Actions.Add(new AdaptiveSubmitAction() { Title = "Create", Data = new AdaptiveCardTaskFetchValue <string>() { Data = JsonConvert.SerializeObject(cardData) } }); CreateColumn.Items.Add(CreateActionSet); var EditColumn = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto }; ChildColumnSet.Columns.Add(EditColumn); var EditActionSet = new AdaptiveActionSet(); EditActionSet.Actions.Add(new AdaptiveSubmitAction().SetOpenTaskModule("Edit", JsonConvert.SerializeObject(ModifyData))); EditColumn.Items.Add(EditActionSet); var DeleteColumn = new AdaptiveColumn() { Width = AdaptiveColumnWidth.Auto }; ChildColumnSet.Columns.Add(DeleteColumn); var DeleteActionSet = new AdaptiveActionSet(); DeleteActionSet.Actions.Add(new AdaptiveSubmitAction() { Title = "Delete", Data = DeleteMenuDate }); DeleteColumn.Items.Add(DeleteActionSet); return(MainColumnSet); }