49 lines
No EOL
1.4 KiB
TypeScript
49 lines
No EOL
1.4 KiB
TypeScript
import { Component, Inject } from 'ng-metadata/core';
|
|
const templateUrl = require('./load-config.html');
|
|
const styleUrl = require('./load-config.css');
|
|
|
|
@Component({
|
|
selector: 'load-config',
|
|
templateUrl,
|
|
styleUrls: [ styleUrl ],
|
|
})
|
|
export class LoadConfigComponent {
|
|
private readyToSubmit: boolean = false;
|
|
private uploadFunc: Function;
|
|
private state: 'load' | 'validate' = 'load';
|
|
|
|
private constructor(@Inject('ApiService') private apiService: any) {
|
|
}
|
|
|
|
private handleTarballSelected(files: File[], callback: Function) {
|
|
this.readyToSubmit = true;
|
|
callback(true)
|
|
}
|
|
|
|
private handleTarballCleared() {
|
|
this.readyToSubmit = false;
|
|
}
|
|
|
|
private uploadTarball() {
|
|
this.uploadFunc(success => {
|
|
if (success) {
|
|
this.state = 'validate';
|
|
}
|
|
else {
|
|
this.apiService.errorDisplay('Error loading configuration',
|
|
'Could not upload configuration. Please reload the page and try again.\n' +
|
|
'If this problem persists, please contact support')();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
private tarballValidatedByUploadBox(files, uploadFiles) {
|
|
this.uploadFunc = uploadFiles;
|
|
}
|
|
} |