public DefaultServerGridProcessor(TagHelperContext context, TagHelperOutput output, GridTagHelper tag, GridOptions options, ContextualizedHelpers helpers)
 {
     this.context = context; this.output = output; this.tag = tag;
     this.options = options; this.helpers = helpers;
     basePrefix   = tag.For.Name;
     AdjustColumns();
 }
 public DefaultServerGridLayoutOptions(
     ContextualizedHelpers helpers,
     IList<RowType> rows,
     IList<KeyValuePair<string, string>> toolbars,
     Template<LayoutTemplateOptions> layoutTemplate,
     IEnumerable<Template<LayoutTemplateOptions>> subTemplates, 
     IHtmlContent mainContent,
     GridType type,
     string id,
     string prefix,
     GridErrorMessages messages,
     string cssClass,
     string caption,
     Type localizerType
     ) : base(rows, toolbars, layoutTemplate, subTemplates, mainContent)
 {
     this.helpers = helpers;
     Type = type;
     Messages = messages;
     Id = id;
     Prefix = prefix;
     CssClass = cssClass;
     Caption = caption;
     var first = rows.FirstOrDefault();
     MustAddButtonColumn = first.MustAddButtonColumn(helpers, Type== GridType.Batch);
     VisibleColumns = first.VisibleColumns(helpers, Type == GridType.Batch);
     LocalizerType = localizerType;
     Localizer = LocalizerType != null ? helpers.LocalizerFactory.Create(LocalizerType) : null;
 }
        public DefaultServerDetailLayoutOptions(
            ContextualizedHelpers helpers,
            IList <RowType> rows,
            IList <KeyValuePair <string, string> > toolbars,
            Template <LayoutTemplateOptions> layoutTemplate,
            IEnumerable <Template <LayoutTemplateOptions> > subTemplates,
            IHtmlContent mainContent,
            string id,
            string prefix,
            string cssClass,
            Type localizerType,
            bool editMode,
            string formAction,
            string formMethod,
            bool?antiforgery,
            bool noSubmit = false
            ) : base(rows, toolbars, layoutTemplate, subTemplates, mainContent)
        {
            this.helpers  = helpers;
            Id            = id;
            Prefix        = prefix;
            CssClass      = cssClass;
            LocalizerType = localizerType;
            Localizer     = LocalizerType != null?helpers.LocalizerFactory.Create(LocalizerType) : null;

            EditMode    = editMode;
            Antiforgery = antiforgery;
            FormAction  = formAction;
            FormMethod  = formMethod;
            NoSubmit    = noSubmit;
        }
 public DefaultServerDetailLayoutOptions(
     ContextualizedHelpers helpers,
     IList<RowType> rows,
     IList<KeyValuePair<string, string>> toolbars,
     Template<LayoutTemplateOptions> layoutTemplate,
     IEnumerable<Template<LayoutTemplateOptions>> subTemplates,
     IHtmlContent mainContent,
     string id,
     string prefix,
     string cssClass,
     Type localizerType,
     bool editMode,
     string formAction,
     string formMethod,
     bool? antiforgery,
     bool noSubmit=false
     ) : base(rows, toolbars, layoutTemplate, subTemplates, mainContent)
 {
     this.helpers = helpers;
     Id = id;
     Prefix = prefix;
     CssClass = cssClass;
     LocalizerType = localizerType;
     Localizer = LocalizerType != null ? helpers.LocalizerFactory.Create(LocalizerType) : null;
     EditMode = editMode;
     Antiforgery = antiforgery;
     FormAction = formAction;
     FormMethod = formMethod;
     NoSubmit = noSubmit;
 }
 public DefaultServerGridProcessor(TagHelperContext context, TagHelperOutput output, GridTagHelper tag, GridOptions options, ContextualizedHelpers helpers)
 {
     this.context = context; this.output = output; this.tag = tag;
     this.options = options; this.helpers = helpers;
     basePrefix = tag.For.Name;
     AdjustColumns();
 }
        public DefaultServerGridLayoutOptions(
            ContextualizedHelpers helpers,
            IList <RowType> rows,
            IList <KeyValuePair <string, string> > toolbars,
            Template <LayoutTemplateOptions> layoutTemplate,
            IEnumerable <Template <LayoutTemplateOptions> > subTemplates,
            IHtmlContent mainContent,
            GridType type,
            string id,
            string prefix,
            GridErrorMessages messages,
            string cssClass,
            string caption,
            Type localizerType,
            ModelExpression query
            ) : base(rows, toolbars, layoutTemplate, subTemplates, mainContent)
        {
            this.helpers = helpers;
            Type         = type;
            Messages     = messages;
            Id           = id;
            Prefix       = prefix;
            CssClass     = cssClass;
            Caption      = caption;
            var first = rows.FirstOrDefault();

            MustAddButtonColumn = first.MustAddButtonColumn(helpers, Type == GridType.Batch);
            VisibleColumns      = first.VisibleColumns(helpers, query?.Model as QueryDescription, Type == GridType.Batch);
            LocalizerType       = localizerType;
            Localizer           = LocalizerType != null?helpers.LocalizerFactory.Create(LocalizerType) : null;
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (string.IsNullOrWhiteSpace(SkipUrlToken))
            {
                SkipUrlToken = "_ skip_";
            }
            if (string.IsNullOrWhiteSpace(TakeUrlToken))
            {
                TakeUrlToken = "_ top_";
            }
            if (Query == null)
            {
                Query = TagContextHelper.GetBindingContext(httpAccessor.HttpContext, BindingContextNames.Query);
            }
            if (For == null)
            {
                For = TagContextHelper.GetBindingContext(httpAccessor.HttpContext, BindingContextNames.Collection);
            }
            if (string.IsNullOrWhiteSpace(UrlDefault) && Url == null && Query == null)
            {
                new ArgumentNullException("url-default/url/query");
            }

            var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);

            if (PageSizeDefault <= 0)
            {
                PageSizeDefault = 10;
            }
            if (MaxPages <= 0)
            {
                MaxPages = 5;
            }

            var    currProvider = ViewContext.TagHelperProvider();
            string operation    = null;

            if (AjaxId == null && Query?.Model != null)
            {
                QueryDescription q = Query?.Model as QueryDescription;
                if (!string.IsNullOrWhiteSpace(q.AttachedTo?.AjaxId))
                {
                    AjaxId = q.AttachedTo.AjaxId;
                }
            }
            if (AjaxId != null)
            {
                operation = "data-operation='ajax-html " + AjaxId + "'";
            }
            else if (AjaxEndpoint != null)
            {
                operation = "data-operation='ajax-json " + AjaxEndpoint + "'";
            }
            var defaultTemplates = currProvider.GetDefaultTemplates(TagName);
            var options          = new Internals.PagerOptions(defaultTemplates.GetLayoutTemplate(LayoutTemplate), operation);
            await currProvider.GetTagProcessor(TagName)(context, output, this, options, ctx);
        }
 public DefaultServerDetailProcessor(TagHelperContext context, TagHelperOutput output, DetailTagHelper tag, GridOptions options, ContextualizedHelpers helpers)
 {
     this.context = context; this.output = output; this.tag = tag;
     this.options = options; this.helpers = helpers;
     basePrefix   = tag.For.Name;
     if (basePrefix == "Model")
     {
         basePrefix = string.Empty;
     }
     AdjustColumns();
 }
 public DefaultServerQueryWindowProcessor(QueryWindowOptions options, ContextualizedHelpers helpers)
 {
     this.options  = options;
     this.helpers  = helpers;
     layoutOptions = new DefaultServerQueryWindowLayoutOptions(
         options.Rows,
         options.Toolbars,
         options.LayoutTemplate,
         helpers.Context.ViewData.GetFullHtmlFieldName(options.For.Name),//name of query input
         options.Header,
         options.GroupingOutput
         );
 }
 public DefaultServerPagerProcessor(
     TagHelperContext context,
     TagHelperOutput output,
     PagerTagHelper tag,
     Internals.PagerOptions options,
     ContextualizedHelpers helpers
     )
 {
     this.context = context;
     this.output = output;
     this.tag = tag;
     this.options = options;
     this.helpers = helpers;
 }
 public DefaultServerPagerProcessor(
     TagHelperContext context,
     TagHelperOutput output,
     PagerTagHelper tag,
     Internals.PagerOptions options,
     ContextualizedHelpers helpers
     )
 {
     this.context = context;
     this.output  = output;
     this.tag     = tag;
     this.options = options;
     this.helpers = helpers;
 }
 public static IHtmlContent RenderHiddenFields(IEnumerable<Column> columns, ContextualizedHelpers helpers, object rowModel)
 {
     StringWriter sb = new StringWriter();
     if (columns != null)
     {
         foreach (var col in columns)
         {
             var o = col.For.Metadata.PropertyGetter(rowModel);
             helpers.Html.Hidden(col.For.Name, o??string.Empty, null).WriteTo(sb, HtmlEncoder.Default);
         }
         var rowPrefix = helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix;
         if(rowPrefix.Length>0 && rowPrefix[rowPrefix.Length - 1] == ']')
         {
             var index = rowPrefix.LastIndexOf('[');
             helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix=string.Empty;
             helpers.Html.Hidden(combinePrefixes(rowPrefix.Substring(0, index), "index"), 
                 rowPrefix.Substring(index+1, rowPrefix.Length-index-2), null).WriteTo(sb, HtmlEncoder.Default);
             helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix = rowPrefix;
         }
     }
     return new HtmlString(sb.ToString());
 }
        public IHtmlContent RenderButton(StandardButtons buttonType,
                                         string arguments,
                                         string cssClass,
                                         ContextualizedHelpers helpers,
                                         IStringLocalizer localizer,
                                         bool visibleText   = false,
                                         bool isSubmit      = false,
                                         string controlType = null)
        {
            ButtonProperties currentButton = null;

            allButtonProperties.TryGetValue(buttonType, out currentButton);
            if (currentButton == null)
            {
                return(new HtmlString(string.Empty));
            }
            if (isSubmit)
            {
                return(new HtmlString(string.Format(visibleText ? buttonTemplateWithTextSubmit: buttonTemplateSubmit,
                                                    cssClass ?? string.Empty,
                                                    localizer != null ?
                                                    localizer[currentButton.ShowText] : currentButton.ShowText,
                                                    currentButton.IconClass
                                                    )));
            }
            else
            {
                return(new HtmlString(string.Format(visibleText ? buttonTemplateWithText : buttonTemplate,
                                                    currentButton.OperationName,
                                                    arguments ?? string.Empty,
                                                    cssClass ?? string.Empty,
                                                    localizer != null ?
                                                    localizer[currentButton.ShowText] : currentButton.ShowText,
                                                    currentButton.IconClass,
                                                    controlType == null ? string.Empty : "data-control-type='" + controlType + "'"
                                                    )));
            }
        }
        public static IHtmlContent RenderHiddenFields(IEnumerable <Column> columns, ContextualizedHelpers helpers, object rowModel)
        {
            StringWriter sb = new StringWriter();

            if (columns != null)
            {
                foreach (var col in columns)
                {
                    var o = col.For.Metadata.PropertyGetter(rowModel);
                    helpers.Html.Hidden(combinePrefixes(col.AdditionalPrefix, col.For.Name), o ?? string.Empty, null).WriteTo(sb, HtmlEncoder.Default);
                }
                var rowPrefix = helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix;
                if (rowPrefix.Length > 0 && rowPrefix[rowPrefix.Length - 1] == ']')
                {
                    var index = rowPrefix.LastIndexOf('[');
                    helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
                    helpers.Html.Hidden(combinePrefixes(rowPrefix.Substring(0, index), "index"),
                                        rowPrefix.Substring(index + 1, rowPrefix.Length - index - 2), null).WriteTo(sb, HtmlEncoder.Default);
                    helpers.Context.ViewData.TemplateInfo.HtmlFieldPrefix = rowPrefix;
                }
            }
            return(new HtmlString(sb.ToString()));
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {

            if (string.IsNullOrWhiteSpace(SkipUrlToken)) new ArgumentNullException("skip-url-token");
            if (string.IsNullOrWhiteSpace(TakeUrlToken)) new ArgumentNullException("take-url-token");
            if (string.IsNullOrWhiteSpace(UrlDefault) && Url == null) new ArgumentNullException("url-default/url");

            var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);

            if (PageSizeDefault <= 0) PageSizeDefault = 10;
            if (MaxPages <= 0) MaxPages = 5;

            var currProvider = ViewContext.TagHelperProvider();
            string operation = null;
            if(AjaxId!= null )
                operation = "data-operation='ajax-html "+ AjaxId + "'";
            else if(AjaxEndpoint != null)
                operation = "data-operation='ajax-json " + AjaxEndpoint + "'";
            var defaultTemplates = currProvider.GetDefaultTemplates(TagName);
            var options = new Internals.PagerOptions(defaultTemplates.GetLayoutTemplate(LayoutTemplate), operation);
            await currProvider.GetTagProcessor(TagName)(context, output, this,  options , ctx);
        }
 public  IHtmlContent RenderButton(StandardButtons buttonType, 
     string arguments, 
     string cssClass, 
     ContextualizedHelpers helpers, 
     IStringLocalizer localizer, 
     bool visibleText=false, 
     bool isSubmit=false,
     string controlType = null)
 {
     ButtonProperties currentButton = null;
     allButtonProperties.TryGetValue(buttonType, out currentButton);
     if(currentButton == null) return new HtmlString(string.Empty);
     if(isSubmit)
         return new HtmlString(string.Format(visibleText ? buttonTemplateWithTextSubmit: buttonTemplateSubmit,
             cssClass??string.Empty,
             localizer != null ?
                 localizer[currentButton.ShowText] : currentButton.ShowText,
             currentButton.IconClass
             ));
     else
         return new HtmlString(string.Format(visibleText ? buttonTemplateWithText : buttonTemplate,
             currentButton.OperationName,
             arguments ?? string.Empty,
             cssClass ?? string.Empty,
             localizer != null ?
                 localizer[currentButton.ShowText] : currentButton.ShowText,
             currentButton.IconClass,
             controlType==null ? string.Empty : "data-control-type='"+ controlType + "'"
             ));
 }
