Ejemplo n.º 1
0
        /// <summary>
        /// Get a string representation of this page converted into HTML
        /// </summary>
        /// <returns>An HTML representation of the page as a string</returns>
        public string ToHtml(int indent = 0)
        {
            var sb = new StringBuilder();

            //Open the containing div
            sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            sb.Append($"<div class=\"container jui-page\" pageid=\"{Id}\">");
            sb.Append(Environment.NewLine);
            indent++;
            //sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            //sb.Append($"<input type=\"hidden\" class=\"jui-page\" pageid=\"{Id}\" >");
            //Add all of the child views
            foreach (var view in _views)
            {
                sb.Append(view.ToHtml(indent));
            }
            sb.Append(Environment.NewLine);
            indent--;
            sb.Append(AbstractView.GetIndentStringFromNumber(indent));
            sb.Append("</div>");
            sb.Append(Environment.NewLine);

            return(sb.ToString());
        }
Ejemplo n.º 2
0
            public static string PageListToHtml(List <string> jsonPages, int selectedPage = 0)
            {
                if (jsonPages == null)
                {
                    throw new ArgumentNullException(nameof(jsonPages));
                }

                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (jsonPages.Count)
                {
                case 0:
                    throw new ArgumentException("There are no pages to convert to HTML");

                case 1: {
                    var page = FromJsonString(jsonPages[0]);
                    return(page.ToHtml());
                }
                }

                var pages = jsonPages.Select(FromJsonString).ToList();

                var sb     = new StringBuilder();
                var indent = 0;

                //Open the tablist
                sb.Append("<ul class=\"nav nav-tabs hs-tabs\" role=\"tablist\">");
                sb.Append(Environment.NewLine);
                indent++;
                //Add tabs
                var pageIndex = -1;

                foreach (var page in pages)
                {
                    pageIndex++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open nav item
                    sb.Append("<li class=\"nav-item\">");
                    sb.Append(Environment.NewLine);
                    indent++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open anchor
                    sb.Append("<a class=\"nav-link waves-light\" id=\"");
                    sb.Append(page.Id);
                    sb.Append(".tab\" data-toggle=\"tab\" href=\"#");
                    sb.Append(page.Id);
                    sb.Append("\" role=\"tab\" aria-controls=\"");
                    sb.Append(page.Id);
                    sb.Append("\" aria-selected=\"");
                    sb.Append(pageIndex == selectedPage ? "true" : "false");
                    sb.Append("\">");
                    sb.Append(page.Name);
                    //Close anchor
                    sb.Append("</a>");
                    sb.Append(Environment.NewLine);
                    indent--;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Close nav item
                    sb.Append("</li>");
                    sb.Append(Environment.NewLine);
                }

                //Close the tablist
                sb.Append("</ul>");
                sb.Append(Environment.NewLine);
                //Open the content div
                sb.Append("<div class=\"tab-content container\">");
                sb.Append(Environment.NewLine);
                pageIndex = -1;
                //Add the tab content divs
                foreach (var page in pages)
                {
                    pageIndex++;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Open the tab pane div
                    sb.Append("<div class=\"tab-pane fade");
                    if (pageIndex == 0)
                    {
                        sb.Append(" active show");
                    }
                    sb.Append("\" role=\"tabpanel\" aria-labelledby=\"");
                    sb.Append(page.Id);
                    sb.Append(".tab\" id=\"");
                    sb.Append(page.Id);
                    sb.Append("\">");
                    sb.Append(Environment.NewLine);
                    indent++;
                    //Add the page content
                    sb.Append(page.ToHtml(indent));
                    indent--;
                    sb.Append(AbstractView.GetIndentStringFromNumber(indent));
                    //Close the tab content div
                    sb.Append("</div>");
                    sb.Append(Environment.NewLine);
                }
                //Close the content div
                sb.Append("</div>");

                return(sb.ToString());
            }