Skip to content

Commit

Permalink
[IMP] cmis_web:document: add version history
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-halleux committed Sep 29, 2022
1 parent 1fff5de commit f419a18
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 4 deletions.
33 changes: 30 additions & 3 deletions cmis_web/i18n/cmis_web.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-10 07:19+0000\n"
"PO-Revision-Date: 2022-06-10 07:19+0000\n"
"POT-Creation-Date: 2022-09-29 09:27+0000\n"
"PO-Revision-Date: 2022-09-29 09:27+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -51,6 +51,13 @@ msgstr ""
msgid "A document with the same name already exists."
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Actions"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
Expand Down Expand Up @@ -148,6 +155,7 @@ msgstr ""
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#: code:addons/cmis_web/static/src/xml/document_viewer.xml:0
#, python-format
msgid "Close"
Expand Down Expand Up @@ -291,12 +299,20 @@ msgstr ""
msgid "Description"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#, python-format
msgid "Document history"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/document_viewer.xml:0
#: code:addons/cmis_web/static/src/xml/document_viewer.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Download"
msgstr ""
Expand Down Expand Up @@ -326,6 +342,7 @@ msgstr ""
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Import new version"
msgstr ""
Expand Down Expand Up @@ -436,6 +453,7 @@ msgstr ""
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Name"
msgstr ""
Expand Down Expand Up @@ -518,6 +536,8 @@ msgstr ""
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Preview"
msgstr ""
Expand Down Expand Up @@ -609,6 +629,13 @@ msgstr ""
msgid "Show _MENU_ entries"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Show document history"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
Expand All @@ -635,7 +662,6 @@ msgstr ""
#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Update"
msgstr ""
Expand All @@ -657,6 +683,7 @@ msgstr ""
#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Version"
msgstr ""
Expand Down
22 changes: 21 additions & 1 deletion cmis_web/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-06-10 07:19+0000\n"
"POT-Creation-Date: 2022-09-29 09:27+0000\n"
"PO-Revision-Date: 2019-04-25 16:05+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -51,6 +51,12 @@ msgstr ": activer pour trier la colonne par ordre décroissant"
msgid "A document with the same name already exists."
msgstr "Un document avec le même nom existe déjà."

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
msgid "Actions"
msgstr ""

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
Expand Down Expand Up @@ -277,6 +283,13 @@ msgstr "Supprimer"
msgid "Description"
msgstr "Description"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
#, python-format
msgid "Document history"
msgstr "Historique du document"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/document_viewer.xml:0
Expand Down Expand Up @@ -583,6 +596,13 @@ msgstr "Recherche:"
msgid "Show _MENU_ entries"
msgstr "Afficher _MENU_ éléments"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0
#, python-format
msgid "Show document history"
msgstr "Historique du document"

#. module: cmis_web
#. openerp-web
#: code:addons/cmis_web/static/src/js/form_widgets.js:0
Expand Down
88 changes: 88 additions & 0 deletions cmis_web/static/src/js/form_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,75 @@ odoo.define('cmis_web.form_widgets', function (require) {
},
});

var CmisVersionsHistoryDialog = Dialog.extend({
template: 'CmisVersionsHistoryDialog',
events: {
'change .btn-file :file': 'on_file_change'
},

init: function (parent, versions) {
var self = this;
this.versions = versions;
var options = {
buttons: [
{
text: _t("Close"),
click: function (e) {
e.stopPropagation();
self.$el.parents('.modal').modal('hide');
}
},

],
close: function () {
self.close();
},
title: _t("Document history"),
};
this._super(parent, options);
},

start: function() {
this.register_document_action_events();
return this._super.apply(this, arguments);
},

register_document_action_events: function () {
var self = this;
this.$el.find('.version-download').on('click', function (e) {
e.stopPropagation();
self.on_click_download(e);
});
this.$el.find('.version-preview').on('click', function (e) {
e.stopPropagation();
self.on_click_preview(e);
});
},

_get_version_url: function (version) {},

on_click_preview: function (e) {
var objectId = e.target.attributes.value.nodeValue;
var version = this.versions.find((item) => item.objectId === objectId);
var url = this._get_version_url(version);
if (url) {
window.open(url);
};
},

on_click_download: function(e) {
var objectId = e.target.attributes.value.nodeValue;
var version = this.versions.find((item) => item.objectId === objectId);
if (version) {
window.open(version.url);
}
},

close: function () {
this._super();
}
});

