Compare commits

...

4 Commits

Author SHA1 Message Date
Mads Rasmussen bca29975dd get the create date from the variant 2018-08-10 13:31:14 +02:00
Mads Rasmussen be8bd3d443 emit event on variant change + update the publish state on the info tab 2018-08-10 13:07:37 +02:00
Shannon 6a7b6f7267 Merge branch 'temp8' of https://github.com/umbraco/Umbraco-CMS into temp8 2018-08-09 19:38:36 +10:00
Shannon f738e6d7c7 Fixes js tests 2018-08-09 19:38:20 +10:00
10 changed files with 136 additions and 80 deletions
+5 -5
View File
@@ -955,12 +955,12 @@
"dependencies": {
"extend-shallow": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz",
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
"dev": true,
"requires": {
"is-extendable": "0.1.1"
},
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz"
"is-extendable": "^0.1.0"
}
}
}
},
@@ -1670,9 +1670,9 @@
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha1-dHIq8y6WFOnCh6jQu95IteLxomM=",
"dev": true,
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz"
"dev": true
}
}
},
@@ -158,6 +158,10 @@
});
contentApp.viewModel = variant;
// emit variant change event so content apps can update content
var args = { "node": $scope.content, "variant": variant };
eventsService.emit("editors.content.changeVariant", args);
return variant;
}
@@ -6,7 +6,7 @@
function link(scope, element, attrs, ctrl) {
var evts = [];
var isInfoTab = false;
var isInfoApp = false;
var labels = {};
scope.publishStatus = [];
@@ -16,6 +16,11 @@
function onInit() {
//get the current variant
scope.activeVariant = _.find(scope.node.variants, function (variant) {
return variant.active;
});
userService.getCurrentUser().then(function(user){
// only allow change of media type if user has access to the settings sections
angular.forEach(user.sections, function(section){
@@ -42,7 +47,7 @@
labels.publishedPendingChanges = data[3];
labels.notCreated = data[4];
setNodePublishStatus(scope.node);
setPublishState(scope.node, scope.activeVariant);
});
@@ -172,49 +177,40 @@
});
}
function setNodePublishStatus(node) {
function setPublishState(node, variant) {
// deleted node
if (node.trashed === true) {
scope.publishStatus.push({
label: labels.deleted,
color: "danger"
});
var state = {};
if (node.trashed) {
// deleted node
state.label = labels.deleted;
state.color = "danger";
return;
}
if (node.variants) {
for (var i = 0; i < node.variants.length; i++) {
var variant = node.variants[i];
var status = {
culture: variant.language ? variant.language.culture : null
};
if (variant.state === "NotCreated") {
status.label = labels.notCreated;
status.color = "gray";
}
else if (variant.state === "Draft") {
// draft node
status.label = labels.unpublished;
status.color = "gray";
}
else if (variant.state === "Published") {
// published node
status.label = labels.published;
status.color = "success";
}
else if (variant.state === "PublishedPendingChanges") {
// published node with pending changes
status.label = labels.publishedPendingChanges;
status.color = "success";
}
scope.publishStatus.push(status);
}
if (variant.state === "NotCreated") {
// not created variant
state.label = labels.notCreated;
state.color = "gray";
}
else if (variant.state === "Draft") {
// draft variant
state.label = labels.unpublished;
state.color = "gray";
}
else if (variant.state === "Published") {
// published variant
state.label = labels.published;
state.color = "success";
}
else if (variant.state === "PublishedPendingChanges") {
// published variant with pending changes
state.label = labels.publishedPendingChanges;
state.color = "success";
}
scope.variantState = state;
}
function setPublishDate(date) {
@@ -292,7 +288,7 @@
function formatDatesToLocal() {
// get current backoffice user and format dates
userService.getCurrentUser().then(function (currentUser) {
scope.node.createDateFormatted = dateHelper.getLocalDate(scope.node.createDate, currentUser.locale, 'LLL');
scope.activeVariant.createDateFormatted = dateHelper.getLocalDate(scope.activeVariant.createDate, currentUser.locale, 'LLL');
scope.node.releaseDateYear = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'YYYY')) : null;
scope.node.releaseDateMonth = scope.node.releaseDate ? ucfirst(dateHelper.getLocalDate(scope.node.releaseDate, currentUser.locale, 'MMMM')) : null;
@@ -312,24 +308,30 @@
evts.push(eventsService.on("app.tabChange", function (event, args) {
$timeout(function(){
if (args.alias === "info") {
isInfoTab = true;
isInfoApp = true;
loadAuditTrail();
} else {
isInfoTab = false;
isInfoApp = false;
}
});
}));
// listen for variant change so we can update the content
evts.push(eventsService.on("editors.content.changeVariant", function (event, args) {
setPublishState(args.node, args.variant);
formatDatesToLocal();
}));
// watch for content updates - reload content when node is saved, published etc.
scope.$watch('node.updateDate', function(newValue, oldValue){
if(!newValue) { return; }
if(newValue === oldValue) { return; }
if(newValue === oldValue) { return; }
if(isInfoTab) {
loadAuditTrail();
formatDatesToLocal();
setNodePublishStatus(scope.node);
setPublishState(scope.node);
}
});
@@ -519,25 +519,32 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, notifica
var allNewProps = this.getAllProps(savedVariant);
//check for changed properties of the content
for (var p in allOrigProps) {
var alias = allOrigProps[p].alias;
for (var k = 0; k < allOrigProps.length; k++) {
var origProp = allOrigProps[k];
var alias = origProp.alias;
var newProp = getNewProp(alias, allNewProps);
if (newProp && !_.isEqual(alias, newProp.value)) {
if (newProp && !_.isEqual(origProp.value, newProp.value)) {
//they have changed so set the origContent prop to the new one
var origVal = allOrigProps[p].value;
allOrigProps[p].value = newProp.value;
var origVal = origProp.value;
origProp.value = newProp.value;
//instead of having a property editor $watch their expression to check if it has
// been updated, instead we'll check for the existence of a special method on their model
// and just call it.
if (angular.isFunction(allOrigProps[p].onValueChanged)) {
if (angular.isFunction(origProp.onValueChanged)) {
//send the newVal + oldVal
allOrigProps[p].onValueChanged(allOrigProps[p].value, origVal);
origProp.onValueChanged(origProp.value, origVal);
}
changed.push(allOrigProps[p]);
changed.push(origProp);
}
}
for (var p in allOrigProps) {
}
}
@@ -159,10 +159,18 @@ function formHelper(angularHelper, serverValidationManager, $timeout, notificati
//Check if this is for content properties - specific to content/media/member editors because those are special
// user defined properties with custom controls.
if (parts.length > 2 && parts[0] === "_Properties") {
if (parts.length > 1 && parts[0] === "_Properties") {
var propertyAlias = parts[1];
var culture = parts[2];
var culture = null;
if (parts.length > 2) {
culture = parts[2];
//special check in case the string is formatted this way
if (culture === "null") {
culture = null;
}
}
//if it contains 3 '.' then we will wire it up to a property's html field
if (parts.length > 3) {
@@ -140,8 +140,9 @@ function serverValidationManager($timeout) {
}
}
else if (propertyAlias !== undefined) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//don't add it if it already exists
var exists2 = _.find(callbacks, function (item) {
@@ -165,8 +166,9 @@ function serverValidationManager($timeout) {
}
else if (propertyAlias !== undefined) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//remove all callbacks for the content property
@@ -192,8 +194,9 @@ function serverValidationManager($timeout) {
*/
getPropertyCallbacks: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
var found = _.filter(callbacks, function (item) {
@@ -268,8 +271,9 @@ function serverValidationManager($timeout) {
return;
}
//normalize culture to null
if (!culture) {
culture = null; // if empty or null, always make null
culture = null;
}
//only add the item if it doesn't exist
@@ -306,6 +310,12 @@ function serverValidationManager($timeout) {
if (!propertyAlias) {
return;
}
//normalize culture to null
if (!culture) {
culture = null;
}
//remove the item
this.items = _.reject(this.items, function (item) {
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -354,6 +364,12 @@ function serverValidationManager($timeout) {
* Gets the error message for the content property
*/
getPropertyError: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null;
}
var err = _.find(this.items, function (item) {
//return true if the property alias matches and if an empty field name is specified or the field name matches
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -388,6 +404,12 @@ function serverValidationManager($timeout) {
* Checks if the content property + culture + field name combo has an error
*/
hasPropertyError: function (propertyAlias, culture, fieldName) {
//normalize culture to null
if (!culture) {
culture = null;
}
var err = _.find(this.items, function (item) {
//return true if the property alias matches and if an empty field name is specified or the field name matches
return (item.propertyAlias === propertyAlias && item.culture === culture && (item.fieldName === fieldName || (fieldName === undefined || fieldName === "")));
@@ -435,4 +435,4 @@ angular.module("umbraco")
onInit();
});
});
@@ -169,16 +169,11 @@
<umb-box-content class="block-form">
<umb-control-group data-element="node-info-status" label="@general_status">
<div ng-repeat="status in publishStatus" style="margin-bottom: 5px;">
<span ng-if="status.culture"><em>{{status.culture}}: </em></span>
<umb-badge size="xs" color="{{status.color}}">
{{status.label}}
</umb-badge>
</div>
<umb-badge size="xs" color="{{variantState.color}}">{{variantState.label}}</umb-badge>
</umb-control-group>
<umb-control-group data-element="node-info-create-date" label="@template_createdDate">
{{node.createDateFormatted}} <localize key="general_by">by</localize> {{ node.owner.name }}
{{activeVariant.createDateFormatted}} <localize key="general_by">by</localize> {{ node.owner.name }}
</umb-control-group>
<umb-control-group data-element="node-info-document-type" label="@content_documentType">
@@ -123,7 +123,8 @@ describe('contentEditingHelper tests', function () {
var allProps = contentEditingHelper.getAllProps(content);
//act
formHelper.handleServerValidation({ "_Properties.bodyText.value": ["Required"] });
//note the null, that's because culture is null
formHelper.handleServerValidation({ "_Properties.bodyText.null.value": ["Required"] });
//assert
expect(serverValidationManager.items.length).toBe(1);
@@ -143,7 +144,8 @@ describe('contentEditingHelper tests', function () {
{
"Name": ["Required"],
"UpdateDate": ["Invalid date"],
"_Properties.bodyText.value": ["Required field"],
//note the null, that's because culture is null
"_Properties.bodyText.null.value": ["Required field"],
"_Properties.textarea": ["Invalid format"]
});
@@ -226,6 +228,7 @@ describe('contentEditingHelper tests', function () {
//act
var changed = contentEditingHelper.reBindChangedProperties(origContent, newContent);
//assert
expect(changed.length).toBe(2);
expect(changed[0].alias).toBe("grid");
@@ -10,24 +10,39 @@ describe('file manager tests', function () {
describe('file management', function () {
it('adding a file adds to the collection', function () {
fileManager.setFiles('testProp', ["testFile"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
expect(fileManager.getFiles().length).toBe(1);
});
it('adding a file with the same property id replaces the existing one', function () {
fileManager.setFiles('testProp', ["testFile"]);
fileManager.setFiles('testProp', ["testFile2"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile2"]
});
expect(fileManager.getFiles().length).toBe(1);
expect(fileManager.getFiles()[0].file).toBe("testFile2");
});
it('clears all files', function () {
fileManager.setFiles('testProp1', ["testFile"]);
fileManager.setFiles('testProp2', ["testFile"]);
fileManager.setFiles({
propertyAlias: 'testProp',
files: ["testFile"]
});
fileManager.setFiles({
propertyAlias: 'testProp2',
files: ["testFile"]
});
expect(fileManager.getFiles().length).toBe(2);
fileManager.clearFiles();
expect(fileManager.getFiles().length).toBe(0);
});
});
});
});