Example #1
0
        /// <summary>
        /// It builds a form tag that POSTS an Step Event of a Flow
        /// </summary>
        /// <typeparam name="TFlowType"></typeparam>
        /// <param name="html"></param>
        /// <param name="model"></param>
        /// <param name="htmlId"></param>
        /// <param name="queryString"></param>
        /// <param name="className"></param>
        /// <param name="defaultEvent"></param>
        /// <returns></returns>
        public static async Task <MvcForm> BeginUiFlowFormAsync(this IHtmlHelper html,
                                                                IUiFlowScreenModel model, string htmlId = "", object queryString = null, string className = "",
                                                                ScreenEvent defaultEvent = null)
        {
            var flowType      = model.GetFlowType();
            var concreteModel = (UiFlowScreenModel)model;


            MvcForm result;
            var     flowName    = flowType.ToString();
            var     routeValues = (object)new { flowType = flowName };

            if (queryString != null)
            {
                routeValues = routeValues.MergeObjects(queryString);
            }

            var controllerName = string.IsNullOrEmpty(concreteModel.Metadata.ContainerController)
                                ? flowName
                                : concreteModel.Metadata.ContainerController;



            result = html.BeginForm(nameof(IUiFlowController.OnEvent), controllerName, routeValues, FormMethod.Post,
                                    true,
                                    htmlAttributes: new { @id = $"{flowName}-{htmlId}", @class = className });

            var content      = html.ViewContext.FormContext.EndOfFormContent;
            var contentItems = new List <Task <HtmlString> >();


            if (defaultEvent != null)
            {
                content.Add(html.Hidden(SharedSymbol.FlowEventFormFieldName, defaultEvent));
            }

            contentItems.Add(html.SecureHiddenAsync(UiFlowController.FlowFormKey, false,
                                                    Guid.NewGuid().ToString()));
            contentItems.Add(
                html.SecureHiddenAsync(nameof(UiFlowScreenModel.FlowHandler), false, model.FlowHandler));
            contentItems.Add(html.SecureHiddenAsync(nameof(UiFlowScreenModel.FlowScreenName), false,
                                                    model.FlowScreenName));
            contentItems.Add(html.SecureHiddenAsync(nameof(UiFlowScreenModel.ScreenTitle), false,
                                                    model.ScreenTitle));
            foreach (var modelContainerProperty in concreteModel.Metadata.ContainerProperties)
            {
                if (modelContainerProperty.Value is string value)
                {
                    contentItems.Add(html.SecureHiddenAsync(modelContainerProperty.Key, false, value));
                }
            }

            foreach (var contentItem in contentItems)
            {
                content.Add(await contentItem);
            }

            return(result);
        }
 public static async Task <IHtmlContent> GetButtonToFlowStepAsync <TStepData>(this IHtmlHelper html,
                                                                              string flowType,
                                                                              IUiFlowScreenModel currentScreenModel,
                                                                              ScreenEvent eventToTrigger,
                                                                              string buttonContent,
                                                                              object attributes  = null,
                                                                              object queryString = null,
                                                                              params (Expression <Func <TStepData, object> >, string)[] contextValuesToSetOnCurrentStepData)
        /// <summary>
        /// Resolves a url that changes the view of the current step data without processing a transition
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="html"></param>
        /// <param name="model"></param>
        /// <param name="routeValues"></param>
        /// <param name="linkText"></param>
        /// <remarks>use for filtering, paging and other view customizations</remarks>
        /// <returns></returns>
        public static async Task <string> UiFlowUrlToCurrentStepAsync(this IHtmlHelper html, IUiFlowScreenModel model, object routeValues)
        {
            var controllerName = await html.ResolveModelControllerName(model);

            var modelRouteVals = await html.ResolveFlowActionRouteValues(model, nameof(IUiFlowController.Current));

            if (routeValues != null)
            {
                modelRouteVals = routeValues.MergeObjects(modelRouteVals);
            }

            return(await html.GetActionUrlAsync(nameof(IUiFlowController.Current), controllerName, routeValues : modelRouteVals));
        }
Example #4
0
 public ComponentPreLoader(IViewComponentHelper componentHelper,
                           IUiFlowScreenModel screenModel)
 {
     _componentHelper = componentHelper;
     _screenModel     = screenModel;
 }