From d8399453afdffaf9ea22b2a0d3c4d8945f4cb693 Mon Sep 17 00:00:00 2001 From: Anders Bjerner Date: Tue, 9 May 2023 17:11:22 +0200 Subject: [PATCH] Misc culture related bug fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Would have been nice catching these before releasing v4.0.9 🙃 --- .../Controllers/Api/RedirectsController.cs | 1 + .../Helpers/RedirectsBackOfficeHelper.cs | 8 ++- .../Models/Api/RedirectDestinationModel.cs | 2 +- .../Services/RedirectsService.cs | 6 ++- .../Scripts/Controllers/Dialogs/Redirect.js | 49 ++++++++++--------- .../Scripts/Controllers/Editors/Culture.js | 2 +- 6 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs b/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs index c4ad0a7..3ae2667 100644 --- a/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs +++ b/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs @@ -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) }); diff --git a/src/Skybrud.Umbraco.Redirects/Helpers/RedirectsBackOfficeHelper.cs b/src/Skybrud.Umbraco.Redirects/Helpers/RedirectsBackOfficeHelper.cs index b573da7..96f76b3 100644 --- a/src/Skybrud.Umbraco.Redirects/Helpers/RedirectsBackOfficeHelper.cs +++ b/src/Skybrud.Umbraco.Redirects/Helpers/RedirectsBackOfficeHelper.cs @@ -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; @@ -261,10 +262,15 @@ private RedirectModel Map(IRedirect redirect, Dictionary RedirectsUtils.ConcatUrl(Url, Query, Fragment); - public string Name { get; } + public string Name { get; set; } public string Icon { get; } diff --git a/src/Skybrud.Umbraco.Redirects/Services/RedirectsService.cs b/src/Skybrud.Umbraco.Redirects/Services/RedirectsService.cs index 45f8e21..91976ed 100644 --- a/src/Skybrud.Umbraco.Redirects/Services/RedirectsService.cs +++ b/src/Skybrud.Umbraco.Redirects/Services/RedirectsService.cs @@ -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); } diff --git a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Dialogs/Redirect.js b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Dialogs/Redirect.js index 4cb8a9c..64a2275 100644 --- a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Dialogs/Redirect.js +++ b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Dialogs/Redirect.js @@ -54,7 +54,7 @@ if ($scope.model.destination) { destionation = $scope.model.redirect.destination = $scope.model.destination; - + } } @@ -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(); @@ -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(); @@ -387,33 +388,33 @@ } 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; @@ -421,7 +422,7 @@ properties.culture.culture = r.data.find(x => x.alias == $scope.model.redirect.destination.culture); properties.culture.value = properties.culture.culture?.alias; }); - + } initOnDestinationUpdated(); @@ -432,7 +433,7 @@ initLabels(); init(); - + vm.save = function () { // Map the properties back to an object we can send to the API diff --git a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Editors/Culture.js b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Editors/Culture.js index 89b17e5..42cb054 100644 --- a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Editors/Culture.js +++ b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Controllers/Editors/Culture.js @@ -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