refactor(agent): refactor file-uploader to es6 (#4087)

* refactor(host): convert fileUploader to es6

* refactor(agent): rename main file
pull/4098/head
Chaim Lev-Ari 2020-07-23 10:44:32 +03:00 committed by GitHub
parent 5abd35d4c1
commit 435f15ec6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 30 deletions

View File

@ -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;
});
}
},
]);

View File

@ -1,7 +0,0 @@
angular.module('portainer.agent').component('fileUploader', {
templateUrl: './file-uploader.html',
controller: 'FileUploaderController',
bindings: {
uploadFile: '<onFileSelected',
},
});

View File

@ -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;
}
}
}

View File

@ -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',
},
});