blob: df5b93a6439ff3810a71548a2ebc0a1994dbf5e1 [file] [log] [blame]
Simon Hunt84f4c2a2015-09-23 17:52:45 -07001// js for sample app custom view
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -07002(function () {
3 'use strict';
4
Simon Hunte11ce5a2015-07-21 12:11:04 -07005 // injected refs
Simon Hunt89577e52015-09-25 18:15:19 -07006 var $log, $scope, wss, ks;
Simon Hunte11ce5a2015-07-21 12:11:04 -07007
8 // constants
Simon Hunt89577e52015-09-25 18:15:19 -07009 var dataReq = 'sampleCustomDataRequest',
10 dataResp = 'sampleCustomDataResponse';
Simon Hunte11ce5a2015-07-21 12:11:04 -070011
Simon Hunt89577e52015-09-25 18:15:19 -070012 function addKeyBindings() {
13 var map = {
14 space: [getData, 'Fetch data from server'],
Simon Hunte11ce5a2015-07-21 12:11:04 -070015
Simon Hunt89577e52015-09-25 18:15:19 -070016 _helpFormat: [
17 ['space']
18 ]
19 };
Simon Hunte11ce5a2015-07-21 12:11:04 -070020
Simon Hunt89577e52015-09-25 18:15:19 -070021 ks.keyBindings(map);
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070022 }
23
Simon Hunt89577e52015-09-25 18:15:19 -070024 function getData() {
25 wss.sendEvent(dataReq);
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070026 }
27
Simon Hunt89577e52015-09-25 18:15:19 -070028 function respDataCb(data) {
29 $scope.data = data;
Simon Hunte11ce5a2015-07-21 12:11:04 -070030 $scope.$apply();
31 }
32
Simon Hunt89577e52015-09-25 18:15:19 -070033
Simon Hunt84f4c2a2015-09-23 17:52:45 -070034 angular.module('ovSampleCustom', [])
35 .controller('OvSampleCustomCtrl',
Simon Hunt89577e52015-09-25 18:15:19 -070036 ['$log', '$scope', 'WebSocketService', 'KeyService',
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070037
Simon Hunt89577e52015-09-25 18:15:19 -070038 function (_$log_, _$scope_, _wss_, _ks_) {
Simon Hunte11ce5a2015-07-21 12:11:04 -070039 $log = _$log_;
40 $scope = _$scope_;
Simon Hunte11ce5a2015-07-21 12:11:04 -070041 wss = _wss_;
Simon Hunt89577e52015-09-25 18:15:19 -070042 ks = _ks_;
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070043
Simon Hunte11ce5a2015-07-21 12:11:04 -070044 var handlers = {};
Simon Hunt89577e52015-09-25 18:15:19 -070045 $scope.data = {};
Simon Hunte11ce5a2015-07-21 12:11:04 -070046
Simon Hunt89577e52015-09-25 18:15:19 -070047 // data response handler
48 handlers[dataResp] = respDataCb;
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070049 wss.bindHandlers(handlers);
Simon Hunte11ce5a2015-07-21 12:11:04 -070050
Simon Hunt89577e52015-09-25 18:15:19 -070051 addKeyBindings();
Simon Hunte11ce5a2015-07-21 12:11:04 -070052
Simon Hunt89577e52015-09-25 18:15:19 -070053 // custom click handler
54 $scope.getData = getData;
55
56 // get data the first time...
57 getData();
Simon Hunte11ce5a2015-07-21 12:11:04 -070058
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070059 // cleanup
Simon Hunte11ce5a2015-07-21 12:11:04 -070060 $scope.$on('$destroy', function () {
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070061 wss.unbindHandlers(handlers);
Simon Hunt89577e52015-09-25 18:15:19 -070062 ks.unbindKeys();
Simon Hunt84f4c2a2015-09-23 17:52:45 -070063 $log.log('OvSampleCustomCtrl has been destroyed');
Simon Hunte11ce5a2015-07-21 12:11:04 -070064 });
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070065
Simon Hunt84f4c2a2015-09-23 17:52:45 -070066 $log.log('OvSampleCustomCtrl has been created');
Simon Hunt89577e52015-09-25 18:15:19 -070067 }]);
Bri Prebilic Cole68844ba2015-07-22 15:41:37 -070068
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070069}());