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!
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

83 linhas
2.5KB

  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, createRef } from 'preact';
  8. import makeArvadosRequest from 'make-arvados-request';
  9. import WBPagination from 'wb-pagination';
  10. class WBLiveLogs extends Component {
  11. constructor(...args) {
  12. super(...args);
  13. this.state.page = 0;
  14. this.state.moreItemsPerPage = false;
  15. this.terminalRef = createRef();
  16. }
  17. componentDidMount() {
  18. this.fetchData();
  19. }
  20. componentWillReceiveProps(nextProps) {
  21. if (nextProps.uuid === this.props.uuid);
  22. return;
  23. this.props = nextProps;
  24. this.state.page = 0;
  25. this.fetchData();
  26. }
  27. fetchData() {
  28. const { uuid, app } = this.props;
  29. let { itemsPerPage } = this.props;
  30. const { page, moreItemsPerPage } = this.state;
  31. if (moreItemsPerPage)
  32. itemsPerPage *= 10;
  33. const { arvHost, arvToken } = app.state;
  34. const filters = [
  35. [ 'object_uuid', '=', uuid ]
  36. ];
  37. let prom = makeArvadosRequest(arvHost, arvToken,
  38. '/arvados/v1/logs?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  39. '&offset=' + (itemsPerPage * page) +
  40. '&limit=' + itemsPerPage);
  41. prom = prom.then(xhr => {
  42. const { items } = xhr.response;
  43. this.setState({
  44. content: items
  45. .filter(a => ('text' in a.properties))
  46. .map(a => a.properties.text.trim()).join('\n'),
  47. numPages: Math.ceil(xhr.response.items_available / itemsPerPage)
  48. });
  49. this.terminalRef.current.scrollTo(0, 0);
  50. });
  51. }
  52. render({}, { content, page, numPages, moreItemsPerPage }) {
  53. return (
  54. <div>
  55. <div class="custom-control custom-switch">
  56. <input type="checkbox" class="custom-control-input" id="morePerPageSwitch"
  57. checked = { moreItemsPerPage ? 'checked' : null }
  58. onchange={ e => { this.state.moreItemsPerPage = e.target.checked;
  59. this.state.page = 0; this.fetchData(); } } />
  60. <label class="custom-control-label" for="morePerPageSwitch">More log entries per page</label>
  61. </div>
  62. <WBPagination activePage={ page } numPages={ numPages }
  63. onPageChanged={ page => { this.state.page = page; this.fetchData(); } } />
  64. <pre class="word-wrap terminal" ref={ this.terminalRef }>
  65. { content }
  66. </pre>
  67. </div>
  68. );
  69. }
  70. }
  71. WBLiveLogs.defaultProps = {
  72. itemsPerPage: 100
  73. };
  74. export default WBLiveLogs;