public static IHtmlContent RadioButtonsFor <TModel, TProperty>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TProperty> > property, IEnumerable <SelectListItem> selectList, object htmlAttributes)
        {
            var propertyInfo = property.GetProperty();

            var value = propertyInfo.GetValue(html.ViewData.Model);

            if (value is IEntity)
            {
                value = (value as IEntity).GetId();
            }

            var settings = ToHtmlAttributes(htmlAttributes);

            var result = new HtmlContentBuilder();

            result.AppendHtmlLine($"<div class=\"radio-list\" id=\"{propertyInfo.Name}\">");

            foreach (var item in selectList)
            {
                result.AppendHtmlLine($"<div{settings}>");

                var id = propertyInfo.Name + "_" + selectList.IndexOf(item);

                result.AppendHtml(html.RadioButton(propertyInfo.Name, item.Value, IsSelected(item, value),
                                                   new { id, @class = "form-check-input" }));

                result.AppendHtmlLine($"<label for=\"{id}\" class=\"form-check-label\">{item.Text}</label>");

                result.AppendHtmlLine("</div>");
            }

            result.AppendHtmlLine("</div>");

            return(result);
        }
        public static IHtmlContent HiddenMainHeading(string content, string htmlClass = "", Dictionary <string, string> attributes = null)
        {
            if (attributes == null)
            {
                attributes = new Dictionary <string, string> {
                    { "", "" }
                };
            }

            IHtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            //Start h1
            htmlContentBuilder.AppendHtml("<h1 id='ez-main-heading' style='visibility: hidden;' class='" + htmlClass + "'");

            //Set up attributes
            foreach (KeyValuePair <string, string> attribute in attributes)
            {
                if (!String.IsNullOrEmpty(attribute.Key))
                {
                    htmlContentBuilder.AppendHtml(attribute.Key + "='" + attribute.Value + "'");
                }
            }
            htmlContentBuilder.AppendHtml(">");

            //Content
            htmlContentBuilder.AppendHtmlLine(content);

            //End h1
            htmlContentBuilder.AppendHtmlLine("</h1>");

            return(htmlContentBuilder);
        }
Exemple #3
0
        public override WidgetViewModelPart Display(WidgetDisplayContext widgetDisplayContext)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            htmlContentBuilder.AppendHtmlLine("<!-- head:{0} -->".FormatWith(widgetDisplayContext.Widget.ID));
            htmlContentBuilder.AppendHtmlLine((widgetDisplayContext.Widget as HeadWidget).Content);
            htmlContentBuilder.AppendHtmlLine("<!-- end -->");
            ApplicationContext.As <CMSApplicationContext>().HeaderPart.Add(htmlContentBuilder);
            return(base.Display(widgetDisplayContext));
        }
        public static IHtmlContent SkipMenu()
        {
            IHtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            htmlContentBuilder.AppendHtmlLine("<nav role='navigation' style='opacity: 0'>");
            htmlContentBuilder.AppendHtmlLine("<a id='skip-link' style='opacity: 0' href='#ez-main-heading'>Skip to main content.</a>");
            htmlContentBuilder.AppendHtmlLine("</nav>");

            return(htmlContentBuilder);
        }
Exemple #5
0
        private IHtmlContent CreateContestJson(IDictionary <int, string> contestYears)
        {
            var script = new HtmlContentBuilder();

            script.AppendHtmlLine("<script> if (contest_years == undefined) { var contest_years = {");

            foreach (var pair in contestYears)
            {
                script.AppendLine($"{pair.Key}: {pair.Value},");
            }

            script.AppendHtmlLine("}; } </script>");
            return(script);
        }
        public static IHtmlContent DataGrid(this IHtmlHelper htmlHelper, string name, string dataSourceUrl, List <GridColumn> columns, GridCriteria criteria = null)
        {
            criteria = criteria ?? new GridCriteria();

            var htmlBuilder = new HtmlContentBuilder();

            htmlBuilder.AppendHtmlLine("<script>");
            htmlBuilder.AppendHtmlLine("$(function(){");
            htmlBuilder.AppendHtmlLine($"$('#{name}').dataGridBind('{dataSourceUrl}',{JsonConvert.SerializeObject(criteria)},{JsonConvert.SerializeObject(columns)});");
            htmlBuilder.AppendHtmlLine("});");
            htmlBuilder.AppendHtmlLine("</script>");

            return(htmlBuilder);
        }
