diff --git a/src/file/edit-file-content.js b/src/file/edit-file-content.js new file mode 100644 index 0000000..34a142e --- /dev/null +++ b/src/file/edit-file-content.js @@ -0,0 +1,82 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import {FormGroup, FormControl, Button, Col} from 'react-bootstrap'; +import AppDispatcher from "../common/app-dispatcher"; +import Dialog from '../common/dialogs/dialog'; + +class EditFileContent extends React.Component { + valid = true; + + constructor(props) { + super(props); + + this.state = { + uploadFile: null, + + }; + } + + selectUploadFile(event) { + this.setState({ uploadFile: event.target.files[0] }); + }; + + startEditContent(){ + const formData = new FormData(); + formData.append("file", this.state.uploadFile); + + AppDispatcher.dispatch({ + type: 'files/start-edit', + data: formData, + token: this.props.sessionToken, + id: this.props.file.id + }); + + this.setState({ uploadFile: null }); + }; + + + onClose = () => { + this.props.onClose(); + }; + + + + + render() { + return this.onClose()} blendOutCancel = {true} valid={true}> + + this.selectUploadFile(event)} /> + + + + + + + ; + } +} + +export default EditFileContent; diff --git a/src/file/edit-file-name.js b/src/file/edit-file-name.js deleted file mode 100644 index 05481b3..0000000 --- a/src/file/edit-file-name.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * This file is part of VILLASweb. - * - * VILLASweb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * VILLASweb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with VILLASweb. If not, see . - ******************************************************************************/ - -import React from 'react'; -import {FormGroup, FormControl, FormLabel, Col} from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; - -class EditFileName extends React.Component { - valid = true; - - constructor(props) { - super(props); - - this.state = { - file: {}, - - }; - } - - onClose = canceled => { - if (canceled) { - if (this.props.onClose != null) { - this.props.onClose(); - } - - return; - } - - if (this.valid && this.props.onClose != null) { - this.props.onClose(this.state.file); - } - }; - - handleChange = event => { - this.props.file.name = event.target.value; - this.setState({file: this.props.file}); - - let name = true; - - if (this.state.name === '') { - name = false; - } - - this.valid = name; - - }; - - - - render() { - return this.onClose(c)} valid={true}> -
- - Name - - - - -
-
; - } -} - -export default EditFileName; diff --git a/src/file/edit-files.js b/src/file/edit-files.js index 3e2e003..8cc3421 100644 --- a/src/file/edit-files.js +++ b/src/file/edit-files.js @@ -21,7 +21,7 @@ import Dialog from '../common/dialogs/dialog'; import AppDispatcher from "../common/app-dispatcher"; import Table from "../common/table"; import TableColumn from "../common/table-column"; -import EditFileName from "./edit-file-name"; +import EditFileContent from "./edit-file-content"; class EditFilesDialog extends React.Component { @@ -39,14 +39,9 @@ class EditFilesDialog extends React.Component { }; } - onClose(canceled) { - if (canceled === false) { - if (true) { - this.props.onClose(); - } - } else { - this.props.onClose(); - } + onClose() { + + this.props.onClose(); } selectUploadFile(event) { @@ -87,18 +82,7 @@ class EditFilesDialog extends React.Component { }; - closeEditModal(data){ - if(data !== {} || data !== "undefined"){ - const formData = new FormData(); - formData.append("object", data); - - AppDispatcher.dispatch({ - type: 'files/start-edit', - data: formData, - token: this.props.sessionToken, - id: data.id - }); - } + closeEditModal(){ this.setState({editModal: false}); } @@ -135,7 +119,7 @@ class EditFilesDialog extends React.Component { return ( - this.onClose(c)} blendOutCancel = {true} valid={true} size = 'lg'> + this.onClose()} blendOutCancel = {true} valid={true} size = 'lg'>
@@ -178,7 +162,7 @@ class EditFilesDialog extends React.Component {
- this.closeEditModal(data)} file={this.state.modalFile} /> + this.closeEditModal(data)} sessionToken={this.props.sessionToken} file={this.state.modalFile} />
diff --git a/src/file/file-store.js b/src/file/file-store.js index ae6779d..306c2d6 100644 --- a/src/file/file-store.js +++ b/src/file/file-store.js @@ -67,7 +67,17 @@ class FileStore extends ArrayStore { case 'files/downloaded': // in this case a file is contained in the response (no JSON) - return this.saveFile(state, action) + return this.saveFile(state, action); + + case 'files/start-edit': + FilesDataManager.update(action.data, action.token, action.id); + return state; + + case 'files/edited': + return this.updateElements(state, [action.data]); + + case this.type + '/edit-error': + return state; default: return super.reduce(state, action); diff --git a/src/file/files-data-manager.js b/src/file/files-data-manager.js index cc5cf4b..b03f27a 100644 --- a/src/file/files-data-manager.js +++ b/src/file/files-data-manager.js @@ -65,6 +65,21 @@ class FilesDataManager extends RestDataManager { }); }); } + + update(file, token, id) { + + RestAPI.put(this.makeURL(this.url + '/' + id), file, token).then(response => { + AppDispatcher.dispatch({ + type: this.type + 's/edited', + data: response[this.type] + }); + }).catch(error => { + AppDispatcher.dispatch({ + type: this.type + 's/edit-error', + error: error + }); + }); + } } export default new FilesDataManager(); diff --git a/src/scenario/scenario.js b/src/scenario/scenario.js index d9ba88f..2789de9 100644 --- a/src/scenario/scenario.js +++ b/src/scenario/scenario.js @@ -56,7 +56,6 @@ class Scenario extends React.Component { if (prevState == null) { prevState = {}; } - // get selected scenario const sessionToken = localStorage.getItem("token"); @@ -74,6 +73,16 @@ class Scenario extends React.Component { // obtain all component configurations of a scenario let configs = ConfigStore.getState().filter(config => config.scenarioID === parseInt(props.match.params.scenario, 10)); + let editConfigModal = prevState.editConfigModal || false; + let modalConfigData = (prevState.modalConfigData !== {} && prevState.modalConfigData !== undefined )? prevState.modalConfigData : {}; + let modalConfigIndex = 0; + + if((typeof prevState.configs !== "undefined") && (prevState.newConfig === true ) && (configs.length !== prevState.configs.length)){ + let index = configs.length -1; + editConfigModal = true; + modalConfigData = configs[index]; + modalConfigIndex = index; + } // obtain all files of a scenario let files = FileStore.getState().filter(file => file.scenarioID === parseInt(props.match.params.scenario, 10)); @@ -90,14 +99,15 @@ class Scenario extends React.Component { signals, currentUser, files, + editConfigModal, + modalConfigData, + modalConfigIndex, ics: ICStore.getState(), deleteConfigModal: false, importConfigModal: false, - editConfigModal: prevState.editConfigModal || false, - modalConfigData: (prevState.modalConfigData !== {} && prevState.modalConfigData !== undefined )? prevState.modalConfigData : {}, + newConfig: prevState.newConfig || false, selectedConfigs: [], - modalConfigIndex: 0, filesEditModal: prevState.filesEditModal || false, filesEditSaveState: prevState.filesEditSaveState || [], @@ -200,10 +210,12 @@ class Scenario extends React.Component { token: this.state.sessionToken }); + this.setState({newConfig: true}); + } closeEditConfigModal(data) { - this.setState({ editConfigModal: false }); + this.setState({ editConfigModal: false, newConfig: false }); if (data) { AppDispatcher.dispatch({ diff --git a/src/widget/widgets/image.js b/src/widget/widgets/image.js index 1f08fa3..d931cb2 100644 --- a/src/widget/widgets/image.js +++ b/src/widget/widgets/image.js @@ -26,6 +26,7 @@ class WidgetImage extends React.Component { this.state = { file: undefined, + fileDate: null } } @@ -45,8 +46,9 @@ class WidgetImage extends React.Component { let file = this.props.files.find(file => file.id === parseInt(this.props.widget.customProperties.file, 10)); + if (file !== undefined) { - if (this.state.file === undefined || (this.state.file.id !== file.id)) { + if (this.state.file === undefined || (this.state.file.id !== file.id) || this.state.fileDate !== file.date) { AppDispatcher.dispatch({ type: 'files/start-download', @@ -54,7 +56,7 @@ class WidgetImage extends React.Component { token: this.props.token }); - this.setState({ file: file }) + this.setState({ file: file, fileDate: file.date }); } } @@ -65,7 +67,6 @@ class WidgetImage extends React.Component { } render() { - let objectURL='' if(this.state.file !== undefined && this.state.file.objectURL !== undefined) { objectURL = this.state.file.objectURL