From 3358c703127acac81b44232044f24e11fc0a61a8 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 10 Sep 2018 15:32:12 +0200 Subject: [PATCH 1/4] Fixes: Stay on the same content app when changing language --- .../components/content/edit.controller.js | 4 -- .../content/umbvariantcontent.directive.js | 14 ++++++- .../umbvariantcontenteditors.directive.js | 29 +++++++++++++- .../editor/umbeditorheader.directive.js | 7 ++++ .../editor/umbeditornavigation.directive.js | 8 +++- .../src/views/components/content/edit.html | 7 ++-- .../content/umb-variant-content-editors.html | 3 +- .../content/umb-variant-content.html | 39 ++++++++++--------- .../components/editor/umb-editor-header.html | 13 ++++--- 9 files changed, 88 insertions(+), 36 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index eff1025e60..280bb4ba1d 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -46,10 +46,6 @@ } bindEvents(); - - // set first app to active - // We need to track active - $scope.content.apps[0].active = true; resetVariantFlags(); } diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js index b2045fcb2d..4905188536 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js @@ -15,7 +15,8 @@ openVariants: "<", onCloseSplitView: "&", onSelectVariant: "&", - onOpenSplitView: "&" + onOpenSplitView: "&", + onSelectApp: "&" }, controllerAs: 'vm', controller: umbVariantContentController @@ -33,6 +34,7 @@ vm.selectVariant = selectVariant; vm.openSplitView = openSplitView; vm.backToListView = backToListView; + vm.selectApp = selectApp; /** Called when the component has linked all elements, this is when the form controller is available */ function postLink() { @@ -65,6 +67,16 @@ } } + /** + * Used to proxy a callback + * @param {any} item + */ + function selectApp(item) { + if(vm.onSelectApp) { + vm.onSelectApp({"app": item}); + } + } + /** * Used to proxy a callback * @param {any} variant diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js index 4366a883f7..7d6d5dc131 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js @@ -15,11 +15,12 @@ controller: umbVariantContentEditorsController }; - function umbVariantContentEditorsController($scope, $element, $location, $timeout) { + function umbVariantContentEditorsController($scope, $location, $timeout) { var prevContentDateUpdated = null; var vm = this; + var activeAppAlias = null; vm.$onInit = onInit; vm.$onChanges = onChanges; @@ -29,6 +30,7 @@ vm.openSplitView = openSplitView; vm.closeSplitView = closeSplitView; vm.selectVariant = selectVariant; + vm.selectApp = selectApp; //Used to track how many content views there are (for split view there will be 2, it could support more in theory) vm.editors = []; @@ -37,6 +39,8 @@ /** Called when the component initializes */ function onInit() { + // set first app to active + vm.content.apps[0].active = true; prevContentDateUpdated = angular.copy(vm.content.updateDate); setActiveCulture(); } @@ -141,7 +145,7 @@ //with a copy of the contentApps. This is required because each editor renders it's own //header and content apps section and the content apps contains the view for editing content itself //and we need to assign a view model to the subView so that it is scoped to the current - //editor so that split views work. + //editor so that split views work. //copy the apps from the main model if not assigned yet to the variant if (!variant.apps) { @@ -191,6 +195,16 @@ vm.openVariants[editorIndex] = variant.language.culture; } + // make sure the same app it set to active in the new variant + if(activeAppAlias) { + angular.forEach(variant.apps, function(app) { + app.active = false; + if(app.alias === activeAppAlias) { + app.active = true; + } + }); + } + return variant; } /** @@ -288,6 +302,17 @@ } } + + /** + * Stores the active app in a variable so we can remember it when changing language + * @param {any} app This is the model of the selected app + */ + function selectApp(app) { + if(app && app.alias) { + activeAppAlias = app.alias; + } + } + } angular.module('umbraco.directives').component('umbVariantContentEditors', umbVariantContentEditors); diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js index 6bb9f4e1f6..81218fdbad 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorheader.directive.js @@ -246,6 +246,12 @@ Use this directive to construct a header inside the main editor window. } }; + scope.selectNavigationItem = function(item) { + if(scope.onSelectNavigationItem) { + scope.onSelectNavigationItem({"item": item}); + } + } + scope.openIconPicker = function () { var iconPicker = { icon: scope.icon.split(' ')[0], @@ -336,6 +342,7 @@ Use this directive to construct a header inside the main editor window. openVariants: "<", hideChangeVariant: " - + diff --git a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content-editors.html b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content-editors.html index 9d2a95d9ae..9d879fac22 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content-editors.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content-editors.html @@ -12,7 +12,8 @@ open-variants="vm.openVariants" on-open-split-view="vm.openSplitView(variant)" on-close-split-view="vm.closeSplitView($index)" - on-select-variant="vm.selectVariant(variant, $index)"> + on-select-variant="vm.selectVariant(variant, $index)" + on-select-app="vm.selectApp(app)"> diff --git a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html index 50b9e6d85e..763fd89816 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/content/umb-variant-content.html @@ -1,27 +1,30 @@ 
- +
- + diff --git a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html index 6cc84d8cea..5444f55e87 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html @@ -92,15 +92,18 @@
- +
- +
From 3001c656d188aa16ca338c9363b7979eb6c1d9a9 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 10 Sep 2018 15:39:04 +0200 Subject: [PATCH 2/4] remove unused code --- .../src/views/media/media.edit.controller.js | 36 +++---------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js index 39fe794bf3..6ea060b3d5 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js @@ -79,10 +79,7 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, editorState.set($scope.content); - // We don't get the info tab from the server from version 7.8 so we need to manually add it - //contentEditingHelper.addInfoTab($scope.content.tabs); - - init($scope.content); + init(); $scope.page.loading = false; @@ -96,29 +93,7 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, }); } - function init(content) { - - // prototype content and info apps - var contentApp = { - "name": "Content", - "alias": "content", - "icon": "icon-document", - "view": "views/media/apps/content/content.html" - }; - - var infoApp = { - "name": "Info", - "alias": "info", - "icon": "icon-info", - "view": "views/media/apps/info/info.html" - }; - - var listview = { - "name": "Child items", - "alias": "childItems", - "icon": "icon-list", - "view": "views/media/apps/listview/listview.html" - }; + function init() { // set first app to active $scope.content.apps[0].active = true; @@ -154,7 +129,7 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, syncTreeNode($scope.content, data.path); - init($scope.content); + init(); $scope.page.saveButtonState = "success"; @@ -216,10 +191,7 @@ function mediaEditController($scope, $routeParams, $q, appState, mediaResource, }); } - // We don't get the info tab from the server from version 7.8 so we need to manually add it - //contentEditingHelper.addInfoTab($scope.content.tabs); - - init($scope.content); + init(); $scope.page.loading = false; From 8e713e2350e45d2e214694da60cc6f2f29b15a93 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 10 Sep 2018 15:41:54 +0200 Subject: [PATCH 3/4] clean up dependecies --- .../directives/components/content/edit.controller.js | 8 ++++---- .../src/views/media/media.edit.controller.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index 280bb4ba1d..e5ec9172c6 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -1,10 +1,10 @@ (function () { 'use strict'; - function ContentEditController($rootScope, $scope, $routeParams, $q, $timeout, $window, $location, - appState, contentResource, entityResource, navigationService, notificationsService, angularHelper, - serverValidationManager, contentEditingHelper, treeService, fileManager, formHelper, umbRequestHelper, - keyboardService, umbModelMapper, editorState, $http, eventsService, relationResource, overlayService, localizationService) { + function ContentEditController($rootScope, $scope, $routeParams, $q, $window, + appState, contentResource, entityResource, navigationService, notificationsService, + serverValidationManager, contentEditingHelper, treeService, formHelper, umbRequestHelper, + editorState, $http, eventsService, relationResource, overlayService) { var evts = []; var infiniteMode = $scope.infiniteModel && $scope.infiniteModel.infiniteMode; diff --git a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js index 6ea060b3d5..cc63b5f9f0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/media/media.edit.controller.js @@ -6,7 +6,7 @@ * @description * The controller for the media editor */ -function mediaEditController($scope, $routeParams, $q, appState, mediaResource, entityResource, navigationService, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, fileManager, treeService, formHelper, umbModelMapper, editorState, umbRequestHelper, $http, eventsService) { +function mediaEditController($scope, $routeParams, $q, appState, mediaResource, entityResource, navigationService, notificationsService, angularHelper, serverValidationManager, contentEditingHelper, fileManager, formHelper, editorState, umbRequestHelper, $http, eventsService) { var evts = []; var nodeId = null; From cc7ae2b930ed2705e919dff43a76babd16ae9639 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 10 Sep 2018 20:23:15 +0200 Subject: [PATCH 4/4] split up editor-header into editor-header and editor-content-header --- .../content/umbvariantcontent.directive.js | 5 - .../umbeditorcontentheader.directive.js | 124 ++++++++++++++++++ .../editor/umbeditorheader.directive.js | 89 +------------ .../content/umb-variant-content.html | 8 +- .../editor/umb-editor-content-header.html | 83 ++++++++++++ .../components/editor/umb-editor-header.html | 29 +--- 6 files changed, 215 insertions(+), 123 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-content-header.html diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js index 4905188536..5ad7a9079a 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontent.directive.js @@ -33,7 +33,6 @@ vm.selectVariant = selectVariant; vm.openSplitView = openSplitView; - vm.backToListView = backToListView; vm.selectApp = selectApp; /** Called when the component has linked all elements, this is when the form controller is available */ @@ -53,10 +52,6 @@ } } - function backToListView() { - $location.path(vm.page.listViewPath); - }; - /** * Used to proxy a callback * @param {any} variant diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js new file mode 100644 index 0000000000..3cdcd5b12a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/editor/umbeditorcontentheader.directive.js @@ -0,0 +1,124 @@ +(function () { + 'use strict'; + + function EditorContentHeader($location, $routeParams) { + + function link(scope, el, attr, ctrl) { + + if (!scope.serverValidationNameField) { + scope.serverValidationNameField = "Name"; + } + if (!scope.serverValidationAliasField) { + scope.serverValidationAliasField = "Alias"; + } + + scope.vm = {}; + scope.vm.dropdownOpen = false; + scope.vm.currentVariant = ""; + + function onInit() { + setCurrentVariant(); + } + + function setCurrentVariant() { + angular.forEach(scope.variants, function (variant) { + if (variant.active) { + scope.vm.currentVariant = variant; + } + }); + } + + scope.goBack = function () { + $location.path('/' + $routeParams.section + '/' + $routeParams.tree + '/' + $routeParams.method + '/' + scope.menu.currentNode.parentId); + }; + + scope.selectVariant = function (event, variant) { + + if (scope.onSelectVariant) { + scope.vm.dropdownOpen = false; + scope.onSelectVariant({ "variant": variant }); + } + }; + + scope.selectNavigationItem = function(item) { + if(scope.onSelectNavigationItem) { + scope.onSelectNavigationItem({"item": item}); + } + } + + scope.closeSplitView = function () { + if (scope.onCloseSplitView) { + scope.onCloseSplitView(); + } + }; + + scope.openInSplitView = function (event, variant) { + if (scope.onOpenInSplitView) { + scope.vm.dropdownOpen = false; + scope.onOpenInSplitView({ "variant": variant }); + } + }; + + /** + * keep track of open variants - this is used to prevent the same variant to be open in more than one split view + * @param {any} culture + */ + scope.variantIsOpen = function(culture) { + if(scope.openVariants.indexOf(culture) !== -1) { + return true; + } + } + + onInit(); + + //watch for the active culture changing, if it changes, update the current variant + if (scope.variants) { + scope.$watch(function () { + for (var i = 0; i < scope.variants.length; i++) { + var v = scope.variants[i]; + if (v.active) { + return v.language.culture; + } + } + return scope.vm.currentVariant.language.culture; //should never get here + }, function (newValue, oldValue) { + if (newValue !== scope.vm.currentVariant.language.culture) { + setCurrentVariant(); + } + }); + } + } + + + var directive = { + transclude: true, + restrict: 'E', + replace: true, + templateUrl: 'views/components/editor/umb-editor-content-header.html', + scope: { + name: "=", + nameLocked: "=", + menu: "=", + hideMenu: " - - + diff --git a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-content-header.html b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-content-header.html new file mode 100644 index 0000000000..bc20745018 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-content-header.html @@ -0,0 +1,83 @@ +
+ +
+ +
+ + + +
+ +
+ +
+
+ + + + + + {{vm.currentVariant.language.name}} +   + + + + {{vm.currentVariant.language.name}} + + + + + + {{variant.language.name}} + + +
Open in split view
+
+
+ +
+ +
{{ name }}
+ +
+ +
+ +
+ + + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html index 5444f55e87..267d805d0a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/editor/umb-editor-header.html @@ -34,7 +34,7 @@ ng-model="name" ng-class="{'name-is-empty': $parent.name===null || $parent.name===''}" umb-auto-focus - val-server-field="{{serverValidationNameField}}" + val-server-field="Name" required autocomplete="off" /> @@ -45,28 +45,9 @@ alias="$parent.alias" alias-from="$parent.name" enable-lock="true" - server-validation-field="{{serverValidationAliasField}}"> + server-validation-field="Alias"> - - {{vm.currentVariant.language.name}} -   - - - - {{vm.currentVariant.language.name}} - - - - - - {{variant.language.name}} - - -
Open in split view
-
-
-
{{ name }}
@@ -85,12 +66,6 @@ -
- - - -
-