- }
-
- render() {
- return (
- <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false} >
- <Modal.Header closeButton>
- <Modal.Title>Manage Dictionaries</Modal.Title>
- </Modal.Header>
- <Modal.Body>
- {!this.state.dictNameFlag? <MaterialTable
- title={"Dictionary List"}
- data={this.state.dictionaryNames}
- columns={this.state.dictColumns}
- icons={this.state.tableIcons}
- onRowClick={(event, rowData) => {this.getDictionaryElements(rowData.name);this.setState({dictNameFlag: true, exportFilename: rowData.name, dictionaryName: rowData.name})}}
- options={{
- headerStyle: rowHeaderStyle,
- }}
- editable={{
- onRowAdd: newData =>
- new Promise((resolve, reject) => {
- setTimeout(() => {
- {
- const dictionaryNames = this.state.dictionaryNames;
- var validData = true;
- if(/[^a-zA-Z0-9-_.]/.test(newData.name)) {
- validData = false;
- alert('Please enter alphanumberic input. Only allowed special characters are:(period, hyphen, underscore)');
- }
- for (var i = 0; i < this.state.dictionaryNames.length; i++) {
- if (this.state.dictionaryNames[i].name === newData.name) {
- validData = false;
- alert(newData.name + ' dictionary name already exists')
- }
- }
- if(validData){
- dictionaryNames.push(newData);
- this.setState({ dictionaryNames }, () => resolve());
- this.setState({addDict: true, newDict: newData});
- }
- }
- resolve();
- }, 1000);
- }),
- onRowUpdate: (newData, oldData) =>
- new Promise((resolve, reject) => {
- setTimeout(() => {
- {
- const dictionaryNames = this.state.dictionaryNames;
- var validData = true;
- if(/[^a-zA-Z0-9-_.]/.test(newData.name)) {
- validData = false;
- alert('Please enter alphanumberic input. Only allowed special characters are:(period, hyphen, underscore)');
- }
- if(validData){
- const index = dictionaryNames.indexOf(oldData);
- dictionaryNames[index] = newData;
- this.setState({ dictionaryNames }, () => resolve());
- this.setState({addDict: true, newDict: newData});
- }
- }
- resolve();
- }, 1000);
- }),
- onRowDelete: oldData =>
- new Promise((resolve, reject) => {
- setTimeout(() => {
- {
- let data = this.state.dictionaryNames;
- const index = data.indexOf(oldData);
- data.splice(index, 1);
- this.setState({ data }, () => resolve());
- this.setState({delDict: true, delData: oldData})
- }
- resolve()
- }, 1000)
- })
- }}
- />:""
+ addDictionaryRow(newData) {
+ let validData = true;
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ if (/[^a-zA-Z0-9-_.]/.test(newData.name)) {
+ validData = false;
+ alert('Please enter alphanumeric input. Only allowed special characters are:(period, hyphen, underscore)');
+ reject(() => {});
+ }
+ for (let i = 0; i < this.state.dictionaries.length; i++) {
+ if (this.state.dictionaries[i].name === newData.name) {
+ validData = false;
+ alert(newData.name + ' dictionary name already exists')
+ reject(() => {});
+ }
+ }
+ if (validData) {
+ this.addReplaceDictionaryRequest(newData);
+ }
+ resolve();
+ }, 1000);
+ });
+ }
+
+
+ updateDictionaryRow(oldData, newData) {
+ let validData = true;
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ if (/[^a-zA-Z0-9-_.]/.test(newData.name)) {
+ validData = false;
+ alert('Please enter alphanumberic input. Only allowed special characters are:(period, hyphen, underscore)');
+ }
+ if (validData) {
+ this.addReplaceDictionaryRequest(newData);
+ }
+ resolve();
+ }, 1000);
+ });
+ }
+
+ deleteDictionaryRow(oldData) {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ this.deleteDictionaryRequest(oldData.name);
+ resolve();
+ }, 1000);
+ });
+ }
+
+ addDictionaryElementRow(newData) {
+ return new Promise((resolve, reject) => {
+ setTimeout(() => {
+ let dictionaryElements = this.state.dictionaryElements;
+ let errorMessage = '';
+ for (let i = 0; i < this.state.dictionaryElements.length; i++) {
+ if (this.state.dictionaryElements[i].shortName === newData.shortName) {
+ alert('Short Name "' + newData.shortName + '" already exists');
+ reject(() => {});
+ }
+ }
+ if (newData.shortName !== '' && /[^a-zA-Z0-9-_.]/.test(newData.shortName)) {
+ errorMessage += '\nShort Name is limited to alphanumeric characters and also period, hyphen, and underscore';
+ }
+ if (!newData.shortName){
+ errorMessage += '\nShort Name must be specified';
+ }
+ if (!newData.name){
+ errorMessage += '\nElement Name must be specified';
+ }
+ if (!newData.type){
+ errorMessage += '\nElement Type must be specified';
+ }
+ if (!newData.description){
+ errorMessage += '\nElement Description must be specified';
+ }
+ if (errorMessage === '') {
+ dictionaryElements.push(newData);
+ this.updateDictionaryElementsRequest(dictionaryElements);
+ resolve();
+ } else {
+ alert(errorMessage);
+ reject(() => {});
+ }
+ }, 1000);
+ });
+ }
+
+ updateDictionaryElementRow(newData, oldData) {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ let dictionaryElements = this.state.dictionaryElements;
+ let validData = true;
+ if (!newData.type) {
+ validData = false;
+ alert('Element Type cannot be null');
+ }
+ if (validData) {
+ const index = dictionaryElements.indexOf(oldData);
+ dictionaryElements[index] = newData;
+ this.updateDictionaryElementsRequest(dictionaryElements);
+ }
+ resolve();
+ }, 1000);
+ });
+ }
+
+
+ deleteDictionaryElementRow(oldData) {
+ return new Promise((resolve) => {
+ setTimeout(() => {
+ this.deleteDictionaryElementRequest(this.state.currentSelectedDictionary, oldData.shortName);
+ resolve();
+ }, 1000);
+ });
+ }
+
+ render() {
+ return (
+ <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false} >
+ <Modal.Header closeButton>
+ <Modal.Title>Manage Dictionaries</Modal.Title>
+ </Modal.Header>
+ <Modal.Body>
+ {this.state.currentSelectedDictionary === null ? <MaterialTable
+ title={"Dictionary List"}
+ data={this.state.dictionaries}
+ columns={this.state.dictColumns}
+ icons={this.state.tableIcons}
+ onRowClick={(event, rowData) => {
+ this.setState({
+ currentSelectedDictionary : rowData.name,
+ exportFilename: rowData.name
+ })
+ this.getDictionaryElements(rowData.name);
+ }}
+ options={{
+ headerStyle: rowHeaderStyle,
+ }}
+ editable={{
+ onRowAdd: this.addDictionaryRow,
+ onRowUpdate: this.updateDictionaryRow,
+ onRowDelete: this.deleteDictionaryRow
+ }}
+ /> : null