From 7cc300f59c4e6bf0b3715e4bde65d142c2b93f94 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 16 Jul 2018 18:40:47 +1000 Subject: [PATCH] Gets all of the content for both variant and invariant content loading in the editor and for split views too --- src/Umbraco.Web.UI.Client/bower.json | 2 +- .../components/content/edit.controller.js | 58 +++++++++++++- .../editor/umbeditorheader.directive.js | 11 ++- .../validation/valformmanager.directive.js | 40 ++++++---- .../src/common/services/navigation.service.js | 77 +++++++++++++++++++ src/Umbraco.Web.UI.Client/src/init.js | 30 +------- .../src/views/components/content/edit.html | 5 +- .../apps/content/content.controller.js | 26 ++++--- 8 files changed, 183 insertions(+), 66 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/bower.json b/src/Umbraco.Web.UI.Client/bower.json index 71b393ae9c..1734172820 100644 --- a/src/Umbraco.Web.UI.Client/bower.json +++ b/src/Umbraco.Web.UI.Client/bower.json @@ -25,7 +25,7 @@ "angular-i18n": "~1.7.2", "signalr": "^2.2.1", "typeahead.js": "~0.10.5", - "underscore": "~1.7.0", + "underscore": "~1.9.1", "rgrove-lazyload": "*", "bootstrap-social": "~4.8.0", "jquery": "2.2.4", 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 2900d22540..76274a4901 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 @@ -69,7 +69,7 @@ // set the active variant var activeVariant = null; _.each($scope.content.variants, function (v) { - if (v.language.culture === $scope.culture) { + if (v.language && v.language.culture === $scope.culture) { v.active = true; activeVariant = v; } @@ -102,17 +102,36 @@ function initVariant(variant) { //The model that is assigned to the editor contains the current content variant along //with a copy of the contentApps. This is required because each editor renders it's own - //content apps section and the content apps contains the view for editing content itself + //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. This is a bit hacky but it's required because the content //app stuff isn't built to have a scoped model to an editor, it's built to have a single global //model but that doesn't work for having split view. + //copy the apps from the main model if not assigned yet to the variant if (!variant.apps) { - //copy from the main model variant.apps = angular.copy($scope.content.apps); } + //if this is a variant has a culture/language than we need to assign the language drop down info + if (variant.language) { + //if the variant list that defines the header drop down isn't assigned to the variant then assign it now + if (!variant.variants) { + variant.variants = _.map($scope.content.variants, function (v) { + return _.pick(v, "active", "language", "validationError", "isEdited", "state"); + }); + } + //ensure the current culture is set as the active one + for (var i = 0; i < variant.variants.length; i++) { + if (variant.variants[i].language.culture === variant.language.culture) { + variant.variants[i].active = true; + } + else { + variant.variants[i].active = false; + } + } + } + //the assign the variant to a view model to the content app var contentApp = _.find(variant.apps, function (a) { return a.alias === "content"; @@ -508,6 +527,30 @@ }); }; + $scope.selectVariant = function (editorIndex, variantDropDownItem) { + + //if the editor index is zero, then update the query string to track the lang selection, otherwise if it's part + //of a 2nd split view editor then update the model directly. + if (editorIndex === 0) { + //if we've made it this far, then update the query string + $location.search("cculture", variantDropDownItem.language.culture); + } + else { + //set all variant drop down items as inactive for this editor and then set the selected on as active + var editor = $scope.editors[editorIndex]; + for (var i = 0; i < editor.content.variants.length; i++) { + editor.content.variants[i].active = false; + } + variantDropDownItem.active = true; + + //get the variant content model and initialize the editor with that + var variant = _.find($scope.content.variants, function (v) { + return v.language.culture === variantDropDownItem.language.culture; + }); + editor.content = initVariant(variant); + } + }; + $scope.closeSplitView = function (index, editor) { //TODO: hacking animation states - these should hopefully be easier to do when we upgrade angular editor.loading = true; @@ -519,6 +562,8 @@ $scope.openInSplitView = function (selectedVariant) { + var selectedCulture = selectedVariant.language.culture; + //only the content app can be selected since no other apps are shown, and because we copy all of these apps //to the "editors" we need to update this across all editors for (var e = 0; e < $scope.editors.length; e++) { @@ -534,8 +579,13 @@ } } + //Find the whole variant model based on the culture that was chosen + var variant = _.find($scope.content.variants, function (v) { + return v.language.culture === selectedCulture; + }); + var editor = { - content: initVariant(selectedVariant) + content: initVariant(variant) }; $scope.editors.push(editor); 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 3e318982f1..9275917578 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 @@ -204,7 +204,7 @@ Use this directive to construct a header inside the main editor window. (function () { 'use strict'; - function EditorHeaderDirective(iconHelper, $location, editorService) { + function EditorHeaderDirective(iconHelper, editorService) { function link(scope, el, attr, ctrl) { @@ -231,8 +231,10 @@ Use this directive to construct a header inside the main editor window. }; scope.selectVariant = function (event, variant) { - scope.vm.dropdownOpen = false; - $location.search("cculture", variant.language.culture); + if (scope.onSelectVariant) { + scope.vm.dropdownOpen = false; + scope.onSelectVariant({ "variant": variant }); + } }; scope.openIconPicker = function () { @@ -318,7 +320,8 @@ Use this directive to construct a header inside the main editor window. showBackButton: " 1" on-open-in-split-view="openInSplitView(variant)" - on-close-split-view="closeSplitView($index, editor)"> + on-close-split-view="closeSplitView($index, editor)" + on-select-variant="selectVariant($index, variant)"> diff --git a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js index e50af0bfb4..7c4ed5aaa4 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/apps/content/content.controller.js @@ -27,18 +27,22 @@ onInit(); - $scope.$watch(function () { - return $scope.subView.viewModel.language.culture; - }, function (newVal, oldVal) { - if (newVal !== oldVal) { - vm.loading = true; + //if this variant has a culture/language assigned, then we need to watch it since it will change + //if the language drop down changes and we need to re-init + if ($scope.subView.viewModel.language) { + $scope.$watch(function () { + return $scope.subView.viewModel.language.culture; + }, function (newVal, oldVal) { + if (newVal !== oldVal) { + vm.loading = true; - //TODO: Can we minimize the flicker? - $timeout(function () { - onInit(); - }, 100); - } - }); + //TODO: Can we minimize the flicker? + $timeout(function () { + onInit(); + }, 100); + } + }); + } } angular.module("umbraco").controller("Umbraco.Editors.Content.Apps.ContentController", ContentAppContentController);