Skip to content

Commit

Permalink
Fix the search admin menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed May 7, 2024
1 parent 5a45ac5 commit 2054b41
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static List<string> AddPrefixToClasses(string unprefixed)
{
return unprefixed?.Split(' ')
.ToList()
.Select(c => "icon-class-" + c)
.Select(c => NavigationConstants.CssClassPrefix + c)
.ToList()
?? [];
}
Expand Down
6 changes: 4 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Queries/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search
.AddClass("search")
.Id("search")
.Add(S["Queries"], S["Queries"].PrefixPosition(), contentItems => contentItems
.Add(S["All queries"], "1", queries => queries
.Add(S["Queries"], S["Queries"].PrefixPosition(), queries => queries
.Add(S["All queries"], "1", allQueries => allQueries
.Action("Index", "Admin", "OrchardCore.Queries")
.AddClass("searchallqueries")
.Id("searchallqueries")
.Permission(Permissions.ManageQueries)
.LocalNav()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)

builder
.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search
.AddClass("azure-ai-service")
.Id("azureaiservice")
.AddClass("search")
.Id("search")
.Add(S["Indexing"], S["Indexing"].PrefixPosition(), indexing => indexing
.Add(S["Azure AI Indices"], S["Azure AI Indices"].PrefixPosition(), indexes => indexes
.Action("Index", "Admin", "OrchardCore.Search.AzureAI")
.AddClass("azureaiindices")
.Id("azureaiindices")
.Permission(AzureAISearchIndexPermissionHelper.ManageAzureAISearchIndexes)
.LocalNav()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)

builder
.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search
.AddClass("elasticsearch").Id("Elasticsearch")
.AddClass("search")
.Id("search")
.Add(S["Indexing"], S["Indexing"].PrefixPosition(), import => import
.Add(S["Elasticsearch Indices"], S["Elasticsearch Indices"].PrefixPosition(), indexes => indexes
.Action("Index", "Admin", "OrchardCore.Search.Elasticsearch")
.AddClass("elasticsearchindices")
.Id("elasticsearchindices")
.Permission(Permissions.ManageElasticIndexes)
.LocalNav()
)
)
.Add(S["Queries"], S["Queries"].PrefixPosition(), import => import
.Add(S["Run Elasticsearch Query"], S["Run Elasticsearch Query"].PrefixPosition(), queries => queries
.Action("Query", "Admin", "OrchardCore.Search.Elasticsearch")
.AddClass("elasticsearchquery")
.Id("elasticsearchquery")
.Permission(Permissions.ManageElasticIndexes)
.LocalNav()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)

builder
.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search
.AddClass("search").Id("search")
.AddClass("search")
.Id("search")
.Add(S["Indexing"], S["Indexing"].PrefixPosition(), import => import
.Add(S["Lucene Indices"], S["Lucene Indices"].PrefixPosition(), indexes => indexes
.Action("Index", "Admin", "OrchardCore.Search.Lucene")
.AddClass("luceneindices")
.Id("luceneindices")
.Permission(Permissions.ManageLuceneIndexes)
.LocalNav()
)
)
.Add(S["Queries"], S["Queries"].PrefixPosition(), import => import
.Add(S["Run Lucene Query"], S["Run Lucene Query"].PrefixPosition(), queries => queries
.Action("Query", "Admin", "OrchardCore.Search.Lucene")
.AddClass("lucenequery")
.Id("lucenequery")
.Permission(Permissions.ManageLuceneIndexes)
.LocalNav()
)
Expand Down
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Search/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder)
.Id("search")
.Add(S["Settings"], S["Settings"].PrefixPosition(), settings => settings
.Action("Index", "Admin", _routeValues)
.AddClass("searchsettings")
.Id("searchsettings")
.Permission(Permissions.ManageSearchSettings)
.LocalNav()
)
Expand Down
27 changes: 15 additions & 12 deletions src/OrchardCore.Themes/TheAdmin/Views/NavigationItem-admin.cshtml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
@using OrchardCore.Navigation
@{
TagBuilder li = Tag(Model, "li");

// Morphing the shape to keep Model untouched
// Morphing the shape to keep Model untouched.
Model.Metadata.Alternates.Clear();
Model.Metadata.Type = "NavigationItemLink";
Model.Metadata.Alternates.Add("NavigationItemLink_Id__" + Model.Id);

var prefix = "icon-class-";
if (Model.Id != null)
{
Model.Metadata.Alternates.Add("NavigationItemLink_Id__" + Model.Id);
}

// Extract classes that are not icons from Model.Classes
// Extract classes that are not icons from 'Model.Classes'.
var notIconClasses = ((IEnumerable<string>)Model.Classes)
.ToList()
.Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
.Where(c => !c.StartsWith(NavigationConstants.CssClassPrefix, StringComparison.OrdinalIgnoreCase))
.ToArray();

if (notIconClasses.Count() > 0)
if (notIconClasses.Length > 0)
{
li.Attributes["class"] = string.Join(" ", notIconClasses);
li.Attributes["class"] = string.Join(' ', notIconClasses);
}
else
{
// This removes the class attribute on the li element else
// an empty class attribute gets rendered
// This removes the class attribute on the li element when
// an empty class attribute gets rendered.
li.Attributes.Remove("class");
}

Expand All @@ -29,7 +32,7 @@
li.AddCssClass("active");
}

// Render sub-items (MenuItem)
// Render sub-items (MenuItem).
if (Model.HasItems)
{
li.AddCssClass("has-items");
Expand All @@ -38,7 +41,7 @@

if (li.Attributes.Where(a => a.Key == "id").Count() > 0)
{
figure.Attributes["aria-labelledby"] = li.Attributes["id"] ;
figure.Attributes["aria-labelledby"] = li.Attributes["id"];
figCaption.Attributes["id"] = li.Attributes["id"];
li.Attributes["id"] = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
@using OrchardCore.Localization
@using OrchardCore.Navigation
@{
// Morphing the shape to keep Model untouched
// Morphing the shape to keep Model untouched.
Model.Metadata.Alternates.Clear();
Model.Metadata.Type = "NavigationItemText";
Model.Metadata.Alternates.Add("NavigationItemText_Id__" + Model.Id);

if (Model.Id != null)
{
Model.Metadata.Alternates.Add("NavigationItemText_Id__" + Model.Id);
}

TagBuilder tag = Tag(Model, "a");
tag.Attributes["id"] = null;

if (Model.Href == null || Model.Href.ToString() == "#")
{
tag.Attributes["href"] = "#m" + Model.GetHashCode().ToString();
}
else
}
else
{
tag.Attributes["href"] = Model.Href;
}

var prefix = "icon-class-";

// Extract classes that are not icons from Model.Classes.
// Extract classes that are not icons from 'Model.Classes'.
var notIconClasses = ((IEnumerable<string>)Model.Classes)
.Where(c => !c.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
.Where(c => !c.StartsWith(NavigationConstants.CssClassPrefix, StringComparison.OrdinalIgnoreCase))
.ToArray();

if (notIconClasses.Length > 0)
{
tag.Attributes["class"] = string.Join(' ', notIconClasses);
}
else
{
// This removes the class attribute on the li element when
// an empty class attribute gets rendered.
tag.Attributes.Remove("class");
}

tag.AddCssClass("item-label d-flex");

Expand Down
10 changes: 10 additions & 0 deletions src/OrchardCore/OrchardCore.Navigation.Core/NavigationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ namespace OrchardCore.Navigation;

public static class NavigationConstants
{
public const string CssClassPrefix = "icon-class-";

public const string AdminMenuContentPosition = "1";

public const string AdminMenuDesignPosition = "2";

public const string AdminMenuSearchPosition = "6";

public const string AdminMenuSecurityPosition = "7";

public const string AdminMenuAuditTrailPosition = "7.5";

public const string AdminMenuWorkflowsPosition = "8";

public const string AdminMenuConfigurationPosition = "100";

public const string AdminId = "admin";

public const string AdminMenuId = "adminMenu";
}

0 comments on commit 2054b41

Please sign in to comment.