Simon Hunt | a2b11a5 | 2016-02-22 22:05:47 -0800 | [diff] [blame] | 1 | // js for driver view |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 2 | (function () { |
| 3 | 'use strict'; |
| 4 | |
| 5 | // injected refs |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 6 | var $log, $scope, fs, wss, mast; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 7 | |
| 8 | // constants |
Thomas Vachuska | 7266738 | 2016-02-22 14:27:48 -0800 | [diff] [blame] | 9 | var detailsReq = 'driverDataRequest', |
| 10 | detailsResp = 'driverDataResponse', |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 11 | topPad = 13, |
| 12 | labelFudge = 14; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 13 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 14 | // d3 selections |
| 15 | var tabular, dMatrix, tabHdRot, tabGrid, first; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 16 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 17 | function fixSizes() { |
| 18 | var dy = fs.noPxStyle(tabular, 'height') + |
| 19 | fs.noPxStyle(tabHdRot, 'height') + mast.mastHeight() + topPad, |
| 20 | tHeight = fs.windowSize(dy).height + 'px', |
| 21 | rowHdr = tabGrid.select('.row-header'), |
| 22 | w; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 23 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 24 | tabGrid.style('height', tHeight); |
| 25 | if (!rowHdr.empty()) { |
| 26 | w = fs.noPxStyle(rowHdr, 'width') + labelFudge; |
| 27 | first.style('width', w + 'px'); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 28 | } |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | function respDetailsCb(data) { |
Simon Hunt | a2b11a5 | 2016-02-22 22:05:47 -0800 | [diff] [blame] | 32 | $scope.behaviours = data.behaviours; |
| 33 | $scope.drivers = data.drivers; |
| 34 | $scope.matrix = data.matrix; |
| 35 | $scope.$apply(); |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 36 | fixSizes(); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | angular.module('ovDriverMatrix', []) |
Simon Hunt | 24d0c5c | 2016-03-03 00:05:08 -0800 | [diff] [blame] | 40 | .run(['IconService', function (is) { |
| 41 | // Create our icon-to-glyph binding here: |
| 42 | is.registerIconMapping('nav_drivers', 'cog'); |
| 43 | }]) |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 44 | .controller('OvDriverMatrixCtrl', |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 45 | ['$rootScope', '$window', '$log', '$scope', '$sce', |
| 46 | 'FnService', 'WebSocketService', 'MastService', |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 47 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 48 | function ($rootScope, $window, _$log_, _$scope_, $sce, |
| 49 | _fs_, _wss_, _mast_) { |
| 50 | $log = _$log_; |
| 51 | $scope = _$scope_; |
| 52 | fs = _fs_; |
| 53 | wss = _wss_; |
| 54 | mast = _mast_; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 55 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 56 | var handlers = {}, |
| 57 | unbindWatch; |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 58 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 59 | tabular = d3.select('.tabular-header'); |
| 60 | dMatrix = d3.select('.driver-matrix'); |
| 61 | tabHdRot = d3.select('.table-header-rotated'); |
| 62 | tabGrid = d3.select('.table-grid'); |
| 63 | first = tabHdRot.select('.first'); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 64 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 65 | unbindWatch = $rootScope.$watchCollection( |
| 66 | function () { |
| 67 | return { |
| 68 | h: $window.innerHeight, |
| 69 | w: $window.innerWidth |
| 70 | }; |
| 71 | }, fixSizes |
| 72 | ); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 73 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 74 | $scope.behaviours = []; |
| 75 | $scope.drivers = []; |
| 76 | $scope.matrix = {}; |
Thomas Vachuska | 7266738 | 2016-02-22 14:27:48 -0800 | [diff] [blame] | 77 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 78 | handlers[detailsResp] = respDetailsCb; |
| 79 | wss.bindHandlers(handlers); |
Simon Hunt | a2b11a5 | 2016-02-22 22:05:47 -0800 | [diff] [blame] | 80 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 81 | wss.sendEvent(detailsReq); |
Simon Hunt | a2b11a5 | 2016-02-22 22:05:47 -0800 | [diff] [blame] | 82 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 83 | function cellHit(d, b) { |
| 84 | var drec = $scope.matrix[d], |
| 85 | brec = drec && drec[b]; |
| 86 | return !!brec; |
| 87 | } |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 88 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 89 | $scope.cellMarked = cellHit; |
| 90 | $scope.checkmark = $sce.trustAsHtml("✓"); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 91 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 92 | // cleanup |
| 93 | $scope.$on('$destroy', function () { |
| 94 | unbindWatch(); |
| 95 | wss.unbindHandlers(handlers); |
| 96 | $log.log('OvDriverMatrixCtrl has been destroyed'); |
| 97 | }); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 98 | |
Simon Hunt | c23145b | 2016-03-08 23:57:56 -0800 | [diff] [blame] | 99 | $log.log('OvDriverMatrixCtrl has been created'); |
Thomas Vachuska | bbf1050 | 2015-12-09 13:41:58 -0800 | [diff] [blame] | 100 | }]); |
| 101 | }()); |