'use strict'; import React, { Component } from 'react'; import { translate } from 'react-i18next'; import { requiresAuthenticatedUser, withPageHelpers, Title, Toolbar, NavButton } from '../lib/page'; import { Table } from '../lib/table'; import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling'; import moment from 'moment'; import axios from '../lib/axios'; import { ReportState } from '../../../shared/reports'; @translate() @withErrorHandling @withPageHelpers @requiresAuthenticatedUser export default class List extends Component { constructor(props) { super(props); this.state = {}; } @withAsyncErrorHandler async fetchPermissions() { const request = { createReport: { entityTypeId: 'namespace', requiredOperations: ['createReport'] }, executeReportTemplate: { entityTypeId: 'reportTemplate', requiredOperations: ['execute'] }, createReportTemplate: { entityTypeId: 'namespace', requiredOperations: ['createReportTemplate'] }, viewReportTemplate: { entityTypeId: 'reportTemplate', requiredOperations: ['view'] }, }; const result = await axios.post('/rest/permissions-check', request); this.setState({ createPermitted: result.data.createReport && result.data.executeReportTemplate, templatesPermitted: result.data.createReportTemplate || result.data.viewReportTemplate }); } componentDidMount() { this.fetchPermissions(); } @withAsyncErrorHandler async stop(table, id) { await axios.post(`/rest/report-stop/${id}`); table.refresh(); } @withAsyncErrorHandler async start(table, id) { await axios.post(`/rest/report-start/${id}`); table.refresh(); } render() { const t = this.props.t; const actions = data => { const actions = []; const perms = data[8]; const permsReportTemplate = data[9]; let viewContent, startStop, refreshTimeout; const state = data[6]; const id = data[0]; const mimeType = data[7]; if (state === ReportState.PROCESSING || state === ReportState.SCHEDULED) { viewContent = { label: , }; startStop = { label: , action: (table) => this.stop(table, id) }; refreshTimeout = 1000; } else if (state === ReportState.FINISHED) { if (mimeType === 'text/html') { viewContent = { label: , link: `reports/view/${id}` }; } else if (mimeType === 'text/csv') { viewContent = { label: , href: `reports/download/${id}` }; } startStop = { label: , action: (table) => this.start(table, id) }; } else if (state === ReportState.FAILED) { viewContent = { label: , }; startStop = { label: , action: (table) => this.start(table, id) }; } if (perms.includes('viewContent')) { actions.push(viewContent); } if (perms.includes('viewOutput')) { actions.push( { label: , link: `reports/output/${id}` } ); } if (perms.includes('execute') && permsReportTemplate.includes('execute')) { actions.push(startStop); } if (perms.includes('edit') && permsReportTemplate.includes('execute')) { actions.push({ label: , link: `/reports/edit/${id}` }); } if (perms.includes('share')) { actions.push({ label: , link: `/reports/share/${id}` }); } return { refreshTimeout, actions }; }; const columns = [ { data: 0, title: "#" }, { data: 1, title: t('Name') }, { data: 2, title: t('Template') }, { data: 3, title: t('Description') }, { data: 4, title: t('Created'), render: data => data ? moment(data).fromNow() : '' }, { data: 5, title: t('Namespace') } ]; return (