public static string FormatDocumentLink_WithMicrodata(this IDocument document, string documentTitle, string defaultTitle, bool preferDocumentTitle, DocumentGroupPlacement groupPlacement, int tabId, int moduleId, string microdata, DateTime now) { var title = (preferDocumentTitle && !string.IsNullOrWhiteSpace(documentTitle)) ? ((groupPlacement == DocumentGroupPlacement.InTitle) ? TextUtils.FormatList(": ", document.Group, documentTitle) : documentTitle) : ((groupPlacement == DocumentGroupPlacement.InTitle && !string.IsNullOrWhiteSpace(document.Group)) ? document.Group : defaultTitle); if (!string.IsNullOrWhiteSpace(document.Url)) { var linkMarkup = "<a href=\"" + UniversityUrlHelper.LinkClickIdnHack(document.Url, tabId, moduleId) + "\" " + TextUtils.FormatList(" ", !document.IsPublished(now) ? "class=\"u8y-not-published-element\"" : string.Empty, microdata) + " target=\"_blank\">" + title + "</a>"; if (groupPlacement == DocumentGroupPlacement.BeforeTitle) { return(TextUtils.FormatList(": ", document.Group, linkMarkup)); } if (groupPlacement == DocumentGroupPlacement.AfterTitle) { return(TextUtils.FormatList(": ", linkMarkup, document.Group)); } return(linkMarkup); } return(string.Empty); }
// TODO: Calculate initial capacity for StringBuilder? string FormatDocumentsLinkWithData(IEnumerable <IDocument> documents, string linkText, string columnSlug, string microdata = "") { var microdataAttrs = !string.IsNullOrEmpty(microdata) ? " " + microdata : string.Empty; var docCount = documents.Count(); if (docCount > 0) { var docCountText = (docCount > 1 || string.IsNullOrEmpty(linkText)) ? " [" + docCount + "]" : string.Empty; var table = new StringBuilder( $"<span{microdataAttrs}>" + $"<a type=\"button\" href=\"#\" data-toggle=\"modal\" data-target=\"#u8y-epp-docs-dlg-{Context.Module.ModuleId}\"" + $" data-table=\"doct-{RowId}-{columnSlug}\">{(linkText + docCountText).TrimStart ()}</a>" + $"<table id=\"doct-{RowId}-{columnSlug}\" class=\"d-none\">" + $"<thead><tr><th>{TitleColumnHeader}</th><th>{GroupColumnHeader}</th></tr></thead><tbody>" ); foreach (var document in documents) { var docTitle = !string.IsNullOrEmpty(document.Title) ? document.Title : Localization.GetString("LinkOpen.Text", Context.LocalResourceFile); var docUrl = UniversityUrlHelper.LinkClickIdnHack(document.Url, Context.Module.TabId, Context.Module.ModuleId); var rowCssClassAttr = !document.IsPublished(HttpContext.Current.Timestamp) ? " class=\"u8y-not-published\"" : string.Empty; table.Append($"<tr{rowCssClassAttr}><td><a href=\"{docUrl}\" target=\"_blank\">{docTitle}</a></td><td>{document.Group}</td></tr>"); } table.Append("</tbody></table></span>"); return(table.ToString()); } if (!string.IsNullOrEmpty(linkText)) { return($"<span{microdataAttrs}>{linkText}</span>"); } return(string.Empty); }