UNPKG

@simplenodeorm/simplenodereport

Version:

Simple Node Report is a React report designer for the simplenodeorm. Simple Node Report allows the user to create, save and run WYSIWYG style HTML reports in simplenodeorm. To use the report designer call the application with the desired simplenodeorm c

94 lines (80 loc) 3.09 kB
/* * Copyright (c) 2019 simplenodeorm.org */ import React from 'react'; import ReactDOM from 'react-dom'; import '../app/App.css'; import {DocumentTree} from '@simplenodeorm/simplenodeclientbase/lib/DocumentTree'; import {clearDocumentDesignData} from './helpers'; import config from '../config/appconfig.json'; class ReportDocumentTree extends DocumentTree { constructor(props) { super(props); this.loadDocument = this.loadDocument.bind(this); this.deleteDocument = this.deleteDocument.bind(this); this.setCurrentReport = this.setCurrentReport.bind(this); } getConfig() { return config; } showRightClickMenu(info) { const tree = this; if (info.node.props.isLeaf) { this.state.selectedDocument = info.node.props.eventKey; const cm = this.getContextMenu(info); ReactDOM.render(<ul><li><button onClick={tree.loadDocument}>{config.textmsg.loaddocument}</button></li>{!config.demoMode && <li><button onClick={tree.deleteDocument}>{config.textmsg.deletedocument}</button></li>}</ul>, cm); } } loadDocument() { this.clearContextMenu(); const curcomp = this; const {selectedDocument} = this.state; this.sendRequest('/api/report/load/' + selectedDocument, (data) => { curcomp.loadDocumentData(data); }, (err) => { curcomp.props.setStatus(curcomp.formatError(err), true); }); } deleteDocument() { this.clearContextMenu(); const curcomp = this; const {selectedDocument} = this.state; let pos = selectedDocument.indexOf('.'); let response = window.confirm('Delete document ' + selectedDocument.substring(pos+1).replace('_', ' ').replace('.json', '') + '?'); if (response) { this.sendRequest('/api/report/delete/' + selectedDocument, (data) => { curcomp.props.setStatus('document deleted', false); curcomp.loadDocumentGroups(); }, (err) => { curcomp.props.setStatus(curcomp.formatError(err), true); }); } this.clearContextMenu(); curcomp.setState({selectedDocument: ''}); } loadDocumentGroups() { const curcomp = this; this.sendRequest( '/api/report/document/groups', (data) => { curcomp.setState({groups: data}); }, (err) => { curcomp.props.setStatus(curcomp.formatError(err), true); }); } loadDocumentData(doc) { clearDocumentDesignData(); this.props.getDesignPanel().removeAllReportObjects(); this.props.getDesignPanel().refreshLayout(doc); this.props.getToolbar().setState({canSave: true, canAddObject: true}); } setCurrentReport(doc) { this.removeWaitMessage(); this.props.setCurrentReport(doc.documentName); } } export { ReportDocumentTree };