Exemple #7
0
        public static IHtmlContent CreateDirectoryTree(this IHtmlHelper helper, string slug, VolumeDirectory directory, bool show = false, int indent = 1)
        {
            var htmlBuilder   = new HtmlContentBuilder();
            var identifier    = Guid.NewGuid();
            var collapseId    = $"collapse_{identifier}";
            var topLevelClass = show ? "collapse show" : "collapse";
            var leftMargin    = indent * 8;

            if (directory.IsEmpty)
            {
                htmlBuilder
                .AppendHtml("<h4 class=\"h5 border-bottom border-dark text-muted\">")
                .AppendHtml($"<i class=\"far fa-folder\"></i> {directory.Name}")
                .AppendHtml("</h4>");

                return(htmlBuilder);
            }

            htmlBuilder
            .AppendHtml("<h4 class=\"h5 border-bottom border-dark\">")
            .AppendHtml($"<i class=\"far fa-folder\"></i> <a class=\"text-dark text-decoration-none\" data-toggle=\"collapse\" href=\"#{collapseId}\" role=\"button\" aria-expanded=\"false\" aria-controls=\"{collapseId}\">")
            .Append(directory.Name)
            .AppendHtml("</a></h4>")
            .AppendLine()
            .AppendHtmlLine($"<div class=\"{topLevelClass}\" id=\"{collapseId}\">")
            .AppendHtmlLine($"<div style=\"margin-left: {leftMargin}px;\">");

            if (directory.HasDirectories)
            {
                foreach (var childDirectory in directory.Directories)
                {
                    htmlBuilder.AppendHtml(helper.CreateDirectoryTree(slug, childDirectory, false, indent + 1));
                }
            }

            if (directory.HasFiles)
            {
                foreach (var file in directory.Files)
                {
                    if (FileHelper.CanEdit(file.Name))
                    {
                        htmlBuilder
                        .AppendHtml("<div>")
                        .AppendHtml("<i class=\"far fa-file\"></i> ")
                        .AppendHtml(helper.RouteLink(file.Name, "EditServerFile", new { slug, fileHash = HashHelper.CreateHash(file.RelativePath) }))
                        .AppendHtml("</div>");
                    }
                    else
                    {
                        htmlBuilder.AppendHtml($"<div class=\"text-muted\"><i class=\"far fa-file\"></i> {file.Name}</div>");
                    }
                }
            }

            htmlBuilder
            .AppendHtmlLine("</div>")
            .AppendHtmlLine("</div>");

            return(htmlBuilder);
        }
        private IHtmlContent GenerateHtml()
        {
            var builder = new HtmlContentBuilder();

            builder.AppendHtmlLine($"<ul class=\"pagination {this.SizeClass}\">");

            AppendFirstPage(builder, this.Data);
            AppendPreviousPage(builder, this.Data);
            AppendPage(builder, this.Data);
            AppendNextPage(builder, this.Data);
            AppendLastPage(builder, this.Data);

            builder.AppendHtmlLine("</ul>");

            return(builder);
        }
        internal static HtmlContentBuilder CreateHtmlContentBuilder(PaginatedOptions options)
        {
            HtmlContentBuilder content = new HtmlContentBuilder();

            content.AppendHtml($"<ul class=\"{options.CssClassUl}\">");
            content.AppendHtmlLine(Environment.NewLine);
            return(content);
        }
Exemple #10
0
        static void BuildMenuTree(TreeViewNode node, List <TreeViewNode> sources, HtmlContentBuilder htmlBuilder, bool showCheckbox = true, string actionsHtml = "")
        {
            var children = sources.Where(x => x.ParentId != null && node.Id != null && x.ParentId.ToString() == node.Id.ToString());

            htmlBuilder.AppendHtmlLine($"<li class='list-group-item {(children.Any() ? "" : "pl-4")} border-top'>");

            if (children.Any())
            {
                htmlBuilder.AppendHtmlLine("<a class='collapse-icon' href='#'><i class='fa fa-fw fa-plus'></i></a>");
            }

            if (showCheckbox)
            {
                htmlBuilder.AppendHtmlLine("<div class='custom-control custom-checkbox d-inline'>");
                htmlBuilder.AppendHtmlLine($"<input type='checkbox' class='custom-control-input' id='node_{node.Id}' name='idArray' value='{node.Id}'>");
                htmlBuilder.AppendHtmlLine($"<label class='custom-control-label' for='node_{node.Id}'> {node.Name}</label>");
                htmlBuilder.AppendHtmlLine("</div>");
            }

            // actions
            //if ( editUrl != "" ) {
            //	htmlBuilder.AppendHtmlLine($"<a href='#' class='ml-1' data-toggle='modal' data-target='#modal_dialog_layout' data-modal-title='Edit' data-modal-url='{editUrl}/{node.Id}' data-modal-size='lg'><i class='fa fa-fw fa-edit'></i></a>");
            //}
            //if ( removeUrl != "" ) {
            //	htmlBuilder.AppendHtmlLine($"<a href='#' class='text-danger' data-toggle='modal' data-target='#modal_confirm_layout' data-url='{removeUrl}?handler=Remove&idArray={node.Id}' data-alert-panel='#alert_panel' data-update-panel='#menuContainer'><i class='fa fa-fw fa-remove'></i></a>");
            //}
            htmlBuilder.AppendHtmlLine(actionsHtml.Replace("#=Id #", node.Id == null ? "" : node.Id.ToString()));

            if (children.Any())
            {
                htmlBuilder.AppendHtmlLine($"<ul class='list-group list-group-flush tree-view-custom d-none mt-1 pt-2' id='collapse_{node.Id}'>");

                foreach (var child in children)
                {
                    BuildMenuTree(child, sources, htmlBuilder, showCheckbox, actionsHtml);
                }

                htmlBuilder.AppendHtmlLine("</ul>");
            }

            htmlBuilder.AppendHtmlLine("</li>");
        }
