/// <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), "_"); } FWListOptions 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 FWListControl(RequestContext, metadata, options); control.Attributes.Add("data-control", "list"); context.Items["TemplateOptions"] = options; ChildContent.GetContent(); return(control); }
private FWListOptions CreateComponentConfig() { // Configures the grid method service. var service = ServiceProvider.GetService(Service); if (service == null) { throw new FWImplementationNotFoundException(Service); } var options = new FWListOptions($"{ViewContext.ViewData.ModelMetadata.ModelType.Name}_{Id}") { Id = Id, ServiceType = Service, ServiceMethod = Service.GetMethod(Method), ViewPath = ViewContext.View.Path }; // Caches the options for 2 hours. MemoryCache.Set(options.CacheKey, options, new TimeSpan(2, 0, 0)); return(options); }
/// <summary> /// Creates a new List control. /// </summary> /// <param name="requestContext">The request helper.</param> /// <param name="metadata">The model metadata.</param> /// <param name="options">Initialization options for the list.</param> public FWListControl(FWRequestContext requestContext, ModelMetadata metadata, FWListOptions options) : base(options.Id) { _fullRender = true; _cacheKey = options.CacheKey; RequestContext = requestContext; ListType = metadata.ModelType.GetGenericArguments().First(); ParentType = metadata.ContainerType ?? metadata.ModelType; if (_paginationInterface.IsAssignableFrom(options.FilterType)) { _paginator = new FWPaginator(Activator.CreateInstance(options.FilterType) as IFWPagination); } }