diff --git a/src/SeoToolkit.Umbraco.Common.Core/ContentApps/SeoContentAppFactory.cs b/src/SeoToolkit.Umbraco.Common.Core/ContentApps/SeoContentAppFactory.cs index ef85fb88..2aee5347 100644 --- a/src/SeoToolkit.Umbraco.Common.Core/ContentApps/SeoContentAppFactory.cs +++ b/src/SeoToolkit.Umbraco.Common.Core/ContentApps/SeoContentAppFactory.cs @@ -23,7 +23,7 @@ public SeoContentAppFactory(ISeoSettingsService seoSettingsService, public ContentApp GetContentAppFor(object source, IEnumerable userGroups) { - if (source is not IContent { HasIdentity: true } content || !_seoSettingsService.IsEnabled(content.ContentTypeId)) + if (source is not IContent content || !_seoSettingsService.IsEnabled(content.ContentTypeId)) return null; using var scope = _serviceScopeFactory.CreateScope(); diff --git a/src/SeoToolkit.Umbraco.Common.Core/Controllers/SeoContentController.cs b/src/SeoToolkit.Umbraco.Common.Core/Controllers/SeoContentController.cs index 764851be..ecfb2a12 100644 --- a/src/SeoToolkit.Umbraco.Common.Core/Controllers/SeoContentController.cs +++ b/src/SeoToolkit.Umbraco.Common.Core/Controllers/SeoContentController.cs @@ -24,8 +24,6 @@ public SeoContentController(IContentService contentService, SeoDisplayCollection public IActionResult Get(int contentId) { var content = _contentService.GetById(contentId); - if (content is null) return NotFound(); - return new JsonResult(new SeoContentViewModel { Displays = _seoDisplayCollection.Select(it => it.Get(content)).WhereNotNull().ToArray() diff --git a/src/SeoToolkit.Umbraco.Common.Core/Interfaces/ISeoDisplayProvider.cs b/src/SeoToolkit.Umbraco.Common.Core/Interfaces/ISeoDisplayProvider.cs index 10684220..a8d5f1d2 100644 --- a/src/SeoToolkit.Umbraco.Common.Core/Interfaces/ISeoDisplayProvider.cs +++ b/src/SeoToolkit.Umbraco.Common.Core/Interfaces/ISeoDisplayProvider.cs @@ -5,6 +5,6 @@ namespace SeoToolkit.Umbraco.Common.Core.Interfaces { public interface ISeoDisplayProvider { - SeoDisplayViewModel Get(IContent content); + SeoDisplayViewModel Get(IContent? content); } } diff --git a/src/SeoToolkit.Umbraco.Common/wwwroot/ContentApps/Content/seoContent.controller.js b/src/SeoToolkit.Umbraco.Common/wwwroot/ContentApps/Content/seoContent.controller.js index 78578528..3d4aa07b 100644 --- a/src/SeoToolkit.Umbraco.Common/wwwroot/ContentApps/Content/seoContent.controller.js +++ b/src/SeoToolkit.Umbraco.Common/wwwroot/ContentApps/Content/seoContent.controller.js @@ -1,6 +1,6 @@ (function () { - function SeoContentController($scope, $http, editorState, eventsService, notificationsService) { + function SeoContentController($scope, $http, editorState, eventsService, notificationsService, contentAppHelper) { var unsubscribe = []; var vm = this; @@ -21,14 +21,14 @@ } function save() { - vm.defaultButtonScope.defaultButton.saveButtonState = "busy"; $scope.$broadcast("seoContentSubmitting"); - notificationsService.success("SEO content saved!"); - vm.defaultButtonScope.defaultButton.saveButtonState = "success"; } function init() { + if (!contentAppHelper.CONTENT_BASED_APPS.includes("seoContent")) { + contentAppHelper.CONTENT_BASED_APPS.push("seoContent"); + } $http.get("backoffice/SeoToolkit/SeoContent/Get?contentId=" + editorState.getCurrent().id).then( function (response) { if (response.status === 200) { @@ -38,39 +38,20 @@ }); } - function initSaveButton() { - const maxTries = 20; - var tries = 0; - var currentScope = $scope.$parent; - while (currentScope && !currentScope.hasOwnProperty("defaultButton") && tries <= maxTries) { - currentScope = currentScope.$parent; - tries++; - } - - if (maxTries > tries) { - vm.defaultButtonScope = currentScope; - } - - if (vm.defaultButtonScope) { - vm.defaultButtonScope.defaultButton = { - letter: 'S', - labelKey: "buttons_save", - handler: save, - hotKey: "ctrl+s", - hotKeyWhenHidden: true, - alias: "save", - addEllipsis: "true" - } - } - } - unsubscribe.push(eventsService.on("app.tabChange", (e, data) => { if (data.alias !== "seoContent") { return; } - initSaveButton(); + if (unsubscribe.length == 1) { + unsubscribe.push(eventsService.on("content.saved", () => { + save(); + })); + unsubscribe.push(eventsService.on("content.unpublished", () => { + save(); + })); + } })); vm.$onDestroy = function () { diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Controllers/MetaFieldsController.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Controllers/MetaFieldsController.cs index 587f438c..1a542b5e 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Controllers/MetaFieldsController.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Controllers/MetaFieldsController.cs @@ -63,14 +63,9 @@ public IActionResult Get(int nodeId, string culture) using var ctx = _umbracoContextFactory.EnsureUmbracoContext(); var content = ctx.UmbracoContext.Content.GetById(true, nodeId); - if (content is null) - { - _logger.LogInformation("Could not find content by id {0}", nodeId); - return NotFound(); - } - var metaTags = _seoService.Get(content, false); - var userValues = _seoValueService.GetUserValues(nodeId); + var metaTags = content is null ? _seoService.GetEmpty() : _seoService.Get(content, false); + var userValues = content is null ? new Dictionary() : _seoValueService.GetUserValues(nodeId); return new JsonResult(new MetaFieldsSettingsViewModel { diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/IMetaTagsProvider.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/IMetaTagsProvider.cs index e3e4672a..dd01a369 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/IMetaTagsProvider.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/IMetaTagsProvider.cs @@ -9,5 +9,7 @@ public interface IMetaTagsProvider event EventHandler BeforeMetaTagsGet; MetaTagsModel Get(IPublishedContent content, bool includeUserValues); + + MetaTagsModel GetEmpty(); } } diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/Services/IMetaFieldsService.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/Services/IMetaFieldsService.cs index 2b9f6d55..fb5801fe 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/Services/IMetaFieldsService.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Interfaces/Services/IMetaFieldsService.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Umbraco.Cms.Core.Models.PublishedContent; +using Umbraco.Cms.Core.Models.PublishedContent; using SeoToolkit.Umbraco.MetaFields.Core.Models.SeoService; namespace SeoToolkit.Umbraco.MetaFields.Core.Interfaces.Services @@ -9,5 +6,6 @@ namespace SeoToolkit.Umbraco.MetaFields.Core.Interfaces.Services public interface IMetaFieldsService { MetaTagsModel Get(IPublishedContent content, bool includeUserValues); + MetaTagsModel GetEmpty(); } } diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs index 730bdd7d..8d411ce1 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Providers/DefaultMetaTagsProvider.cs @@ -116,5 +116,12 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues) return metaTags; } } + + public MetaTagsModel GetEmpty() + { + var allFields = _seoFieldCollection.GetAll().ToArray(); + + return new MetaTagsModel(allFields.ToDictionary(it => it, it => (object)null)); + } } } diff --git a/src/SeoToolkit.Umbraco.MetaFields.Core/Services/MetaFieldsService/MetaFieldsService.cs b/src/SeoToolkit.Umbraco.MetaFields.Core/Services/MetaFieldsService/MetaFieldsService.cs index 2eefe7e3..766734ee 100644 --- a/src/SeoToolkit.Umbraco.MetaFields.Core/Services/MetaFieldsService/MetaFieldsService.cs +++ b/src/SeoToolkit.Umbraco.MetaFields.Core/Services/MetaFieldsService/MetaFieldsService.cs @@ -18,5 +18,10 @@ public MetaTagsModel Get(IPublishedContent content, bool includeUserValues) { return _metaTagsProvider.Get(content, includeUserValues); } + + public MetaTagsModel GetEmpty() + { + return _metaTagsProvider.GetEmpty(); + } } } diff --git a/src/SeoToolkit.Umbraco.MetaFields/wwwroot/MetaFields/Interface/ContentApps/SeoSettings/seoSettings.controller.js b/src/SeoToolkit.Umbraco.MetaFields/wwwroot/MetaFields/Interface/ContentApps/SeoSettings/seoSettings.controller.js index 1c191b9a..8edcdb9b 100644 --- a/src/SeoToolkit.Umbraco.MetaFields/wwwroot/MetaFields/Interface/ContentApps/SeoSettings/seoSettings.controller.js +++ b/src/SeoToolkit.Umbraco.MetaFields/wwwroot/MetaFields/Interface/ContentApps/SeoSettings/seoSettings.controller.js @@ -125,6 +125,10 @@ save(); })); + vm.$onDestroy = function () { + unsubscribe.forEach(x => x()); + } + init(); }