Exemple #11
0
        public static IHtmlContent SmartLink(this IHtmlHelper html, string link, string text, string cssClass = null)
        {
            if (link.IsNullOrEmpty())
            {
                link = "/";
            }
            bool self = IsOpenSelf(link);
            HtmlContentBuilder builder = new HtmlContentBuilder();

            builder.AppendHtmlLine("<a " + (cssClass.IsNullOrWhiteSpace() ? "" : "class=\"" + cssClass + "\"") + " target=\"" + (self ? "_self" : "_blank") + "\" href=\"" + link + "\">" + text + "</a>");
            return(builder);
        }
Exemple #12
0
        public static IHtmlContent TreeView(this IHtmlHelper htmlHelper, List <TreeViewNode> nodes, bool showCheckbox = true, string actionsHtml = "")
        {
            if (nodes == null)
            {
                throw new ArgumentNullException(nameof(nodes), "Please provide the treeview data.");
            }

            var htmlBuilder = new HtmlContentBuilder();
            var rootMenus   = nodes.Where(x => x.ParentId == null).ToArray();

            htmlBuilder.AppendHtmlLine("<ul class='list-group list-group-flush tree-view-custom'>");

            foreach (var node in rootMenus)
            {
                BuildMenuTree(node, nodes, htmlBuilder, showCheckbox, actionsHtml);
            }

            htmlBuilder.AppendHtmlLine("</ul>");
            htmlBuilder.AppendHtmlLine(Scripts);
            return(htmlBuilder);
        }
        public static IHtmlContent Figure(string imageSrc, string imageAlt, string description)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            //Start figure
            htmlContentBuilder.AppendHtmlLine("<figure role='group'>");

            //Add image
            htmlContentBuilder.AppendHtmlLine("<img src='" + imageSrc + "' alt='" + imageAlt + "'>");

            //Adding caption
            htmlContentBuilder.AppendHtml("<figcaption>"
                                          + description
                                          + "</figcaption>"
                                          );

            //End figure
            htmlContentBuilder.AppendHtmlLine("</figure>");

            return(htmlContentBuilder);
        }
Exemple #14
0
        public override Task <string> RenderAsync(IViewRender viewRender,
                                                  IElementHelper elementHelper,
                                                  string guid,
                                                  Dictionary <string, dynamic> viewModel,
                                                  Page page,
                                                  FormSchema formSchema,
                                                  IWebHostEnvironment environment,
                                                  FormAnswers formAnswers,
                                                  List <object> results = null)
        {
            var htmlContent = new HtmlContentBuilder();

            var paymentSummaryElement = page.Elements.FirstOrDefault(_ => _.Type == EElementType.PaymentSummary);

            htmlContent.AppendHtmlLine($"<p class=\"smbc-body\">The cost is &pound{paymentSummaryElement.Properties.Value}</p>");
            htmlContent.AppendHtmlLine("<p class=\"smbc-body\">Use the button below to continue to our payments page where you&#39;ll need your credit or debit card details.</p>");

            using (var writer = new StringWriter())
            {
                htmlContent.WriteTo(writer, HtmlEncoder.Default);
                return(Task.FromResult(writer.ToString()));
            }
        }
Exemple #15
0
        public IHtmlContent Render()
        {
            HtmlContentBuilder builder = new HtmlContentBuilder();

            foreach (var entry in this.ContentBag)
            {
                foreach (var content in entry.Value)
                {
                    builder.AppendHtmlLine(content);
                }
            }

            return(builder);
        }
Exemple #16
0
        public IHtmlContent Generate <TModel, TProperty>(IHtmlHelper html, object viewModel, Expression <Func <TModel, TProperty> > property, object htmlAttributes)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            var propertyInfo = property.GetProperty();
            var propertyName = propertyInfo.Name;
            var blob         = propertyInfo.GetValue(viewModel) as BlobViewModel ?? new BlobViewModel();

            var result = new HtmlContentBuilder();

            string getId(string prop) => $"\"{propertyName}_{prop}\"";

            string GetHiddenInput(Expression <Func <BlobViewModel, object> > expression)
            {
                var propName = expression.GetProperty().Name;
                var id       = getId(propName);
                var func     = expression.Compile();

                return($@"<input type=""hidden"" id={id} name={id} class=""{propName}"" value=""{func(blob)}"" />");
            }

            result.AppendHtmlLine($@"
                <div class=""file-upload"">
                    <span class=""current-file"" aria-label=""Preview the file""{" style=\"display:none\"".OnlyWhen(blob.IsEmpty)}>
                        <a target=""_blank"" href=""{blob.Url?.HtmlEncode()}"">{blob.Filename.OrEmpty().HtmlEncode()}</a>
                    </span>
                    <label for={getId("fileInput")} hidden>HiddenLabel</label>
                    {html.TextBox(propertyName, "value".OnlyWhen(blob.HasValue), string.Empty, HiddenFieldSettings).GetString()}
                    <input type=""file"" id={getId("fileInput")} name=""files"" {OliveMvcExtensions.ToHtmlAttributes(htmlAttributes)}/>
                    {GetHiddenInput(x => x.Action)}
                    {GetHiddenInput(x => x.TempFileId)}
                    {GetHiddenInput(x => x.Filename)}
                    {GetHiddenInput(x => x.ItemId)}
                    {GetHiddenInput(x => x.Url)}
                    {GetHiddenInput(x => x.IsEmpty)}
                    <div class=""progress-bar"" role=""progressbar""></div>
                    <span class=""delete-file fa fa-remove btn"" style=""display: none""></span>
                </div>
            ");

            return(result);
        }
