From a1c966a332e5f41e81b16a2541acdb8350637ca4 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 2 Mar 2020 15:44:14 +0100 Subject: [PATCH] Added ability to move objects. --- frontend/src/js/misc/wb-move-object.js | 13 ++++++ frontend/src/js/page/wb-browse.js | 56 ++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 frontend/src/js/misc/wb-move-object.js diff --git a/frontend/src/js/misc/wb-move-object.js b/frontend/src/js/misc/wb-move-object.js new file mode 100644 index 0000000..a5b08fe --- /dev/null +++ b/frontend/src/js/misc/wb-move-object.js @@ -0,0 +1,13 @@ +import makeArvadosRequest from 'make-arvados-request'; +import arvadosTypeName from 'arvados-type-name'; + +function wbMoveObject(arvHost, arvToken, uuid, newOwnerUuid) { + const typeName = arvadosTypeName(uuid); + return makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/' + typeName + 's/' + + uuid, { 'method': 'PUT', 'data': JSON.stringify({ + 'owner_uuid': newOwnerUuid + }) }); +} + +export default wbMoveObject; diff --git a/frontend/src/js/page/wb-browse.js b/frontend/src/js/page/wb-browse.js index bf205de..d96ca11 100644 --- a/frontend/src/js/page/wb-browse.js +++ b/frontend/src/js/page/wb-browse.js @@ -11,6 +11,28 @@ import WBWorkflowListing from 'wb-workflow-listing'; import WBRenameDialog from 'wb-rename-dialog'; import WBDeleteDialog from 'wb-delete-dialog'; import WBNewProjectDialog from 'wb-new-project-dialog'; +import wbMoveObject from 'wb-move-object'; + +class WBBrowseProjectTabs extends Component { + render({ ownerUuid, selected, newProjectDialogRef, projectListingRef, + moveHere, copyHere }) { + + return ( + New Project ), + 'onClick': () => newProjectDialogRef.current.show(ownerUuid, + () => projectListingRef.current.fetchItems() ) } : null, + ( ownerUuid && Object.keys(selected).length > 0 ) ? + { 'name': ( Move Here ), + 'onClick': moveHere } : null, + ( ownerUuid && Object.keys(selected).length > 0 ) ? + { 'name': ( Copy Here ), + 'onClick': copyHere } : null + ] } /> + ); + } +} class WBBrowse extends Component { constructor(...args) { @@ -19,6 +41,7 @@ class WBBrowse extends Component { this.deleteDialogRef = createRef(); this.newProjectDialogRef = createRef(); this.projectListingRef = createRef(); + this.projectTabsRef = createRef(); this.state.selected = {}; } @@ -73,17 +96,36 @@ class WBBrowse extends Component {
{ - if (e.target.value === 'on') + if (e.target.checked) selected[uuid] = true; else delete selected[uuid]; + this.projectTabsRef.current.setState({}); } } /> { '\u00A0' }
); } + moveHere() { + const { ownerUuid, app } = this.props; + const { selected } = this.state; + const { arvHost, arvToken } = app.state; + let prom = new Promise(accept => accept()); + const uuids = Object.keys(selected); + for (let i = 0; i < uuids.length; i++) { + prom = prom.then(() => wbMoveObject(arvHost, arvToken, uuids[i], ownerUuid)); + prom = prom.then(() => ( delete selected[uuids[i]] )); + prom = prom.catch(() => {}); + } + prom = prom.then(() => this.setState({})); + } + + copyHere() { + + } + render({ mode, ownerUuid, activePage, app, - objTypeTab, collectionPage, processPage, workflowPage }) { + objTypeTab, collectionPage, processPage, workflowPage }, { selected }) { return (
@@ -99,12 +141,10 @@ class WBBrowse extends Component { - New Project ), - 'onClick': () => this.newProjectDialogRef.current.show(ownerUuid, - () => this.projectListingRef.current.fetchItems() ) } : null - ] } /> + this.moveHere() } + copyHere={ () => this.copyHere() } />