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.

65 lines
1.8KB

  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.terminalRef = createRef();
  9. }
  10. componentDidMount() {
  11. this.fetchData();
  12. }
  13. componentWillReceiveProps(nextProps) {
  14. if (nextProps.uuid === this.props.uuid);
  15. return;
  16. this.props = nextProps;
  17. this.state.page = 0;
  18. this.fetchData();
  19. }
  20. fetchData() {
  21. const { uuid, app, itemsPerPage } = this.props;
  22. const { page } = this.state;
  23. const { arvHost, arvToken } = app.state;
  24. const filters = [
  25. [ 'object_uuid', '=', uuid ]
  26. ];
  27. let prom = makeArvadosRequest(arvHost, arvToken,
  28. '/arvados/v1/logs?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  29. '&offset=' + (itemsPerPage * page) +
  30. '&limit=' + itemsPerPage);
  31. prom = prom.then(xhr => {
  32. const { items } = xhr.response;
  33. this.setState({
  34. content: items
  35. .filter(a => ('text' in a.properties))
  36. .map(a => a.properties.text.trim()).join('\n'),
  37. numPages: Math.ceil(xhr.response.items_available / itemsPerPage)
  38. });
  39. this.terminalRef.current.scrollTo(0, 0);
  40. });
  41. }
  42. render({}, { content, page, numPages }) {
  43. return (
  44. <div>
  45. <WBPagination activePage={ page } numPages={ numPages }
  46. onPageChanged={ page => { this.state.page = page; this.fetchData(); } } />
  47. <pre class="word-warp terminal" ref={ this.terminalRef }>
  48. { content }
  49. </pre>
  50. </div>
  51. );
  52. }
  53. }
  54. WBLiveLogs.defaultProps = {
  55. itemsPerPage: 1000
  56. };
  57. export default WBLiveLogs;