Пример #1
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new ArgumentNullException(ForAttributeName);
            }
            if (KeyName == null && !FromRow.HasValue)
            {
                throw new ArgumentNullException(KeyAttributeName);
            }
            var rc = context.GetFatherReductionContext();

            if (rc.RowParsingDisabled)
            {
                output.TagName = string.Empty;
                output.Content.SetHtmlContent(string.Empty);
                return;
            }
            var nc = new ReductionContext(TagTokens.Row, 0, rc.Defaults);

            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();

            RowType inherit = null;

            if (FromRow.HasValue)
            {
                var count = 0;
                foreach (var item in rc.Results)
                {
                    if (item.Token == TagTokens.Row)
                    {
                        if (FromRow.Value == count)
                        {
                            inherit = item.Result as RowType;
                            continue;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }
            }
            var collector = new RowCollector(nc, FromRow);
            var res       = collector.Process(this, rc.Defaults);

            if (res != null)
            {
                rc.Results.Add(new ReductionResult(TagTokens.Row, 0, res));
            }
            output.TagName = string.Empty;
            output.Content.SetHtmlContent(string.Empty);
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var rc = ViewContext.ViewData[ImportSettingsTagHelper.contextName] as ReductionContext;

            output.TagName = string.Empty;
            if (rc != null)
            {
                context.SetChildrenReductionContext(rc);
            }
            var res = await output.GetChildContentAsync();

            output.TagName = string.Empty;
            output.Content.SetHtmlContent(res);
        }
Пример #3
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var rc = context.GetFatherReductionContext();

            output.TagName = string.Empty;
            output.Content.SetHtmlContent(string.Empty);

            //get row definitions
            IList <RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
                                   null :
                                   RowType.GetRowsCollection(RowsCacheKey);
            IList <KeyValuePair <string, string> > toolbars = string.IsNullOrEmpty(RowsCacheKey) ?
                                                              null :
                                                              RowType.GetToolbarsCollection(RowsCacheKey);

            if (rows != null || toolbars != null)
            {
                return;
            }
            var currProvider     = ViewContext.TagHelperProvider();
            var defaultTemplates = currProvider.GetDefaultTemplates(TagHlperForDefaults);
            var nc = new ReductionContext(TagTokens.RowContainer, 0, defaultTemplates, rows != null);

            TagContextHelper.OpenRowContainerContext(contextAccessor.HttpContext);
            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, contextAccessor.HttpContext, true);
                }
            }
            if (toolbars == null)
            {
                toolbars = res.Item2;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                {
                    RowType.CacheToolbarGroup(RowsCacheKey, toolbars, contextAccessor.HttpContext, true);
                }
            }
            TagContextHelper.CloseRowContainerContext(contextAccessor.HttpContext, new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars));
        }
