Share report template functionality
This commit is contained in:
parent
e6ad0e239e
commit
4822a50d0b
35 changed files with 614 additions and 128 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate, Trans } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page'
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import URL from 'url-parse';
|
||||
import axios from '../lib/axios';
|
||||
|
@ -11,6 +11,7 @@ import { Button } from '../lib/bootstrap-components';
|
|||
@translate()
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class API extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate, Trans } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page'
|
||||
import {
|
||||
withForm, Form, Fieldset, FormSendMethod, InputField, ButtonRow, Button
|
||||
} from '../lib/form';
|
||||
|
@ -15,6 +15,7 @@ import mailtrainConfig from 'mailtrainConfig';
|
|||
@withForm
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class Account extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -120,6 +121,8 @@ export default class Account extends Component {
|
|||
this.updateFormValue('currentPassword', '');
|
||||
|
||||
this.clearFormStatusMessage();
|
||||
this.enableForm();
|
||||
|
||||
} else {
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('warning', t('There are errors in the form. Please fix them and submit again.'));
|
||||
|
|
|
@ -4,7 +4,7 @@ import React, { Component } from 'react';
|
|||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import {
|
||||
withForm, Form, FormSendMethod, InputField, CheckBox, ButtonRow, Button, AlignedRow
|
||||
withForm, Form, FormSendMethod, InputField, ButtonRow, Button
|
||||
} from '../lib/form';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ export default class Login extends Component {
|
|||
this.setFormStatusMessage('info', t('Verifying credentials ...'));
|
||||
|
||||
const submitSuccessful = await this.validateAndSendFormValuesToURL(FormSendMethod.POST, '/rest/login');
|
||||
/* FIXME, once we turn Mailtrain to single-page application, we should receive authenticated config (from client-helpers.js:getAuthenticatedConfig)
|
||||
as part of login response. Then we should integrate it in the mailtrainConfig global variable. */
|
||||
|
||||
if (submitSuccessful) {
|
||||
const query = new URL(this.props.location.search, true).query;
|
||||
|
|
|
@ -5,12 +5,12 @@ import ReactDOM from 'react-dom';
|
|||
import { I18nextProvider } from 'react-i18next';
|
||||
import i18n from '../lib/i18n';
|
||||
|
||||
import { Section } from '../lib/page'
|
||||
import Account from './Account'
|
||||
import Login from './Login'
|
||||
import Reset from './Forgot'
|
||||
import ResetLink from './Reset'
|
||||
import API from './API'
|
||||
import { Section } from '../lib/page';
|
||||
import Account from './Account';
|
||||
import Login from './Login';
|
||||
import Reset from './Forgot';
|
||||
import ResetLink from './Reset';
|
||||
import API from './API';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function handleError(that, error) {
|
|||
function withErrorHandling(target) {
|
||||
const inst = target.prototype;
|
||||
|
||||
if (inst._withErrorHandlingApplied) return;
|
||||
if (inst._withErrorHandlingApplied) return target;
|
||||
inst._withErrorHandlingApplied = true;
|
||||
|
||||
const contextTypes = target.contextTypes || {};
|
||||
|
|
|
@ -356,7 +356,7 @@ class TreeTableSelect extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
@translate()
|
||||
@translate(null, { withRef: true })
|
||||
class TableSelect extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -369,6 +369,7 @@ class TableSelect extends Component {
|
|||
|
||||
static propTypes = {
|
||||
dataUrl: PropTypes.string,
|
||||
data: PropTypes.array,
|
||||
columns: PropTypes.array,
|
||||
selectionKeyIndex: PropTypes.number,
|
||||
selectionLabelIndex: PropTypes.number,
|
||||
|
@ -426,6 +427,10 @@ class TableSelect extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
refresh() {
|
||||
this.table.refresh();
|
||||
}
|
||||
|
||||
render() {
|
||||
const props = this.props;
|
||||
const owner = this.context.formStateOwner;
|
||||
|
@ -443,7 +448,7 @@ class TableSelect extends Component {
|
|||
</span>
|
||||
</div>
|
||||
<div className={'mt-tableselect-table' + (this.state.open ? '' : ' mt-tableselect-table-hidden')}>
|
||||
<Table dataUrl={props.dataUrl} columns={props.columns} selectMode={props.selectMode} selectionAsArray={this.props.selectionAsArray} withHeader={props.withHeader} selection={owner.getFormValue(id)} onSelectionDataAsync={::this.onSelectionDataAsync} onSelectionChangedAsync={::this.onSelectionChangedAsync}/>
|
||||
<Table ref={node => this.table = node} data={props.data} dataUrl={props.dataUrl} columns={props.columns} selectMode={props.selectMode} selectionAsArray={this.props.selectionAsArray} withHeader={props.withHeader} selection={owner.getFormValue(id)} onSelectionDataAsync={::this.onSelectionDataAsync} onSelectionChangedAsync={::this.onSelectionChangedAsync}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -451,7 +456,7 @@ class TableSelect extends Component {
|
|||
return wrapInput(id, htmlId, owner, props.label, props.help,
|
||||
<div>
|
||||
<div>
|
||||
<Table dataUrl={props.dataUrl} columns={props.columns} selectMode={props.selectMode} selectionAsArray={this.props.selectionAsArray} withHeader={props.withHeader} selection={owner.getFormValue(id)} onSelectionChangedAsync={::this.onSelectionChangedAsync}/>
|
||||
<Table ref={node => this.table = node} data={props.data} dataUrl={props.dataUrl} columns={props.columns} selectMode={props.selectMode} selectionAsArray={this.props.selectionAsArray} withHeader={props.withHeader} selection={owner.getFormValue(id)} onSelectionChangedAsync={::this.onSelectionChangedAsync}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
@ -459,6 +464,15 @@ class TableSelect extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Refreshes the table. This method is provided to allow programmatic refresh from a handler outside the table.
|
||||
The reference to the table can be obtained by ref.
|
||||
*/
|
||||
TableSelect.prototype.refresh = function() {
|
||||
this.getWrappedInstance().refresh()
|
||||
};
|
||||
|
||||
|
||||
class ACEEditor extends Component {
|
||||
static propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
|
|
|
@ -38,4 +38,9 @@
|
|||
|
||||
.mt-tableselect-dropdown input[readonly] {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
h3.legend {
|
||||
font-size: 21px;
|
||||
margin-bottom: 20px;
|
||||
}
|
|
@ -9,6 +9,7 @@ import './page.css';
|
|||
import { withErrorHandling } from './error-handling';
|
||||
import interoperableErrors from '../../../shared/interoperable-errors';
|
||||
import { DismissibleAlert, Button } from './bootstrap-components';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
|
||||
class PageContent extends Component {
|
||||
|
@ -200,10 +201,16 @@ class SectionContent extends Component {
|
|||
this.setFlashMessage(severity, text);
|
||||
}
|
||||
|
||||
errorHandler(error) {
|
||||
if (error instanceof interoperableErrors.NotLoggedInError) {
|
||||
ensureAuthenticated() {
|
||||
if (!mailtrainConfig.isAuthenticated) {
|
||||
/* FIXME, once we turn Mailtrain to single-page application, this should become navigateTo */
|
||||
window.location = '/account/login?next=' + encodeURIComponent(this.props.root);
|
||||
}
|
||||
}
|
||||
|
||||
errorHandler(error) {
|
||||
if (error instanceof interoperableErrors.NotLoggedInError) {
|
||||
this.ensureAuthenticated();
|
||||
} else if (error.response && error.response.data && error.response.data.message) {
|
||||
console.error(error);
|
||||
this.navigateToWithFlashMessage(this.props.root, 'danger', error.response.data.message);
|
||||
|
@ -312,7 +319,7 @@ class DropdownLink extends Component {
|
|||
}
|
||||
|
||||
function withPageHelpers(target) {
|
||||
withErrorHandling(target);
|
||||
target = withErrorHandling(target);
|
||||
|
||||
const inst = target.prototype;
|
||||
|
||||
|
@ -346,16 +353,32 @@ function withPageHelpers(target) {
|
|||
return this.context.sectionContent.navigateToWithFlashMessage(path, severity, text);
|
||||
}
|
||||
|
||||
inst.axios
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function requiresAuthenticatedUser(target) {
|
||||
const comp1 = withPageHelpers(target);
|
||||
|
||||
function comp2(props, context) {
|
||||
comp1.call(this, props, context);
|
||||
context.sectionContent.ensureAuthenticated();
|
||||
}
|
||||
|
||||
comp2.prototype = comp1.prototype;
|
||||
|
||||
for (const attr in comp1) {
|
||||
comp2[attr] = comp1[attr];
|
||||
}
|
||||
|
||||
return comp2;
|
||||
}
|
||||
|
||||
export {
|
||||
Section,
|
||||
Title,
|
||||
Toolbar,
|
||||
NavButton,
|
||||
DropdownLink,
|
||||
withPageHelpers
|
||||
withPageHelpers,
|
||||
requiresAuthenticatedUser
|
||||
};
|
|
@ -6,7 +6,6 @@ import { translate } from 'react-i18next';
|
|||
import PropTypes from 'prop-types';
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import '../../public/jquery/jquery-ui-1.12.1.min.js';
|
||||
|
||||
import 'datatables.net';
|
||||
import 'datatables.net-bs';
|
||||
|
@ -82,13 +81,20 @@ class Table extends Component {
|
|||
selMap.set(elem, undefined);
|
||||
}
|
||||
|
||||
if (this.table) {
|
||||
const self = this;
|
||||
this.table.rows().every(function() {
|
||||
const data = this.data();
|
||||
const key = data[self.props.selectionKeyIndex];
|
||||
if (props.data) {
|
||||
for (const rowData of props.data) {
|
||||
const key = rowData[props.selectionKeyIndex];
|
||||
if (selMap.has(key)) {
|
||||
selMap.set(key, data);
|
||||
selMap.set(key, rowData);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (this.table) {
|
||||
this.table.rows().every(function() {
|
||||
const rowData = this.data();
|
||||
const key = rowData[props.selectionKeyIndex];
|
||||
if (selMap.has(key)) {
|
||||
selMap.set(key, rowData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -118,26 +124,28 @@ class Table extends Component {
|
|||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async fetchSelectionData() {
|
||||
async fetchAndNotifySelectionData() {
|
||||
if (this.props.onSelectionDataAsync) {
|
||||
const keysToFetch = [];
|
||||
for (const pair of this.selectionMap.entries()) {
|
||||
if (!pair[1]) {
|
||||
keysToFetch.push(pair[0]);
|
||||
if (!this.props.data) {
|
||||
const keysToFetch = [];
|
||||
for (const pair of this.selectionMap.entries()) {
|
||||
if (!pair[1]) {
|
||||
keysToFetch.push(pair[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keysToFetch.length > 0) {
|
||||
const response = await axios.post(this.props.dataUrl, {
|
||||
operation: 'getBy',
|
||||
column: this.props.selectionKeyIndex,
|
||||
values: keysToFetch
|
||||
});
|
||||
if (keysToFetch.length > 0) {
|
||||
const response = await axios.post(this.props.dataUrl, {
|
||||
operation: 'getBy',
|
||||
column: this.props.selectionKeyIndex,
|
||||
values: keysToFetch
|
||||
});
|
||||
|
||||
for (const row of response.data) {
|
||||
const key = row[this.props.selectionKeyIndex];
|
||||
if (this.selectionMap.has(key)) {
|
||||
this.selectionMap.set(key, row);
|
||||
for (const row of response.data) {
|
||||
const key = row[this.props.selectionKeyIndex];
|
||||
if (this.selectionMap.has(key)) {
|
||||
this.selectionMap.set(key, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +301,7 @@ class Table extends Component {
|
|||
clearTimeout(this.refreshTimeoutId);
|
||||
});
|
||||
|
||||
this.fetchSelectionData();
|
||||
this.fetchAndNotifySelectionData();
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
|
@ -314,7 +322,7 @@ class Table extends Component {
|
|||
}
|
||||
|
||||
this.updateSelectInfo();
|
||||
this.fetchSelectionData();
|
||||
this.fetchAndNotifySelectionData();
|
||||
}
|
||||
|
||||
async notifySelection(eventCallback, newSelectionMap) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page';
|
||||
import { withForm, Form, FormSendMethod, InputField, TextArea, ButtonRow, Button, TreeTableSelect } from '../lib/form';
|
||||
import axios from '../lib/axios';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
|
@ -13,6 +14,7 @@ import { ModalDialog } from '../lib/bootstrap-components';
|
|||
@withForm
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class CUD extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -28,6 +30,10 @@ export default class CUD extends Component {
|
|||
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
edit: PropTypes.bool
|
||||
}
|
||||
|
||||
isEditGlobal() {
|
||||
return this.state.entityId === 1;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { TreeTable } from '../lib/tree';
|
||||
|
||||
@translate()
|
||||
@withPageHelpers
|
||||
@requiresAuthenticatedUser
|
||||
export default class List extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import ReactDOM from 'react-dom';
|
|||
import { I18nextProvider } from 'react-i18next';
|
||||
import i18n from '../lib/i18n';
|
||||
|
||||
import { Section } from '../lib/page'
|
||||
import CUD from './CUD'
|
||||
import List from './List'
|
||||
import { Section } from '../lib/page';
|
||||
import CUD from './CUD';
|
||||
import List from './List';
|
||||
|
||||
const getStructure = t => ({
|
||||
'': {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate, Trans } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page';
|
||||
import {
|
||||
withForm, Form, FormSendMethod, InputField, TextArea, TableSelect, TableSelectMode, ButtonRow, Button,
|
||||
Fieldset
|
||||
|
@ -16,6 +17,7 @@ import moment from 'moment';
|
|||
@withForm
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class CUD extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -33,6 +35,10 @@ export default class CUD extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
edit: PropTypes.bool
|
||||
}
|
||||
|
||||
isDelete() {
|
||||
return this.props.match.params.action === 'delete';
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { withPageHelpers, Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { Table } from '../lib/table';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import moment from 'moment';
|
||||
|
@ -11,6 +11,7 @@ import { ReportState } from '../../../shared/reports';
|
|||
|
||||
@translate()
|
||||
@withErrorHandling
|
||||
@withPageHelpers
|
||||
export default class List extends Component {
|
||||
|
||||
@withAsyncErrorHandler
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page'
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import axios from '../lib/axios';
|
||||
|
||||
@translate()
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class Output extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page'
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import axios from '../lib/axios';
|
||||
import { ReportState } from '../../../shared/reports';
|
||||
|
@ -10,6 +10,7 @@ import { ReportState } from '../../../shared/reports';
|
|||
@translate()
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class View extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
|
@ -5,13 +5,15 @@ import ReactDOM from 'react-dom';
|
|||
import { I18nextProvider } from 'react-i18next';
|
||||
import i18n from '../lib/i18n';
|
||||
|
||||
import { Section } from '../lib/page'
|
||||
import ReportsCUD from './CUD'
|
||||
import ReportsList from './List'
|
||||
import ReportsView from './View'
|
||||
import ReportsOutput from './Output'
|
||||
import ReportTemplatesCUD from './templates/CUD'
|
||||
import ReportTemplatesList from './templates/List'
|
||||
import { Section } from '../lib/page';
|
||||
import ReportsCUD from './CUD';
|
||||
import ReportsList from './List';
|
||||
import ReportsView from './View';
|
||||
import ReportsOutput from './Output';
|
||||
import ReportTemplatesCUD from './templates/CUD';
|
||||
import ReportTemplatesList from './templates/List';
|
||||
import Share from '../shares/Share';
|
||||
|
||||
|
||||
const getStructure = t => {
|
||||
const subPaths = {};
|
||||
|
@ -59,11 +61,16 @@ const getStructure = t => {
|
|||
title: t('Create Report Template'),
|
||||
params: [':wizard?'],
|
||||
render: props => (<ReportTemplatesCUD {...props} />)
|
||||
},
|
||||
share: {
|
||||
title: t('Share Report Template'),
|
||||
params: [':id'],
|
||||
render: props => (<Share title={entity => t('Share Report Template "{{name}}"', {name: entity.name})} getUrl={id => `/rest/report-templates/${id}`} entityTypeId="reportTemplate" {...props} />)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate, Trans } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../../lib/page'
|
||||
import { withForm, Form, FormSendMethod, InputField, TextArea, Dropdown, ACEEditor, ButtonRow, Button } from '../../lib/form';
|
||||
|
@ -25,6 +26,10 @@ export default class CUD extends Component {
|
|||
this.initForm();
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
edit: PropTypes.bool
|
||||
}
|
||||
|
||||
isDelete() {
|
||||
return this.props.match.params.action === 'delete';
|
||||
}
|
||||
|
|
|
@ -3,12 +3,18 @@
|
|||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { DropdownMenu } from '../../lib/bootstrap-components';
|
||||
import { Title, Toolbar, DropdownLink } from '../../lib/page';
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title, Toolbar, DropdownLink } from '../../lib/page';
|
||||
import { Table } from '../../lib/table';
|
||||
import moment from 'moment';
|
||||
|
||||
@translate()
|
||||
@withPageHelpers
|
||||
@requiresAuthenticatedUser
|
||||
export default class List extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
|
@ -16,6 +22,10 @@ export default class List extends Component {
|
|||
{
|
||||
label: 'Edit',
|
||||
link: '/reports/templates/edit/' + data[0]
|
||||
},
|
||||
{
|
||||
label: 'Share',
|
||||
link: '/reports/templates/share/' + data[0]
|
||||
}
|
||||
];
|
||||
|
||||
|
|
179
client/src/shares/Share.js
Normal file
179
client/src/shares/Share.js
Normal file
|
@ -0,0 +1,179 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate } from 'react-i18next';
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import {
|
||||
withForm, Form, FormSendMethod, TableSelect, ButtonRow, Button
|
||||
} from '../lib/form';
|
||||
import { Table } from '../lib/table';
|
||||
import axios from '../lib/axios';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
@translate()
|
||||
@withForm
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class Share extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
entityId: parseInt(props.match.params.id)
|
||||
};
|
||||
|
||||
this.initForm();
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
title: PropTypes.func,
|
||||
getUrl: PropTypes.func,
|
||||
entityTypeId: PropTypes.string
|
||||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async loadEntity() {
|
||||
const response = await axios.get(this.props.getUrl(this.state.entityId));
|
||||
this.setState({
|
||||
entity: response.data
|
||||
});
|
||||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async deleteShare(userId) {
|
||||
const data = {
|
||||
entityTypeId: this.props.entityTypeId,
|
||||
entityId: this.state.entityId,
|
||||
userId
|
||||
};
|
||||
|
||||
await axios.put('/rest/shares', data);
|
||||
this.sharesTable.refresh();
|
||||
this.usersTableSelect.refresh();
|
||||
}
|
||||
|
||||
clearShareFields() {
|
||||
this.populateFormValues({
|
||||
entityTypeId: this.props.entityTypeId,
|
||||
entityId: this.state.entityId,
|
||||
userId: null,
|
||||
role: null
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadEntity();
|
||||
this.clearShareFields();
|
||||
}
|
||||
|
||||
localValidateFormValues(state) {
|
||||
const t = this.props.t;
|
||||
|
||||
if (!state.getIn(['userId', 'value'])) {
|
||||
state.setIn(['userId', 'error'], t('User must not be empty'));
|
||||
} else {
|
||||
state.setIn(['userId', 'error'], null);
|
||||
}
|
||||
|
||||
if (!state.getIn(['role', 'value'])) {
|
||||
state.setIn(['role', 'error'], t('Role must be selected'));
|
||||
} else {
|
||||
state.setIn(['role', 'error'], null);
|
||||
}
|
||||
}
|
||||
|
||||
async submitHandler() {
|
||||
const t = this.props.t;
|
||||
|
||||
this.disableForm();
|
||||
this.setFormStatusMessage('info', t('Saving ...'));
|
||||
|
||||
const submitSuccessful = await this.validateAndSendFormValuesToURL(FormSendMethod.PUT, '/rest/shares');
|
||||
|
||||
if (submitSuccessful) {
|
||||
this.hideFormValidation();
|
||||
this.clearShareFields();
|
||||
this.enableForm();
|
||||
|
||||
this.clearFormStatusMessage();
|
||||
this.sharesTable.refresh();
|
||||
this.usersTableSelect.refresh();
|
||||
|
||||
} else {
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('warning', t('There are errors in the form. Please fix them and try again.'));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
const roles = mailtrainConfig.roles[this.props.entityTypeId];
|
||||
|
||||
const actions = data => [
|
||||
{
|
||||
label: 'Delete',
|
||||
action: () => this.deleteShare(data[4])
|
||||
}
|
||||
];
|
||||
|
||||
const sharesColumns = [
|
||||
{ data: 1, title: t('Username') },
|
||||
{ data: 2, title: t('Name') },
|
||||
{ data: 3, title: t('Role'), render: data => roles[data] ? roles[data].name : data }
|
||||
];
|
||||
|
||||
|
||||
let usersLabelIndex = 1;
|
||||
const usersColumns = [
|
||||
{ data: 0, title: "#" },
|
||||
{ data: 1, title: "Username" },
|
||||
];
|
||||
|
||||
if (mailtrainConfig.isAuthMethodLocal) {
|
||||
usersColumns.push({ data: 2, title: "Full Name" });
|
||||
usersLabelIndex = 2;
|
||||
}
|
||||
|
||||
|
||||
const rolesColumns = [
|
||||
{ data: 1, title: "Name" },
|
||||
{ data: 2, title: "Description" },
|
||||
];
|
||||
|
||||
|
||||
const rolesData = [];
|
||||
for (const key in roles) {
|
||||
const role = roles[key];
|
||||
rolesData.push([ key, role.name, role.description ]);
|
||||
}
|
||||
|
||||
|
||||
if (this.state.entity) {
|
||||
return (
|
||||
<div>
|
||||
<Title>{this.props.title(this.state.entity)}</Title>
|
||||
|
||||
<h3 className="legend">{t('Add User')}</h3>
|
||||
<Form stateOwner={this} onSubmitAsync={::this.submitHandler}>
|
||||
<TableSelect ref={node => this.usersTableSelect = node} id="userId" label={t('User')} withHeader dropdown dataUrl={`/rest/shares-users-table/${this.props.entityTypeId}/${this.state.entityId}`} columns={usersColumns} selectionLabelIndex={usersLabelIndex}/>
|
||||
<TableSelect id="role" label={t('Role')} withHeader dropdown data={rolesData} columns={rolesColumns} selectionLabelIndex={1}/>
|
||||
|
||||
<ButtonRow>
|
||||
<Button type="submit" className="btn-primary" icon="ok" label={t('Share')}/>
|
||||
</ButtonRow>
|
||||
</Form>
|
||||
|
||||
<hr/>
|
||||
<h3 className="legend">{t('Existing Users')}</h3>
|
||||
|
||||
<Table ref={node => this.sharesTable = node} withHeader dataUrl={`/rest/shares-table/${this.props.entityTypeId}/${this.state.entityId}`} columns={sharesColumns} actions={actions}/>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (<p>{t('Loading ...')}</p>)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title } from '../lib/page';
|
||||
import { withForm, Form, FormSendMethod, InputField, ButtonRow, Button } from '../lib/form';
|
||||
import axios from '../lib/axios';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
|
@ -16,6 +17,7 @@ import mailtrainConfig from 'mailtrainConfig';
|
|||
@withForm
|
||||
@withPageHelpers
|
||||
@withErrorHandling
|
||||
@requiresAuthenticatedUser
|
||||
export default class CUD extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -37,6 +39,10 @@ export default class CUD extends Component {
|
|||
});
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
edit: PropTypes.bool
|
||||
}
|
||||
|
||||
isDelete() {
|
||||
return this.props.match.params.action === 'delete';
|
||||
}
|
||||
|
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { requiresAuthenticatedUser, withPageHelpers, Title, Toolbar, NavButton } from '../lib/page';
|
||||
import { Table } from '../lib/table';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
@translate()
|
||||
@withPageHelpers
|
||||
@requiresAuthenticatedUser
|
||||
export default class List extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ import ReactDOM from 'react-dom';
|
|||
import { I18nextProvider } from 'react-i18next';
|
||||
import i18n from '../lib/i18n';
|
||||
|
||||
import { Section } from '../lib/page'
|
||||
import CUD from './CUD'
|
||||
import List from './List'
|
||||
import { Section } from '../lib/page';
|
||||
import CUD from './CUD';
|
||||
import List from './List';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
const getStructure = t => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue