IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

231 行
8.4KB

  1. import { h, Component, createRef } from 'preact';
  2. import { route } from 'preact-router';
  3. import WBNavbarCommon from 'wb-navbar-common';
  4. import WBProjectListing from 'wb-project-listing';
  5. import WBInlineSearch from 'wb-inline-search';
  6. import WBArvadosCrumbs from 'wb-arvados-crumbs';
  7. import WBTabs from 'wb-tabs';
  8. import WBProcessListing from 'wb-process-listing';
  9. import WBCollectionListing from 'wb-collection-listing';
  10. import WBWorkflowListing from 'wb-workflow-listing';
  11. import WBRenameDialog from 'wb-rename-dialog';
  12. import WBDeleteDialog from 'wb-delete-dialog';
  13. import WBNewProjectDialog from 'wb-new-project-dialog';
  14. import wbMoveObject from 'wb-move-object';
  15. import wbCopyCollection from 'wb-copy-collection';
  16. import arvadosTypeName from 'arvados-type-name';
  17. class WBBrowseProjectTabs extends Component {
  18. render({ ownerUuid, selected, newProjectDialogRef, projectListingRef,
  19. moveHere, copyHere }) {
  20. return (
  21. <WBTabs tabs={ [
  22. { 'name': 'Projects', 'isActive': true },
  23. ownerUuid ? { 'name': ( <span><i class="fas fa-plus-square text-success"></i> New Project</span> ),
  24. 'onClick': () => newProjectDialogRef.current.show(ownerUuid,
  25. () => projectListingRef.current.fetchItems() ) } : null,
  26. ( ownerUuid && Object.keys(selected).length > 0 ) ?
  27. { 'name': ( <span><i class="fas fa-compress-arrows-alt text-warning"></i> Move Here</span> ),
  28. 'onClick': moveHere } : null,
  29. ( ownerUuid && (uuids => uuids.length > 0 && uuids.length ===
  30. uuids.map(arvadosTypeName).filter(a => (a === 'collection')).length )(Object.keys(selected)) ) ?
  31. { 'name': ( <span><i class="fas fa-file-import text-warning"></i> Copy Here</span> ),
  32. 'onClick': copyHere } : null
  33. ] } />
  34. );
  35. }
  36. }
  37. class WBBrowse extends Component {
  38. constructor(...args) {
  39. super(...args);
  40. this.renameDialogRef = createRef();
  41. this.deleteDialogRef = createRef();
  42. this.newProjectDialogRef = createRef();
  43. this.projectListingRef = createRef();
  44. this.projectTabsRef = createRef();
  45. this.state.selected = {};
  46. }
  47. getUrl(params) {
  48. const mode = ('mode' in params ? params.mode : this.props.mode);
  49. if (mode === 'shared-with-me')
  50. return '/shared-with-me/' +
  51. ('activePage' in params ? params.activePage : (this.props.activePage || '')) + '/' +
  52. ('textSearch' in params ? params.textSearch : (this.props.textSearch || ''));
  53. let res = '/browse/' +
  54. ('ownerUuid' in params ? params.ownerUuid : (this.props.ownerUuid || '')) + '/' +
  55. ('activePage' in params ? params.activePage : (this.props.activePage || '')) + '/' +
  56. ('objTypeTab' in params ? params.objTypeTab : (this.props.objTypeTab || '')) + '/' +
  57. ('collectionPage' in params ? params.collectionPage : (this.props.collectionPage || '')) + '/' +
  58. ('processPage' in params ? params.processPage : (this.props.processPage || '')) + '/' +
  59. ('workflowPage' in params ? params.workflowPage : (this.props.workflowPage || '')) + '/' +
  60. encodeURIComponent('textSearch' in params ? params.textSearch : (this.props.textSearch || ''));
  61. return res;
  62. }
  63. route(params) {
  64. route(this.getUrl(params));
  65. }
  66. renameDialog(item, callback) {
  67. // throw Error('Not implemented');
  68. this.renameDialogRef.current.show(item, callback);
  69. }
  70. renderRenameLink(item, callback) {
  71. return (
  72. <a href="#" title="Rename" onclick={ e => { e.preventDefault(); this.renameDialog(item, callback); } }>
  73. <i class="fas fa-edit text-secondary"></i>
  74. </a>
  75. );
  76. }
  77. renderDeleteButton(item, callback) {
  78. return (
  79. <button class="btn btn-outline-danger m-1" title="Delete"
  80. onclick={ () => this.deleteDialogRef.current.show(item, callback) }>
  81. <i class="fas fa-trash"></i>
  82. </button>
  83. );
  84. }
  85. renderSelectionCell(item) {
  86. const { selected } = this.state;
  87. const { uuid } = item;
  88. return (
  89. <div>
  90. <input type="checkbox" checked={ (uuid in selected) }
  91. onChange={ e => {
  92. if (e.target.checked)
  93. selected[uuid] = true;
  94. else
  95. delete selected[uuid];
  96. this.projectTabsRef.current.setState({});
  97. } } /> { '\u00A0' }
  98. </div>
  99. );
  100. }
  101. renderSharingButton(item) {
  102. return (
  103. <a class="btn btn-outline-success m-1" title="Share"
  104. href={ '/sharing/' + item.uuid }>
  105. <i class="fas fa-share-alt"></i>
  106. </a>
  107. );
  108. }
  109. moveOrCopyOp(op) {
  110. const { ownerUuid, app } = this.props;
  111. const { selected } = this.state;
  112. const { arvHost, arvToken } = app.state;
  113. let prom = new Promise(accept => accept());
  114. const uuids = Object.keys(selected);
  115. for (let i = 0; i < uuids.length; i++) {
  116. prom = prom.then(() => op(arvHost, arvToken, uuids[i], ownerUuid));
  117. prom = prom.then(() => ( delete selected[uuids[i]] ));
  118. prom = prom.catch(() => {});
  119. }
  120. prom = prom.then(() => this.setState({}));
  121. }
  122. moveHere() {
  123. this.moveOrCopyOp(wbMoveObject);
  124. }
  125. copyHere() {
  126. this.moveOrCopyOp(wbCopyCollection);
  127. }
  128. render({ mode, ownerUuid, activePage, app,
  129. objTypeTab, collectionPage, processPage, workflowPage,
  130. textSearch }, { selected }) {
  131. const commonProps = {
  132. renderRenameLink: (it, cb) => this.renderRenameLink(it, cb),
  133. renderDeleteButton: (it, cb) => this.renderDeleteButton(it, cb),
  134. renderSelectionCell: it => this.renderSelectionCell(it),
  135. renderSharingButton: it => this.renderSharingButton(it),
  136. textSearch,
  137. app,
  138. appState: app.state,
  139. arvHost: app.state.arvHost,
  140. arvToken: app.state.arvToken,
  141. ownerUuid
  142. };
  143. return (
  144. <div>
  145. <WBRenameDialog app={ app } ref={ this.renameDialogRef } />
  146. <WBDeleteDialog app={ app } ref={ this.deleteDialogRef } />
  147. <WBNewProjectDialog app={ app } ref={ this.newProjectDialogRef } />
  148. <WBNavbarCommon app={ app }
  149. activeItem={ mode === 'shared-with-me' ? 'shared-with-me' :
  150. (!ownerUuid) ? 'all-projects' :
  151. (ownerUuid === app.state.currentUser.uuid) ? 'home' : null }
  152. textSearch={ textSearch }
  153. textSearchNavigate={ textSearch => route(this.getUrl({ textSearch,
  154. activePage: 0, collectionPage: 0, processPage: 0, workflowPage: 0 })) } />
  155. <WBArvadosCrumbs mode={ mode } uuid={ ownerUuid } app={ app } />
  156. <WBBrowseProjectTabs ref={ this.projectTabsRef } ownerUuid={ ownerUuid }
  157. selected={ selected } newProjectDialogRef={ this.newProjectDialogRef }
  158. projectListingRef={ this.projectListingRef } moveHere={ () => this.moveHere() }
  159. copyHere={ () => this.copyHere() } />
  160. <WBProjectListing ref={ this.projectListingRef }
  161. mode={ mode }
  162. itemsPerPage="5"
  163. activePage={ Number(activePage || 0) }
  164. getPageUrl={ i => this.getUrl({ 'activePage': i }) }
  165. { ...commonProps } />
  166. { (mode !== 'browse') ? null : (
  167. <WBTabs tabs={ [
  168. { 'id': 'collection', 'name': 'Collections', 'isActive': (!objTypeTab || objTypeTab === 'collection') },
  169. { 'id': 'process', 'name': 'Processes', 'isActive': (objTypeTab === 'process') },
  170. { 'id': 'workflow', 'name': 'Workflows', 'isActive': (objTypeTab === 'workflow') } ] }
  171. onTabChanged={ tab => this.route({ 'objTypeTab': tab['id'] }) } />
  172. ) }
  173. {
  174. (mode !== 'browse') ? null :
  175. (!objTypeTab || objTypeTab === 'collection') ? (
  176. <WBCollectionListing
  177. itemsPerPage="20"
  178. activePage={ Number(collectionPage || 0) }
  179. getPageUrl={ i => this.getUrl({ 'collectionPage': i }) }
  180. { ...commonProps } />
  181. ) : (objTypeTab === 'process') ? (
  182. <WBProcessListing
  183. itemsPerPage="20"
  184. activePage={ Number(processPage || 0) }
  185. onPageChanged={ i => this.route({ 'processPage': i }) }
  186. { ...commonProps } />
  187. ) : (objTypeTab === 'workflow') ? (
  188. <WBWorkflowListing
  189. itemsPerPage="20"
  190. page={ Number(workflowPage || 0) }
  191. getPageUrl={ i => this.getUrl({ 'workflowPage': i }) }
  192. { ...commonProps } />
  193. ) : null
  194. }
  195. </div>
  196. );
  197. }
  198. }
  199. export default WBBrowse;