var CmisObjectWrapper = core.Class.extend({

init: function (parent, cmis_object, cmis_session) {
Expand Down Expand Up @@ -1041,6 +1110,20 @@ odoo.define('cmis_web.form_widgets', function (require) {

},

on_click_show_history: function () {
var self = this;
// without the objectId in the options, this returns a "versionSeriesId does not exist" error.
// Exactly why it does is anyone's guess...
var options = {includeAllowableActions: true, objectId: this.value};
this.cmis_session.getAllVersions(this.value, options)
.ok(function (versions) {
var wrapped_versions = self.wrap_cmis_objects(versions)
var dialog = new CmisVersionsHistoryDialog(self, wrapped_versions);
dialog.open();
});

},

_cancel_checkout: function () {
this.cmis_session.cancelCheckOut(this.document.objectId);
},
Expand Down Expand Up @@ -1088,6 +1171,10 @@ odoo.define('cmis_web.form_widgets', function (require) {
self.stopEvent(e);
self.on_click_import_new_version();
});
$el_actions.find('.content-action-history').on('click', function (e) {
self.stopEvent(e);
self.on_click_show_history();
});
$el_actions.find('.content-action-get-properties').on('click', function (e) {
self.stopEvent(e);
self.on_click_get_properties();
Expand Down Expand Up @@ -2123,6 +2210,7 @@ odoo.define('cmis_web.form_widgets', function (require) {
FieldCmisDocument: FieldCmisDocument,
CmisCreateFolderDialog: CmisCreateFolderDialog,
CmisCreateDocumentDialog: CmisCreateDocumentDialog,
CmisVersionsHistoryDialog: CmisVersionsHistoryDialog,
CmisDuplicateDocumentResolver: CmisDuplicateDocumentResolver,
DEFAULT_CMIS_OPTIONS: DEFAULT_CMIS_OPTIONS,
};
Expand Down
36 changes: 36 additions & 0 deletions cmis_web/static/src/scss/form_widgets.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ div.field_cmis_folder_content_actions {
}
}

span.field_cmis_document_actions {
a.dropdown-toggle.fa-align-justify {
top: 0px;
}
ul.dropdown-menu {
width: auto;
}
.divider {
height: 1px;
margin: 8px 0;
overflow: hidden;
background-color: #e5e5e5;
}

a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.42857143;
color: #333333;
white-space: nowrap;
}
a:hover {
color: white;
background-color: #00A09D;
}
}

form.cmis_update_content_stream,
form.cmis_create_document,
form.cmis_duplicate_document_resolver{
Expand Down Expand Up @@ -188,3 +217,10 @@ div.field_cmis_document.no-version div.select-cmis{
div.field_cmis_document.show-file-name span.file-name{
display: inherit !important;
}

div.cmis-version-row {
height: 30px;
.version-text {
line-height: 30px;
}
}
40 changes: 40 additions & 0 deletions cmis_web/static/src/xml/form_widgets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,45 @@
</div>
</t>

<t t-name='CmisVersionsHistoryDialog'>
<div class="cmis-document-history">
<div class="versions border-top container">
<t t-set="versions" t-value="widget.versions"/>
<div class="cmis-version-row row border border-top-0">
<div class="col-sm-1">Version</div>
<div class="col-sm-4">Name</div>
<div class="col-sm-4">Actions</div>
</div>
<div t-foreach="versions" t-as="version">
<div class="cmis-version-row row border border-top-0">
<div class="col-sm-1 version-text" t-esc="version.versionLabel"/>
<div class="col-sm-4 version-text" t-esc="version.name"/>
<div class="col-sm-4" t-if="version.allowableActions.canGetContentStream">
<button type="button"
t-att-id="'download_' + version.objectId"
t-att-value = "version.objectId"
class="btn btn-default btn-xs version-download px-2"
data-toggle="tooltip"
title="Download"
aria-label="Preview">
<span t-att-value="version.objectId" class="fa fa fa-download"></span>
</button>
<button type="button"
t-att-id="'preview_' + version.objectId"
t-att-value = "version.objectId"
class="btn btn-default btn-xs version-preview px-2"
data-toggle="tooltip"
title="Preview"
aria-label="Preview">
<span t-att-value="version.objectId" class="fa fa-eye"></span>
</button>
</div>
</div>
</div>
</div>
</div>
</t>

<t t-name="FieldCmisDocument">
<div t-att-class="'oe_form_field ' + widget.widget_class" t-att-style="widget.attrs.style">
<t t-call="CmisDocumentWaiting" />
Expand Down Expand Up @@ -464,6 +503,7 @@
<ul class="dropdown-menu btn-block" t-att-aria-labelledby="object.getSuccinctProperty('cmis:objectId')" overflow-working="0">
<li t-if='canUpdateProperties'><a class='content-action-rename' href="#">Rename</a></li>
<li><a class='content-action-checkin' href="#">Import new version</a></li>
<li><a class='content-action-history' href="#">Show document history</a></li>
</ul>
</div>
</t>
Expand Down
8 changes: 8 additions & 0 deletions cmis_web_alf/static/src/js/form_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,12 @@ form_widgets.FieldCmisDocument.include({
},
});

form_widgets.CmisVersionsHistoryDialog.include({
_get_version_url: function (version) {
var noderef = version.getSuccinctProperty("alfcmis:nodeRef").split("://").join("/");
return `${version.alfresco_api_location}/node/content/${noderef}/${version.name}`;

},
});

});

0 comments on commit f419a18

Please sign in to comment.