source : CarRight.js

  1. 'use strict';
  2. /**
  3. * This widget displays when car(s) are to the left of you
  4. * <p>
  5. * Example(s):
  6. * <p><b>
  7. * <sra-car-right ></sra-car-right><br />
  8. * </b>
  9. * <img src="../widgets/CarRight/icon.png" />
  10. * @ngdoc directive
  11. * @name sra-car-right
  12. * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 20.
  13. * @author Jeffrey Gilliam
  14. * @since 1.6
  15. * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
  16. * @license Apache License 2.0
  17. */
  18. define(['SIMRacingApps','css!widgets/CarRight/CarRight'],
  19. function(SIMRacingApps) {
  20. var self = {
  21. name: "sraCarRight",
  22. url: 'CarRight',
  23. template: 'CarRight.html',
  24. defaultWidth: 300,
  25. defaultHeight: 300,
  26. defaultInterval: 20 //initialize with the default interval
  27. };
  28. self.module = angular.module('SIMRacingApps'); //get the main module
  29. self.module.directive(self.name,
  30. ['sraDispatcher', '$filter','$rootScope',
  31. function(sraDispatcher, $filter, $rootScope) {
  32. return {
  33. restrict: 'EA',
  34. scope: true,
  35. templateUrl: sraDispatcher.getWidgetUrl(self.url) + '/' + self.template,
  36. controller: [ '$scope', function($scope) {
  37. $scope.directiveName = self.name;
  38. $scope.defaultWidth = self.defaultWidth;
  39. $scope.defaultHeight = self.defaultHeight;
  40. $scope.defaultInterval = self.defaultInterval;
  41. $scope.arrow = "";
  42. }]
  43. , link: function($scope,$element,$attrs) {
  44. //copy arguments to our $scope
  45. //$scope.value = $scope[self.name] = $attrs[self.name] || $attrs.sraArgsCar || $attrs.sraArgsCarNumber || "REFERENCE";
  46. $scope.value =
  47. $scope[self.name] = sraDispatcher.getTruthy($scope.sraArgsCAR, $attrs.sraArgsCar, $attrs.sraArgsCarNumber, $scope.sraArgsVALUE, $attrs[self.name], $attrs.sraArgsValue, "REFERENCE");
  48. //removed these attributes from the template because sraCar was not resolved at the time of compilation
  49. $attrs.sraArgsData =
  50. ";Car/" + $scope.value + "/SpotterMessage";
  51. $scope.$watch("data.Car['"+$scope.value+"'].SpotterMessage.Value", function() {
  52. if ($scope.data.Car[$scope.value].SpotterMessage.Value == "CARRIGHT"
  53. || $scope.data.Car[$scope.value].SpotterMessage.Value == "CARLEFTRIGHT") {
  54. $scope.arrow = ">";
  55. }
  56. else
  57. if ($scope.data.Car[$scope.value].SpotterMessage.Value == "CARSRIGHT") {
  58. $scope.arrow = ">>";
  59. }
  60. else {
  61. $scope.arrow = "";
  62. }
  63. });
  64. /**standard code that should be in every directive **/
  65. $rootScope.$on('sraResize', sraDispatcher.resize($scope,$element,self.defaultWidth,self.defaultHeight));
  66. $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
  67. }
  68. };
  69. }]);
  70. return self;
  71. });