public ContextualizedHelpers CreateChild(ViewContext context, IHtmlHelper html, IPrincipal user = null, IViewComponentHelper component = null, IUrlHelper urlHelper = null, IStringLocalizerFactory localizerFactory = null)
        {
            var res = new ContextualizedHelpers(context, html, user ?? _user, component ?? _component, urlHelper ?? _urlHelper, localizerFactory ?? LocalizerFactory);

            res.cachedTemplateResult = cachedTemplateResult;
            return(res);
        }
Example #2
0
 public async Task <IHtmlContent> InvokeDisplay(ContextualizedHelpers helpers, ModelExpression expression)
 {
     if (DisplayTemplate == null)
     {
         return(new HtmlString(string.Empty));
     }
     return(await DisplayTemplate.Invoke(expression, this, helpers));
 }
Example #3
0
 public IHtmlContent RenderUrl(ContextualizedHelpers helpers, string actionMethod, object parameters)
 {
     if (ControllerType == null)
     {
         return(null);
     }
     return(new HtmlString(helpers.UrlHelper.Action(actionMethod, ControllerType.Name.Substring(0, ControllerType.Name.Length - 10), parameters)));
 }
Example #4
0
 public async Task <IHtmlContent> InvokeDisplay(object o, ContextualizedHelpers helpers, string overridePrefix = null)
 {
     if (DisplayTemplate == null)
     {
         return(new HtmlString(string.Empty));
     }
     return(await DisplayTemplate.Invoke(
                new ModelExpression(combinePrefixes(AdditionalPrefix, For.Name), For.ModelExplorer.GetExplorerForModel(o)),
                this, helpers, overridePrefix));
 }
Example #5
0
 public IHtmlContent RenderHiddens(ContextualizedHelpers ctx, object rowModel)
 {
     if (renderHiddens == null)
     {
         return(new HtmlString(string.Empty));
     }
     else
     {
         return(renderHiddens(hiddens, ctx, rowModel));
     }
 }
Example #6
0
 public async Task <IHtmlContent> InvokeDisplay(object o, string prefix, ContextualizedHelpers helpers)
 {
     if (DisplayTemplate == null)
     {
         return(new HtmlString(string.Empty));
     }
     //await PrerenderInLineColumnTemplates(o, prefix, helpers);
     return(await DisplayTemplate.Invoke(
                new ModelExpression(prefix, For.ModelExplorer.GetExplorerForModel(o)),
                this, helpers));
 }
Example #7
0
 public async Task <IHtmlContent> InvokeGrouping(object o, string prefix, ContextualizedHelpers helpers, Type destinationType)
 {
     if (GroupingTemplate == null)
     {
         return(new HtmlString(string.Empty));
     }
     //await PrerenderInLineColumnTemplates(o, prefix, helpers);
     return(await GroupingTemplate.Invoke(
                new ModelExpression(prefix, For.ModelExplorer.GetExplorerForModel(o)),
                this, helpers, null, destinationType));
 }
Example #8
0
 protected async Task PrerenderInLineColumnTemplates(object o, string prefix, ContextualizedHelpers helpers)
 {
     foreach (var col in Columns)
     {
         if (col.DisplayTemplate != null && col.DisplayTemplate.Type == TemplateType.InLine)
         {
             var model      = col.For.Metadata.PropertyGetter(o);
             var expression = new ModelExpression(combinePrefixes(prefix, combinePrefixes(col.AdditionalPrefix, col.For.Name)),
                                                  col.For.ModelExplorer.GetExplorerForModel(model));
             helpers.AddCachedTemplateResult(col.DisplayTemplate, await col.InvokeDisplay(helpers, expression));
         }
         if (col.EditTemplate != null && col.EditTemplate.Type == TemplateType.InLine)
         {
             var model      = col.For.Metadata.PropertyGetter(o);
             var expression = new ModelExpression(combinePrefixes(prefix, combinePrefixes(col.AdditionalPrefix, col.For.Name)),
                                                  col.For.ModelExplorer.GetExplorerForModel(model));
             helpers.AddCachedTemplateResult(col.EditTemplate, await col.InvokeEdit(helpers, expression));
         }
     }
 }
Example #9
0
 public int VisibleColumns(ContextualizedHelpers helpers, bool editOnly = false)
 {
     return(MustAddButtonColumn(helpers, editOnly) ? ColumnsCount + 1 : ColumnsCount);
 }
Example #10
0
 public bool MustAddButtonColumn(ContextualizedHelpers helpers, bool editOnly = false)
 {
     return(!CustomButtons && ((RequiredFunctionalities(helpers.User) & (editOnly ? Functionalities.EditOnlyHasRowButtons : Functionalities.HasRowButtons)) != 0));
 }
