Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inherited property group id/key when local properties are added #11231

Merged
merged 3 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,45 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje

array.push(placeholder);

},

rebindSavedContentType: function (contentType, savedContentType) {
// The saved content type might have updated values (eg. new IDs/keys), so make sure the view model is updated
contentType.ModelState = savedContentType.ModelState;
contentType.id = savedContentType.id;
contentType.groups.forEach(function (group) {
if (!group.alias) return;

var k = 0;
while (k < savedContentType.groups.length && savedContentType.groups[k].alias != group.alias)
k++;

if (k == savedContentType.groups.length) {
group.id = 0;
return;
}

var savedGroup = savedContentType.groups[k];
group.id = savedGroup.id;
group.key = savedGroup.key;
group.contentTypeId = savedGroup.contentTypeId;

group.properties.forEach(function (property) {
if (property.id || !property.alias) return;

k = 0;
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
k++;

if (k == savedGroup.properties.length) {
property.id = 0;
return;
}

var savedProperty = savedGroup.properties[k];
property.id = savedProperty.id;
});
});
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

return {

formatChangePasswordModel: function(model) {
formatChangePasswordModel: function (model) {
if (!model) {
return null;
}
Expand All @@ -59,26 +59,23 @@
},

formatContentTypePostData: function (displayModel, action) {

//create the save model from the display model
// Create the save model from the display model
var saveModel = _.pick(displayModel,
'compositeContentTypes', 'isContainer', 'allowAsRoot', 'allowedTemplates', 'allowedContentTypes',
'alias', 'description', 'thumbnail', 'name', 'id', 'icon', 'trashed',
'key', 'parentId', 'alias', 'path', 'allowCultureVariant', 'allowSegmentVariant', 'isElement');

// TODO: Map these
saveModel.allowedTemplates = _.map(displayModel.allowedTemplates, function (t) { return t.alias; });
saveModel.defaultTemplate = displayModel.defaultTemplate ? displayModel.defaultTemplate.alias : null;
var realGroups = _.reject(displayModel.groups, function (g) {
//do not include these tabs
// Do not include groups with init state
return g.tabState === "init";
});
saveModel.groups = _.map(realGroups, function (g) {

var saveGroup = _.pick(g, 'inherited', 'id', 'sortOrder', 'name', 'key', 'alias', 'type');
var saveGroup = _.pick(g, 'id', 'sortOrder', 'name', 'key', 'alias', 'type');

var realProperties = _.reject(g.properties, function (p) {
//do not include these properties
// Do not include properties with init state or inherited from a composition
return p.propertyState === "init" || p.inherited === true;
});

Expand All @@ -89,16 +86,21 @@

saveGroup.properties = saveProperties;

//if this is an inherited group and there are not non-inherited properties on it, then don't send up the data
if (saveGroup.inherited === true && saveProperties.length === 0) {
return null;
if (g.inherited === true) {
if (saveProperties.length === 0) {
// All properties are inherited from the compositions, no need to save this group
return null;
} else if (g.contentTypeId != saveModel.id) {
// We have local properties, but the group id is not local, ensure a new id/key is generated on save
saveGroup = _.omit(saveGroup, 'id', 'key');
}
}

return saveGroup;
});

//we don't want any null groups
saveModel.groups = _.reject(saveModel.groups, function (g) {
// Do not include empty/null groups
return !g;
});

Expand Down Expand Up @@ -127,17 +129,17 @@
},

/** formats the display model used to display the dictionary to the model used to save the dictionary */
formatDictionaryPostData : function(dictionary, nameIsDirty) {
formatDictionaryPostData: function (dictionary, nameIsDirty) {
var saveModel = {
parentId: dictionary.parentId,
id: dictionary.id,
name: dictionary.name,
nameIsDirty: nameIsDirty,
translations: [],
key : dictionary.key
key: dictionary.key
};

for(var i = 0; i < dictionary.translations.length; i++) {
for (var i = 0; i < dictionary.translations.length; i++) {
saveModel.translations.push({
isoCode: dictionary.translations[i].isoCode,
languageId: dictionary.translations[i].languageId,
Expand Down Expand Up @@ -362,7 +364,7 @@
parentId: displayModel.parentId,
//set the action on the save model
action: action,
variants: _.map(displayModel.variants, function(v) {
variants: _.map(displayModel.variants, function (v) {
return {
name: v.name || "", //if its null/empty,we must pass up an empty string else we get json converter errors
properties: getContentProperties(v.tabs),
Expand Down Expand Up @@ -392,7 +394,7 @@
* @param {} displayModel
* @returns {}
*/
formatContentGetData: function(displayModel) {
formatContentGetData: function (displayModel) {

// We need to check for invariant properties among the variant variants,
// as the value of an invariant property is shared between different variants.
Expand Down Expand Up @@ -458,12 +460,12 @@
* Formats the display model used to display the relation type to a model used to save the relation type.
* @param {Object} relationType
*/
formatRelationTypePostData : function(relationType) {
formatRelationTypePostData: function (relationType) {
var saveModel = {
id: relationType.id,
name: relationType.name,
alias: relationType.alias,
key : relationType.key,
key: relationType.key,
isBidirectional: relationType.isBidirectional,
parentObjectType: relationType.parentObjectType,
childObjectType: relationType.childObjectType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,35 +324,9 @@
scope: $scope,
content: vm.contentType,
infiniteMode: infiniteMode,
// we need to rebind... the IDs that have been created!
rebindCallback: function (origContentType, savedContentType) {
vm.contentType.ModelState = savedContentType.ModelState;
vm.contentType.id = savedContentType.id;
vm.contentType.groups.forEach(function (group) {
if (!group.name) return;
var k = 0;
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
k++;
if (k == savedContentType.groups.length) {
group.id = 0;
return;
}
var savedGroup = savedContentType.groups[k];
if (!group.id) group.id = savedGroup.id;

group.properties.forEach(function (property) {
if (property.id || !property.alias) return;
k = 0;
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
k++;
if (k == savedGroup.properties.length) {
property.id = 0;
return;
}
var savedProperty = savedGroup.properties[k];
property.id = savedProperty.id;
});
});
rebindCallback: function (_, savedContentType) {
// we need to rebind... the IDs that have been created!
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
}
}).then(function (data) {
// allow UI to access server validation state
Expand Down
35 changes: 3 additions & 32 deletions src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,38 +295,9 @@
saveMethod: mediaTypeResource.save,
scope: $scope,
content: vm.contentType,
// we need to rebind... the IDs that have been created!
rebindCallback: function (origContentType, savedContentType) {
vm.contentType.id = savedContentType.id;
vm.contentType.groups.forEach(function (group) {
if (!group.name) return;

var k = 0;
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
k++;
if (k == savedContentType.groups.length) {
group.id = 0;
return;
}

var savedGroup = savedContentType.groups[k];
if (!group.id) group.id = savedGroup.id;

group.properties.forEach(function (property) {
if (property.id || !property.alias) return;

k = 0;
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
k++;
if (k == savedGroup.properties.length) {
property.id = 0;
return;
}

var savedProperty = savedGroup.properties[k];
property.id = savedProperty.id;
});
});
rebindCallback: function (_, savedContentType) {
// we need to rebind... the IDs that have been created!
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
}
}).then(function (data) {
//success
Expand Down
43 changes: 7 additions & 36 deletions src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@

//we are creating so get an empty data type item
memberTypeResource.getScaffold(memberTypeId)
.then(function (dt) {
init(dt);
.then(function (dt) {
init(dt);

vm.page.loading = false;
});
vm.page.loading = false;
});
}
else {
loadMemberType();
Expand Down Expand Up @@ -215,38 +215,9 @@
saveMethod: memberTypeResource.save,
scope: $scope,
content: vm.contentType,
// we need to rebind... the IDs that have been created!
rebindCallback: function (origContentType, savedContentType) {
vm.contentType.id = savedContentType.id;
vm.contentType.groups.forEach(function (group) {
if (!group.name) return;

var k = 0;
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
k++;
if (k == savedContentType.groups.length) {
group.id = 0;
return;
}

var savedGroup = savedContentType.groups[k];
if (!group.id) group.id = savedGroup.id;

group.properties.forEach(function (property) {
if (property.id || !property.alias) return;

k = 0;
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
k++;
if (k == savedGroup.properties.length) {
property.id = 0;
return;
}

var savedProperty = savedGroup.properties[k];
property.id = savedProperty.id;
});
});
rebindCallback: function (_, savedContentType) {
// we need to rebind... the IDs that have been created!
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
}
}).then(function (data) {
//success
Expand Down