Skip to content

Commit

Permalink
Misc culture related bug fixes
Browse files Browse the repository at this point in the history
Would have been nice catching these before releasing v4.0.9 🙃
  • Loading branch information
abjerner committed May 9, 2023
1 parent 3969052 commit d839945
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public object GetCultures(int id) {
return cultures.Select(x => new {
alias = x.Key,
name = _localizationService.GetLanguageByIsoCode(x.Key)?.CultureName,
nodeName = content.Name(culture: x.Key),
url = content.Url(culture: x.Key)
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Linq;
using Skybrud.Essentials.Reflection;
using Skybrud.Essentials.Strings;
using Skybrud.Essentials.Strings.Extensions;
using Skybrud.Umbraco.Redirects.Config;
using Skybrud.Umbraco.Redirects.Dashboards;
Expand Down Expand Up @@ -261,10 +262,15 @@ private RedirectModel Map(IRedirect redirect, Dictionary<Guid, RedirectRootNodeM
}
}

// Look up the current URL of the destination (with respect for the selected culture)
// Look up the current URL and name of the destination (with respect for the selected culture)
if (TryGetContent(redirect.Destination.Id, out IPublishedContent? published)) {

string url = published.Url(destination.Culture);
if (!string.IsNullOrEmpty(url)) destination.Url = url;

string? name = published.Name(destination.Culture);
if (!string.IsNullOrEmpty(name)) destination.Name = name;

}

// Set the backoffice URL of the page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RedirectDestinationModel {

public string DisplayUrl => RedirectsUtils.ConcatUrl(Url, Query, Fragment);

public string Name { get; }
public string Name { get; set; }

public string Icon { get; }

Expand Down
6 changes: 5 additions & 1 deletion src/Skybrud.Umbraco.Redirects/Services/RedirectsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,12 @@ public virtual string GetDestinationUrl(IRedirectBase redirect, Uri? uri) {

}

string? contentUrl = content?.Url(redirect.Destination.Culture);

if (string.IsNullOrWhiteSpace(contentUrl)) contentUrl = content?.Url(redirect.Destination.Culture);

// Put the destination URL back together
return RedirectsUtils.ConcatUrl(content?.Url() ?? redirect.Destination.Url, query, fragment);
return RedirectsUtils.ConcatUrl(contentUrl ?? redirect.Destination.Url, query, fragment);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
if ($scope.model.destination) {

destionation = $scope.model.redirect.destination = $scope.model.destination;

}

}
Expand Down Expand Up @@ -319,28 +319,28 @@
properties.culture.hidden = true;
return;
}

skybrudRedirectsService.getCulturesByNodeId(properties.destionation.value.id).then(function(r) {
properties.culture.config = { cultures: r.data };
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;


let culture = null;

if ($routeParams.mculture) {
culture = r.data.find(x => x.alias == $routeParams.mculture.toLowerCase()) ?? r.data[0];
} else {
culture = r.data[0];
}


properties.culture.culture = culture;
properties.culture.value = culture.alias;
});

});

// When the scope is destroyed we need to unsubscribe
$scope.$on("$destroy", function () {
unsubscribe();
Expand All @@ -356,11 +356,12 @@
if (!properties.destionation.value) return;
if (!args.culture) return;

// Update teh destination URL to reflect the selected culture
// Update teh destination URL and name to reflect the selected culture
properties.destionation.value.url = args.culture.url;

properties.destionation.value.name = args.culture.nodeName;

});

// When the scope is destroyed we need to unsubscribe
$scope.$on("$destroy", function () {
unsubscribe();
Expand All @@ -387,41 +388,41 @@
}

function init() {

if ($scope.model.destination) {

if ($scope.model.destination.type == "content") {

skybrudRedirectsService.getCulturesByNodeId($scope.model.destination.id).then(function(r) {

// Set the property editor configuration with the available cultures
properties.culture.config = { cultures: r.data };

// Does the destination have any cultures?
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;

// Look for the selected culture - or use the first culture as fallback
properties.culture.culture = getCultureFromRoute(r.data);
properties.culture.value = properties.culture.culture?.alias;

// Make sure we set destination URL to the destination of the current culture
$scope.model.destination.url = properties.culture.culture.url;

});

}

} else if ($scope.model.redirect && $scope.model.redirect.destination && $scope.model.redirect.destination.type === "content") {

skybrudRedirectsService.getCulturesByNodeId($scope.model.redirect.destination.id).then(function(r) {
properties.culture.config = { cultures: r.data };
properties.culture.hidden = r.data.length == 0;
if (properties.culture.hidden) return;
properties.culture.culture = r.data.find(x => x.alias == $scope.model.redirect.destination.culture);
properties.culture.value = properties.culture.culture?.alias;
});

}

initOnDestinationUpdated();
Expand All @@ -432,7 +433,7 @@
initLabels();

init();

vm.save = function () {

// Map the properties back to an object we can send to the API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const vm = this;

vm.updated = function () {
$scope.model.value = $scope.model.culture.alias;
$scope.model.value = $scope.model.culture.alias;
eventsService.emit("skybrud.umbraco.redirects.culture.updated", {
alias: $scope.model.culture.alias,
culture: $scope.model.culture
Expand Down

0 comments on commit d839945

Please sign in to comment.