1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

authenticated upload

This commit is contained in:
Ricardo Hernandez-Montoya 2017-05-08 12:24:52 +02:00
parent e2be97dcd3
commit e0c5ffbd8f
4 changed files with 14 additions and 8 deletions

View file

@ -35,6 +35,7 @@ import EditWidgetOrientation from './edit-widget-orientation';
class EditWidgetDialog extends Component {
static propTypes = {
sessionToken: PropTypes.string.isRequired,
show: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired
};
@ -109,7 +110,7 @@ class EditWidgetDialog extends Component {
)
} else if (this.props.widget.type === 'Image') {
dialogControls.push(
<EditImageWidgetControl key={1} widget={this.state.temporal} files={this.props.files} validate={(id) => this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />
<EditImageWidgetControl key={1} sessionToken={this.props.sessionToken} widget={this.state.temporal} files={this.props.files} validate={(id) => this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />
)
} else if (this.props.widget.type === 'Gauge') {
dialogControls.push(

View file

@ -30,6 +30,7 @@ import Dropzone from '../components/dropzone';
import Widget from './widget';
import EditWidget from '../components/dialog/edit-widget';
import UserStore from '../stores/user-store';
import VisualizationStore from '../stores/visualization-store';
import ProjectStore from '../stores/project-store';
import SimulationStore from '../stores/simulation-store';
@ -40,7 +41,7 @@ import NotificationsFactory from '../data-managers/notifications-factory';
class Visualization extends Component {
static getStores() {
return [ VisualizationStore, ProjectStore, SimulationStore, FileStore ];
return [ VisualizationStore, ProjectStore, SimulationStore, FileStore, UserStore ];
}
static calculateState(prevState) {
@ -49,6 +50,7 @@ class Visualization extends Component {
}
return {
sessionToken: UserStore.getState().token,
visualizations: VisualizationStore.getState(),
projects: ProjectStore.getState(),
simulations: SimulationStore.getState(),
@ -384,7 +386,7 @@ class Visualization extends Component {
</ContextMenu>
))}
<EditWidget show={this.state.editModal} onClose={(data) => this.closeEdit(data)} widget={this.state.modalData} simulation={this.state.simulation} files={this.state.files} />
<EditWidget sessionToken={this.state.sessionToken} show={this.state.editModal} onClose={(data) => this.closeEdit(data)} widget={this.state.modalData} simulation={this.state.simulation} files={this.state.files} />
</div>
</div>
);

View file

@ -28,13 +28,16 @@ class FilesDataManager extends RestDataManager {
super('file', '/files');
}
upload(file) {
RestAPI.upload(this.makeURL('/upload'), file).then(response => {
upload(file, token = null) {
RestAPI.upload(this.makeURL('/upload'), file, token).then(response => {
AppDispatcher.dispatch({
type: 'files/uploaded'
});
console.log(response);
// Trigger a files reload
AppDispatcher.dispatch({
type: 'files/start-load',
token: token
});
}).catch(error => {
AppDispatcher.dispatch({
type: 'files/upload-error',

View file

@ -30,7 +30,7 @@ class FileStore extends ArrayStore {
reduce(state, action) {
switch (action.type) {
case 'files/start-upload':
FilesDataManager.upload(action.data);
FilesDataManager.upload(action.data, action.token);
return state;
case 'files/uploaded':