// // Copyright (C) Stanislaw Adaszewski, 2020 // Contact: s.adaszewski@gmail.com // Website: https://adared.ch/wba // License: GNU Affero General Public License, Version 3 // import { h, Component, createRef } from 'preact'; import WBNavbarCommon from 'wb-navbar-common'; import WBArvadosCrumbs from 'wb-arvados-crumbs'; import WBNameAndUuid from 'wb-name-and-uuid'; import WBSelect from 'wb-select'; import WBTable from 'wb-table'; import WBPickObjectDialog from 'wb-pick-object-dialog'; import makeArvadosRequest from 'make-arvados-request'; class WBSharingPage extends Component { constructor(...args) { super(...args); this.state.rows = []; this.dialogRef = createRef(); } componentDidMount() { this.fetchData(); } fetchData() { const { app, uuid } = this.props; const { arvHost, arvToken } = app.state; let prom = makeArvadosRequest(arvHost, arvToken, '/arvados/v1/permissions/' + encodeURIComponent(uuid) + '?limit=100000'); prom = prom.then(xhr => this.setState({ 'entries': xhr.response.items, 'rows': this.prepareRows(xhr.response.items) })); } deleteEntry(it) { it._delete = true; this.setState({ rows: this.prepareRows(this.state.entries) }); } prepareRows(items) { const { app } = this.props; return items.filter(it => (!it._delete)).map(it => [ ( ), ( this.modifyEntry(it, e.target.value) } /> ), ( ) ]); } modifyEntry(it, newPermissionName) { it.name = newPermissionName; it._dirty = true; // this.setState({ rows: this.prepareRows(this.state.entries) }); } addEntry(it, permissionName='can_read') { // throw Error('Not implemented'); const { uuid } = this.props; let { entries } = this.state; if (entries.filter(e => (e.tail_uuid === it.uuid)).length > 0) return; // already in the list const e = { //_dirty: true, link_class: 'permission', head_uuid: uuid, tail_uuid: it.uuid, name: permissionName }; entries = entries.concat([e]); this.setState({ entries, rows: this.prepareRows(entries) }); } disableControls() { $('input, select, button').attr('disabled', 'disabled'); $('a').each(function() { $(this).data('old_href', $(this).attr('href')); }); $('a').attr('href', null); } enableControls() { $('input, select, button').attr('disabled', null); $('a').each(function() { $(this).attr('href', $(this).data('old_href')); }); } save() { const { entries } = this.state; const { arvHost, arvToken } = this.props.app.state; let prom = new Promise(accept => accept()); this.disableControls(); this.setState({ working: true }); for (let i = 0; i < entries.length; i++) { const e = entries[i]; //if (!e._dirty && !e._delete) //continue; if (!e.uuid) { prom = prom.then(() => makeArvadosRequest(arvHost, arvToken, '/arvados/v1/links', { 'method': 'POST', 'data': JSON.stringify({ 'link_class': 'permission', 'head_uuid': e.head_uuid, 'tail_uuid': e.tail_uuid, 'name': e.name }) })); } else if (e._delete) { prom = prom.then(() => makeArvadosRequest(arvHost, arvToken, '/arvados/v1/links/' + e.uuid, { 'method': 'DELETE' })); } else if (e._dirty) { prom = prom.then(() => makeArvadosRequest(arvHost, arvToken, '/arvados/v1/links/' + e.uuid, { 'method': 'PUT', 'data': JSON.stringify({ 'name': e.name }) })); } prom = prom.catch(() => {}); } prom = prom.then(() => { this.enableControls(); this.fetchData(); this.setState({ working: false }); }); } render({ app, uuid }, { rows, working }) { return (
This is the sharing management page for { uuid }
{ working ? (
) : null }
); } } export default WBSharingPage;