Refactoring ADB add keys to its own directive so it can be shared.

This commit is contained in:
Gunther Brunner
2014-09-29 18:37:28 +09:00
parent 13d40a4649
commit 9d38bced21
8 changed files with 48 additions and 82 deletions

View File

@@ -1,44 +0,0 @@
module.exports = function AdbKeysCtrl($scope, AdbKeysService) {
$scope.title = ''
$scope.key = ''
//$scope.$watch('showClipboard', function (e) {
// console.log('hi',e)
// $scope.showClipboard = true
//})
$scope.addKey = function () {
if ($scope.title && $scope.key) {
var title = $scope.title
var fingerprint = '97:ca:ae:fa:09:0b:c4:fe:22:94:7d:b2:be:77:66:a1'
console.log('Adding key')
//$scope.adbKeys.push({
// title: title,
// fingerprint: fingerprint
//})
$scope.closeAddKey()
}
}
$scope.closeAddKey = function () {
$scope.title = ''
$scope.key = ''
$scope.adbkeyform.$setPristine()
$scope.showAdd = false
}
$scope.changed = function () {
//console.log('changedx', $scope.key)
}
$scope.$watch('key', function (newValue) {
//console.log('newValue', newValue)
if (newValue && !$scope.title) {
$scope.title = AdbKeysService.hostNameFromKey(newValue)
}
})
}

View File

@@ -1,14 +1,37 @@
module.exports = function addAdbKeyDirective() {
module.exports = function addAdbKeyDirective(AdbKeysService) {
return {
restrict: 'E',
//replace: true,
//scope: {
// showAdd: '=',
// showClipboard: '='
//},
controller: require('./add-adb-key-controller.js'),
restrict: 'EA',
replace: true,
scope: {
showAdd: '=',
showClipboard: '='
},
template: require('./add-adb-key.jade'),
link: function (scope) {
scope.addForm = {
title: '',
key: ''
}
scope.addKey = function () {
console.log('Add key')
scope.closeAddKey()
}
scope.closeAddKey = function () {
scope.addForm.title = ''
scope.addForm.key = ''
console.log('scope', scope)
// TODO: cannot access to the form by name?
//scope.adbkeyform.$setPristine()
scope.showAdd = false
}
scope.$watch('addForm.key', function (newValue) {
if (newValue && !scope.addForm.title) {
scope.addForm.title = AdbKeysService.hostNameFromKey(newValue)
}
})
}
}

View File

@@ -1,10 +1,10 @@
.panel.panel-default(ng-if='showAdd').stf-add-adb-key
.panel.panel-default.stf-add-adb-key(ng-show='showAdd')
.panel-heading
h3.panel-title(translate) Add ADB Key
.panel-body
form.form-horizontal(name='adbkeyform', ng-submit='addKey(key)')
div(ng-show='true')
div(ng-show='showClipboard')
.alert.alert-info.selectable <strong>Tip: </strong>Run this command to copy the key to your clipboard
a(ng-href='/#!/docs/adb-keys').pull-right
@@ -19,7 +19,7 @@
i.fa.fa-key.fa-fw
span(translate) Key
.col-md-11
textarea(rows='4', ng-model='key', ng-change='changed()', ng-required='true',
textarea(rows='4', name='deviceKey', ng-model='addForm.key', ng-required='true',
autocorrect='off', autocapitalize='off', spellcheck='false',
focus-element='focusAddKey', ng-paste='focusAddTitle = true').form-control
@@ -28,7 +28,7 @@
i.fa.fa-laptop.fa-fw
span(translate) Device
.col-md-11
input(type='text', ng-model='title', ng-required='true',
input(type='text', name='deviceTitle', ng-model='addForm.title', ng-required='true',
text-focus-select, focus-element='focusAddTitle').form-control
button.btn.btn-primary-outline.btn-sm.pull-right(type='submit')

View File

@@ -5,6 +5,5 @@ module.exports = angular.module('stf.add-adb-key', [
require('stf/common-ui').name
])
.directive('addAdbKey', require('./add-adb-key-directive'))
.controller('addAdbKeyCtrl', require('./add-adb-key-controller.js'))
.factory('AdbKeysService', require('./adb-keys-service'))