public async Task Process(FlowActionTagHelper target, IHtmlHelper htmlHelper, TagHelperContext context, TagHelperOutput output) { foreach (var attribute in context.AllAttributes) { output.Attributes.Add(attribute); } switch (target.SerializeAsTagType) { case FlowActionTagHelper.TagType.NotRelevantToThis: case FlowActionTagHelper.TagType.Button: output.TagName = "button"; output.Attributes.SetAttribute("name", SharedSymbol.FlowEventFormFieldName); output.Attributes.SetAttribute("value", (string)target.TriggerEvent); break; case FlowActionTagHelper.TagType.Anchor: output.PreElement.AppendHtml($"<input type=\"hidden\" name=\"{SharedSymbol.FlowEventFormFieldName}\" value=\"\" />"); output.TagName = "a"; output.Attributes.SetAttribute("data-event-field-name", SharedSymbol.FlowEventFormFieldName); output.Attributes.SetAttribute("data-trigger-event", target.TriggerEvent); output.Attributes.SetAttribute("href", "#"); break; default: throw new ArgumentOutOfRangeException(); } }
public async Task Process(FlowActionTagHelper target, IHtmlHelper htmlHelper, TagHelperContext context, TagHelperOutput output) { var content = (await output.GetChildContentAsync()).GetContent(); IHtmlContent htmlContent; var attrsObject = (object)context.AllAttributes .Where(x => !FlowActionTagHelper.DesignerOnlySymbols.Any(att => att.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))) .ToDictionary(x => x.Name, x => x.Value).ToExpandoObject(); if (target.Type == FlowActionTagHelper.FlowActionType.StartFlow) { var containerViewModel = await LocateContainer(); htmlContent = await htmlHelper.DisplayFlowLinkAsync2(containerViewModel, content, target.FlowName, target.FlowParameters, attrsObject); } else if (target.Type == FlowActionTagHelper.FlowActionType.ReloadStepWithChanges) { var uiFlowScreenModel = htmlHelper.ViewData.Model is FlowComponentViewModel model ? (UiFlowScreenModel)model.ScreenModel : (UiFlowScreenModel)htmlHelper.ViewData.Model; htmlContent = await htmlHelper.UiFlowActionLinkToCurrentStepAsync(uiFlowScreenModel, target.FlowParameters, content, attrsObject); } else { throw new ArgumentOutOfRangeException(); } output.TagName = null; output.Content.SetHtmlContent(htmlContent); async Task <UiFlowScreenModel> LocateContainer() { UiFlowScreenModel result = null; var currentHandler = (htmlHelper.ViewData.Model as UiFlowScreenModel)?.FlowHandler ?? (htmlHelper.ViewData.Model as FlowComponentViewModel)?.ScreenModel?.FlowHandler; switch (target.FlowLocation) { case FlowActionTagHelper.StartFlowLocation.NotRelevantToThis: case FlowActionTagHelper.StartFlowLocation.NotContained: break; case FlowActionTagHelper.StartFlowLocation.SameContainerAsMe: if (currentHandler != null) { var ctx = await _contextRepository.Get(currentHandler); if (ctx.ContainerFlowHandler != null) { ctx = await _contextRepository.Get(ctx.ContainerFlowHandler); result = ctx.GetCurrentStepData <UiFlowScreenModel>(); } } break; case FlowActionTagHelper.StartFlowLocation.ContainedInMe: if (currentHandler != null) { var ctx = await _contextRepository.Get(currentHandler); result = ctx.GetCurrentStepData <UiFlowScreenModel>(); } break; default: throw new ArgumentOutOfRangeException(); } return(result); } }