mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Fix installation from file upload.
This commit is contained in:
parent
a9641f3271
commit
be0510b93a
3 changed files with 80 additions and 35 deletions
|
@ -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
|
||||
url: url
|
||||
})
|
||||
return tx
|
||||
}
|
||||
else {
|
||||
return $upload.upload({
|
||||
|
||||
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
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,26 +29,47 @@ module.exports = function UploadCtrl($scope, $rootScope, SettingsService, gettex
|
|||
$scope.upload = uploadResult
|
||||
})
|
||||
if (uploadResult.success) {
|
||||
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(uploadResult.body)
|
||||
var install = $rootScope.control.install(options)
|
||||
return install.promise
|
||||
.progressed(function (installResult) {
|
||||
$scope.$apply(function () {
|
||||
installResult.manifest = uploadResult.body.manifest
|
||||
installResult.manifest = options.manifest
|
||||
$scope.installation = installResult
|
||||
})
|
||||
})
|
||||
.then(function (installResult) {
|
||||
$scope.$apply(function () {
|
||||
installResult.manifest = uploadResult.body.manifest
|
||||
installResult.manifest = options.manifest
|
||||
$scope.treeData = installResult.manifest
|
||||
$scope.installation = installResult
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$scope.uninstall = function (packageName) {
|
||||
var tx = $rootScope.control.uninstall(packageName)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue