2018-07-03 13:06:54 -04:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Inject,
|
|
|
|
Output,
|
|
|
|
} from 'ng-metadata/core';
|
|
|
|
const templateUrl = require('./load-config.component.html');
|
2018-06-15 15:42:10 -04:00
|
|
|
|
2018-06-22 13:21:44 -04:00
|
|
|
declare var bootbox: any;
|
|
|
|
|
2018-06-12 11:28:58 -04:00
|
|
|
@Component({
|
|
|
|
selector: 'load-config',
|
|
|
|
templateUrl,
|
|
|
|
})
|
|
|
|
export class LoadConfigComponent {
|
2018-06-18 16:01:30 -04:00
|
|
|
private readyToSubmit: boolean = false;
|
2018-06-15 15:42:10 -04:00
|
|
|
private uploadFunc: Function;
|
2018-06-19 13:46:34 -04:00
|
|
|
@Output() public configLoaded: EventEmitter<any> = new EventEmitter();
|
2018-06-15 15:42:10 -04:00
|
|
|
|
|
|
|
private handleTarballSelected(files: File[], callback: Function) {
|
2018-06-18 16:01:30 -04:00
|
|
|
this.readyToSubmit = true;
|
2018-06-15 15:42:10 -04:00
|
|
|
callback(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleTarballCleared() {
|
2018-06-18 16:01:30 -04:00
|
|
|
this.readyToSubmit = false;
|
2018-06-15 15:42:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private uploadTarball() {
|
2018-06-18 11:01:14 -04:00
|
|
|
this.uploadFunc(success => {
|
|
|
|
if (success) {
|
2018-06-19 13:46:34 -04:00
|
|
|
this.configLoaded.emit({});
|
|
|
|
} else {
|
2018-06-22 13:21:44 -04: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 11:01:14 -04:00
|
|
|
}
|
2018-06-14 17:18:58 -04:00
|
|
|
});
|
2018-06-12 11:28:58 -04:00
|
|
|
}
|
2018-06-15 15:42:10 -04: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 16:01:30 -04:00
|
|
|
private tarballValidatedByUploadBox(files, uploadFiles) {
|
2018-06-15 15:42:10 -04:00
|
|
|
this.uploadFunc = uploadFiles;
|
|
|
|
}
|
2018-06-12 11:28:58 -04:00
|
|
|
}
|