Пример #4
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var rc = context.GetFatherReductionContext();

            if (rc.RowParsingDisabled)
            {
                output.TagName = string.Empty;
                output.Content.SetHtmlContent(string.Empty);
                return;
            }
            var nc = new ReductionContext(TagTokens.Column, 0, rc.Defaults);

            context.SetChildrenReductionContext(nc);
            await output.GetChildContentAsync();

            output.TagName = string.Empty;
            output.Content.SetHtmlContent(string.Empty);
            var collector = new ColumnCollector(nc);

            rc.Results.Add(new ReductionResult(TagTokens.Column, Remove ? -1 : 1, collector.Process(this, rc.Defaults)));
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            //estabilish context
            if (For == null)
            {
                throw new ArgumentNullException(ForAttributeName);
            }
            if (Mode != null && Mode.Metadata.UnderlyingOrModelType != typeof(bool))
            {
                throw new ArgumentException(ModeName, string.Format(Resources.MustBeBool, ModeName));
            }
            if (ModelNullRow != null && Mode.Metadata.UnderlyingOrModelType != typeof(int))
            {
                throw new ArgumentException(ModelNullRowName, string.Format(Resources.MustBeInt, ModelNullRowName));
            }
            var basePrefix = For.Name;

            if (basePrefix == "Model")
            {
                basePrefix = string.Empty;
            }
            ;
            string fullName         = ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(basePrefix);
            string id               = OverrideId ?? TagBuilder.CreateSanitizedId(fullName, IdAttributeDotReplacement);
            var    currProvider     = ViewContext.TagHelperProvider();
            var    defaultTemplates = currProvider.GetDefaultTemplates(TagName);
            var    ctx              = new Core.Templates.ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);
            //

            //get row definitions
            IList <RowType> rows = string.IsNullOrEmpty(RowsCacheKey) ?
                                   null :
                                   RowType.GetRowsCollection(RowsCacheKey);
            var nc = new Core.OptionsParsing.ReductionContext(Core.OptionsParsing.TagTokens.RowContainer, 0, defaultTemplates, rows != null);

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

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

            if (rows == null)
            {
                rows = res.Item1;
                if (!string.IsNullOrEmpty(RowsCacheKey))
                {
                    RowType.CacheRowGroup(RowsCacheKey, rows, httpAccessor.HttpContext);
                }
            }
            var toolbars = res.Item2;

            TagContextHelper.CloseRowContainerContext(httpAccessor.HttpContext, new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars));
            //Prepare detail options
            var options = new Core.TagHelpers.Internals.GridOptions(rows, toolbars, GridType.Batch, id, fullName)
            {
                CssClass           = CssClass,
                ErrorMessages      = null,
                ClientRowSelection = ClientRowSelection,
                ServerRowSelection = ServerRowSelection,
                LayoutTemplate     = defaultTemplates.GetLayoutTemplate(LayoutTemplate),
                SubTemplates       = null
            };
            //finally process!
            await currProvider.GetTagProcessor(TagName)(context, output, this, options, ctx);
        }
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (For == null)
            {
                throw new ArgumentNullException(ForAttributeName);
            }

            if (Type == QueryWindowType.Grouping && GroupingOutput == null)
            {
                throw new ArgumentNullException(GroupingOutputName);
            }
            if (!typeof(QueryDescription).GetTypeInfo().IsAssignableFrom(For.Metadata.ModelType))
            {
                throw new ArgumentException(ForAttributeName);
            }
            if (CollectionFor == null)
            {
                throw new ArgumentNullException(CollectionForAttributeName);
            }


            var currProvider = ViewContext.TagHelperProvider();

            var tagPrefix = Type == QueryWindowType.Filtering ? "query-filter-" :
                            (Type == QueryWindowType.Sorting ? "query-sort-" : "query-group-");


            var windowTag = tagPrefix + "inline";
            var ctx       = new Core.Templates.ContextualizedHelpers(ViewContext, html, httpAccessor, component, urlHelperFactory, factory);


            var windowDefaultTemplates = currProvider.GetDefaultTemplates(windowTag);



            IList <RowType> rows = string.IsNullOrEmpty(RowCollection) ?
                                   null :
                                   RowType.GetRowsCollection(RowCollection);
            IList <KeyValuePair <string, string> > toolbars = string.IsNullOrEmpty(RowCollection) ?
                                                              null :
                                                              RowType.GetToolbarsCollection(RowCollection);

            if (rows == null && !string.IsNullOrEmpty(RowCollection))
            {
                object orows;
                httpAccessor.HttpContext.Items.TryGetValue("_request_cache_" + RowCollection, out orows);
                rows = orows as IList <RowType>;
            }
            if (toolbars == null)
            {
                var nc = new Core.OptionsParsing.ReductionContext(Core.OptionsParsing.TagTokens.RowContainer, 0, windowDefaultTemplates, true);
                context.SetChildrenReductionContext(nc);

                await output.GetChildContentAsync();

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


                toolbars = res.Item2;
                if (!string.IsNullOrEmpty(RowCollection))
                {
                    RowType.CacheToolbarGroup(RowCollection, toolbars, httpAccessor.HttpContext);
                }
            }
            var windowOptions = new QueryWindowOptions(rows, toolbars)
            {
                ClientCustomProcessorFor = ClientCustomProcessorFor,
                CollectionFor            = CollectionFor,
                For            = For,
                SourceFor      = SourceFor,
                GroupingOutput = GroupingOutput,
                Header         = null,
                LayoutTemplate = string.IsNullOrEmpty(LayoutTemplate) ? windowDefaultTemplates.LayoutTemplate :
                                 new Template <LayoutTemplateOptions>(TemplateType.Partial, LayoutTemplate),
                TotalPagesContainer = TotalPagesContainer
            };
            Func <Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >, Task <IHtmlContent> > toExecute =
                async group =>
            {
                if (windowOptions.Rows == null && group != null)
                {
                    windowOptions.UpdateRows(group.Item1, group.Item2);
                }
                if (windowOptions.Rows == null)
                {
                    return(new HtmlString(string.Empty));
                }
                var mainRow = windowOptions.Rows.FirstOrDefault();
                if (mainRow == null)
                {
                    return(new HtmlString(string.Empty));
                }

                windowOptions.Header = localizeWindow(mainRow, windowOptions.Header);
                if (Type == QueryWindowType.Filtering && mainRow.FilterTemplate == null)
                {
                    mainRow.FilterTemplate = windowDefaultTemplates.ERowTemplate;
                    foreach (var col in mainRow.Columns)
                    {
                        col.FilterTemplate = windowDefaultTemplates.EColumnTemplate;
                    }
                }
                else if (Type == QueryWindowType.Grouping && mainRow.GroupingTemplate == null)
                {
                    mainRow.GroupingTemplate = windowDefaultTemplates.ERowTemplate;
                }
                else if (Type == QueryWindowType.Sorting && mainRow.SortingTemplate == null)
                {
                    mainRow.SortingTemplate = windowDefaultTemplates.ERowTemplate;
                }
                await currProvider.GetTagProcessor(windowTag)(null, null, this, windowOptions, ctx);

                return(windowOptions.Result);
            };

            TagContextHelper.OpenBindingContext(httpAccessor.HttpContext, BindingContextNames.Query, For);
            output.TagName = string.Empty;
            output.Content.SetHtmlContent(await toExecute(new Tuple <IList <RowType>, IList <KeyValuePair <string, string> > >(rows, toolbars)));
            TagContextHelper.CloseBindingContext(httpAccessor.HttpContext, BindingContextNames.Query);
        }
        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);
            }
        }