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
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
this.upload = function(files) {
|
this.uploadUrl = function(url) {
|
||||||
var tx = TransactionService.create({
|
var tx = TransactionService.create({
|
||||||
id: 'storage'
|
id: 'storage'
|
||||||
})
|
})
|
||||||
if (typeof files === 'string') {
|
socket.emit('storage.upload', channel, tx.channel, {
|
||||||
socket.emit('storage.upload', channel, tx.channel, {
|
url: url
|
||||||
url: files
|
})
|
||||||
})
|
return tx
|
||||||
return tx
|
}
|
||||||
}
|
|
||||||
else {
|
this.uploadFile = function(files) {
|
||||||
return $upload.upload({
|
// Let's fake it till we can make it
|
||||||
|
var result = new TransactionService.TransactionResult({
|
||||||
|
id: 'storage'
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
promise:
|
||||||
|
$upload.upload({
|
||||||
url: '/api/v1/resources'
|
url: '/api/v1/resources'
|
||||||
, method: 'POST'
|
, method: 'POST'
|
||||||
, file: files[0]
|
, file: files[0]
|
||||||
})
|
})
|
||||||
.then(function(response) {
|
.then(
|
||||||
return install(response.data)
|
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
|
$scope.installation = null
|
||||||
}
|
}
|
||||||
|
|
||||||
$rootScope.install = function ($files) {
|
$rootScope.installUrl = function (url) {
|
||||||
$scope.upload = {
|
$scope.upload = {
|
||||||
progress: 0,
|
progress: 0,
|
||||||
lastData: 'uploading'
|
lastData: 'uploading'
|
||||||
}
|
}
|
||||||
|
|
||||||
var upload = $rootScope.control.upload($files)
|
var upload = $rootScope.control.uploadUrl(url)
|
||||||
$scope.installation = null
|
$scope.installation = null
|
||||||
return upload.promise
|
return upload.promise
|
||||||
.progressed(function (uploadResult) {
|
.progressed(function (uploadResult) {
|
||||||
|
@ -29,27 +29,48 @@ module.exports = function UploadCtrl($scope, $rootScope, SettingsService, gettex
|
||||||
$scope.upload = uploadResult
|
$scope.upload = uploadResult
|
||||||
})
|
})
|
||||||
if (uploadResult.success) {
|
if (uploadResult.success) {
|
||||||
if ($scope.installEnabled) {
|
return $scope.maybeInstall(uploadResult.body)
|
||||||
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
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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) {
|
$scope.uninstall = function (packageName) {
|
||||||
var tx = $rootScope.control.uninstall(packageName)
|
var tx = $rootScope.control.uninstall(packageName)
|
||||||
return tx.promise.then(function (result) {
|
return tx.promise.then(function (result) {
|
||||||
|
|
|
@ -14,15 +14,15 @@
|
||||||
|
|
||||||
//.col-md-10.col-md-offset-1
|
//.col-md-10.col-md-offset-1
|
||||||
.input-group.form-inline
|
.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
|
placeholder='http://...').form-control
|
||||||
span.input-group-btn
|
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')
|
tooltip='Upload From Link', ng-disabled='!remoteUrl')
|
||||||
i.fa.fa-upload
|
i.fa.fa-upload
|
||||||
|
|
||||||
.drop-area(ng-file-drop='$root.install($files)').file-input.btn-file
|
.drop-area(ng-file-drop='$root.installFile($files)').file-input.btn-file
|
||||||
input(type='file', ng-file-select='$root.install($files)')
|
input(type='file', ng-file-select='$root.installFile($files)')
|
||||||
|
|
||||||
i.fa.fa-2x.fa-download.drop-area-icon
|
i.fa.fa-2x.fa-download.drop-area-icon
|
||||||
p.drop-area-text(translate) Drop file to upload
|
p.drop-area-text(translate) Drop file to upload
|
||||||
|
@ -71,6 +71,8 @@
|
||||||
span(translate) Storing...
|
span(translate) Storing...
|
||||||
strong(ng-switch-when='fail')
|
strong(ng-switch-when='fail')
|
||||||
span(translate) Upload failed
|
span(translate) Upload failed
|
||||||
|
strong(ng-switch-when='success')
|
||||||
|
span(translate) Upload complete
|
||||||
|
|
||||||
span(ng-switch='installation.lastData')
|
span(ng-switch='installation.lastData')
|
||||||
strong(ng-switch-when='pushing_app')
|
strong(ng-switch-when='pushing_app')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue