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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

117 lignes
3.8KB

  1. //
  2. // Copyright (C) Stanislaw Adaszewski, 2020
  3. // Contact: s.adaszewski@gmail.com
  4. // Website: https://adared.ch/wba
  5. // License: GNU Affero General Public License, Version 3
  6. //
  7. import { h, Component } from 'preact';
  8. import makeArvadosRequest from 'make-arvados-request';
  9. import WBTable from 'wb-table';
  10. import WBPagination from 'wb-pagination';
  11. import WBNameAndUuid from 'wb-name-and-uuid';
  12. import wbFetchObjects from 'wb-fetch-objects';
  13. import wbFormatDate from 'wb-format-date';
  14. import urlForObject from 'url-for-object';
  15. import arvadosObjectName from 'arvados-object-name';
  16. class WBWorkflowListing extends Component {
  17. constructor(...args) {
  18. super(...args);
  19. this.state.rows = [];
  20. this.state.numPages = 0;
  21. }
  22. componentDidMount() {
  23. this.fetchItems();
  24. }
  25. prepareRows(items, ownerLookup) {
  26. const { renderRenameLink, renderDeleteButton,
  27. renderSelectionCell, renderSharingButton,
  28. renderEditDescription } = this.props;
  29. return items.map(item => [
  30. renderSelectionCell(item),
  31. (
  32. <div>
  33. <div>
  34. <a href={ urlForObject(item) }>
  35. { arvadosObjectName(item) }
  36. </a> { renderRenameLink(item, () => this.fetchItems()) }
  37. </div>
  38. <div>{ item.uuid }</div>
  39. </div>
  40. ),
  41. (<div>
  42. { item.description } { renderEditDescription(item, () => this.fetchItems()) }
  43. </div>),
  44. ( <WBNameAndUuid uuid={ item.owner_uuid } lookup={ ownerLookup } /> ),
  45. wbFormatDate(item.created_at),
  46. (<div>
  47. <a class="btn btn-outline-success mx-1 my-1" title="Launch"
  48. href={ urlForObject(item, 'launch') }><i class="fas fa-running"></i></a>
  49. <button class="btn btn-outline-primary mx-1 my-1" title="View"><i class="far fa-eye"></i></button>
  50. { renderDeleteButton(item, () => this.fetchItems()) }
  51. { renderSharingButton(item) }
  52. </div>)
  53. ]);
  54. }
  55. fetchItems() {
  56. const { arvHost, arvToken } = this.props.app.state;
  57. const { page, itemsPerPage, ownerUuid, textSearch } = this.props;
  58. const filters = [];
  59. if (ownerUuid)
  60. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  61. if (textSearch)
  62. filters.push([ 'any', 'ilike', '%' + textSearch + '%' ]);
  63. const select = ['uuid', 'name', 'description', 'owner_uuid', 'created_at'];
  64. let prom = makeArvadosRequest(arvHost, arvToken,
  65. '/arvados/v1/workflows?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  66. '&select=' + encodeURIComponent(JSON.stringify(select)) +
  67. '&limit=' + encodeURIComponent(itemsPerPage) +
  68. '&offset=' + encodeURIComponent(itemsPerPage * page));
  69. let workflowResp;
  70. prom = prom.then(xhr => (workflowResp = xhr.response));
  71. prom = prom.then(() => wbFetchObjects(arvHost, arvToken,
  72. workflowResp.items.map(it => it.owner_uuid)));
  73. let ownerLookup;
  74. prom = prom.then(lookup => (ownerLookup = lookup));
  75. prom = prom.then(() =>
  76. this.setState({
  77. 'numPages': Math.ceil(workflowResp['items_available'] / workflowResp['limit']),
  78. 'rows': this.prepareRows(workflowResp.items, ownerLookup)
  79. }));
  80. }
  81. componentWillReceiveProps(nextProps, nextState) {
  82. this.props = nextProps;
  83. this.fetchItems();
  84. }
  85. render({ app, ownerUuid, page, getPageUrl }, { rows, numPages }) {
  86. return (
  87. <div>
  88. <WBTable columns={ [ '', 'Name', 'Description', 'Owner', 'Created At', 'Actions' ] }
  89. headerClasses={ [ 'w-1' ] }
  90. rows={ rows } />
  91. <WBPagination numPages={ numPages }
  92. activePage={ page }
  93. getPageUrl={ getPageUrl } />
  94. </div>
  95. );
  96. }
  97. }
  98. WBWorkflowListing.defaultProps = {
  99. 'itemsPerPage': 100,
  100. 'ownerUuid': null,
  101. 'renderSharingButton': () => null,
  102. 'renderEditDescription': () => null
  103. };
  104. export default WBWorkflowListing;