diff --git a/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs b/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs index 808048d..ce6279d 100644 --- a/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs +++ b/src/Skybrud.Umbraco.Redirects/Controllers/Api/RedirectsController.cs @@ -18,6 +18,7 @@ using Umbraco.Cms.Core.Web; using Umbraco.Cms.Web.BackOffice.Controllers; using Umbraco.Cms.Web.Common.Attributes; +using Umbraco.Extensions; #pragma warning disable 1591 @@ -37,23 +38,47 @@ public class RedirectsController : UmbracoAuthorizedApiController { private readonly IContentService _contentService; private readonly IMediaService _mediaService; private readonly IUmbracoContextAccessor _umbracoContextAccessor; + private readonly ILocalizationService _localizationService; #region Constructors public RedirectsController(ILogger logger, IRedirectsService redirectsService, RedirectsBackOfficeHelper backOffice, IContentService contentService, IMediaService mediaService, - IUmbracoContextAccessor umbracoContextAccessor) { + IUmbracoContextAccessor umbracoContextAccessor, ILocalizationService localizationService) { _logger = logger; _redirects = redirectsService; _backOffice = backOffice; _contentService = contentService; _mediaService = mediaService; _umbracoContextAccessor = umbracoContextAccessor; + _localizationService = localizationService; } #endregion + /// + /// Returns a list of cultures for the content node with the specified . If the node is not vary by culture, an empty list will be returned instead. + /// + /// The ID of the content node. + /// A list of cultures. + [HttpGet] + public object GetCultures(int id) { + + var content = _umbracoContextAccessor.GetRequiredUmbracoContext().Content?.GetById(id); + if (content is null) return NotFound(); + + var cultures = content.Cultures; + + if (cultures.Count == 1 && cultures.ContainsKey("")) return Array.Empty(); + + return cultures.Select(x => new { + alias = x.Key, + name = _localizationService.GetLanguageByIsoCode(x.Key)?.CultureName + }); + + } + /// /// Gets a list of root nodes based on the domains added to Umbraco. A root node will only be included in the /// list once - even if it has been assigned multiple domains. diff --git a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Services/RedirectsService.js b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Services/RedirectsService.js index a7d4a34..91a4503 100644 --- a/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Services/RedirectsService.js +++ b/src/Skybrud.Umbraco.Redirects/wwwroot/Scripts/Services/RedirectsService.js @@ -45,7 +45,7 @@ link.url = link.url.substr(0, pos); } } - + // Append the query and fragment to the anchor value (if specified) link.anchor = ""; if (link.query) link.anchor = link.query; @@ -136,7 +136,7 @@ // Convert our link object to something Umbraco's link picker can understand const target = service.toUmbracoLink(link); - // Open the link picker overlay + // Open the link picker overlay editorService.linkPicker({ size: "medium", currentTarget: target, @@ -151,13 +151,13 @@ // Invoke the callback (if specified) if (callback) callback(newLink); - + }, close: function () { editorService.close(); } }); - + }, addRedirect: function (options) { @@ -242,10 +242,10 @@ title: "Confirm delete", content: `Are you sure you want to delete the redirect at ${options.redirect.destination.displayUrl} ?`, submit: function() { - + // Update the button state in the UI overlay.submitButtonState = "busy"; - + // Delete the redirect service.deleteRedirect(options.redirect, function () { if (typeof options.submit === "function") { @@ -256,7 +256,7 @@ }, function () { overlay.submitButtonState = "error"; }); - + }, close: function() { options.close(overlay); @@ -270,7 +270,7 @@ localizationService.localize("redirects_overlayDeleteMessage", [options.redirect.destination.displayUrl], overlay.content).then(function (value) { overlay.content = value; }); - + // Open the overlay overlayService.confirmDelete(overlay); @@ -298,8 +298,8 @@ }, - getCulturesByNodeId: function(id) { - return $http.get("/umbraco/api/Redirects/GetCultures?id=" + id); + getCulturesByNodeId: function (id) { + return $http.get(`${baseUrl}GetCultures?id=${id}`); } };