Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '2.0'
  • Loading branch information
andrerom committed Apr 11, 2018
2 parents 67faa77 + d258339 commit 172db3b
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 79 deletions.
28 changes: 24 additions & 4 deletions Resources/public/js/views/fields/ez-relationlist-editview.js
Expand Up @@ -131,18 +131,38 @@ YUI.add('ez-relationlist-editview', function (Y) {
var relatedContents = this.get('relatedContents'),
relatedContentsJSON = [];

Y.Array.each(relatedContents, function (value) {
relatedContentsJSON.push(value.toJSON());
});
if (relatedContents !== null) {
relatedContentsJSON = relatedContents.reduce(Y.bind(function (total, value) {
var relatedContentJSON = value.toJSON();
if (this._isNewRelation(value) || relatedContentJSON.resources.MainLocation) {
total.push(relatedContentJSON);
}

return total;
}, this), []);
}

return {
relatedContents: relatedContentsJSON,
relatedContents: relatedContentsJSON,
loadingError: this.get('loadingError'),
isLoaded: relatedContents !== null,
isEmpty: this._isFieldEmpty(),
isRequired: this.get('fieldDefinition').isRequired,
};
},

/**
* Check if relation to the content is new (non-existed before edit)
*
* @method _isNewRelation
* @protected
* @param {eZ.ContentInfo|ez.eZ.Content} object
* @return {boolean}
*/
_isNewRelation: function (object) {
return object.name === 'contentInfoModel';
},

/**
* Tap event handler for the remove relation buttons.
* It remove the content related to the button from the relation list.
Expand Down
14 changes: 11 additions & 3 deletions Resources/public/js/views/fields/ez-relationlist-view.js
Expand Up @@ -65,12 +65,20 @@ YUI.add('ez-relationlist-view', function (Y) {
var relatedContents = this.get('relatedContents'),
relatedContentsJSON = [];

Y.Array.each(relatedContents, function (value) {
relatedContentsJSON.push(value.toJSON());
});
if (relatedContents !== null) {
relatedContentsJSON = relatedContents.reduce(Y.bind(function (total, value) {
var relatedContentJSON = value.toJSON();
if (relatedContentJSON.resources.MainLocation) {
total.push(relatedContentJSON);
}

return total;
}, this), []);
}

return {
relatedContents: relatedContentsJSON,
isLoaded: relatedContents !== null,
loadingError: this.get('loadingError'),
};
},
Expand Down
74 changes: 39 additions & 35 deletions Resources/public/templates/fields/edit/relationlist.hbt
Expand Up @@ -19,44 +19,48 @@
{{#if isEmpty}}
<p class="ez-relation-empty">{{translate "relationlist.empty" "fieldedit"}}</p>
{{else}}
{{#if relatedContents }}
<table class="pure-table pure-table-striped ez-relationlist-contents">
<thead>
<tr>
<th>{{translate "relationlist.table.name" "fieldedit"}}</th>
<th>{{translate "relationlist.table.published" "fieldedit"}}</th>
<th>{{translate "relationlist.table.modified" "fieldedit"}}</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each relatedContents}}
<tr class="ez-relation-content" data-content-id="{{id}}">
<td class="ez-relation-content-name" data-icon="&#xe601;" title="{{ name }}">{{ name }}</td>
<td class="ez-relation-property">{{ publishedDate }}</td>
<td class="ez-relation-property">{{ lastModificationDate }}</td>
<td class="ez-relation-remove-content">
<button data-content-id="{{id}}" class=" ez-button ez-button-delete ez-font-icon pure-button" {{#if ../isNotTranslatable}}disabled="disabled"{{/if}}>
{{translate "relationlist.remove" "fieldedit"}}
</button>
</td>
{{#if isLoaded }}
{{#if relatedContents }}
<table class="pure-table pure-table-striped ez-relationlist-contents">
<thead>
<tr>
<th>{{translate "relationlist.table.name" "fieldedit"}}</th>
<th>{{translate "relationlist.table.published" "fieldedit"}}</th>
<th>{{translate "relationlist.table.modified" "fieldedit"}}</th>
<th></th>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
{{#if loadingError}}
<p class="ez-asynchronousview-error ez-font-icon">
{{translate "relationlist.error" "fieldedit"}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">
{{translate "relationlist.retry" "fieldedit"}}
</button>
</p>
</thead>
<tbody>
{{#each relatedContents}}
<tr class="ez-relation-content" data-content-id="{{id}}">
<td class="ez-relation-content-name" data-icon="&#xe601;" title="{{ name }}">{{ name }}</td>
<td class="ez-relation-property">{{ publishedDate }}</td>
<td class="ez-relation-property">{{ lastModificationDate }}</td>
<td class="ez-relation-remove-content">
<button data-content-id="{{id}}" class=" ez-button ez-button-delete ez-font-icon pure-button" {{#if ../isNotTranslatable}}disabled="disabled"{{/if}}>
{{translate "relationlist.remove" "fieldedit"}}
</button>
</td>
</tr>
{{/each}}
</tbody>
</table>
{{else}}
<p class="ez-font-icon ez-asynchronousview-loading">
{{translate "relationlist.loading" "fieldedit"}}
</p>
{{#if loadingError}}
<p class="ez-asynchronousview-error ez-font-icon">
{{translate "relationlist.error" "fieldedit"}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">
{{translate "relationlist.retry" "fieldedit"}}
</button>
</p>
{{else}}
<p class="ez-relation-empty">{{translate "relationlist.empty" "fieldedit"}}</p>
{{/if}}
{{/if}}
{{else}}
<p class="ez-font-icon ez-asynchronousview-loading">
{{translate "relationlist.loading" "fieldedit"}}
</p>
{{/if}}
{{/if}}
<p class="ez-relation-tools">
Expand Down
47 changes: 25 additions & 22 deletions Resources/public/templates/fields/view/relationlist.hbt
Expand Up @@ -3,32 +3,35 @@
<p class="ez-fieldview-name"><strong>{{ translate_property fieldDefinition.names }}</strong></p>
</div>
<div class="ez-fieldview-value pure-u"><div class="ez-fieldview-value-content">
{{#if isEmpty}}
{{#if isEmpty }}
{{translate 'fieldview.field.empty' 'fieldview'}}
{{else}}
{{#if relatedContents }}
<ul>
{{#each relatedContents}}
<li class="ez-relationlistview-item" title="{{ name }}">
<a href="{{path "viewLocation" id=resources.MainLocation languageCode=mainLanguageCode}}">{{ name }}</a>
</li>
{{/each}}
</ul>
{{#if loadingError}}
<div class="ez-asynchronousview-error ez-font-icon">
{{translate 'relationlist.error.loading' 'fieldview'}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">{{translate 'fieldview.retry' 'fieldview'}}</button>
</div>
{{/if}}
{{else}}
{{#if loadingError}}
<div class="ez-asynchronousview-error ez-font-icon">
{{translate 'relationlist.error.loading' 'fieldview'}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">{{translate 'fieldview.retry' 'fieldview'}}</button>
</div>
{{#if isLoaded }}
{{#if relatedContents }}
<ul>
{{#each relatedContents}}
<li class="ez-relationlistview-item" title="{{ name }}">
<a href="{{path "viewLocation" id=resources.MainLocation languageCode=mainLanguageCode}}">{{ name }}</a>
</li>
{{/each}}
</ul>
{{#if loadingError}}
<div class="ez-asynchronousview-error ez-font-icon">
{{translate 'relationlist.error.loading' 'fieldview'}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">{{translate 'fieldview.retry' 'fieldview'}}</button>
</div>
{{/if}}
{{else}}
<div class="ez-font-icon ez-asynchronousview-loading">{{translate 'relationlist.loading' 'fieldview'}}</div>
{{translate 'fieldview.field.empty' 'fieldview'}}
{{#if loadingError}}
<div class="ez-asynchronousview-error ez-font-icon">
{{translate 'relationlist.error.loading' 'fieldview'}}
<button class="ez-asynchronousview-retry ez-button ez-font-icon pure-button">{{translate 'fieldview.retry' 'fieldview'}}</button>
</div>
{{/if}}
{{/if}}
{{ else }}
<div class="ez-font-icon ez-asynchronousview-loading">{{translate 'relationlist.loading' 'fieldview'}}</div>
{{/if}}
{{/if}}
</div></div>
Expand Down
19 changes: 17 additions & 2 deletions Tests/js/views/fields/assets/ez-relation-editview-tests.js
Expand Up @@ -22,7 +22,12 @@ YUI.add('ez-relation-editview-tests', function (Y) {

setUp: function () {
this.destinationContent = new Y.Mock();
this.destinationContentToJSON = {anythingJSONed: 'somethingJSONed'};
this.destinationContentToJSON = {
anythingJSONed: 'somethingJSONed',
resources: {
MainLocation: true
}
};
Y.Mock.expect(this.destinationContent, {
method: 'toJSON',
returns: this.destinationContentToJSON
Expand Down Expand Up @@ -308,9 +313,19 @@ YUI.add('ez-relation-editview-tests', function (Y) {
contentInfoMock = new Y.Mock(),
fakeEventFacade = {selection: {contentInfo: contentInfoMock}};

Y.Mock.expect(contentInfoMock, {
property: 'name',
value: 'contentInfoModel'
});

Y.Mock.expect(contentInfoMock, {
method: 'toJSON',
returns: {name: 'me', publishedDate: 'yesterday', lastModificationDate: 'tomorrow'}
returns: {
name: 'me',
publishedDate: 'yesterday',
lastModificationDate: 'tomorrow',
resources: {}
}
});

Y.Mock.expect(contentInfoMock, {
Expand Down
7 changes: 6 additions & 1 deletion Tests/js/views/fields/assets/ez-relation-view-tests.js
Expand Up @@ -13,7 +13,12 @@ YUI.add('ez-relation-view-tests', function (Y) {

setUp: function () {
this.destinationContent = new Y.Mock();
this.destinationContentToJSON = {anythingJSONed: 'somethingJSONed'};
this.destinationContentToJSON = {
anythingJSONed: 'somethingJSONed',
resources: {
MainLocation: true
}
};
Y.Mock.expect(this.destinationContent, {
method: 'toJSON',
returns: this.destinationContentToJSON
Expand Down
47 changes: 41 additions & 6 deletions Tests/js/views/fields/assets/ez-relationlist-editview-tests.js
Expand Up @@ -44,6 +44,7 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {
this.jsonContentType = {};
this.jsonVersion = {};
this.loadingError = false;
this.isLoaded = true;
this.content = new Y.Mock();
this.version = new Y.Mock();
this.contentType = new Y.Mock();
Expand Down Expand Up @@ -86,7 +87,7 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {

this.view.template = function (variables) {
Y.Assert.isObject(variables, "The template should receive some variables");
Y.Assert.areEqual(10, Y.Object.keys(variables).length, "The template should receive 10 variables");
Y.Assert.areEqual(11, Y.Object.keys(variables).length, "The template should receive 11 variables");
Y.Assert.areSame(
that.jsonContent, variables.content,
"The content should be available in the field edit view template"
Expand All @@ -113,7 +114,11 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {
);
Y.Assert.areSame(
that.view.get('loadingError'), variables.loadingError,
"The field should be available in the field edit view template"
"The loadingError be available in the field edit view template"
);
Y.Assert.areSame(
that.isLoaded, variables.isLoaded,
"The isLoaded should be available in the field edit view template"
);
Y.Array.each(that.view.get('relatedContents'), function (destContent) {
destContentToJSONArray.push(destContent.toJSON());
Expand Down Expand Up @@ -350,7 +355,12 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {
contentIdsArray = Y.Array.dedupe(that.view.get('destinationContentsIds'));
Y.Mock.expect(contentInfoMock1, {
method: 'toJSON',
returns: {name: 'me', publishedDate: 'yesterday', lastModificationDate: 'tomorrow'}
returns: {
name: 'me',
publishedDate: 'yesterday',
lastModificationDate: 'tomorrow',
resources: {}
}
});

Y.Mock.expect(contentInfoMock1, {
Expand All @@ -359,9 +369,24 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {
returns: 42
});

Y.Mock.expect(contentInfoMock1, {
property: 'name',
value: 'contentInfoModel'
});

Y.Mock.expect(contentInfoMock2, {
method: 'toJSON',
returns: {name: 'me', publishedDate: 'yesterday', lastModificationDate: 'tomorrow'}
returns: {
name: 'me',
publishedDate: 'yesterday',
lastModificationDate: 'tomorrow',
resources: {}
}
});

Y.Mock.expect(contentInfoMock2, {
property: 'name',
value: 'contentInfoModel'
});

Y.Mock.expect(contentInfoMock2, {
Expand Down Expand Up @@ -463,7 +488,12 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {

setUp: function () {
this.destinationContent1 = new Y.Mock();
this.destinationContent1ToJSON = {anythingJSONed: 'somethingJSONed'};
this.destinationContent1ToJSON = {
anythingJSONed: 'somethingJSONed',
resources: {
MainLocation: true
}
};

Y.Mock.expect(this.destinationContent1, {
method: 'toJSON',
Expand All @@ -483,7 +513,12 @@ YUI.add('ez-relationlist-editview-tests', function (Y) {
}
});
this.destinationContent2 = new Y.Mock();
this.destinationContent2ToJSON = {anythingJSONed2: 'somethingJSONed2'};
this.destinationContent2ToJSON = {
anythingJSONed2: 'somethingJSONed2',
resources: {
MainLocation: true
}
};

Y.Mock.expect(this.destinationContent2, {
method: 'toJSON',
Expand Down

0 comments on commit 172db3b

Please sign in to comment.