Exemple #17
0
        public IHtmlContent Generate <TModel, TProperty>(IHtmlHelper html, object viewModel, Expression <Func <TModel, TProperty> > property, object htmlAttributes)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            var propertyInfo = property.GetProperty();
            var propertyName = propertyInfo.Name;
            var blob         = propertyInfo.GetValue(viewModel) as Blob ?? Blob.Empty();

            var action = html.Request().HasFormContentType ? html.Request().Form[propertyName] : StringValues.Empty;

            if (action == "KEEP")
            {
                blob = GetOldValue(viewModel, propertyName) ?? blob;
            }

            var result = new HtmlContentBuilder();

            // For validation to work, this works instead of Hidden.
            if (action.ToString().IsEmpty() && blob.HasValue())
            {
                action = "KEEP";
            }

            result.AppendHtmlLine($@"
                <div class=""file-upload"">
                    <span class=""current-file"" aria-label=""Preview the file""{" style=\"display:none\"".OnlyWhen(blob.IsEmpty())}>
                        <a target=""_blank"" href=""{blob.Url().HtmlEncode()}"">{blob.FileName.OrEmpty().HtmlEncode()}</a>
                    </span>
                    <label for=""{propertyName}_fileInput"" hidden>HiddenLabel</label>
                    <input type=""file"" id=""{propertyName}_fileInput"" name=""files"" {OliveMvcExtensions.ToHtmlAttributes(htmlAttributes)}/>
                    {html.TextBox(propertyName, action.OrEmpty(), string.Empty, HiddenFieldSettings).GetString()}
                    <div class=""progress-bar"" role=""progressbar""></div>
                    <span class=""delete-file fa fa-remove btn"" style=""display: none""></span>
                </div>
            ");

            return(result);
        }
        public static IHtmlContent UseDnsPrefetch(this RazorPage page)
        {
            var serviceLocation = page.Context.RequestServices.GetService <ServiceLocation>();
            var builder         = new HtmlContentBuilder();

            string[] domains =
            {
                serviceLocation.API,
                serviceLocation.OSS,
                serviceLocation.CDN,
                serviceLocation.Account
            };
            foreach (var domain in domains)
            {
                builder.AppendHtmlLine($@"<link rel='dns-prefetch' href='{domain}'>");
            }
            return(builder);
        }
        public static IHtmlContent EasyTable(IEnumerable <object> list, string htmlClass = "")
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            //Start table
            htmlContentBuilder.AppendHtmlLine("<table class='table " + htmlClass + "'>");

            //Table heading
            htmlContentBuilder.AppendHtmlLine("<tr>");
            foreach (object item in list)
            {
                var PropertyInfos = item.GetType().GetProperties();
                foreach (PropertyInfo info in PropertyInfos)
                {
                    htmlContentBuilder.AppendHtmlLine("<th scope='col'>" + info.Name + "</th>");
                }
            }
            htmlContentBuilder.AppendHtmlLine("</tr>");

            //Content of tables
            foreach (object item in list)
            {
                htmlContentBuilder.AppendHtmlLine("<tr>");

                var PropertyInfos = item.GetType().GetProperties();

                //Gets first column data and adds scope
                PropertyInfo firstInfo = PropertyInfos.FirstOrDefault();
                htmlContentBuilder.AppendHtmlLine("<td scope='row'>" + firstInfo.GetValue(item) + "</td>");

                //Loop through rest of data
                foreach (PropertyInfo info in PropertyInfos.Skip(1))
                {
                    htmlContentBuilder.AppendHtmlLine("<td>" + info.GetValue(item) + "</td>");
                }

                htmlContentBuilder.AppendHtmlLine("</tr>");
            }
            //End table
            return(htmlContentBuilder);
        }
