コード例 #1
0
        /// <summary>
        /// Creates the framework control.
        /// </summary>
        /// <param name="context">Contains information associated with the current HTML tag.</param>
        /// <param name="output">A stateful HTML element used to generate an HTML tag.</param>
        /// <returns>The control instance.</returns>
        protected override IFWHtmlElement RenderControl(TagHelperContext context, TagHelperOutput output)
        {
            if (Id == null)
            {
                Id = TagBuilder.CreateSanitizedId(Path.GetFileNameWithoutExtension(ViewContext.View.Path), "_");
            }

            FWGridOptions options = CreateComponentConfig();

            // Gets the metadata from the return type of the service method.
            var metadata = RequestContext.MetadataProvider.GetMetadataForType(options.ServiceMethod.ReturnParameter.ParameterType);
            var control  = new FWGridControl(RequestContext, metadata, options)
            {
                AutoSizeColumns = AutoSizeColumns
            };

            control.Attributes.Add("data-control", "grid");
            if (AutoGenerateColumns.HasValue)
            {
                options.FluentConfiguration.Add(x => x.AutoGenerateColumns(AutoGenerateColumns.Value));
                control.AutoGenerateColumns(AutoGenerateColumns.Value);
            }

            context.Items["TemplateOptions"] = options;
            ChildContent.GetContent();

            return(control);
        }
コード例 #2
0
        private FWGridOptions CreateComponentConfig()
        {
            // Configures the grid method service.
            var service = ServiceProvider.GetService(Service);

            if (service == null)
            {
                throw new FWImplementationNotFoundException(Service);
            }

            var options = new FWGridOptions($"{ViewContext.ViewData.ModelMetadata.ModelType.Name}_{Id}")
            {
                Id              = Id,
                ServiceType     = Service,
                ServiceMethod   = Service.GetMethod(Method),
                ViewPath        = ViewContext.View.Path,
                AutoSizeColumns = AutoSizeColumns
            };

            // Caches the options for 2 hours.
            MemoryCache.Set(options.CacheKey, options, new TimeSpan(2, 0, 0));

            return(options);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new Grid control.
        /// </summary>
        /// <param name="requestContext">The request helper.</param>
        /// <param name="metadata">The model metadata.</param>
        /// <param name="options">Initialization options for the grid.</param>
        public FWGridControl(FWRequestContext requestContext, ModelMetadata metadata, FWGridOptions options)
            : base(requestContext, null, metadata, options.Id)
        {
            _fullRender = true;
            _cacheKey   = options.CacheKey;

            // Checks if the filter has a pagination.
            if (_pagination.IsAssignableFrom(options.FilterType))
            {
                var dataOptions = Activator.CreateInstance(options.FilterType);
                InitializeDataFiltering(dataOptions as IFWPagination);
            }
        }