mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Dragging an APK on the screen works now. Shares a lot of code with the upload controller, they should be merged somehow.
This commit is contained in:
parent
c0a515e75b
commit
d14b9965b0
4 changed files with 145 additions and 64 deletions
|
@ -18,6 +18,7 @@
|
|||
"laxcomma": true,
|
||||
"laxbreak": true,
|
||||
"browser": true,
|
||||
"devel": true,
|
||||
"globals": {
|
||||
"describe": false,
|
||||
"it": false,
|
||||
|
|
|
@ -13,13 +13,15 @@ module.exports = function StorageServiceFactory($http, $upload) {
|
|||
})
|
||||
}
|
||||
|
||||
service.storeFile = function(type, files) {
|
||||
service.storeFile = function(type, files, options) {
|
||||
var resolver = Promise.defer()
|
||||
var input = options.filter ? files.filter(options.filter) : files
|
||||
|
||||
if (input.length) {
|
||||
$upload.upload({
|
||||
url: '/api/v1/s/' + type
|
||||
, method: 'POST'
|
||||
, file: files
|
||||
, file: input
|
||||
})
|
||||
.then(
|
||||
function(value) {
|
||||
|
@ -32,6 +34,12 @@ module.exports = function StorageServiceFactory($http, $upload) {
|
|||
resolver.progress(progressEvent)
|
||||
}
|
||||
)
|
||||
}
|
||||
else {
|
||||
var err = new Error('No input files')
|
||||
err.code = 'no_input_files'
|
||||
resolver.reject(err)
|
||||
}
|
||||
|
||||
return resolver.promise
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
module.exports = function ($scope, gettext, $routeParams, $location, DeviceService, GroupService, ControlService, FatalMessageService) {
|
||||
|
||||
module.exports = function ControlPanesController(
|
||||
$scope
|
||||
, $http
|
||||
, gettext
|
||||
, $routeParams
|
||||
, $location
|
||||
, DeviceService
|
||||
, GroupService
|
||||
, ControlService
|
||||
, StorageService
|
||||
, FatalMessageService
|
||||
) {
|
||||
var sharedTabs = [
|
||||
{
|
||||
title: gettext('Screenshots'),
|
||||
|
@ -68,30 +78,76 @@ module.exports = function ($scope, gettext, $routeParams, $location, DeviceServi
|
|||
$scope.device = null
|
||||
$scope.control = null
|
||||
|
||||
|
||||
// @TODO Find a way to reuse this in the upload controller (or the other
|
||||
// way around)
|
||||
$scope.installFileForced = function ($files) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: 0,
|
||||
lastData: 'uploading'
|
||||
progress: 0
|
||||
, lastData: 'uploading'
|
||||
}
|
||||
})
|
||||
|
||||
return StorageService.storeFile('apk', $files, {
|
||||
filter: function(file) {
|
||||
return /\.apk$/i.test(file.name)
|
||||
}
|
||||
})
|
||||
.progressed(function(e) {
|
||||
if (e.lengthComputable) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: e.loaded / e.total * 100
|
||||
, lastData: 'uploading'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.then(function(res) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: 100
|
||||
, lastData: 'processing'
|
||||
}
|
||||
})
|
||||
|
||||
var href = res.data.resources.file0.href
|
||||
return $http.get(href + '/manifest')
|
||||
.then(function(res) {
|
||||
$scope.upload = {
|
||||
progress: 100
|
||||
, lastData: 'success'
|
||||
, settled: true
|
||||
}
|
||||
|
||||
return $scope.control.uploadFile($files)
|
||||
.progressed(function (uploadResult) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = uploadResult
|
||||
if (res.data.success) {
|
||||
return $scope.installForced({
|
||||
href: href
|
||||
, launch: true
|
||||
, manifest: res.data.manifest
|
||||
})
|
||||
})
|
||||
.then(function (uploadResult) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = uploadResult
|
||||
})
|
||||
if (uploadResult.success) {
|
||||
return $scope.maybeInstallForced(uploadResult.body)
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
$scope.$apply(function () {
|
||||
if (err.code === 'no_input_files') {
|
||||
$scope.upload = null
|
||||
}
|
||||
else {
|
||||
console.log('Upload error', err)
|
||||
$scope.upload = {
|
||||
progress: 100
|
||||
, lastData: 'fail'
|
||||
, settled: true
|
||||
, error: err.message
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
$scope.maybeInstallForced = function (options) {
|
||||
$scope.installForced = function (options) {
|
||||
return $scope.control.install(options)
|
||||
.progressed(function (installResult) {
|
||||
$scope.$apply(function () {
|
||||
|
@ -108,7 +164,6 @@ module.exports = function ($scope, gettext, $routeParams, $location, DeviceServi
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
DeviceService.get($routeParams.serial, $scope)
|
||||
.then(function (device) {
|
||||
return GroupService.invite(device)
|
||||
|
|
|
@ -38,25 +38,35 @@ module.exports = function UploadCtrl(
|
|||
}
|
||||
|
||||
$scope.installFile = function ($files) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: 0
|
||||
, lastData: 'uploading'
|
||||
}
|
||||
})
|
||||
|
||||
return StorageService.storeFile('apk', $files)
|
||||
return StorageService.storeFile('apk', $files, {
|
||||
filter: function(file) {
|
||||
return /\.apk$/i.test(file.name)
|
||||
}
|
||||
})
|
||||
.progressed(function(e) {
|
||||
if (e.lengthComputable) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: e.loaded / e.total * 100
|
||||
, lastData: 'uploading'
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.then(function(res) {
|
||||
$scope.$apply(function () {
|
||||
$scope.upload = {
|
||||
progress: 100
|
||||
, lastData: 'processing'
|
||||
}
|
||||
})
|
||||
|
||||
var href = res.data.resources.file0.href
|
||||
return $http.get(href + '/manifest')
|
||||
|
@ -77,12 +87,20 @@ module.exports = function UploadCtrl(
|
|||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
$scope.$apply(function () {
|
||||
if (err.code === 'no_input_files') {
|
||||
$scope.upload = null
|
||||
}
|
||||
else {
|
||||
console.log('Upload error', err)
|
||||
$scope.upload = {
|
||||
progress: 100
|
||||
, lastData: 'fail'
|
||||
, settled: true
|
||||
, error: err.message
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -103,6 +121,9 @@ module.exports = function UploadCtrl(
|
|||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
return Promise.reject(new Error('Installation not enabled'))
|
||||
}
|
||||
}
|
||||
|
||||
$scope.uninstall = function (packageName) {
|
||||
|
@ -120,14 +141,10 @@ module.exports = function UploadCtrl(
|
|||
|
||||
$scope.taskFinished = function () {
|
||||
if ($scope.installEnabled) {
|
||||
if ($scope.upload && $scope.upload.settled &&
|
||||
$scope.installation && $scope.installation.settled) {
|
||||
return true
|
||||
}
|
||||
return $scope.upload && ($scope.upload.error || $scope.upload.settled &&
|
||||
$scope.installation && $scope.installation.settled)
|
||||
} else {
|
||||
if ($scope.upload && $scope.upload.settled) {
|
||||
return true
|
||||
}
|
||||
return $scope.upload && $scope.upload.settled
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue