From cad4a319a09d022bf1e7164b57566a775ab34733 Mon Sep 17 00:00:00 2001 From: Tomas Stolarik Date: Mon, 13 Dec 2021 13:51:59 +0100 Subject: [PATCH] ANDROID-4665 add environment switch UI --- res/app/control-panes/dashboard/dashboard.pug | 4 +- .../environment/environment-controller.js | 39 +++++++++++++++++++ .../dashboard/environment/environment-spec.js | 20 ++++++++++ .../dashboard/environment/environment.css | 19 +++++++++ .../dashboard/environment/environment.pug | 35 +++++++++++++++++ .../dashboard/environment/index.js | 12 ++++++ res/app/control-panes/dashboard/index.js | 3 +- 7 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 res/app/control-panes/dashboard/environment/environment-controller.js create mode 100644 res/app/control-panes/dashboard/environment/environment-spec.js create mode 100644 res/app/control-panes/dashboard/environment/environment.css create mode 100644 res/app/control-panes/dashboard/environment/environment.pug create mode 100644 res/app/control-panes/dashboard/environment/index.js diff --git a/res/app/control-panes/dashboard/dashboard.pug b/res/app/control-panes/dashboard/dashboard.pug index 26927d10f..56b326375 100644 --- a/res/app/control-panes/dashboard/dashboard.pug +++ b/res/app/control-panes/dashboard/dashboard.pug @@ -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"') diff --git a/res/app/control-panes/dashboard/environment/environment-controller.js b/res/app/control-panes/dashboard/environment/environment-controller.js new file mode 100644 index 000000000..5939d9ba0 --- /dev/null +++ b/res/app/control-panes/dashboard/environment/environment-controller.js @@ -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\"') + } + +} diff --git a/res/app/control-panes/dashboard/environment/environment-spec.js b/res/app/control-panes/dashboard/environment/environment-spec.js new file mode 100644 index 000000000..3d8d63349 --- /dev/null +++ b/res/app/control-panes/dashboard/environment/environment-spec.js @@ -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('') + })) + +}) diff --git a/res/app/control-panes/dashboard/environment/environment.css b/res/app/control-panes/dashboard/environment/environment.css new file mode 100644 index 000000000..1430b75dd --- /dev/null +++ b/res/app/control-panes/dashboard/environment/environment.css @@ -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; +} diff --git a/res/app/control-panes/dashboard/environment/environment.pug b/res/app/control-panes/dashboard/environment/environment.pug new file mode 100644 index 000000000..caaefef48 --- /dev/null +++ b/res/app/control-panes/dashboard/environment/environment.pug @@ -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 diff --git a/res/app/control-panes/dashboard/environment/index.js b/res/app/control-panes/dashboard/environment/index.js new file mode 100644 index 000000000..100649ed7 --- /dev/null +++ b/res/app/control-panes/dashboard/environment/index.js @@ -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')) diff --git a/res/app/control-panes/dashboard/index.js b/res/app/control-panes/dashboard/index.js index 03d63d164..e338bfab4 100644 --- a/res/app/control-panes/dashboard/index.js +++ b/res/app/control-panes/dashboard/index.js @@ -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(