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
2014-04-04 19:46:59 +09:00

79 lines
2.1 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.install = function ($files) {
$scope.upload = {
progress: 0,
lastData: 'uploading'
}
var upload = $rootScope.control.upload($files)
$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) {
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
})
})
}
}
})
}
$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.installEnabled = true
// SettingsService.bind($scope, {
// key: 'installEnabled',
// storeName: 'Upload'
// })
//
// //$scope.launchEnabled = true
// SettingsService.bind($scope, {
// key: 'launchEnabled',
// storeName: 'Upload'
// })
}