1
0
mirror of https://github.com/Foltik/Shimapan synced 2025-02-27 01:16:28 -05:00
shimapan/public/js/components/UploadComp.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-10-11 14:02:27 -04:00
function UploadController($scope, Upload, $timeout, AuthService) {
2017-10-11 10:15:19 -04:00
$scope.errToString = function(err) {
if (err === 'maxSize')
return "File too large.";
2017-10-09 22:01:02 -04:00
else
2017-10-11 10:15:19 -04:00
return err;
};
2017-10-09 22:01:02 -04:00
2017-10-11 10:15:19 -04:00
$scope.uploadFiles = function(files, errorFiles) {
$scope.files = $scope.files ? $scope.files.concat(files) : files;
$scope.errorFiles = $scope.errorFiles ? $scope.errorFiles.concat(errorFiles) : errorFiles;
2017-10-09 22:01:02 -04:00
angular.forEach(files, function (file) {
file.upload = Upload.upload({
url: '/upload',
method: 'POST',
2017-10-11 14:02:27 -04:00
headers: {
'Authorization': AuthService.getAuthHeader()
},
2017-10-09 22:01:02 -04:00
file: file
});
file.upload.then(
function (response) {
$timeout(function () {
file.result = response.data;
});
},
function (response) {
if (response.status > 0)
$scope.errorMsg = response.status + ': ' + response.data;
},
function (evt) {
file.progress = Math.floor(Math.min(100.0, 100 * evt.loaded / evt.total));
}
);
});
};
2017-10-11 10:15:19 -04:00
}
2017-10-11 14:02:27 -04:00
angular.module('UploadComp', ['ngFileUpload', 'AuthSvc']).component('uploadComponent', {
2017-10-11 10:15:19 -04:00
templateUrl: '/views/upload-form.html',
controller: UploadController,
controllerAs: 'vm'
});