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.

67 lines
1.8KB

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