Skip to content

Commit

Permalink
Merge pull request #67 from tstolarik/master
Browse files Browse the repository at this point in the history
ANDROID-4665 add environment switch UI
  • Loading branch information
tstolarik authored Dec 14, 2021
2 parents d7d84be + cad4a31 commit 7c98f70
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 2 deletions.
4 changes: 3 additions & 1 deletion res/app/control-panes/dashboard/dashboard.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
div(ng-include='"control-panes/dashboard/apps/apps.pug"')
.col-md-12
div(ng-include='"control-panes/dashboard/install/install.pug"')

.col-md-12
div(ng-include='"control-panes/dashboard/environment/environment.pug"')

.col-md-6
.col-md-12
div(ng-include='"control-panes/dashboard/clipboard/clipboard.pug"')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = function EnvironmentCtrl($scope) {
$scope.result = null

$scope.run = function(command) {
if (command === 'clear') {
$scope.clear()
return
}

$scope.command = ''

return $scope.control.shell(command)
.progressed(function(result) {
$scope.result = result
$scope.data = result.data.join('')
$scope.$digest()
})
.then(function(result) {
$scope.result = result
$scope.data = result.data.join('')
$scope.$digest()
})
}

$scope.clear = function() {
$scope.command = ''
$scope.data = ''
$scope.result = null
}

$scope.switchTo = function(string) {
$scope.run('am start -a android.intent.action.VIEW -d \"wandera-dev://?action=set_environment&environment=' + string + '\"')
}

$scope.switchToCustom = function(string) {
$scope.run('am start -a android.intent.action.VIEW -d \"wandera-dev://?action=set_environment&environment=CUSTOM\&url=' + string + '.fi2.wandera.cz\"')
}

}
20 changes: 20 additions & 0 deletions res/app/control-panes/dashboard/environment/environment-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('EnvironmentCtrl', function() {

beforeEach(angular.mock.module(require('./').name))

var scope, ctrl

beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new()
ctrl = $controller('EnvironmentCtrl', {$scope: scope})
}))

it('should clear the results', inject(function() {
scope.result = ['result']
scope.run('clear')
expect(scope.result).toBe(null)
expect(scope.data).toBe('')
expect(scope.command).toBe('')
}))

})
19 changes: 19 additions & 0 deletions res/app/control-panes/dashboard/environment/environment.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.stf-environment .environment-results {
font-size: 12px;
color: #fefefe;
background: #444;
}

.stf-environment .environment-results-empty {
font-style: italic;
}

.stf-environment .environment-input {
font-family: Monaco, Menlo, Consolas, "Courier New", monospace;
font-size: 12px;
width: 75%;
}

.stf-environment .url-suffix {
margin-left: 16px;
}
35 changes: 35 additions & 0 deletions res/app/control-panes/dashboard/environment/environment.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.widget-container.fluid-height.stf-environment(ng-controller='EnvironmentCtrl')
.heading
stacked-icon(icon='fa-exchange', color='color-yellow')
span(translate) Switch enviroment
clear-button(ng-click='clear()', ng-disabled='!command && !data').btn-xs
help-icon(topic='Remote-Shell', uib-tooltip='{{"Switches Wandera\'s environment to DEV, QA, PROD or FI" | translate}}')


.widget-content.padded
button.btn.btn-xs.btn-info-outline(ng-click='switchTo("DEV")',
uib-tooltip='{{ "Switch to DEV" | translate }}')
i.fa.fa-exchange
span(translate) DEV
button.btn.btn-xs.btn-info-outline(ng-click='switchTo("QA")',
uib-tooltip='{{ "Switch to QA" | translate }}')
i.fa.fa-exchange
span(translate) QA
button.btn.btn-xs.btn-info-outline(ng-click='switchTo("PRODUCTION")',
uib-tooltip='{{ "Switch to PRODUCTION" | translate }}')
i.fa.fa-exchange
span(translate) PRODUCTION
// NOTE: autofill doesn't work here
form(method='post', enable-autofill, ng-submit='run(command)')

.widget-content.padded
.input-group.form-inline
input(type=text, ng-model='command', Xtext-focus-select,
autocapitalize='off', spellcheck='false',
tabindex='30', accesskey='S', autocomplete='on' placeholder='FI name').form-control.environment-input
span.url-suffix .fi2.wandera.cz
span.input-group-btn
button.btn.btn-primary-outline(ng-click='switchToCustom(command)', ng-disabled='!command')
i.fa.fa-play
pre.environment-results.selectable(ng-show='data') {{data}}
pre.environment-results.selectable.environment-results-empty(ng-show='result.settled && !data') No output
12 changes: 12 additions & 0 deletions res/app/control-panes/dashboard/environment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require('./environment.css')

module.exports = angular.module('stf.environment', [
require('stf/common-ui').name,
require('gettext').name
])
.run(['$templateCache', function($templateCache) {
$templateCache.put('control-panes/dashboard/environment/environment.pug',
require('./environment.pug')
)
}])
.controller('EnvironmentCtrl', require('./environment-controller'))
3 changes: 2 additions & 1 deletion res/app/control-panes/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = angular.module('stf.dashboard', [
require('./apps/index').name,
require('./clipboard/index').name,
require('./remote-debug/index').name,
require('./enrollment/index').name
require('./enrollment/index').name,
require('./environment/index').name
])
.run(['$templateCache', function($templateCache) {
$templateCache.put(
Expand Down

0 comments on commit 7c98f70

Please sign in to comment.