Exemple #20
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (string.IsNullOrEmpty(this.Message))
            {
                return;
            }

            var content = new HtmlContentBuilder();

            content.AppendHtmlLine($"<div class=\"alert alert-{this.Type}\">");
            content.AppendHtmlLine("    <button type=\"button\" class=\"close\" data-dismiss=\"alert\">");
            content.AppendHtmlLine("        <span aria-hidden=\"true\">&times;</span>");
            content.AppendHtmlLine("        <span class=\"sr-only\">Close</span>");
            content.AppendHtmlLine("    </button>");
            content.AppendHtmlLine(this.Message);
            content.AppendHtmlLine("</div>");

            output.Content.SetHtmlContent(content);
        }
        public IHtmlContent CachedShapeWrapper(IShape Shape)
        {
            // No need to optimize this code as it will be used for debugging purpose

            var contentBuilder = new HtmlContentBuilder();
            var metadata       = Shape.Metadata;
            var cache          = metadata.Cache();

            contentBuilder.AppendLine();
            contentBuilder.AppendHtmlLine($"<!-- CACHED SHAPE: {cache.CacheId} ({Guid.NewGuid()})");
            contentBuilder.AppendHtmlLine($"          VARY BY: {String.Join(", ", cache.Contexts)}");
            contentBuilder.AppendHtmlLine($"     DEPENDENCIES: {String.Join(", ", cache.Tags)}");
            contentBuilder.AppendHtmlLine($"       EXPIRES ON: {cache.ExpiresOn}");
            contentBuilder.AppendHtmlLine($"    EXPIRES AFTER: {cache.ExpiresAfter}");
            contentBuilder.AppendHtmlLine($"  EXPIRES SLIDING: {cache.ExpiresSliding}");
            contentBuilder.AppendHtmlLine("-->");

            contentBuilder.AppendHtml(metadata.ChildContent);

            contentBuilder.AppendLine();
            contentBuilder.AppendHtmlLine($"<!-- END CACHED SHAPE: {cache.CacheId} -->");

            return(contentBuilder);
        }
        public IHtmlContent Generate <TModel, TProperty>(IHtmlHelper html, object model, Expression <Func <TModel, TProperty> > property, object htmlAttributes)
        {
            var propertyInfo = property.GetProperty();
            var blob         = propertyInfo.GetValue(model) as Blob ?? Blob.Empty();
            var value        = html.ViewContext.HttpContext.Request.HasFormContentType ?
                               html.ViewContext.HttpContext.Request.Form[propertyInfo.Name] :
                               Microsoft.Extensions.Primitives.StringValues.Empty;

            if (value == "KEEP")
            {
                var itemProperty         = model.GetType().GetProperty("Item");
                var item                 = itemProperty.GetValue(model);
                var originalPropertyInfo = item.GetType().GetProperty(propertyInfo.Name);
                blob = originalPropertyInfo.GetValue(item) as Blob ?? Blob.Empty();
            }

            // Note: If this method is called with an IEnumerable<Blob> property,
            // then the existing data will never be loaded.
            var result = new HtmlContentBuilder();

            result.AppendHtmlLine("<div class=\"file-upload\">");
            result.AppendHtmlLine($"<span class=\"current-file\" aria-label=\"Preview the file\"{" style=\"display:none\"".OnlyWhen(blob.IsEmpty())}>" +
                                  $"<a target=\"_blank\" href=\"{blob.Url().HtmlEncode()}\">{blob.FileName.OrEmpty().HtmlEncode()}</a></span>");

            result.AppendHtmlLine($"<label for=\"{propertyInfo.Name}_fileInput\" hidden>HiddenLabel</label>");
            result.AppendHtmlLine($"<input type=\"file\" id=\"{propertyInfo.Name}_fileInput\" name=\"files\" {OliveMvcExtensions.ToHtmlAttributes(htmlAttributes)}/>");

            // For validation to work, this works instead of Hidden.
            if (value.ToString().IsEmpty() && blob.HasValue())
            {
                value = "KEEP";
            }
            result.AppendHtml(html.TextBox(propertyInfo.Name, value.OrEmpty(), string.Empty,
                                           new { tabindex = "-1", style = "width:1px; height:0; border:0; padding:0; margin:0;", @class = "file-id", autocomplete = "off" }));
            result.AppendHtmlLine("<div class=\"progress-bar\" role=\"progressbar\"></div>");
            result.AppendHtmlLine("<span class=\"delete-file fa fa-remove btn\" style=\"display: none\"></span>");
            result.AppendHtmlLine("</div>");

            return(result);
        }
Exemple #23
0
        protected virtual IHtmlContent DoGenerate <TModel, TProperty>(IHtmlHelper html, object viewModel, Expression <Func <TModel, TProperty> > property, object htmlAttributes)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            PropertyInfo = property.GetProperty();
            Blob         = PropertyInfo.GetValue(viewModel) as BlobViewModel ?? new BlobViewModel();

            var result = new HtmlContentBuilder();

            result.AppendHtmlLine($@"
                <div class=""file-upload"">
                    <span class=""current-file"" aria-label=""Preview the file""{" style=\"display:none\"".OnlyWhen(Blob.IsEmpty)}>
                        <a target=""_blank"" href=""{Blob.Url?.HtmlEncode()}"">{Blob.Filename.OrEmpty().HtmlEncode()}</a>
                    </span>
                    <label for={GetId("fileInput")} hidden>HiddenLabel</label>
                    {html.TextBox(PropertyInfo.Name, string.Empty, string.Empty, HiddenFieldSettings).GetString()}
                    <input type=""file"" id={GetId("fileInput")} name=""files"" {GetHtmlAttributes(htmlAttributes)}/>
                    {GetHiddenInput(x => x.Action)}
                    {GetHiddenInput(x => x.TempFileId)}
                    {GetHiddenInput(x => x.Filename)}
                    {GetHiddenInput(x => x.ItemId)}
                    {GetHiddenInput(x => x.Url)}
                    {GetHiddenInput(x => x.IsEmpty)}
                    <div class=""progress-bar"" role=""progressbar""></div>
                    <span class=""delete-file fas fa-times btn"" style=""display: none""></span>
                </div>
            ");

            return(result);
        }
