Skip to content

Commit

Permalink
Merge pull request #25 from AaronSadlerUK/feature/15-allow-labels-to-…
Browse files Browse the repository at this point in the history
…show-child-nodes-of-a

15 Allow labels to show child nodes of a page
  • Loading branch information
AaronSadlerUK committed Sep 7, 2021
2 parents cbf9fe0 + e5774e6 commit 53940a1
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 55 deletions.
7 changes: 5 additions & 2 deletions TestSite.V9/App_Plugins/UmbNav/js/umbnav.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
allowImageIcon: dialogOptions.config.allowImageIcon,
hideIncludeChildren: dialogOptions.config.hideIncludeChildren,
allowLabels: dialogOptions.config.allowLabels,
allowDisplayAsLabel: dialogOptions.config.allowDisplayAsLabel,
currentTarget: item,
submit: function (model) {

Expand All @@ -127,8 +128,9 @@
model.target.target = null;
model.target.noopener = false;
model.target.noreferrer = false;
model.target.includeChildren = false;
model.target.includeChildNodes = false;
model.target.udi = null;
model.target.id = null;
} else {
model.target.description = model.target.url + model.target.anchor;
if (model.target.anchor && model.target.anchor[0] !== '?' && model.target.anchor[0] !== '#') {
Expand Down Expand Up @@ -200,7 +202,8 @@
naviHide: data.naviHide,
culture: data.culture,
includeChildNodes: data.includeChildNodes,
itemType: data.itemType
itemType: data.itemType,
displayAsLabel: data.displayAsLabel
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
vm.toggleDisplayLoggedIn = toggleDisplayLoggedIn;
vm.toggleDisplayLoggedOut = toggleDisplayLoggedOut;
vm.toggleChildren = toggleChildren;
vm.toggleDisplayAsLabel = toggleDisplayAsLabel;
vm.openMediaPicker = openMediaPicker;
vm.showAdvanced = false;
vm.labels = {};
Expand Down Expand Up @@ -52,6 +53,9 @@
localizationService.localizeMany(['umbnav_linkTypeDescription']).then(function (data) {
vm.labels.linkTypeDescription = data[0];
});
localizationService.localizeMany(['umbnav_displayAsLabel']).then(function (data) {
vm.labels.displayAsLabel = data[0];
});
if (!$scope.model.title) {
localizationService.localize('defaultdialogs_selectLink').then(function (value) {
$scope.model.title = value;
Expand All @@ -70,6 +74,7 @@
};
$scope.showTarget = $scope.model.hideTarget !== true;
$scope.showDisplay = $scope.model.allowDisplay === true;
$scope.showDisplayAsLabel = $scope.model.allowDisplayAsLabel === true;
$scope.showNoopener = $scope.model.hideNoopener !== true;
$scope.showNoreferrer = $scope.model.hideNoreferrer !== true;
$scope.showAnchor = $scope.model.hideAnchor !== true;
Expand Down Expand Up @@ -147,6 +152,7 @@
vm.hideLoggedIn = $scope.model.target.hideLoggedIn;
vm.hideLoggedOut = $scope.model.target.hideLoggedOut;
vm.includeChildren = $scope.model.target.includeChildNodes;
vm.displayAsLabel = $scope.model.target.displayAsLabel;
vm.showNoopener = $scope.model.target.noopener === 'noopener' && $scope.model.target.id === null || $scope.model.target.udi === null;
vm.showNoreferrer = $scope.model.target.noreferrer === 'noreferrer' && $scope.model.target.id === null || $scope.model.target.udi === null;
} else if (dialogOptions.anchors) {
Expand Down Expand Up @@ -278,6 +284,9 @@
function toggleChildren(model, value) {
$scope.model.target.includeChildren = model ? true : false;
}
function toggleDisplayAsLabel(model, value) {
$scope.model.target.displayAsLabel = model ? true : false;
}
function close() {
if ($scope.model && $scope.model.close) {
$scope.model.close();
Expand Down
1 change: 1 addition & 0 deletions TestSite.V9/App_Plugins/UmbNav/lang/en-us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<key alias="title">Title</key>
<key alias="itemType">Menu Item Type</key>
<key alias="linkTypeDescription">Select menu item type</key>
<key alias="displayAsLabel">Display as label</key>
</area>
</language>
7 changes: 7 additions & 0 deletions TestSite.V9/App_Plugins/UmbNav/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ <h5>
</umb-checkbox>
</umb-control-group>

<umb-control-group ng-if="showDisplayAsLabel" label="@umbnav_displayAsLabel">
<umb-checkbox model="vm.displayAsLabel"
on-change="vm.toggleDisplayAsLabel(model, value)"
text="{{vm.labels.displayAsLabel}}">
</umb-checkbox>
</umb-control-group>

<umb-control-group ng-if="showIncludeChildren && model.target.itemType == 'link'" label="@umbnav_includeChildren">
<umb-checkbox model="vm.includeChildren"
on-change="vm.toggleChildren(model, value)"
Expand Down
7 changes: 5 additions & 2 deletions TestSite/App_Plugins/UmbNav/js/umbnav.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
allowImageIcon: dialogOptions.config.allowImageIcon,
hideIncludeChildren: dialogOptions.config.hideIncludeChildren,
allowLabels: dialogOptions.config.allowLabels,
allowDisplayAsLabel: dialogOptions.config.allowDisplayAsLabel,
currentTarget: item,
submit: function (model) {

Expand All @@ -127,8 +128,9 @@
model.target.target = null;
model.target.noopener = false;
model.target.noreferrer = false;
model.target.includeChildren = false;
model.target.includeChildNodes = false;
model.target.udi = null;
model.target.id = null;
} else {
model.target.description = model.target.url + model.target.anchor;
if (model.target.anchor && model.target.anchor[0] !== '?' && model.target.anchor[0] !== '#') {
Expand Down Expand Up @@ -200,7 +202,8 @@
naviHide: data.naviHide,
culture: data.culture,
includeChildNodes: data.includeChildNodes,
itemType: data.itemType
itemType: data.itemType,
displayAsLabel: data.displayAsLabel
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions TestSite/App_Plugins/UmbNav/js/umbnav.settings.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
vm.toggleDisplayLoggedIn = toggleDisplayLoggedIn;
vm.toggleDisplayLoggedOut = toggleDisplayLoggedOut;
vm.toggleChildren = toggleChildren;
vm.toggleDisplayAsLabel = toggleDisplayAsLabel;
vm.openMediaPicker = openMediaPicker;
vm.showAdvanced = false;
vm.labels = {};
Expand Down Expand Up @@ -52,6 +53,9 @@
localizationService.localizeMany(['umbnav_linkTypeDescription']).then(function (data) {
vm.labels.linkTypeDescription = data[0];
});
localizationService.localizeMany(['umbnav_displayAsLabel']).then(function (data) {
vm.labels.displayAsLabel = data[0];
});
if (!$scope.model.title) {
localizationService.localize('defaultdialogs_selectLink').then(function (value) {
$scope.model.title = value;
Expand All @@ -70,6 +74,7 @@
};
$scope.showTarget = $scope.model.hideTarget !== true;
$scope.showDisplay = $scope.model.allowDisplay === true;
$scope.showDisplayAsLabel = $scope.model.allowDisplayAsLabel === true;
$scope.showNoopener = $scope.model.hideNoopener !== true;
$scope.showNoreferrer = $scope.model.hideNoreferrer !== true;
$scope.showAnchor = $scope.model.hideAnchor !== true;
Expand Down Expand Up @@ -147,6 +152,7 @@
vm.hideLoggedIn = $scope.model.target.hideLoggedIn;
vm.hideLoggedOut = $scope.model.target.hideLoggedOut;
vm.includeChildren = $scope.model.target.includeChildNodes;
vm.displayAsLabel = $scope.model.target.displayAsLabel;
vm.showNoopener = $scope.model.target.noopener === 'noopener' && $scope.model.target.id === null || $scope.model.target.udi === null;
vm.showNoreferrer = $scope.model.target.noreferrer === 'noreferrer' && $scope.model.target.id === null || $scope.model.target.udi === null;
} else if (dialogOptions.anchors) {
Expand Down Expand Up @@ -278,6 +284,9 @@
function toggleChildren(model, value) {
$scope.model.target.includeChildren = model ? true : false;
}
function toggleDisplayAsLabel(model, value) {
$scope.model.target.displayAsLabel = model ? true : false;
}
function close() {
if ($scope.model && $scope.model.close) {
$scope.model.close();
Expand Down
1 change: 1 addition & 0 deletions TestSite/App_Plugins/UmbNav/lang/en-us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<key alias="title">Title</key>
<key alias="itemType">Menu Item Type</key>
<key alias="linkTypeDescription">Select menu item type</key>
<key alias="displayAsLabel">Display as label</key>
</area>
</language>
7 changes: 7 additions & 0 deletions TestSite/App_Plugins/UmbNav/views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ <h5>
</umb-checkbox>
</umb-control-group>

<umb-control-group ng-if="showDisplayAsLabel" label="@umbnav_displayAsLabel">
<umb-checkbox model="vm.displayAsLabel"
on-change="vm.toggleDisplayAsLabel(model, value)"
text="{{vm.labels.displayAsLabel}}">
</umb-checkbox>
</umb-control-group>

<umb-control-group ng-if="showIncludeChildren && model.target.itemType == 'link'" label="@umbnav_includeChildren">
<umb-checkbox model="vm.includeChildren"
on-change="vm.toggleChildren(model, value)"
Expand Down
43 changes: 22 additions & 21 deletions TestSite/Views/Partials/Navigation/TopNavigation.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
if (item.Children != null && item.Children.Any())
{
<li>
<a class="@item.CustomClasses" href="@item.Url()" target="@item.Target" rel="@item.Noopener @item.Noreferrer">
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>
@item.GetItemHtml()
@*<a class="@item.CustomClasses" href="@item.Url()" target="@item.Target" rel="@item.Noopener @item.Noreferrer">
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>*@
<ul>
@foreach (var child in item.Children)
{
Expand All @@ -48,16 +49,16 @@
{
<li>
@*<a class="@item.CustomClasses" href="@item.Url()" target="@item.Target" rel="@item.Noopener @item.Noreferrer">
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>*@
@if (item.Image != null)
{
<img src="@item.Image.Url()" alt="@item.Title" width="30" height="30" />
}
@item.Title
@if (item.IsActive)
{
<text>Active</text>
}
</a>*@
@item.GetItemHtml()
</li>
}
Expand Down
3 changes: 3 additions & 0 deletions src/UmbNav.Core/Models/UmbNavItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,8 @@ public class UmbNavItem

[JsonIgnore]
public bool IsActive { get; set; }

[JsonProperty("displayAsLabel")]
public bool DisplayAsLabel { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/UmbNav.Core/PropertyEditors/UmbNavV8Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class UmbNavV8Configuration
[ConfigurationField("allowDisplay", "Allow Member Visibility", "boolean", Description = "Allow the ability to hide menu items based on member authentication status")]
public bool AllowDisplay { get; set; } = false;

[ConfigurationField("allowDisplayAsLabel", "Allow a Link To Display as a Label", "boolean", Description = "Allow the ability to display a link item as a label")]
public bool AllowDisplayAsLabel { get; set; } = false;

[ConfigurationField("allowCustomClasses", "Allow Custom Classes", "boolean", Description = "Allow the ability to set custom classes on an item")]
public bool AllowCustomClasses { get; set; } = false;

Expand Down
71 changes: 43 additions & 28 deletions src/UmbNav.Core/Services/UmbNavMenuBuilderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public IEnumerable<UmbNavItem> BuildMenu(IEnumerable<UmbNavItem> items, int leve
continue;
}

if (item.MenuItemType is "nolink")
if (item.MenuItemType is "nolink" || item.DisplayAsLabel)
{
item.ItemType = UmbNavItemType.Label;
item.Anchor = null;
Expand All @@ -72,7 +72,11 @@ public IEnumerable<UmbNavItem> BuildMenu(IEnumerable<UmbNavItem> items, int leve
item.Noreferrer = null;
item.IncludeChildNodes = false;
item.Udi = null;
continue;

//if (!item.DisplayAsLabel)
//{
// continue;
//}
}

var children = new List<UmbNavItem>();
Expand All @@ -85,46 +89,52 @@ public IEnumerable<UmbNavItem> BuildMenu(IEnumerable<UmbNavItem> items, int leve
{
IPublishedContent umbracoContent = null;
string currentCulture = null;
#if NETCOREAPP
if (_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
if (item.MenuItemType != "nolink")
{
#if NETCOREAPP
if (_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
{
if (item.Udi != null)
{
currentCulture = publishedSnapshot.Content.GetById(item.Udi)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Udi);
}
else if (item.Key != Guid.Empty)
{
currentCulture = publishedSnapshot.Content.GetById(item.Key)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Key);
}
else
{
currentCulture = publishedSnapshot.Content.GetById(item.Id)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Id);
}
}
#else
if (item.Udi != null)
{
currentCulture = publishedSnapshot.Content.GetById(item.Udi)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Udi);
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Udi)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Udi);
}
else if (item.Key != Guid.Empty)
{
currentCulture = publishedSnapshot.Content.GetById(item.Key)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Key);
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Key)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Key);
}
else
{
currentCulture = publishedSnapshot.Content.GetById(item.Id)?.GetCultureFromDomains();
umbracoContent = publishedSnapshot.Content.GetById(item.Id);
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Id)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Id);
}
}
#else
if (item.Udi != null)
{
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Udi)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Udi);
}
else if (item.Key != Guid.Empty)
{
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Key)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Key);
}
else
{
currentCulture = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Id)?.GetCultureFromDomains();
umbracoContent = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(item.Id);
}
#endif
}

if (umbracoContent != null)
{
item.ItemType = UmbNavItemType.Content;
if (!item.DisplayAsLabel)
{
item.ItemType = UmbNavItemType.Content;
}
item.Content = umbracoContent;

if (umbracoContent.Key == currentPublishedContentKey)
Expand Down Expand Up @@ -205,6 +215,11 @@ public IEnumerable<UmbNavItem> BuildMenu(IEnumerable<UmbNavItem> items, int leve
}

item.Level = level;

if (item.DisplayAsLabel && item.Content == null || item.MenuItemType is "link" && item.Content == null)
{
item.ItemType = UmbNavItemType.Link;
}
}
//items = items.Where(x => x.ItemType == UmbNavItemType.Link);
foreach (var removeItem in removeItems)
Expand Down
Loading

0 comments on commit 53940a1

Please sign in to comment.