2018-07-03 17:06:54 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Inject,
|
|
|
|
Output,
|
|
|
|
} from 'ng-metadata/core';
|
|
|
|
const templateUrl = require('./load-config.component.html');
|
2018-06-15 19:42:10 +00:00
|
|
|
|
2018-06-22 17:21:44 +00:00
|
|
|
declare var bootbox: any;
|
|
|
|
|
2018-06-12 15:28:58 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'load-config',
|
|
|
|
templateUrl,
|
|
|
|
})
|
|
|
|
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 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-22 17:21:44 +00:00
|
|
|
bootbox.dialog({
|
|
|
|
"message": 'Could not upload configuration. Please check you have provided a valid tar file' +
|
|
|
|
'If this problem persists, please contact support',
|
|
|
|
"title": 'Error Loading Configuration',
|
|
|
|
"buttons": {
|
|
|
|
"close": {
|
|
|
|
"label": "Close",
|
|
|
|
"className": "btn-primary"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2018-06-18 15:01:14 +00:00
|
|
|
}
|
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
|
|
|
}
|