1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

Merge pull request #481 from openstf/add-automation-label

Use automation label in device list for devices accessed using API
This commit is contained in:
Vishal Banthia 2016-11-25 03:59:20 +05:30 committed by GitHub
commit 445cfcf0bc
15 changed files with 78 additions and 19 deletions

View file

@ -153,6 +153,7 @@ dbapi.saveDeviceInitialState = function(serial, device) {
, reverseForwards: []
, remoteConnect: false
, remoteConnectUrl: null
, usage: null
}
return db.run(r.table('devices').get(serial).update(data))
.then(function(stats) {
@ -212,6 +213,20 @@ dbapi.setDeviceAbsent = function(serial) {
}))
}
dbapi.setDeviceUsage = function(serial, usage) {
return db.run(r.table('devices').get(serial).update({
usage: usage
, usageChangedAt: r.now()
}))
}
dbapi.unsetDeviceUsage = function(serial) {
return db.run(r.table('devices').get(serial).update({
usage: null
, usageChangedAt: r.now()
}))
}
dbapi.setDeviceAirplaneMode = function(serial, enabled) {
return db.run(r.table('devices').get(serial).update({
airplaneMode: enabled

View file

@ -148,6 +148,7 @@ function addUserDevice(req, res) {
.handler()
req.options.channelRouter.on(wireutil.global, messageListener)
var usage = 'automation'
req.options.push.send([
device.channel
@ -165,6 +166,7 @@ function addUserDevice(req, res) {
, match: 'exact'
}
})
, usage
)
)
])

View file

@ -30,7 +30,7 @@ module.exports = syrup.serial()
return currentGroup
})
plugin.join = function(newGroup, timeout, identifier) {
plugin.join = function(newGroup, timeout, usage) {
return plugin.get()
.then(function() {
if (currentGroup.group !== newGroup.group) {
@ -57,10 +57,11 @@ module.exports = syrup.serial()
, wireutil.envelope(new wire.JoinGroupMessage(
options.serial
, currentGroup
, usage
))
])
plugin.emit('join', currentGroup, identifier)
plugin.emit('join', currentGroup)
return currentGroup
})
@ -113,7 +114,7 @@ module.exports = syrup.serial()
var reply = wireutil.reply(options.serial)
grouputil.match(ident, message.requirements)
.then(function() {
return plugin.join(message.owner, message.timeout)
return plugin.join(message.owner, message.timeout, message.usage)
})
.then(function() {
push.send([

View file

@ -175,10 +175,14 @@ module.exports = function(options) {
})
.on(wire.JoinGroupMessage, function(channel, message, data) {
dbapi.setDeviceOwner(message.serial, message.owner)
if (message.usage) {
dbapi.setDeviceUsage(message.serial, message.usage)
}
appDealer.send([channel, data])
})
.on(wire.LeaveGroupMessage, function(channel, message, data) {
dbapi.unsetDeviceOwner(message.serial, message.owner)
dbapi.unsetDeviceUsage(message.serial)
appDealer.send([channel, data])
})
.on(wire.DeviceLogMessage, function(channel, message, data) {

View file

@ -174,6 +174,7 @@ module.exports = function(options) {
serial: message.serial
, owner: message.owner
, likelyLeaveReason: 'owner_change'
, usage: message.usage
}
, user
)
@ -397,8 +398,15 @@ module.exports = function(options) {
, wireutil.envelope(new wire.AdbKeysUpdatedMessage())
])
})
.catch(dbapi.DuplicateSecondaryIndexError, function() {
// No-op
.catch(dbapi.DuplicateSecondaryIndexError, function(err) {
socket.emit('user.keys.adb.error', {
message: 'Someone already added this key'
})
})
.catch(Error, function(err) {
socket.emit('user.keys.adb.error', {
message: err.message
})
})
})
.on('user.keys.adb.accept', function(data) {

View file

@ -261,6 +261,7 @@ message GroupMessage {
required OwnerMessage owner = 1;
optional uint32 timeout = 2;
repeated DeviceRequirement requirements = 3;
optional string usage = 4;
}
message AutoGroupMessage {
@ -275,6 +276,7 @@ message UngroupMessage {
message JoinGroupMessage {
required string serial = 1;
required OwnerMessage owner = 2;
optional string usage = 3;
}
message JoinGroupByAdbFingerprintMessage {

View file

@ -10,7 +10,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'),
using: gettext('Stop Using'),
busy: gettext('Busy'),
available: gettext('Use')
available: gettext('Use'),
automation: gettext('Stop Automation')
}[text] || gettext('Unknown')
}
})
@ -25,7 +26,8 @@ module.exports = angular.module('stf.device-status', [])
ready: gettext('Ready'),
using: gettext('Using'),
busy: gettext('Busy'),
available: gettext('Available')
available: gettext('Available'),
automation: gettext('Automating'),
}[text] || gettext('Unknown')
}
})