Exemple #24
0
        /// <inheritdoc />
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Reset the TagName. We don't want `partial` to render.
            output.TagName = null;

            var filePath = Path.Combine(Path.GetDirectoryName(ViewContext.ExecutingFilePath), Name);

            var file = fileProvider.GetFileInfo(filePath);

            if (!file.Exists)
            {
                throw new FileNotFoundException($"Unable to find file {Name} associated with {ViewContext.ExecutingFilePath}", Name);
            }

            await using var fileStream = file.CreateReadStream();
            using var streamReader     = new StreamReader(fileStream);

            var    lines = new HtmlContentBuilder();
            string line;

            while ((line = await streamReader.ReadLineAsync()) != null)
            {
                lines.AppendHtmlLine(line);
            }

            output.Content.SetHtmlContent(lines);
        }
Exemple #25
0
        public override Task <string> RenderAsync(IViewRender viewRender,
                                                  IElementHelper elementHelper,
                                                  string guid,
                                                  Dictionary <string, dynamic> viewModel,
                                                  Page page,
                                                  FormSchema formSchema,
                                                  IWebHostEnvironment environment,
                                                  FormAnswers formAnswers,
                                                  List <object> results = null)
        {
            var htmlContent = new HtmlContentBuilder();
            var pages       = elementHelper.GenerateQuestionAndAnswersList(guid, formSchema);

            htmlContent.AppendHtmlLine("<dl class=\"govuk-summary-list govuk-!-margin-bottom-9\">");
            foreach (var pageSummary in pages)
            {
                foreach (var answer in pageSummary.Answers)
                {
                    htmlContent.AppendHtmlLine("<div class=\"govuk-summary-list__row\">");
                    htmlContent.AppendHtmlLine($"<dt class=\"govuk-summary-list__key\">{answer.Key}</dt>");
                    htmlContent.AppendHtmlLine($"<dd class=\"govuk-summary-list__value\">{answer.Value}</dd>");

                    if (Properties != null && Properties.AllowEditing)
                    {
                        htmlContent.AppendHtmlLine($"<dd class=\"govuk-summary-list__actions\"><a class=\"govuk-link\" href=\"{pageSummary.PageSlug}\">Change <span class=\"govuk-visually-hidden\">{answer.Key}</span></a></dd>");
                    }

                    htmlContent.AppendHtmlLine("</div>");
                }
            }
            htmlContent.AppendHtmlLine("</dl>");

            using (var writer = new StringWriter())
            {
                htmlContent.WriteTo(writer, HtmlEncoder.Default);

                return(Task.FromResult(writer.ToString()));
            }
        }