Ejemplo n.º 17
0
 public IHtmlContent RenderButton(StandardButtons buttonType, string arguments, string cssClass, ContextualizedHelpers helpers, IStringLocalizer localizer, bool visibleText = false, bool isSubmit = false, string controlType = null)
 {
     return(new HtmlString(string.Empty));
 }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //estabilish context
            if (For == null) throw new ArgumentNullException(ForAttributeName);
            if (RequiredFunctionalities == null)
            {
                if(Type == GridType.Immediate)
                    RequiredFunctionalities =  (x) => Functionalities.FullDetail;
                else
                    RequiredFunctionalities = (x) => Functionalities.FullInLine;
            }
            string fullName = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name);
            string id = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
            var currProvider = ViewContext.TagHelperProvider();
            var actTagName = TagName + (Type == GridType.Batch ? "-batch" : "-immediate");
            var defaultTemplates = currProvider.GetDefaultTemplates(actTagName);
            var ctx = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);
            //

            //get row definitions
            IList<RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
                null :
                RowType.GetRowsCollection(RowsCacheKey);
            var nc = new ReductionContext(TagTokens.RowContainer, 0,defaultTemplates, rows != null);
            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();
            var collector = new RowContainerCollector(nc);
            var res= collector.Process(this, defaultTemplates) as Tuple<IList<RowType>, IList<KeyValuePair<string, string>>>;
            if (rows == null)
            {
                rows = res.Item1;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                    RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext);
                foreach(var row in rows)
                {
                    if(row.ControllerType != null)
                    {
                        Action action = () =>
                        {
                            ControllerHelpers.DeclareServerRowtype(row.ControllerType, row);
                        };
                        CacheViewPartsFilter.AddAction(httpAccessor.HttpContext, action);
                    }
                }
            }
            var toolbars = res.Item2;
            //

            //Prepare grid options
            var options = new GridOptions(rows, toolbars, Type, id, fullName)
            {
                CssClass=CssClass,
                ErrorMessages=ErrorMessages,
                ClientRowSelection=ClientRowSelection,
                ServerRowSelection=ServerRowSelection,
                LayoutTemplate=defaultTemplates.GetLayoutTemplate(LayoutTemplate),
                SubTemplates=defaultTemplates.GetLayoutParts(LayoutParts)
            };
            //finally process!
            await currProvider.GetTagProcessor(actTagName)(context, output, this, options, ctx);
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //estabilish context
            if (For == null)
            {
                throw new ArgumentNullException(ForAttributeName);
            }
            if (RequiredFunctionalities == null)
            {
                if (Type == GridType.Immediate)
                {
                    RequiredFunctionalities = (x) => Functionalities.FullDetail;
                }
                else
                {
                    RequiredFunctionalities = (x) => Functionalities.FullInLine;
                }
            }
            string fullName         = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(For.Name);
            string id               = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
            var    currProvider     = ViewContext.TagHelperProvider();
            var    actTagName       = TagName + (Type == GridType.Batch ? "-batch" : "-immediate");
            var    defaultTemplates = currProvider.GetDefaultTemplates(actTagName);
            var    ctx              = new ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);

            //
            //estabilish context for children controls
            TagContextHelper.OpenBindingContext(httpAccessor.HttpContext, BindingContextNames.Collection, For);
            TagContextHelperAdvanced.OpenPermissionBindingContext(httpAccessor.HttpContext, new PermissionInfos
            {
                ClientUserPermissions = ClientRequiredFunctionalities,
                UserPermissions       = RequiredFunctionalities
            });
            if (QueryFor != null && QueryEnabled.HasValue && QueryEnabled.Value)
            {
                TagContextHelper.OpenBindingContext(httpAccessor.HttpContext, BindingContextNames.Query, QueryFor);
                TagContextHelper.OpenTypeBindingContext(httpAccessor.HttpContext, BindingContextNames.GroupingType, GroupingOutput ?? For.Metadata.ElementType);
            }
            //get row definitions
            IList <RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
                                   null :
                                   RowType.GetRowsCollection(RowsCacheKey);
            var nc = new ReductionContext(TagTokens.RowContainer, 0, defaultTemplates, rows != null);

            context.SetChildrenReductionContext(nc);
            TagContextHelper.OpenRowContainerContext(httpAccessor.HttpContext);
            await output.GetChildContentAsync();

            var collector = new RowContainerCollector(nc);
            var res       = collector.Process(this, defaultTemplates) as Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >;

            if (rows == null)
            {
                rows = res.Item1;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                {
                    RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext);
                    httpAccessor.HttpContext.Items["_request_cache_" + RowsCacheKey] = rows;
                }
                foreach (var row in rows)
                {
                    if (row.ControllerType != null)
                    {
                        Action action = () =>
                        {
                            ControllerHelpers.DeclareServerRowtype(row.ControllerType, row);
                        };
                        CacheViewPartsFilter.AddAction(httpAccessor.HttpContext, action);
                    }
                }
            }
            var toolbars = res.Item2;

            TagContextHelper.CloseRowContainerContext(httpAccessor.HttpContext, new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars));
            //

            //Prepare grid options
            var options = new GridOptions(rows, toolbars, Type, id, fullName)
            {
                CssClass           = CssClass,
                ErrorMessages      = ErrorMessages,
                ClientRowSelection = ClientRowSelection,
                ServerRowSelection = ServerRowSelection,
                LayoutTemplate     = defaultTemplates.GetLayoutTemplate(LayoutTemplate),
                SubTemplates       = defaultTemplates.GetLayoutParts(LayoutParts)
            };
            //finally process!
            await currProvider.GetTagProcessor(actTagName)(context, output, this, options, ctx);

            if (QueryFor != null && QueryEnabled.HasValue && QueryEnabled.Value)
            {
                TagContextHelper.CloseTypeBindingContext(httpAccessor.HttpContext, BindingContextNames.GroupingType);
                TagContextHelper.CloseBindingContext(httpAccessor.HttpContext, BindingContextNames.Query);
            }
            TagContextHelperAdvanced.ClosePermissionBindingContext(httpAccessor.HttpContext);
            TagContextHelper.CloseBindingContext(httpAccessor.HttpContext, BindingContextNames.Collection);
            if (!ViewContext.FormContext.CanRenderAtEndOfForm)
            {
                TagContextHelper.CloseFormContext(httpAccessor.HttpContext, output);
            }
        }
 public DefaultServerQueryButtonProcessor(TagHelperOutput output, ContextualizedHelpers helpers, QueryButtonOptions options)
 {
     this.output  = output;
     this.options = options;
     this.helpers = helpers;
 }
Ejemplo n.º 21
0
 public static int VisibleColumns(this RowType row, ContextualizedHelpers helpers, QueryDescription query, bool editOnly = false)
 {
     return(row.MustAddButtonColumn(helpers, query, editOnly) ? row.ColumnsCount + 1 : row.ColumnsCount);
 }
Ejemplo n.º 22
0
        public static bool MustAddButtonColumn(this RowType row, ContextualizedHelpers helpers, QueryDescription query, bool editOnly = false)
        {
            var userPermissions = row.RequiredFunctionalitiesExt(helpers.User, query);

            return(!row.CustomButtons && ((userPermissions & (editOnly ? Functionalities.EditOnlyHasRowButtons : Functionalities.HasRowButtons)) != 0));
        }