Example #11
0
 public async Task <IHtmlContent> RenderColumn(object rowModel, Column col, bool editMode, ContextualizedHelpers ctx, bool filterMode = false)
 {
     if (col.For == null)
     {
         var expression = new ModelExpression(combinePrefixes(col.AdditionalPrefix, string.Empty), For.ModelExplorer.GetExplorerForModel(rowModel));
         return(filterMode ? await col.InvokeFilter(ctx, expression) : (editMode ? await col.InvokeEdit(ctx, expression) : await col.InvokeDisplay(ctx, expression)));
     }
     else if (col.ColumnConnection == null)
     {
         var model = col.For.Metadata.PropertyGetter(rowModel);
         if (filterMode)
         {
             return(await col.InvokeFilter(model, ctx));
         }
         else if (editMode)
         {
             return(await col.InvokeEdit(model, ctx));
         }
         else
         {
             return(await col.InvokeDisplay(model, ctx));
         }
     }
     else if (filterMode && col.ColumnConnection.QueryDisplay)
     {
         var displayFor = col.ColumnConnection.DisplayProperty;
         var model      = displayFor.Metadata.PropertyGetter(rowModel);
         var expression = new ModelExpression(combinePrefixes(col.AdditionalPrefix, displayFor.Name), displayFor.ModelExplorer.GetExplorerForModel(model));
         return(await col.InvokeFilter(ctx, expression));
     }
     else if (col.ColumnConnection is ColumnConnectionInfosStatic && (editMode || filterMode))
     {
         var model = col.For.Metadata.PropertyGetter(rowModel);
         return(filterMode ? await col.InvokeFilter(model, ctx) : await col.InvokeEdit(model, ctx));
     }
     else if (!(editMode || filterMode))
     {
         var displayFor = col.ColumnConnection.DisplayProperty;
         var model      = displayFor.Metadata.PropertyGetter(rowModel);
         var expression = new ModelExpression(combinePrefixes(col.AdditionalPrefix, displayFor.Name), displayFor.ModelExplorer.GetExplorerForModel(model));
         return(await col.InvokeDisplay(ctx, expression));
     }
     else
     {
         var expression = new ModelExpression(combinePrefixes(col.AdditionalPrefix, string.Empty), For.ModelExplorer.GetExplorerForModel(rowModel));
         return(filterMode ? await col.InvokeFilter(ctx, expression) : await col.InvokeEdit(ctx, expression));
     }
 }
Example #12
0
        public async Task <IHtmlContent> Invoke(ModelExpression expression, O options, ContextualizedHelpers helpers, string overridePrefix = null, object data = null)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            ModelExplorer model = expression.ModelExplorer;

            if (Type == TemplateType.Partial)
            {
                if (helpers == null)
                {
                    throw new ArgumentNullException(nameof(helpers));
                }
                var h      = helpers.Html;
                var origVd = helpers.Context.ViewData;
                if (h == null)
                {
                    throw new ArgumentNullException(nameof(h));
                }
                var fatherPrefix = (origVd[RenderingScope.Field] as RenderingScope)?.FatherPrefix;
                var vd           = new ViewDataDictionary <object>(origVd);
                vd.Model         = model.Model;
                vd.ModelExplorer = model.GetExplorerForModel(model.Model);
                if (overridePrefix != null)
                {
                    vd.TemplateInfo.HtmlFieldPrefix = combinePrefixes(overridePrefix, expression.Name);
                }
                else
                {
                    vd.TemplateInfo.HtmlFieldPrefix = origVd.GetFullHtmlFieldName(combinePrefixes(fatherPrefix, expression.Name));
                }
                vd["Options"] = options;
                vd["ContextualizedHelpers"] = helpers;
                vd["LocalizerFactory"]      = helpers.LocalizerFactory;
                if (data != null)
                {
                    vd["ExtraData"] = data;
                }
                vd.Remove(RenderingScope.Field);
                return(await h.PartialAsync(TemplateName, model.Model, vd));
            }
            else if (Type == TemplateType.ViewComponent)
            {
                if (helpers == null)
                {
                    throw new ArgumentNullException(nameof(helpers));
                }
                var origVd       = helpers.Context.ViewData;
                var fatherPrefix = (origVd[RenderingScope.Field] as RenderingScope)?.FatherPrefix;
                if (data != null)
                {
                    return(await helpers.Component.InvokeAsync(TemplateName, new
                    {
                        model = model.Model,
                        options = options,
                        prefix = overridePrefix != null ? combinePrefixes(overridePrefix, expression.Name) : origVd.GetFullHtmlFieldName(combinePrefixes(fatherPrefix, expression.Name)),
                        modelState = origVd.ModelState,
                        extraData = data
                    }));
                }
                else
                {
                    return(await helpers.Component.InvokeAsync(TemplateName, new {
                        model = model.Model,
                        options = options,
                        prefix = overridePrefix != null ? combinePrefixes(overridePrefix, expression.Name) : origVd.GetFullHtmlFieldName(combinePrefixes(fatherPrefix, expression.Name)),
                        modelState = origVd.ModelState
                    }));
                }
            }
            else if (Type == TemplateType.InLine)
            {
                var res = helpers.GetCachedTemplateResult(this);
                if (res != null)
                {
                    return(res);
                }
                using (await Lock.LockAsync())
                {
                    originalContext.HttpContext = helpers.CurrentHttpContext;

                    var origVd = originalContext.ViewData;
                    using (new TagHelpersProviderContext(OriginalProvider, originalContext))
                    {
                        using (new RenderingScope(
                                   expression.Model,
                                   overridePrefix != null ? combinePrefixes(overridePrefix, expression.Name) : helpers.Context.ViewData.GetFullHtmlFieldName(expression.Name),
                                   origVd,
                                   options))
                        {
                            return(FTemplate(model.Model, default(O), helpers));
                        }
                    }
                }
            }
            else
            {
                if (helpers == null)
                {
                    throw new ArgumentNullException(nameof(helpers));
                }
                var origVd = helpers.Context.ViewData;
                using (new RenderingScope(
                           expression.Model,
                           origVd,
                           expression.Name,
                           options))
                {
                    return(FTemplate(model.Model, options, helpers));
                }
            }
        }