mirror of https://github.com/portainer/portainer
refactor(agent): refactor file-uploader to es6 (#4087)
* refactor(host): convert fileUploader to es6 * refactor(agent): rename main filepull/4098/head
parent
5abd35d4c1
commit
435f15ec6a
|
@ -1,23 +0,0 @@
|
||||||
angular.module('portainer.agent').controller('FileUploaderController', [
|
|
||||||
'$q',
|
|
||||||
function FileUploaderController($q) {
|
|
||||||
var ctrl = this;
|
|
||||||
|
|
||||||
ctrl.state = {
|
|
||||||
uploadInProgress: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
ctrl.onFileSelected = onFileSelected;
|
|
||||||
|
|
||||||
function onFileSelected(file) {
|
|
||||||
if (!file) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrl.state.uploadInProgress = true;
|
|
||||||
$q.when(ctrl.uploadFile(file)).finally(function toggleProgress() {
|
|
||||||
ctrl.state.uploadInProgress = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]);
|
|
|
@ -1,7 +0,0 @@
|
||||||
angular.module('portainer.agent').component('fileUploader', {
|
|
||||||
templateUrl: './file-uploader.html',
|
|
||||||
controller: 'FileUploaderController',
|
|
||||||
bindings: {
|
|
||||||
uploadFile: '<onFileSelected',
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
export class FileUploaderController {
|
||||||
|
constructor($async) {
|
||||||
|
Object.assign(this, { $async });
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
uploadInProgress: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onFileSelected = this.onFileSelected.bind(this);
|
||||||
|
this.onFileSelectedAsync = this.onFileSelectedAsync.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
onFileSelected(file) {
|
||||||
|
return this.$async(this.onFileSelectedAsync, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
async onFileSelectedAsync(file) {
|
||||||
|
if (!file) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state.uploadInProgress = true;
|
||||||
|
try {
|
||||||
|
await this.uploadFile(file);
|
||||||
|
} finally {
|
||||||
|
this.state.uploadInProgress = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import angular from 'angular';
|
||||||
|
import { FileUploaderController } from './fileUploaderController';
|
||||||
|
|
||||||
|
angular.module('portainer.agent').component('fileUploader', {
|
||||||
|
templateUrl: './fileUploader.html',
|
||||||
|
controller: FileUploaderController,
|
||||||
|
bindings: {
|
||||||
|
uploadFile: '<onFileSelected',
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue