Skip to content

Commit

Permalink
[WIP] field cmis_document migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
benwillig committed Dec 21, 2023
1 parent adadf0e commit dd886fd
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 13 deletions.
12 changes: 12 additions & 0 deletions cmis_field/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def create_document_field_value(self, model_name, res_id, field_name, documents)
return {'value': value}
return {'value': None}

@http.route(
'/web/cmis/field/cmis_document/get_document_parent',
type='json',
methods=['POST'],
auth="user"
)
def get_document_parent(self, model_name, res_id, backend_id, field_name):
env = http.request.env
record = env[model_name].browse(int(res_id))
backend = env["cmis.backend"].browse(int(backend_id))
return record._fields[field_name].get_create_parents(record, backend)[record.id]

def _decode_files(self, documents):
for doc in documents:
file_ = doc.get("data")
Expand Down
8 changes: 4 additions & 4 deletions cmis_field/fields/cmis_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def _description_backend(self, env):
else:
msg = _('No backend found. Please check your configuration.')
return {'backend_error': msg}
return backend.get_web_description()[backend.id]
result = backend.get_web_description()[backend.id]
return result

def get_cmis_object(self, record):
"""Returns an instance of
Expand Down Expand Up @@ -135,10 +136,9 @@ def clean_up_document(cmis_object_id, backend_id, dbname):
pass

# remove created resource in case of rollback
test_mode = getattr(threading.currentThread(), 'testing', False)
test_mode = getattr(threading.current_thread(), 'testing', False)
if not test_mode:
record.env.cr.after(
'rollback',
record.env.cr.postrollback.add(
partial(
clean_up_document,
object_id,
Expand Down
1 change: 1 addition & 0 deletions cmis_web/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"web.assets_backend": [
"/cmis_web/static/lib/cmisjs/superagent.7.2.0.js",
"/cmis_web/static/lib/cmisjs/cmis.0.3.1.js",
"/cmis_web/static/src/cmis_document/*",
"/cmis_web/static/src/cmis_folder/cmis_folder.js",
"/cmis_web/static/src/cmis_folder/cmis_folder.scss",
"/cmis_web/static/src/cmis_folder/cmis_folder.xml",
Expand Down
31 changes: 25 additions & 6 deletions cmis_web/static/src/cmis_actions/cmis_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,35 @@ import {CmisAttachmentViewer} from "../cmis_attachment_viewer/cmis_attachment_vi
import {CmisObjectWrapper} from "../cmis_object_wrapper_service";
import {Dropdown} from "@web/core/dropdown/dropdown";
import {DropdownItem} from "@web/core/dropdown/dropdown_item";
import {cmisTableProps} from "../cmis_table/cmis_table";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";

const {Component} = owl;
const {Component, useState} = owl;

export class CmisActions extends Component {
setup() {
this.dialogService = useService("dialog");
this.allowableActions = this.props.cmisObject.allowableActions;
this.dynamicActions = this.props.dynamicActions || {};

this.state = useState({
dynamicActions: this.dynamicActions,
});
}

onClickDynamicAction(name) {
this.props.dynamicActions[name].actionClick(this.props.cmisObject);
}

onClickDownload() {
window.open(this.props.cmisObject.url);
}

onClickPreview() {
const props = this.props;
this.dialogService.add(CmisAttachmentViewer, {
cmisObject: this.props.cmisObject,
cmisFolderObjects: this.props.cmisFolderObjects,
cmisObject: props.cmisObject,
cmisFolderObjects: [props.cmisObject],
});
}

Expand All @@ -50,9 +59,19 @@ export class CmisActions extends Component {
CmisActions.template = "cmis_web.CmisActions";
CmisActions.components = {Dropdown, DropdownItem};
CmisActions.props = {
...cmisTableProps,
cmisObject: CmisObjectWrapper,
cmisFolderObjects: {type: Array, element: CmisObjectWrapper},
renameObject: Function,
updateDocumentContent: Function,
deleteObject: {
type: Function,
optional: true,
},
dynamicActions: [
{
type: Object,
optional: true,
},
],
};

registry.category("view_widgets").add("cmis_actions", CmisActions);
18 changes: 18 additions & 0 deletions cmis_web/static/src/cmis_actions/cmis_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
>
<i class="fa fa-align-justify" />
<Dropdown toggler="'parent'">
<t
t-if="allowableActions.canUpdateProperties"
t-foreach="state.dynamicActions"
t-as="dynamicActionName"
t-key="dynamicActionName"
>
<t
t-set="dynamicAction"
t-value="state.dynamicActions[dynamicActionName]"
/>
<DropdownItem t-if="allowableActions.canUpdateProperties">
<div
t-on-click="ev => this.onClickDynamicAction(dynamicActionName)"
>
<span t-esc="dynamicAction.name" />
</div>
</DropdownItem>
</t>
<DropdownItem t-if="allowableActions.canUpdateProperties">
<div t-on-click="onRename">Rename</div>
</DropdownItem>
Expand Down
Loading

0 comments on commit dd886fd

Please sign in to comment.