View file

@ -19,8 +19,13 @@ module.exports = function EnhanceDeviceServiceFactory($filter, AppState) {
if (data.ready) {
data.state = 'ready'
if (data.using) {
if (data.usage === 'automation') {
data.state = 'automation'
}
else {
data.state = 'using'
}
}
else {
if (data.owner) {
data.state = 'busy'

View file

@ -10,7 +10,8 @@ module.exports = function StateClassesService() {
present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-outline',
offline: 'state-offline btn-warning-outline'
offline: 'state-offline btn-warning-outline',
automation: 'state-automation btn-info'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline'
@ -27,7 +28,8 @@ module.exports = function StateClassesService() {
present: 'state-present',
preparing: 'state-preparing',
unauthorized: 'state-unauthorized',
offline: 'state-offline'
offline: 'state-offline',
automation: 'state-automation'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = ''
@ -37,4 +39,3 @@ module.exports = function StateClassesService() {
return service
}

View file

@ -13,12 +13,21 @@ module.exports = function addAdbKeyDirective(AdbKeysService) {
, key: ''
}
$scope.$on('user.keys.adb.error', function(event, error) {
$scope.$apply(function() {
$scope.error = error.message
})
})
$scope.$on('user.keys.adb.updated', function() {
$scope.closeAddKey()
})
$scope.addKey = function() {
UserService.addAdbKey({
title: $scope.addForm.title
, key: $scope.addForm.key
})
$scope.closeAddKey()
}
$scope.closeAddKey = function() {
@ -27,6 +36,7 @@ module.exports = function addAdbKeyDirective(AdbKeysService) {
// TODO: cannot access to the form by name inside a directive?
//$scope.adbkeyform.$setPristine()
$scope.showAdd = false
$scope.error = ''
}
},
link: function(scope) {

View file

@ -1,3 +1,7 @@
.stf-add-adb-key {
.stf-add-adb-key .form-adb-key {
margin-bottom: 60px;
}
.stf-add-adb-key .clip-board {
margin-bottom: 20px;
}

View file

@ -2,9 +2,9 @@
.panel-heading
h3.panel-title(translate) Add ADB Key
.panel-body
form.form-horizontal(name='adbkeyform', ng-submit='addKey(key)')
form.form-horizontal.stf-add-adb-key.form-adb-key(name='adbkeyform', ng-submit='addKey(key)')
div(ng-show='showClipboard')
.stf-add-adb-key.clip-board(ng-show='showClipboard')
.alert.alert-info.selectable
strong(translate) Tip:
@ -13,8 +13,6 @@
textarea(readonly, rows='1', text-focus-select, ng-copy='focusAddKey = true'
).form-control.remote-debug-textarea pbcopy < ~/.android/adbkey.pub
br
.form-group
label.control-label(for='adb-device-key')
i.fa.fa-key.fa-fw
@ -36,4 +34,5 @@
i.fa.fa-plus.fa-fw
span(translate) Add Key
error-message(message='{{error}}')

View file

@ -24,6 +24,10 @@ module.exports = function UserServiceFactory(
socket.emit('user.keys.adb.remove', key)
}
socket.on('user.keys.adb.error', function(error) {
$rootScope.$broadcast('user.keys.adb.error', error)
})
socket.on('user.keys.adb.added', function(key) {
UserService.getAdbKeys().push(key)
$rootScope.$broadcast('user.keys.adb.updated', user.adbKeys)

View file

@ -571,6 +571,7 @@ function DeviceStatusCell(options) {
, preparing: 'state-preparing btn-primary-outline btn-success-outline'
, unauthorized: 'state-unauthorized btn-danger-outline'
, offline: 'state-offline btn-warning-outline'
, automation: 'state-automation btn-info'
}
return _.defaults(options, {

View file

@ -66,7 +66,8 @@ module.exports = function DeviceListIconsDirective(
present: 'state-present btn-primary-outline',
preparing: 'state-preparing btn-primary-outline btn-success-outline',
unauthorized: 'state-unauthorized btn-danger-outline',
offline: 'state-offline btn-warning-outline'
offline: 'state-offline btn-warning-outline',
automation: 'state-automation btn-info'
}[state]
if (typeof stateClasses === 'undefined') {
stateClasses = 'btn-default-outline'