1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00
OpenSTF/res/app/control-panes/dashboard/upload/upload-controller.js
Gunther Brunner c2b4bf4a90 Progress is floored now.
Tried doing upload & installation in multiple times but it looks bad because the animation is tweened.
2014-04-07 15:50:03 +09:00

132 lines
3.2 KiB
JavaScript

module.exports = function UploadCtrl($scope, $rootScope, SettingsService, gettext) {
$scope.upload = null
$scope.installation = null
$scope.installEnabled = true
$scope.launchEnabled = true
$scope.clear = function () {
$scope.upload = null
$scope.installation = null
}
$rootScope.installUrl = function (url) {
$scope.upload = {
progress: 0,
lastData: 'uploading'
}
var upload = $rootScope.control.uploadUrl(url)
$scope.installation = null
return upload.promise
.progressed(function (uploadResult) {
$scope.$apply(function () {
$scope.upload = uploadResult
})
})
.then(function (uploadResult) {
$scope.$apply(function () {
$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(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) {
if (result.success) {
$scope.$apply(function () {
$scope.clear()
})
} else {
console.error(result.error)
}
})
}
$scope.taskFinished = function () {
if ($scope.installEnabled) {
if ($scope.upload && $scope.upload.settled &&
$scope.installation && $scope.installation.settled) {
return true
}
} else {
if ($scope.upload && $scope.upload.settled) {
return true
}
}
return false
}
$scope.taskProgress = function () {
var progress = 0
if ($scope.installEnabled) {
if ($scope.upload) {
progress += $scope.upload.progress
}
if ($scope.installation) {
progress += $scope.installation.progress
}
progress = Math.floor(progress / 2)
} else {
if ($scope.upload) {
progress = $scope.upload.progress
}
}
return progress
}
//
// $scope.installEnabled = true
// SettingsService.bind($scope, {
// key: 'installEnabled',
// storeName: 'Upload'
// })
//
// //$scope.launchEnabled = true
// SettingsService.bind($scope, {
// key: 'launchEnabled',
// storeName: 'Upload'
// })
}