Exemple #26
0
        public static HtmlString DataGrid <T>(this IHtmlHelper helper, IEnumerable <T> data, DataColumn[] columns, DataGridOptions option)
            where T : class
        {
            var _query           = helper.ViewContext.HttpContext.Request.QueryString;
            var _queryDictionary = QueryHelpers.ParseQuery(_query.ToString());
            var _queryItems      = _queryDictionary.SelectMany(x => x.Value, (col, value) => new KeyValuePair <string, string>(col.Key, value)).ToList();
            var _queryParams     = _query.ToUriComponent();

            if (!option.PagerAndShortAction.IsEmpty())
            {
                var psss = option.PagerAndShortAction.Split('?');
                if (psss.Length > 1)
                {
                    _queryParams = _queryParams.Replace("?" + psss[1], "");
                }
            }

            var _colCount = 0;
            var items     = data;

            if (items == null)
            {
                var content = new HtmlContentBuilder().AppendHtml(option.EmptyData);
                return(new HtmlString(content.GetString()));
            }

            var _sorter = new Sorter(_queryItems, option.SortKeyword, option.PagerAndShortAction);
            var _filter = new Filter(_queryDictionary, _queryItems, option.PagerKeyword,
                                     helper.ViewContext.RouteData, option.PagerAndShortAction,
                                     option.PagerJsFunction, option.GridDiv);

            if (option.FilteringEnabled && !(data is PagedList <T>) && !(data is StaticPagedList <T>))
            {
                var kp = _filter.GetWhereString();
                if (kp.Where != null)
                {
                    items = items.AsQueryable().Where(kp.Where, kp.Params.ToArray());
                }
            }

            #region SORT DATA
            if (option.Sortable && !(data is PagedList <T>) && !(data is StaticPagedList <T>))
            {
                if (_sorter.List.Count == 0 && option.DefaultSorting)
                {
                    if (!option.SortDefaultFieldName.IsEmpty())
                    {
                        _sorter.List.Add(new SorterInfo()
                        {
                            Direction = option.SortDefaultDirection, Keyword = option.SortDefaultFieldName
                        });
                    }
                    if (option.SortDefaultFieldNames != null)
                    {
                        foreach (string sortinfodefaultname in option.SortDefaultFieldNames)
                        {
                            _sorter.List.Add(new SorterInfo()
                            {
                                Direction = option.SortDefaultDirection,
                                Keyword   = sortinfodefaultname
                            });
                        }
                    }
                }
                var sorting = string.Empty;
                foreach (var info in _sorter.List)
                {
                    if (!sorting.IsEmpty())
                    {
                        sorting += ",";
                    }
                    sorting += String.Format("{0} {1}", info.Keyword, info.Direction);
                }
                if (!sorting.IsEmpty())
                {
                    items = items.AsQueryable().OrderBy(sorting);
                }
            }
            #endregion

            #region DO PAGING
            var currentPageSize      = option.DefaultPageSize;
            var currentPageIndexItem = _queryItems.FirstOrDefault(d => d.Key == option.PagerKeyword);
            var pageIndex            = 0;
            if (!currentPageIndexItem.Value.IsEmpty())
            {
                int.TryParse(currentPageIndexItem.Value, out pageIndex);
            }
            if (option.PagerEnabled && !(data is PagedList <T>) && !(data is StaticPagedList <T>))
            {
                var currentPageSizeStr = _queryItems.FirstOrDefault(d => d.Key == option.PageSizeKeyword);
                if (!currentPageSizeStr.Value.IsEmpty())
                {
                    int.TryParse(currentPageSizeStr.Value, out currentPageSize);
                }
                items = new PagedList <T>(items, pageIndex, currentPageSize);
            }
            #endregion

            T firstItem = default;
            if (items != null && items.Any())
            {
                firstItem = items.First();
            }
            Type firstItemType = null;
            if (firstItem != null)
            {
                firstItemType = firstItem.GetType();
            }

            var writer      = new HtmlContentBuilder();
            var baseUrl     = LibGeneral.GetContentUrl(helper.ViewContext.RouteData);
            var fs          = $@"/{baseUrl}/{option.PagerAndShortAction}{_queryParams}";
            var _refreshUrl = $"{option.PagerJsFunction}(\"{fs}\",\"{option.GridDiv}\");";

            if (option.PagerEnabled && (option.PagerLocation == PagerLocationTypes.Top || option.PagerLocation == PagerLocationTypes.TopAndBottom))
            {
                if (data is PagedList <T> || data is StaticPagedList <T> )
                {
                    var pager = RenderPager(helper, data, option, currentPageSize, _queryItems);
                    writer.AppendHtmlLine(pager);
                }
                else
                {
                    var pager = RenderPager(helper, items, option, currentPageSize, _queryItems);
                    writer.AppendHtmlLine(pager);
                }
            }

            writer.AppendHtmlLine($"<div id='dataGrid-{option.GridDiv}' data-refreshurl='{_refreshUrl}'> ");
            var cssTable = string.Empty;
            if (!option.CssTable.IsEmpty())
            {
                cssTable = $" class=\"{option.CssTable}\"";
            }
            var idTable = string.Empty;
            if (!option.TableId.IsEmpty())
            {
                idTable = $" id=\"{option.TableId}\"";
            }
            writer.AppendHtmlLine(RenderHeaderBar2(option));
            writer.AppendHtmlLine($"<table{idTable}{cssTable}>");
            if (option.ShowHeader)
            {
                writer.AppendHtmlLine($"<thead>");
                _colCount = columns.Count(d => d.Visible);
                if (option.ButtonDeleteEnabled || option.ButtonEditEnabled || option.ButtonRefreshEnabled)
                {
                    _colCount++;
                }
                if (option.FilteringEnabled)
                {
                    writer.AppendHtmlLine(RenderFilterRow(helper, columns, firstItemType, _filter));
                }
                writer.AppendHtmlLine(RenderHeader <T>(helper, columns, option, firstItemType, _refreshUrl, _sorter, _filter));
                writer.AppendHtmlLine($"</thead>");
            }
            writer.AppendHtmlLine($"<tbody>");
            foreach (var item in items)
            {
                writer.AppendHtmlLine(RenderRow(helper, columns, item, option));
            }
            writer.AppendHtmlLine($"</tbody>");
            writer.AppendHtmlLine("</table>");
            writer.AppendHtmlLine("</div>");
            if (option.FilteringEnabled && columns.Any(d => !d.FilterValue.IsEmpty()))
            {
                writer.AppendHtmlLine(RenderFilterRowFooter(columns, _filter, _colCount));
            }
            if (option.PagerEnabled && (option.PagerLocation == PagerLocationTypes.Bottom || option.PagerLocation == PagerLocationTypes.TopAndBottom))
            {
                if (data is PagedList <T> || data is StaticPagedList <T> )
                {
                    var pager = RenderPager(helper, data, option, currentPageSize, _queryItems);
                    writer.AppendHtmlLine(pager);
                }
                else
                {
                    var pager = RenderPager(helper, items, option, currentPageSize, _queryItems);
                    writer.AppendHtmlLine(pager);
                }
            }
            return(new HtmlString(writer.GetString()));
        }
