blob: 49b41c0d67101de8a7897299a26426d0441387dc [file] [log] [blame]
Simon Hunta2b11a52016-02-22 22:05:47 -08001// js for driver view
Thomas Vachuskabbf10502015-12-09 13:41:58 -08002(function () {
3 'use strict';
4
5 // injected refs
Simon Huntc23145b2016-03-08 23:57:56 -08006 var $log, $scope, fs, wss, mast;
Thomas Vachuskabbf10502015-12-09 13:41:58 -08007
8 // constants
Thomas Vachuska72667382016-02-22 14:27:48 -08009 var detailsReq = 'driverDataRequest',
10 detailsResp = 'driverDataResponse',
Simon Huntc23145b2016-03-08 23:57:56 -080011 topPad = 13,
12 labelFudge = 14;
Thomas Vachuskabbf10502015-12-09 13:41:58 -080013
Simon Huntc23145b2016-03-08 23:57:56 -080014 // d3 selections
15 var tabular, dMatrix, tabHdRot, tabGrid, first;
Thomas Vachuskabbf10502015-12-09 13:41:58 -080016
Simon Huntc23145b2016-03-08 23:57:56 -080017 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 Vachuskabbf10502015-12-09 13:41:58 -080023
Simon Huntc23145b2016-03-08 23:57:56 -080024 tabGrid.style('height', tHeight);
25 if (!rowHdr.empty()) {
26 w = fs.noPxStyle(rowHdr, 'width') + labelFudge;
27 first.style('width', w + 'px');
Thomas Vachuskabbf10502015-12-09 13:41:58 -080028 }
Thomas Vachuskabbf10502015-12-09 13:41:58 -080029 }
30
31 function respDetailsCb(data) {
Simon Hunta2b11a52016-02-22 22:05:47 -080032 $scope.behaviours = data.behaviours;
33 $scope.drivers = data.drivers;
34 $scope.matrix = data.matrix;
35 $scope.$apply();
Simon Huntc23145b2016-03-08 23:57:56 -080036 fixSizes();
Thomas Vachuskabbf10502015-12-09 13:41:58 -080037 }
38
39 angular.module('ovDriverMatrix', [])
Simon Hunt24d0c5c2016-03-03 00:05:08 -080040 .run(['IconService', function (is) {
41 // Create our icon-to-glyph binding here:
42 is.registerIconMapping('nav_drivers', 'cog');
43 }])
Thomas Vachuskabbf10502015-12-09 13:41:58 -080044 .controller('OvDriverMatrixCtrl',
Simon Huntc23145b2016-03-08 23:57:56 -080045 ['$rootScope', '$window', '$log', '$scope', '$sce',
46 'FnService', 'WebSocketService', 'MastService',
Thomas Vachuskabbf10502015-12-09 13:41:58 -080047
Simon Huntc23145b2016-03-08 23:57:56 -080048 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 Vachuskabbf10502015-12-09 13:41:58 -080055
Simon Huntc23145b2016-03-08 23:57:56 -080056 var handlers = {},
57 unbindWatch;
Thomas Vachuskabbf10502015-12-09 13:41:58 -080058
Simon Huntc23145b2016-03-08 23:57:56 -080059 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 Vachuskabbf10502015-12-09 13:41:58 -080064
Simon Huntc23145b2016-03-08 23:57:56 -080065 unbindWatch = $rootScope.$watchCollection(
66 function () {
67 return {
68 h: $window.innerHeight,
69 w: $window.innerWidth
70 };
71 }, fixSizes
72 );
Thomas Vachuskabbf10502015-12-09 13:41:58 -080073
Simon Huntc23145b2016-03-08 23:57:56 -080074 $scope.behaviours = [];
75 $scope.drivers = [];
76 $scope.matrix = {};
Thomas Vachuska72667382016-02-22 14:27:48 -080077
Simon Huntc23145b2016-03-08 23:57:56 -080078 handlers[detailsResp] = respDetailsCb;
79 wss.bindHandlers(handlers);
Simon Hunta2b11a52016-02-22 22:05:47 -080080
Simon Huntc23145b2016-03-08 23:57:56 -080081 wss.sendEvent(detailsReq);
Simon Hunta2b11a52016-02-22 22:05:47 -080082
Simon Huntc23145b2016-03-08 23:57:56 -080083 function cellHit(d, b) {
84 var drec = $scope.matrix[d],
85 brec = drec && drec[b];
86 return !!brec;
87 }
Thomas Vachuskabbf10502015-12-09 13:41:58 -080088
Simon Huntc23145b2016-03-08 23:57:56 -080089 $scope.cellMarked = cellHit;
90 $scope.checkmark = $sce.trustAsHtml("✓");
Thomas Vachuskabbf10502015-12-09 13:41:58 -080091
Simon Huntc23145b2016-03-08 23:57:56 -080092 // cleanup
93 $scope.$on('$destroy', function () {
94 unbindWatch();
95 wss.unbindHandlers(handlers);
96 $log.log('OvDriverMatrixCtrl has been destroyed');
97 });
Thomas Vachuskabbf10502015-12-09 13:41:58 -080098
Simon Huntc23145b2016-03-08 23:57:56 -080099 $log.log('OvDriverMatrixCtrl has been created');
Thomas Vachuskabbf10502015-12-09 13:41:58 -0800100 }]);
101}());