diff --git a/res/app/components/stf/sprintf/index.js b/res/app/components/stf/sprintf/index.js new file mode 100644 index 00000000..c2c13dff --- /dev/null +++ b/res/app/components/stf/sprintf/index.js @@ -0,0 +1,2 @@ +module.exports = angular.module('stf.sprintf', []) + .filter('sprintf', require('./sprintf-filter')) diff --git a/res/app/components/stf/sprintf/sprintf-filter.js b/res/app/components/stf/sprintf/sprintf-filter.js new file mode 100644 index 00000000..6852ccc5 --- /dev/null +++ b/res/app/components/stf/sprintf/sprintf-filter.js @@ -0,0 +1,14 @@ +module.exports = function sprintfFilter() { + function parse(str) { + var args = [].slice.call(arguments, 1) + var i = 0 + + return str.replace(/%s/g, function () { + return args[i++] + }) + } + + return function (input) { + return parse(input, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]) + } +} diff --git a/res/app/components/stf/sprintf/sprintf-spec.js b/res/app/components/stf/sprintf/sprintf-spec.js new file mode 100644 index 00000000..3454499a --- /dev/null +++ b/res/app/components/stf/sprintf/sprintf-spec.js @@ -0,0 +1,13 @@ +describe('sprintf', function() { + + beforeEach(module('stf.sprintf')); + + it('should ...', inject(function($filter) { + + var filter = $filter('sprintf'); + + expect(filter('input')).toEqual('output'); + + })); + +}); \ No newline at end of file diff --git a/res/app/control-panes/device-control/device-control-controller.js b/res/app/control-panes/device-control/device-control-controller.js index b19c6983..5db4d21e 100644 --- a/res/app/control-panes/device-control/device-control-controller.js +++ b/res/app/control-panes/device-control/device-control-controller.js @@ -1,6 +1,6 @@ var _ = require('lodash') -module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $location) { +module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $location, $timeout, gettext, $filter) { $scope.showScreen = true @@ -43,4 +43,62 @@ module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService, $scope.controlDevice = function (device) { $location.path('/control/' + device.serial) } + + function isPortrait(value) { + if (typeof value === 'undefined' && $scope.device) { + value = $scope.device.display.orientation + } + return (value === 0 || value === 180) + } + + function isLandscape(value) { + if (typeof value === 'undefined' && $scope.device) { + value = $scope.device.display.orientation + } + return (value === 90 || value === 270) + } + + $scope.tryToRotate = function (rotation) { + if (rotation === 'portrait') { + $scope.control.rotate(0) + $timeout(function () { + if (isLandscape()) { + $scope.currentRotation = 'landscape' + } + }, 400) + } else if (rotation === 'landscape') { + $scope.control.rotate(90) + $timeout(function () { + if (isPortrait()) { + $scope.currentRotation = 'portrait' + } + }, 400) + } + } + + $scope.currentRotation = 'portrait' + + $scope.$watch('device.display.orientation', function (newValue, oldValue) { + if (isPortrait(newValue)) { + $scope.currentRotation = 'portrait' + } else if (isLandscape(newValue)) { + $scope.currentRotation = 'landscape' + } + }) + + $scope.tooltipPortrait = function () { + var angle = 0 + if (isPortrait()) { + angle = $scope.device.display.orientation + } + return gettext($filter('sprintf')('Portrait (%s°)', angle)) + } + + $scope.tooltipLandscape = function () { + var angle = 90 + if (isLandscape()) { + angle = $scope.device.display.orientation + } + return gettext($filter('sprintf')('Landscape (%s°)', angle)) + } } diff --git a/res/app/control-panes/device-control/device-control.jade b/res/app/control-panes/device-control/device-control.jade index fab4a31f..66af0576 100644 --- a/res/app/control-panes/device-control/device-control.jade +++ b/res/app/control-panes/device-control/device-control.jade @@ -2,21 +2,14 @@ .as-cell.fill-height .as-table.fill-height .stf-vnc-navbar.as-row(ng-show='!$root.basicMode') - .pull-right - span.orientation-degree {{device.display.orientation}}° - - span - button(type='button', ng-click='control.rotate(0)', tooltip='Portrait', tooltip-placement='bottom').btn.btn-sm.btn-primary-outline - i.fa.fa-mobile - button(type='button', ng-click='control.rotate(90)', tooltip='Landscape', tooltip-placement='bottom').btn.btn-sm.btn-primary-outline - i.fa.fa-mobile.fa-rotate-90 - - //span - button(type='button', ng-click='control.rotate(0)', tooltip='Portrait', tooltip-placement='bottom').btn.btn-sm.btn-primary-outline - i.fa.fa-mobile - button(type='button', ng-click='control.rotate(90)', tooltip='Landscape', tooltip-placement='bottom').btn.btn-sm.btn-primary-outline - i.fa.fa-mobile.fa-rotate-90 + .btn-group + label.btn-sm.btn-primary-outline(type='button', ng-click='tryToRotate("portrait")', + ng-model='currentRotation', btn-radio='"portrait"').pointer + i.fa.fa-mobile(tooltip-html-unsafe='{{tooltipPortrait()}}', tooltip-placement='bottom') + label.btn-sm.btn-primary-outline(type='button', ng-click='tryToRotate("landscape")', + ng-model='currentRotation', btn-radio='"landscape"').pointer + i.fa.fa-mobile.fa-rotate-90(tooltip-html-unsafe='{{tooltipLandscape()}}', tooltip-placement='bottom') // NOTE: ui-bootstrap bug: tooltip breaks btn-checkbox so don't put in the same button button(type='button', ng-model='showScreen', btn-checkbox).btn.btn-sm.btn-danger diff --git a/res/app/control-panes/device-control/index.js b/res/app/control-panes/device-control/index.js index 180eb0cc..7183a0b3 100644 --- a/res/app/control-panes/device-control/index.js +++ b/res/app/control-panes/device-control/index.js @@ -3,7 +3,8 @@ require('./device-control.css') module.exports = angular.module('device-control', [ require('stf/device').name, require('stf/control').name, - require('stf/screen').name + require('stf/screen').name, + require('stf/sprintf').name ]) .run(["$templateCache", function ($templateCache) { $templateCache.put('control-panes/device-control/device-control.jade',