diff --git a/res/app/components/stf/control/control-service.js b/res/app/components/stf/control/control-service.js index 19b33456..10fe5a89 100644 --- a/res/app/components/stf/control/control-service.js +++ b/res/app/components/stf/control/control-service.js @@ -109,25 +109,47 @@ module.exports = function ControlServiceFactory( return tx } - this.upload = function(files) { + this.uploadUrl = function(url) { var tx = TransactionService.create({ id: 'storage' }) - if (typeof files === 'string') { - socket.emit('storage.upload', channel, tx.channel, { - url: files - }) - return tx - } - else { - return $upload.upload({ + socket.emit('storage.upload', channel, tx.channel, { + url: url + }) + return tx + } + + this.uploadFile = function(files) { + // Let's fake it till we can make it + var result = new TransactionService.TransactionResult({ + id: 'storage' + }) + return { + promise: + $upload.upload({ url: '/api/v1/resources' , method: 'POST' , file: files[0] }) - .then(function(response) { - return install(response.data) - }) + .then( + function(response) { + result.settled = true + result.progress = 100 + result.success = true + result.lastData = 'success' + result.data.push(result.lastData) + result.body = response.data + return result + } + , function(err) { + result.settled = true + result.progress = 100 + result.success = false + result.error = result.lastData = 'fail' + result.data.push(result.lastData) + return result + } + ) } } diff --git a/res/app/control-panes/dashboard/upload/upload-controller.js b/res/app/control-panes/dashboard/upload/upload-controller.js index 427d7fc8..821c2996 100644 --- a/res/app/control-panes/dashboard/upload/upload-controller.js +++ b/res/app/control-panes/dashboard/upload/upload-controller.js @@ -10,13 +10,13 @@ module.exports = function UploadCtrl($scope, $rootScope, SettingsService, gettex $scope.installation = null } - $rootScope.install = function ($files) { + $rootScope.installUrl = function (url) { $scope.upload = { progress: 0, lastData: 'uploading' } - var upload = $rootScope.control.upload($files) + var upload = $rootScope.control.uploadUrl(url) $scope.installation = null return upload.promise .progressed(function (uploadResult) { @@ -29,27 +29,48 @@ module.exports = function UploadCtrl($scope, $rootScope, SettingsService, gettex $scope.upload = uploadResult }) if (uploadResult.success) { - if ($scope.installEnabled) { - var install = $rootScope.control.install(uploadResult.body) - return install.promise - .progressed(function (installResult) { - $scope.$apply(function () { - installResult.manifest = uploadResult.body.manifest - $scope.installation = installResult - }) - }) - .then(function (installResult) { - $scope.$apply(function () { - installResult.manifest = uploadResult.body.manifest - $scope.treeData = installResult.manifest - $scope.installation = installResult - }) - }) - } + return $scope.maybeInstall(uploadResult.body) } }) } + $rootScope.installFile = function ($files) { + $scope.upload = { + progress: 0, + lastData: 'uploading' + } + + var upload = $rootScope.control.uploadFile($files) + $scope.installation = null + return upload.promise + .then(function (uploadResult) { + $scope.upload = uploadResult + if (uploadResult.success) { + return $scope.maybeInstall(uploadResult.body) + } + }) + } + + $scope.maybeInstall = function (options) { + if ($scope.installEnabled) { + var install = $rootScope.control.install(options) + return install.promise + .progressed(function (installResult) { + $scope.$apply(function () { + installResult.manifest = options.manifest + $scope.installation = installResult + }) + }) + .then(function (installResult) { + $scope.$apply(function () { + installResult.manifest = options.manifest + $scope.treeData = installResult.manifest + $scope.installation = installResult + }) + }) + } + } + $scope.uninstall = function (packageName) { var tx = $rootScope.control.uninstall(packageName) return tx.promise.then(function (result) { diff --git a/res/app/control-panes/dashboard/upload/upload.jade b/res/app/control-panes/dashboard/upload/upload.jade index b802fee2..e9ef6498 100644 --- a/res/app/control-panes/dashboard/upload/upload.jade +++ b/res/app/control-panes/dashboard/upload/upload.jade @@ -14,15 +14,15 @@ //.col-md-10.col-md-offset-1 .input-group.form-inline - input(type=text, ng-model='remoteUrl', ng-enter='$root.install(remoteUrl)', + input(type=text, ng-model='remoteUrl', ng-enter='$root.installUrl(remoteUrl)', placeholder='http://...').form-control span.input-group-btn - button.btn.btn-primary-outline(ng-click='$root.install(remoteUrl)', + button.btn.btn-primary-outline(ng-click='$root.installUrl(remoteUrl)', tooltip='Upload From Link', ng-disabled='!remoteUrl') i.fa.fa-upload - .drop-area(ng-file-drop='$root.install($files)').file-input.btn-file - input(type='file', ng-file-select='$root.install($files)') + .drop-area(ng-file-drop='$root.installFile($files)').file-input.btn-file + input(type='file', ng-file-select='$root.installFile($files)') i.fa.fa-2x.fa-download.drop-area-icon p.drop-area-text(translate) Drop file to upload @@ -71,6 +71,8 @@ span(translate) Storing... strong(ng-switch-when='fail') span(translate) Upload failed + strong(ng-switch-when='success') + span(translate) Upload complete span(ng-switch='installation.lastData') strong(ng-switch-when='pushing_app')