Exemple #27
0
        public static IHtmlContent Carousel(List <CarouselItem> items)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            htmlContentBuilder.AppendHtml(
                "<div id='ez-carousel' class='carousel slide' data-ride='carousel' data-interval='false'>" +
                "<ol class='carousel-indicators'>"
                );

            //Adding tabs at bottom.
            for (int i = 0; i > items.Count; i++)
            {
                if (i == 0)
                {
                    htmlContentBuilder.AppendHtmlLine("<li data-target='#ez-carousel' data-slide-to='" + i.ToString() + "' class='active'></li>");
                }
                else
                {
                    htmlContentBuilder.AppendHtmlLine("<li data-target='#ez-carousel' data-slide-to='" + i.ToString() + "'></li>");
                }
            }

            htmlContentBuilder.AppendHtmlLine("</ol>" +
                                              "<div class='carousel-inner'>"
                                              );

            //Adding each item
            foreach (CarouselItem item in items)
            {
                if (item == items.First())
                {
                    htmlContentBuilder.AppendHtml("<div class='carousel-item active'>" +
                                                  "<img class='d-blockw-100' src='" + item.ImageUrl + "' alt='" + (String.IsNullOrEmpty(item.AltText) ? item.SubHeading : item.AltText) + "'>" +
                                                  "<h3>" + item.Title + "</h3>" +
                                                  "<p>" + item.SubHeading + "</p>" +
                                                  "</div>"
                                                  );
                }
                else
                {
                    htmlContentBuilder.AppendHtml("<div class='carousel-item'>" +
                                                  "<img class='d-blockw-100' src='" + item.ImageUrl + "' alt='" + (String.IsNullOrEmpty(item.AltText) ? item.SubHeading : item.AltText) + "'>" +
                                                  "<h3>" + item.Title + "</h3>" +
                                                  "<p>" + item.SubHeading + "</p>" +
                                                  "</div>"
                                                  );
                }
            }

            htmlContentBuilder.AppendHtmlLine("</div>");

            htmlContentBuilder.AppendHtml("<a class='carousel-control-prev' href='#ez-carousel' role='button' data-slide='prev'>" +
                                          "<span class='carousel-control-prev-icon' aria-hidden='true'></span>" +
                                          "<span class='sr-only'>Previous</span>" +
                                          "</a>" +
                                          "<a class='carousel-control-next' href='#ez-carousel' role='button' data-slide='next'>" +
                                          "<span class='carousel-control-next-icon' aria-hidden='true'></span>" +
                                          "<span class='sr-only'>Next</span>" +
                                          "</a>" +
                                          "</div>"
                                          );

            return(htmlContentBuilder);
        }
Exemple #28
0
        public static IHtmlContent Carousel(List <CarouselItem> items)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            htmlContentBuilder.AppendHtml(
                "<div id='ez-carousel' class='carousel slide' data-interval='false' data-ride='carousel'>" +
                "<ol class='carousel-indicators'>"
                );

            //Adding tabs at bottom.
            for (int i = 0; i > items.Count; i++)
            {
                if (i == 0)
                {
                    htmlContentBuilder.AppendHtmlLine("<li data-target='#ez-carousel' data-slide-to='" + i.ToString() + "' class='active'></li>");
                }
                else
                {
                    htmlContentBuilder.AppendHtmlLine("<li data-target='#ez-carousel' data-slide-to='" + i.ToString() + "'></li>");
                }
            }

            htmlContentBuilder.AppendHtmlLine("</ol>");

            //Wrapper for slides
            htmlContentBuilder.AppendHtml(
                "<div class='carousel-inner' role='listbox'>"
                );

            //Adding each item
            foreach (CarouselItem item in items)
            {
                if (item == items.First())
                {
                    htmlContentBuilder.AppendHtml(
                        "<div class='item active'>" +
                        "<img src = '" + item.ImageUrl + "' alt = '" + item.AltText + "' >" +
                        "<div class='carousel-caption'>" +
                        item.Title +
                        "</div>" +
                        "</div>"
                        );
                }
                else
                {
                    htmlContentBuilder.AppendHtml(
                        "<div class='item'>" +
                        "<img src = '" + item.ImageUrl + "' alt = '" + item.AltText + "' >" +
                        "<div class='carousel-caption'>" +
                        item.Title +
                        "</div>" +
                        "</div>"
                        );
                }
            }

            htmlContentBuilder.AppendHtml(
                "</div>" +
                "<a class='left carousel-control' href='#ez-carousel' role='button' data-slide='prev'>" +
                "<span class='glyphicon glyphicon-chevron-left' aria-hidden='true'></span>" +
                "<span class='sr-only'>Previous</span>" +
                "</a>" +
                "<a class='right carousel-control' href='#ez-carousel' role='button' data-slide='next'>" +
                "<span class='glyphicon glyphicon-chevron-right' aria-hidden='true'></span>" +
                "<span class='sr-only'>Next</span>" +
                "</a>" +
                "</div>"
                );


            return(htmlContentBuilder);
        }