|
|
|
@ -9,19 +9,13 @@ namespace Volo.Docs.Areas.Documents.Helpers.TagHelpers |
|
|
|
[HtmlTargetElement("ul", Attributes = "root-node")] |
|
|
|
public class TreeTagHelper : TagHelper |
|
|
|
{ |
|
|
|
private const string LiItemTemplateWithLink = @"<li class='{0}'>
|
|
|
|
<span class='plus-icon'><i class='fa fa-{1}'></i></span> |
|
|
|
{2} |
|
|
|
{3} |
|
|
|
</li>";
|
|
|
|
private const string LiItemTemplateWithLink = @"<li class='{0}'><span class='plus-icon'><i class='fa fa-{1}'></i></span>{2}{3}</li>"; |
|
|
|
|
|
|
|
private const string ListItemAnchor = @"<a href='{0}' class='{1}'>{2}</a>"; |
|
|
|
|
|
|
|
private const string ListItemSpan = @"<span class='{0}'>{1}</span>"; |
|
|
|
|
|
|
|
|
|
|
|
private const string UlItemTemplate = @"<ul class='nav nav-list tree' style='{1}'>
|
|
|
|
{0} |
|
|
|
</ul>";
|
|
|
|
private const string UlItemTemplate = @"<ul class='nav nav-list tree' style='{1}'>{0}</ul>"; |
|
|
|
|
|
|
|
[HtmlAttributeName("root-node")] |
|
|
|
public NavigationNode RootNode { get; set; } |
|
|
|
@ -98,61 +92,46 @@ namespace Volo.Docs.Areas.Documents.Helpers.TagHelpers |
|
|
|
{ |
|
|
|
var anchorCss = node.Path.IsNullOrEmpty() ? "tree-toggle" : ""; |
|
|
|
var isNodeSelected = node.IsSelected(SelectedDocumentName); |
|
|
|
|
|
|
|
var normalizedPath = node.Path != null && node.Path.EndsWith("." + ProjectFormat) |
|
|
|
? node.Path.Left(node.Path.Length - ProjectFormat.Length - 1) |
|
|
|
: node.Path; |
|
|
|
|
|
|
|
if (node.Path.IsNullOrEmpty() && !node.HasChildItems) |
|
|
|
var listItemCss = node.HasChildItems ? "nav-header" : "last-link"; |
|
|
|
if (isNodeSelected) |
|
|
|
{ |
|
|
|
//span
|
|
|
|
var span = string.Format(ListItemSpan, anchorCss, node.Text.IsNullOrEmpty() ? "?" : node.Text); |
|
|
|
var listItemCss = node.HasChildItems ? "nav-header" : "last-link"; |
|
|
|
if (isNodeSelected) |
|
|
|
{ |
|
|
|
listItemCss += " selected-tree"; |
|
|
|
} |
|
|
|
|
|
|
|
return string.Format(LiItemTemplateWithLink, |
|
|
|
listItemCss, |
|
|
|
node.HasChildItems ? "chevron-right" : "long-arrow-right", |
|
|
|
span, |
|
|
|
content); |
|
|
|
listItemCss += " selected-tree"; |
|
|
|
} |
|
|
|
else if (node.Path.IsNullOrEmpty() && node.HasChildItems) |
|
|
|
|
|
|
|
string listInnerItem; |
|
|
|
if (node.Path.IsNullOrEmpty() && node.IsLeaf) |
|
|
|
{ |
|
|
|
//anchor
|
|
|
|
var path = "javascript:;"; |
|
|
|
var anchor = string.Format(ListItemAnchor, path, anchorCss, node.Text.IsNullOrEmpty() ? "?" : node.Text); |
|
|
|
var listItemCss = node.HasChildItems ? "nav-header" : "last-link"; |
|
|
|
if (isNodeSelected) |
|
|
|
{ |
|
|
|
listItemCss += " selected-tree"; |
|
|
|
} |
|
|
|
|
|
|
|
return string.Format(LiItemTemplateWithLink, |
|
|
|
listItemCss, |
|
|
|
node.HasChildItems ? "chevron-right" : "long-arrow-right", |
|
|
|
anchor, |
|
|
|
content); |
|
|
|
listInnerItem = string.Format(ListItemSpan, anchorCss, node.Text.IsNullOrEmpty() ? "?" : node.Text); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//anchor
|
|
|
|
var path = "/documents/" + ProjectName + "/" + Version + "/" + normalizedPath; |
|
|
|
var anchor = string.Format(ListItemAnchor, path, anchorCss, node.Text.IsNullOrEmpty() ? "?" : node.Text); |
|
|
|
var listItemCss = node.HasChildItems ? "nav-header" : "last-link"; |
|
|
|
if (isNodeSelected) |
|
|
|
{ |
|
|
|
listItemCss += " selected-tree"; |
|
|
|
} |
|
|
|
|
|
|
|
return string.Format(LiItemTemplateWithLink, |
|
|
|
listItemCss, |
|
|
|
node.HasChildItems ? "chevron-right" : "long-arrow-right", |
|
|
|
anchor, |
|
|
|
content); |
|
|
|
listInnerItem = string.Format(ListItemAnchor, NormalizePath(node.Path, node.HasChildItems), anchorCss, node.Text.IsNullOrEmpty() ? "?" : node.Text); |
|
|
|
} |
|
|
|
|
|
|
|
return string.Format(LiItemTemplateWithLink, |
|
|
|
listItemCss, |
|
|
|
node.HasChildItems ? "chevron-right" : "long-arrow-right", |
|
|
|
listInnerItem, |
|
|
|
content); |
|
|
|
} |
|
|
|
|
|
|
|
private string NormalizePath(string path, bool hasChildItems) |
|
|
|
{ |
|
|
|
var pathWithoutFileExtension = RemoveFileExtensionFromPath(path); |
|
|
|
|
|
|
|
return hasChildItems ? "javascript:;" : "/documents/" + ProjectName + "/" + Version + "/" + pathWithoutFileExtension; |
|
|
|
} |
|
|
|
|
|
|
|
private string RemoveFileExtensionFromPath(string path) |
|
|
|
{ |
|
|
|
if (path == null) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
return path.EndsWith("." + ProjectFormat) |
|
|
|
? path.Left(path.Length - ProjectFormat.Length - 1) |
|
|
|
: path; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|