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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.4KB

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