protected void CreateHeadersCore(TagHelperOutput output, List <string> hideProperties, Microsoft.AspNetCore.Mvc.ModelBinding.ModelPropertyCollection properties) { // create headers var headerRow = new TagBuilder("tr") { TagRenderMode = TagRenderMode.Normal }; foreach (var p in properties) { // test against hide list if (hideProperties != null && hideProperties.Contains(p.PropertyName)) { continue; } if (!Utility.DisplayForView(p)) { continue; } // render the cell var headerCell = new TagBuilder("th"); //TODO: Uncomment in order to hide this on mobile when this works (FormIndex) //cell.Attributes.Add("class", styles.TableCellHideMobile); if (p.DisplayName != null) { headerCell.InnerHtml.AppendHtml(p.DisplayName); } else { headerCell.InnerHtml.Append(p.Name); } headerRow.InnerHtml.AppendHtml(headerCell); } // render one last cell for the buttons var lastHeader = new TagBuilder("th"); headerRow.InnerHtml.AppendHtml(lastHeader); output.Content.AppendHtml(headerRow); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; var dl = new TagBuilder("dl"); dl.TagRenderMode = TagRenderMode.Normal; dl.Attributes.Add("class", styles.DescriptionList); output.Content.AppendHtml(dl); // can we conextualise the htmlhelper - if not do not render html values if (htmlHelper is IViewContextAware ht) { ht.Contextualize(ViewContext); } else { RenderValueHtml = false; } // loop through the properties foreach (var p in For.ModelExplorer.Properties) { if (p.Metadata.IsCollectionType) { continue; } // check display if (!Utility.DisplayForView(p.Metadata)) { continue; } // set the name string name = p.Metadata.DisplayName; if (string.IsNullOrWhiteSpace(name)) { name = p.Metadata.PropertyName; } // get the content var value = Utility.GetFormattedHtml(p, ViewContext, htmlHelper, RenderValueHtml); // check for complex object and set value value = Utility.GetComplexValue(p, value, ViewContext, htmlHelper, RenderValueHtml); // render var dt = new TagBuilder("dt"); dt.Attributes.Add("class", styles.DefinitionTerm); dt.InnerHtml.Append(name); var dd = new TagBuilder("dd"); dd.Attributes.Add("class", styles.DefinitionDescription); dd.InnerHtml.AppendHtml(value); // add to list dl.InnerHtml.AppendHtml(dt); dl.InnerHtml.AppendHtml(dd); } }
//TODO: Implement Display(Order) built in attribute public override void Process(TagHelperContext context, TagHelperOutput output) { // setup tag output.TagName = "table"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Add("class", styles.Table); // check that we have a list if (!For.Metadata.IsCollectionType) { return; } // setup properties to hide var hideProperties = HideProperties?.Split(',').Select(p => p.Trim()).ToList(); // get the key property string keyProperty = GetKeyProperty(); // create the headers CreateHeaders(output, hideProperties); // can we conextualise the htmlhelper - if not do not render html values if (htmlHelper is IViewContextAware ht) { ht.Contextualize(ViewContext); } else { RenderValueHtml = false; } // now loop through items var collection = (ICollection)For.Model; foreach (var item in collection) { // create the row var row = new TagBuilder("tr") { TagRenderMode = TagRenderMode.Normal }; // get the explorer var explorer = For.ModelExplorer.GetExplorerForModel(item); // get the key value string keyValue = Utility.GetKeyValue(keyProperty, explorer); // loop through the element properties foreach (var p in explorer.Properties) { if (hideProperties != null && hideProperties.Contains(p.Metadata.PropertyName)) { continue; } if (!Utility.DisplayForView(p.Metadata)) { continue; } // create a model expression from the explorer //var f = new ModelExpression($"{p.Container.Metadata.Name }.{ p.Metadata.Name}", explorer); var value = Utility.GetFormattedHtml(p, ViewContext, htmlHelper, RenderValueHtml); // check for complex object and set value value = Utility.GetComplexValue(p, value, ViewContext, htmlHelper, RenderValueHtml); // render the cell var cell = new TagBuilder("td"); //TODO: Uncomment in order to hide this on mobile when this works (FormIndex) //cell.Attributes.Add("class", styles.TableCellHideMobile); cell.InnerHtml.AppendHtml(value); row.InnerHtml.AppendHtml(cell); } // render the buttons cell if (keyValue != null) { var buttons = new TagBuilder("td"); var routes = new Dictionary <string, string>() { { keyProperty.ToLower(), keyValue } }; if (!string.IsNullOrEmpty(EditPage)) { buttons.InnerHtml.AppendHtml(GenerateEditButton(explorer, keyProperty, keyValue)); } if (!string.IsNullOrEmpty(ViewPage)) { buttons.InnerHtml.AppendHtml(GenerateViewButton(explorer, keyProperty, keyValue)); } if (!string.IsNullOrEmpty(DeletePage)) { buttons.InnerHtml.AppendHtml(GenerateDeleteButton(explorer, keyProperty, keyValue)); } row.InnerHtml.AppendHtml(buttons); } output.Content.AppendHtml(row); } }