/// <summary>
        ///     Generate a <see cref="PagerRenderingList" /> for a series of <see cref="PagerItem" />.
        /// </summary>
        /// <param name="items">The collection of <see cref="PagerItem" /> which are included in the list.</param>
        /// <param name="context">The generation context.</param>
        /// <returns>The generated <see cref="PagerRenderingList" /> instance.</returns>
        private PagerRenderingList GenerateRenderingListCore(IEnumerable <PagerItem> items, PagerGenerationContext context)
        {
            var optionsCache = new Dictionary <PagerItemType, PagerItemOptions>();

            var renderingItemList = new List <PagerRenderingItem>();

            // Owner
            var result = new PagerRenderingList
            {
                Settings = new Dictionary <string, string>(context.Options.AdditionalSettings)
            };

            foreach (var item in items)
            {
                PagerItemOptions itemOptions;

                // Try to get cached options, or create a new option instance
                if (!optionsCache.TryGetValue(item.ItemType, out itemOptions))
                {
                    itemOptions = context.Options.ItemOptions.GetMergedOptionsFor(item);
                    optionsCache[item.ItemType] = itemOptions;
                }

                // Generate item context
                var itemContext = new PagerItemGenerationContext(context, item, itemOptions);

                // Generate item and add to list
                var renderingItem = GenerateRenderingItem(result, itemContext);
                renderingItemList.Add(renderingItem);
            }

            // Result
            result.Items = new ReadOnlyCollection <PagerRenderingItem>(renderingItemList);
            return(result);
        }
Example #2
0
        /// <summary>
        ///     Initialize a new <see cref="PagerRenderingItem" />.
        /// </summary>
        /// <param name="list">The owner list of the pager item.</param>
        public PagerRenderingItem([NotNull] PagerRenderingList list)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            List = list;
        }
 /// <summary>
 ///     Generate a <see cref="PagerRenderingItem" /> for the current pager item.
 /// </summary>
 /// <param name="list">The ownner list of the new item.</param>
 /// <param name="context">The generation context.</param>
 /// <returns>The generated <see cref="PagerRenderingItem" /> instance.</returns>
 private PagerRenderingItem GenerateRenderingItem(PagerRenderingList list, PagerItemGenerationContext context)
 {
     return(new PagerRenderingItem(list)
     {
         Content = context.PagerItemOptions.Content?.GenerateContent(context),
         Link = context.PagerItemOptions.Link?.GenerateLink(context),
         Settings = new Dictionary <string, string>(context.PagerItemOptions.AdditionalSettings),
         State = GetRenderingItemState(context)
     });
 }
Example #4
0
        /// <summary>
        ///     Generate the container tag.
        /// </summary>
        /// <returns>The container tag.</returns>
        protected static TagBuilder GenerateContainer(PagerRenderingList list)
        {
            var tag = new TagBuilder("ul");

            tag.AddCssClass("pagination");             // core CSS class for pagination

            AppendAdditionalAttributes(tag, list.Settings, ListAttributeSettingKeyPrefix);

            return(tag);
        }
Example #5
0
        /// <summary>
        ///     The core method to generate the HTML content.
        /// </summary>
        /// <param name="list">The pager list to generating the content.</param>
        /// <param name="generateContainer">Whether a container element should be generated.</param>
        /// <returns>The final <see cref="IHtmlContent" />.</returns>
        protected static IHtmlContent GeneratePagerCore(PagerRenderingList list, bool generateContainer)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            var content = GeneratePagerItems(list.Items);

            // No container
            if (!generateContainer)
            {
                return(content);
            }

            // With container
            var container = GenerateContainer(list);

            container.InnerHtml.SetHtmlContent(content);

            return(container);
        }
Example #6
0
 /// <summary>
 ///     Generate the entire HTML content for a pager renderling list.
 /// </summary>
 /// <param name="list">The rendering list to be generating.</param>
 /// <param name="context">The pager generation context.</param>
 /// <returns>The entire HTML content for the generated pager.</returns>
 public IHtmlContent GeneratePager(PagerRenderingList list, PagerGenerationContext context)
 {
     return(GeneratePagerCore(list, context.GenerationMode == PagerGenerationMode.Full));
 }
Example #7
0
 /// <summary>
 ///     Initialize a new <see cref="PagerRenderingItem" />.
 /// </summary>
 /// <param name="list">The owner list of the pager item.</param>
 public PagerRenderingItem([NotNull] PagerRenderingList list)
 {
     List = list ?? throw new ArgumentNullException(nameof(list));
 }