Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

[WIP] EZP-27869: Allow to restore a translation from the Version tab #903

Open
wants to merge 4 commits into
base: feature/EZP-25684_Improve_Version_Mngt_Multilingual_Content
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions Resources/public/js/models/ez-versioninfomodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ YUI.add('ez-versioninfomodel', function (Y) {
* @extends eZ.RestModel
*/
Y.eZ.VersionInfo = Y.Base.create('versionInfoModel', Y.eZ.RestModel, [], {


/**
* sync implementation for the VersionInfo. For now, it supports deleting it.
*
Expand Down Expand Up @@ -202,6 +200,23 @@ YUI.add('ez-versioninfomodel', function (Y) {
value: ""
},

/**
* The language code list.
*
* @readOnly
* @attribute languageCodeList
* @type Array
*/
languageCodeList: {
readOnly: true,
getter: function () {
if ( this.get('languageCodes') ) {
return this.get('languageCodes').split(',');
}
return [];
}
},

/**
* The initial language code
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ YUI.add('ez-versionsplugin', function (Y) {
this.onHostEvent('*:createDraft', this._createDraftFromArchivedVersion);
this.onHostEvent('*:deleteVersion', this._confirmDeleteVersion);
this.onHostEvent('*:editVersion', this._redirectToEditVersion);
this.onHostEvent('*:restoreVersionInLanguage', this._restoreVersionInLanguage);
},

_restoreVersionInLanguage: function (e) {
console.log('No API yet to do that', e);
},

/**
Expand Down
21 changes: 21 additions & 0 deletions Resources/public/js/views/tabs/ez-locationviewversionstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ YUI.add('ez-locationviewversionstabview', function (Y) {
'.ez-draft-version-checkbox': {
'change': '_setDraftButtonsState'
},
'.ez-version-in-language-restore': {
'tap': '_restoreVersionInLanguage',
}
};

/**
Expand Down Expand Up @@ -96,6 +99,24 @@ YUI.add('ez-locationviewversionstabview', function (Y) {
return versionsToDisplay;
},

/**
* Tap event handler to restore a version in a given language.
*
* @method _restoreVersionInLanguage
* @protected
* @param {EventFacade} e
*/
_restoreVersionInLanguage: function (e) {
var versionNo = e.target.getAttribute('data-version'),
languageCode = e.target.getAttribute('data-version-language-code');

this.fire('restoreVersionInLanguage', {
content: this.get('content'),
versionNo: versionNo,
languageCode: languageCode,
});
},

/**
* Fire the `loadVersions` event to retrieve the versions
*
Expand Down
6 changes: 5 additions & 1 deletion Resources/public/templates/tabs/versions.hbt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@
{{ formatTime modificationDate day="numeric" month="short" year="numeric" hour="2-digit" minute="2-digit" }}
</td>
<td>
{{languageCodes}}
<ul class="ez-version-language-list">
{{#each languageCodeList}}
<li>{{.}} (<a href="#" class="ez-version-in-language-restore" data-version="{{ ../versionNo }}" data-version-language-code="{{ . }}">{{ translate 'locationview.versions.restore' 'locationview' }}</a>)</li>
{{/each}}
</ul>
</td>
</tr>
{{/each}}
Expand Down
8 changes: 7 additions & 1 deletion Resources/translations/locationview.en.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2017-03-09T16:35:22Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2017-09-18T15:09:42Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
Expand Down Expand Up @@ -518,6 +518,12 @@
<note>key: locationview.versions.remove.selected.archived.version</note>
<jms:reference-file>Resources/public/templates/tabs/versions.hbt</jms:reference-file>
</trans-unit>
<trans-unit id="375d6b33f75515f798fc72ae01d58a73dbb8bd15" resname="locationview.versions.restore">
<source>restore</source>
<target>restore</target>
<note>key: locationview.versions.restore</note>
<jms:reference-file>Resources/public/templates/tabs/versions.hbt</jms:reference-file>
</trans-unit>
<trans-unit id="199990450f06a84725d61f91a899166d0d3305c4" resname="locationview.versions.version">
<source>Version</source>
<target>Version</target>
Expand Down
51 changes: 49 additions & 2 deletions Tests/js/models/assets/ez-versioninfomodel-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-versioninfomodel-tests', function (Y) {
var loadFromHashTest, removeTest,
var loadFromHashTest, removeTest, languageCodeListTest,
Assert = Y.Assert;

loadFromHashTest = new Y.Test.Case({
Expand Down Expand Up @@ -244,8 +244,55 @@ YUI.add('ez-versioninfomodel-tests', function (Y) {
},
});

languageCodeListTest = new Y.Test.Case({
name: "eZ Version Model languageCodeList attribute tests",

setUp: function () {
this.version = new Y.eZ.VersionInfo();
},

tearDown: function () {
this.version.destroy();
delete this.version;
},

"Should return the languages as an array": function () {
var languages = ['fre-FR', 'eng-GB'],
list;

this.version.set('languageCodes', languages.join(','));
list = this.version.get('languageCodeList');

Assert.isArray(
list,
"The list should be an array"
);
Assert.areEqual(
languages.length, list.length,
"The list should contain the language codes"
);
Y.Array.each(list, function (lang, i) {
Assert.areEqual(languages[i], lang);
});
},

"Should return an empty array": function () {
var list = this.version.get('languageCodeList');

Assert.isArray(
list,
"The list should be an array"
);
Assert.areEqual(
0, list.length,
"The list should be an empty array"
);
},

});

Y.Test.Runner.setName("eZ Version Info Model tests");
Y.Test.Runner.add(loadFromHashTest);
Y.Test.Runner.add(removeTest);

Y.Test.Runner.add(languageCodeListTest);
}, '', {requires: ['test', 'json', 'model-tests', 'ez-versioninfomodel', 'ez-restmodel']});
41 changes: 41 additions & 0 deletions Tests/js/views/tabs/assets/ez-locationviewversionstabview-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) {
fireEditVersionEventTest,
selectArchivedVersionTest,
selectDeleteDraftVersionTest,
restoreVersionInLanguageTest,
Assert = Y.Assert,
Mock = Y.Mock,
createCheckableVersionMock = function (versionId, versionNo, checked) {
Expand Down Expand Up @@ -759,6 +760,45 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) {
},
});

restoreVersionInLanguageTest = new Y.Test.Case({
name: "ViewVersionsTabView restore version in language test",
setUp: function () {
this.contentMock = new Mock();

this.view = new Y.eZ.LocationViewVersionsTabView({
content: {},
container: '.container',
});
this.view.render();
},

tearDown: function () {
this.view.destroy();
delete this.view;
},

"Should fire the `restoreVersionInLanguage` event": function () {
var link = this.view.get('container').one('.ez-version-in-language-restore');

this.view.on('restoreVersionInLanguage', this.next(function (e) {
Assert.areSame(
this.view.get('content'), e.content,
"The content should be provided"
);
Assert.areEqual(
link.getAttribute('data-version'), e.versionNo,
"The version number should be provided"
);
Assert.areEqual(
link.getAttribute('data-version-language-code'), e.languageCode,
"The language code should be provided"
);
}, this));
link.simulateGesture('tap');
this.wait();
},
});

Y.Test.Runner.setName("eZ Location View Versions Tab View tests");
Y.Test.Runner.add(attributesTest);
Y.Test.Runner.add(renderTest);
Expand All @@ -768,4 +808,5 @@ YUI.add('ez-locationviewversionstabview-tests', function (Y) {
Y.Test.Runner.add(selectDeleteDraftVersionTest);
Y.Test.Runner.add(fireDeleteVersionEventTest);
Y.Test.Runner.add(fireEditVersionEventTest);
Y.Test.Runner.add(restoreVersionInLanguageTest);
}, '', {requires: ['test', 'ez-locationviewversionstabview', 'node-event-simulate']});
1 change: 1 addition & 0 deletions Tests/js/views/tabs/ez-locationviewversionstabview.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
{{/each}}
</div>

<a href="#" class="ez-version-in-language-restore" data-version="42" data-version-language-code="fre-FR">restore</a>
</script>

<script type="text/javascript" src="../../../../Resources/public/vendors/yui3/build/yui/yui.js"></script>
Expand Down