Configuration submitted on import

This commit is contained in:
VakarisZ 2019-05-09 11:22:19 +03:00
parent 576af97a82
commit 30a55d562a
1 changed files with 24 additions and 17 deletions

View File

@ -74,19 +74,7 @@ class ConfigurePageComponent extends AuthComponent {
onSubmit = ({formData}) => { onSubmit = ({formData}) => {
this.currentFormData = formData; this.currentFormData = formData;
this.updateConfigSection(); this.updateConfigSection();
this.authFetch('/api/configuration/island', this.sendConfig()
{
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(this.state.configuration)
})
.then(res => {
if (!res.ok)
{
throw Error()
}
return res;
})
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
this.setState({ this.setState({
@ -162,7 +150,7 @@ class ConfigurePageComponent extends AuthComponent {
configuration: JSON.parse(event.target.result), configuration: JSON.parse(event.target.result),
selectedSection: 'basic', selectedSection: 'basic',
lastAction: 'import_success' lastAction: 'import_success'
}); }, () => {this.sendConfig()});
this.currentSection = 'basic'; this.currentSection = 'basic';
this.currentFormData = {}; this.currentFormData = {};
} catch(SyntaxError) { } catch(SyntaxError) {
@ -175,6 +163,26 @@ class ConfigurePageComponent extends AuthComponent {
fileDownload(JSON.stringify(this.state.configuration, null, 2), 'monkey.conf'); fileDownload(JSON.stringify(this.state.configuration, null, 2), 'monkey.conf');
}; };
sendConfig() {
return (
this.authFetch('/api/configuration/island',
{
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(this.state.configuration)
})
.then(res => {
if (!res.ok)
{
throw Error()
}
return res;
}).catch(error => {
console.log('bad configuration');
this.setState({lastAction: 'invalid_configuration'});
}));
};
importConfig = (event) => { importConfig = (event) => {
let reader = new FileReader(); let reader = new FileReader();
reader.onload = this.onReadFile; reader.onload = this.onReadFile;
@ -251,13 +259,12 @@ class ConfigurePageComponent extends AuthComponent {
} }
static getFullPBAfile(filename){ static getFullPBAfile(filename){
let pbaFile = [{ return [{
source: filename, source: filename,
options: { options: {
type: 'limbo' type: 'limbo'
} }
}]; }];
return pbaFile
} }
static getMockPBAfile(mockFile){ static getMockPBAfile(mockFile){
@ -355,7 +362,7 @@ class ConfigurePageComponent extends AuthComponent {
{ this.state.lastAction === 'invalid_configuration' ? { this.state.lastAction === 'invalid_configuration' ?
<div className="alert alert-danger"> <div className="alert alert-danger">
<i className="glyphicon glyphicon-exclamation-sign" style={{'marginRight': '5px'}}/> <i className="glyphicon glyphicon-exclamation-sign" style={{'marginRight': '5px'}}/>
An invalid configuration file was imported and submitted, probably outdated. An invalid configuration file was imported or submitted.
</div> </div>
: ''} : ''}
{ this.state.lastAction === 'import_success' ? { this.state.lastAction === 'import_success' ?