public IPayload GetPayload()
        {
            Pagination      pagination = new Pagination();
            PaginationLinks links      = new PaginationLinks();

            if (Query != null)
            {
                pagination = new Pagination()
                {
                    Skip  = Query.Skip ?? 0,
                    Limit = Query.Take ?? Total,
                    Total = Total
                };

                links = new PaginationLinks()
                {
                    Next     = Query.GetNext(Total),
                    Previous = Query.GetPrevious()
                };
            }


            CollectionPayload <T> collectionPayload = new CollectionPayload <T>(data: Data)
            {
                Links      = links,
                Pagination = pagination
            };

            return(collectionPayload);
        }
Exemple #2
0
        /// <summary>
        /// Sets the pagination links.
        /// </summary>
        /// <param name="options">Application Global settings.</param>
        /// <param name="httpContext">The Http Context of the request</param>
        internal void SetLinks(NexusatAspNetCoreOptions options, HttpContext context)
        {
            string requestUrl = context.Request.GetEncodedPathAndQuery();

            // Only one of the following condition can hold
            /// <see cref="Builders.ApiEnumResponseBuilder{T}"/>
            Debug.Assert(ItemsCount.HasValue ^ HasNextPage);

            PageSize = PaginationCursor.PageSize;

            if (PaginationCursor.IsPageSizeBounded) // If unbounded links are not generated
            {
                Links = new PaginationLinks();
                var linkBuilder = new PaginationInfoLinkBuilder(
                    context.Request.GetEncodedPathAndQuery(),
                    options.PaginationPageIndexName,
                    options.PaginationPageSizeName,
                    PaginationCursor.PageSize
                    );
                // First
                Links.First = linkBuilder.GetLink(1);
                // Current
                Links.Current = linkBuilder.GetLink(PaginationCursor.PageIndex);
                // Previous
                if (PaginationCursor.PageIndex > 1)
                {
                    Links.Previous = linkBuilder.GetLink(PaginationCursor.PageIndex - 1);
                }

                if (ItemsCount.HasValue)
                { // calculate links and pageCount
                    int pageCount =
                        (ItemsCount.Value + PaginationCursor.PageSize - 1) / PaginationCursor.PageSize;
                    PagesCount = pageCount;
                    if (pageCount > PaginationCursor.PageIndex)
                    {
                        // Next
                        Links.Next = linkBuilder.GetLink(PaginationCursor.PageIndex + 1);
                    }
                    // Last
                    Links.Last = linkBuilder.GetLink(pageCount);
                }
                else if (HasNextPage) // implies hasn't itemsCount
                {                     // calculate links except the "last"
                    Links.Next = linkBuilder.GetLink(PaginationCursor.PageIndex + 1);
                }
            }
            else     // Unbounded requests have only 1 page of data
            {
                PagesCount = 1;
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates page navigation links as an ul with CSS class=pager
        /// </summary>
        /// <param name="html">helper</param>
        /// <param name="page">Current page</param>
        /// <param name="itemsOnPage">Number of items displayed on a page</param>
        /// <param name="totalItems">Total number of items available</param>
        /// <param name="linkHrefFormat">link format for paging navigation </param>
        /// <param name="currentFormat">format for current page navigation.Default it renders
        /// &lt;span class="current"&gt;{0}&lt;span&gt;</param>
        /// <param name="ulClass">additional CSS class for the ul</param>
        /// <returns></returns>
        public static MvcHtmlString Pager(this HtmlHelper html, int page, int itemsOnPage, int totalItems, Func <int, string> linkHrefFormat,
                                          Func <int, string> currentFormat = null, string ulClass = "")
        {
            var pl = new PaginationLinks();

            pl.Current           = page;
            pl.ItemsOnPage       = itemsOnPage;
            pl.TotalItems        = totalItems;
            pl.LinkUrlFormat     = linkHrefFormat;
            pl.CurrentPageFormat = currentFormat ?? pl.CurrentPageFormat;
            var sb = new StringBuilder();

            if (ulClass != "")
            {
                ulClass = " " + ulClass;
            }
            sb.AppendFormat("<ul class=\"pager{0}\">", ulClass);
            foreach (var link in pl.GetPages())
            {
                sb.AppendFormat("<li>{0}</li>", link);
            }
            sb.Append("</ul>");
            return(new MvcHtmlString(sb.ToString()));
        }
        public virtual void SetRowLists()
        {
            RowList = new List <SNGridRow>();

            List <IWebElement> rows = new List <IWebElement>();

            //get pagination rows
            try
            {
                WebElementPaginationRows = PaginationRows.WaitForElements(5);
                if (WebElementPaginationRows != null)
                {
                    HasPaginationRows = true;
                    //get the pagination links
                    WebElementPaginationLinks = PaginationLinks.WaitForElements(5);
                }
                else
                {
                    HasPaginationRows = false;
                }
                if (Driver.WrappedDriver.GetType() == typeof(DummyDriver))
                {
                    if (DummyElementPaginationRowList == null)
                    {
                        DummyElementPaginationRowList = GetDummyElementsPaginationRows();
                    }
                    WebElementPaginationRows = new ReadOnlyCollection <IWebElement>(DummyElementPaginationRowList);
                }
                //set the top pagination row as the 1st row
                rows.Add(WebElementPaginationRows[0]);
            }
            catch (Exception e)
            {
                //or else the pagination rows do not exist, so do nothing
                HasPaginationRows = false;
            }

            //get the header row
            try
            {
                WebElementHeaderRows = HeaderRow.WaitForElements(5);
                if (WebElementHeaderRows != null)
                {
                    HasHeaderRow = true;
                }
                else
                {
                    HasHeaderRow = false;
                }
                if (Driver.WrappedDriver.GetType() == typeof(DummyDriver))
                {
                    if (DummyElementHeaderRowList == null)
                    {
                        DummyElementHeaderRowList = GetDummyElementsHeaderRows();
                    }
                    WebElementHeaderRows = new ReadOnlyCollection <IWebElement>(DummyElementHeaderRowList);
                }
                //add the header row
                rows.AddRange(WebElementHeaderRows);
            }
            catch (Exception e)
            {
                //or else the header row does not exist, so do nothing
                HasHeaderRow = false;
            }

            //get the data rows
            WebElementDataRows = Rows.WaitForElements(5);
            if (Driver.WrappedDriver.GetType() == typeof(DummyDriver))
            {
                if (DummyElementDataRowList == null)
                {
                    DummyElementDataRowList = GetDummyElementsDataRows();
                }
                WebElementDataRows = new ReadOnlyCollection <IWebElement>(DummyElementDataRowList);
            }
            //add the data rows
            rows.AddRange(WebElementDataRows);

            //if the pagination rows exist
            if (WebElementPaginationRows != null)
            {
                //if there are a top and bottom pagination rows
                if (WebElementPaginationRows.Count == 2)
                {
                    //set the bottom pagination row as the last row
                    rows.Add(WebElementPaginationRows[1]);
                }
            }
            //if the pagination links exist
            if (WebElementPaginationLinks != null)
            {
                //get the pagination link count
                PaginationLinkCount = WebElementPaginationLinks.Count;
            }
            else
            {
                PaginationLinkCount = 0;
            }
            Report.Write("Grid Pagination link count: " + PaginationLinkCount);

            //create the IWebElement row collection
            WebElementRows = new ReadOnlyCollection <IWebElement>(rows);

            /* EXTEND GridRow WITH YOUR OWN CLASS,
             * THEN CALL THIS BASE METHOD FIRST,
             * THEN OVERRIDE THIS METHOD IN YOUR OWN CODE
             * base.SetRowLists();
             * int rowIndex = 0;
             * foreach (var webElement in WebElementRows)
             * {
             *  GridRowType rowType = GetGridRowType(rowIndex);
             *  var lineItem = new GridRow(Driver, gridCssSelector, webElement, rowIndex, rowType, ColumnList, ControlPrefix);
             *  RowList.Add(lineItem);
             *  rowIndex++;
             * }
             */
        }