Fixes how the content app view model works so dirty tracking continues to work properly, previously we tried to omit the apps so we didn' thave a circualar model reference but that doesn't work because that clones the object, so now the view model is just the variant index which works much better.Fixes other js probs

This commit is contained in:
Shannon
2018-10-26 15:07:21 +11:00
parent e280226abc
commit 02221f6dd0
6 changed files with 31 additions and 27 deletions

View File

@@ -194,7 +194,9 @@
return a.alias === "umbContent";
});
contentApp.viewModel = _.omit(variant, 'apps');
//The view model for the content app is simply the index of the variant being edited
var variantIndex = vm.content.variants.indexOf(variant);
contentApp.viewModel = variantIndex;
// make sure the same app it set to active in the new variant
if(activeAppAlias) {

View File

@@ -376,7 +376,7 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
var foundIndex = 0;
if ($scope.model.selection.length > 0) {
for (i = 0; $scope.model.selection.length > i; i++) {
for (var i = 0; $scope.model.selection.length > i; i++) {
var selectedItem = $scope.model.selection[i];
if (selectedItem.id === item.id) {
found = true;

View File

@@ -285,7 +285,7 @@ angular.module("umbraco").controller("Umbraco.Overlays.TreePickerController",
var foundIndex = 0;
if ($scope.model.selection.length > 0) {
for (i = 0; $scope.model.selection.length > i; i++) {
for (var i = 0; $scope.model.selection.length > i; i++) {
var selectedItem = $scope.model.selection[i];
if (selectedItem.id === item.id) {
found = true;

View File

@@ -3,33 +3,39 @@
function ContentAppContentController($scope, $timeout, serverValidationManager) {
//the contentApp's viewModel is actually the index of the variant being edited, not the variant itself.
//if we make the viewModel the variant itself, we end up with a circular reference in the models which isn't ideal
// (i.e. variant.apps[contentApp].viewModel = variant)
//so instead since we already have access to the content, we can just get the variant directly by the index.
var vm = this;
vm.loading = true;
function onInit() {
vm.content = $scope.model.viewModel;
//get the variant by index (see notes above)
vm.content = $scope.content.variants[$scope.model.viewModel];
serverValidationManager.notify();
vm.loading = false;
//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 (vm.content.language) {
$scope.$watch(function () {
return vm.content.language.culture;
}, function (newVal, oldVal) {
if (newVal !== oldVal) {
vm.loading = true;
//TODO: Can we minimize the flicker?
$timeout(function () {
onInit();
}, 100);
}
});
}
}
onInit();
//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.model.viewModel.language) {
$scope.$watch(function () {
return $scope.model.viewModel.language.culture;
}, function (newVal, oldVal) {
if (newVal !== oldVal) {
vm.loading = true;
//TODO: Can we minimize the flicker?
$timeout(function () {
onInit();
}, 100);
}
});
}
}
angular.module("umbraco").controller("Umbraco.Editors.Content.Apps.ContentController", ContentAppContentController);

View File

@@ -22,12 +22,8 @@
//determine a variant is 'dirty' (meaning it will show up as save-able) if it's
// * the active one
// * it's editor is in a $dirty state
// * it's umbContent app viewModel (if any) is in a $dirty state
// * it is in NotCreated state
var contentApp = _.find(variant.apps, function(app) {
return app.alias === "umbContent";
});
return (variant.active || variant.isDirty || (contentApp && contentApp.viewModel && contentApp.viewModel.isDirty));
return (variant.active || variant.isDirty);
}
function pristineVariantFilter(variant) {

View File

@@ -19,7 +19,7 @@
<umb-editor-container>
<div class="umb-editor-sub-views" ng-if="!page.loading">
<div id="sub-view-{{$index}}" ng-repeat="app in content.apps track by app.alias">
<umb-editor-sub-view model="app" content="content" />
<umb-editor-sub-view model="app" content="content" />
</div>
</div>
</umb-editor-container>