2018-06-19 17:46:34 +00:00
|
|
|
import {Component, EventEmitter, Inject, Output} from 'ng-metadata/core';
|
2018-06-12 15:28:58 +00:00
|
|
|
const templateUrl = require('./load-config.html');
|
2018-06-15 19:42:10 +00:00
|
|
|
const styleUrl = require('./load-config.css');
|
|
|
|
|
2018-06-12 15:28:58 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'load-config',
|
|
|
|
templateUrl,
|
2018-06-15 19:42:10 +00:00
|
|
|
styleUrls: [ styleUrl ],
|
2018-06-12 15:28:58 +00:00
|
|
|
})
|
|
|
|
export class LoadConfigComponent {
|
2018-06-18 20:01:30 +00:00
|
|
|
private readyToSubmit: boolean = false;
|
2018-06-15 19:42:10 +00:00
|
|
|
private uploadFunc: Function;
|
2018-06-19 17:46:34 +00:00
|
|
|
@Output() public configLoaded: EventEmitter<any> = new EventEmitter();
|
2018-06-15 19:42:10 +00:00
|
|
|
|
|
|
|
private constructor(@Inject('ApiService') private apiService: any) {
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleTarballSelected(files: File[], callback: Function) {
|
2018-06-18 20:01:30 +00:00
|
|
|
this.readyToSubmit = true;
|
2018-06-15 19:42:10 +00:00
|
|
|
callback(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleTarballCleared() {
|
2018-06-18 20:01:30 +00:00
|
|
|
this.readyToSubmit = false;
|
2018-06-15 19:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private uploadTarball() {
|
2018-06-18 15:01:14 +00:00
|
|
|
this.uploadFunc(success => {
|
|
|
|
if (success) {
|
2018-06-19 17:46:34 +00:00
|
|
|
this.configLoaded.emit({});
|
|
|
|
} else {
|
2018-06-18 20:01:30 +00:00
|
|
|
this.apiService.errorDisplay('Error loading configuration',
|
|
|
|
'Could not upload configuration. Please reload the page and try again.\n' +
|
2018-06-18 15:01:14 +00:00
|
|
|
'If this problem persists, please contact support')();
|
|
|
|
}
|
2018-06-14 21:18:58 +00:00
|
|
|
});
|
2018-06-12 15:28:58 +00:00
|
|
|
}
|
2018-06-15 19:42:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When files are validated, this is called by the child to give us
|
|
|
|
* the callback function to upload
|
|
|
|
* @param files: files to upload
|
|
|
|
* @param uploadFiles: function to call to upload files
|
|
|
|
*/
|
2018-06-18 20:01:30 +00:00
|
|
|
private tarballValidatedByUploadBox(files, uploadFiles) {
|
2018-06-15 19:42:10 +00:00
|
|
|
this.uploadFunc = uploadFiles;
|
|
|
|
}
|
2018-06-12 15:28:58 +00:00
|
|
|
}
|