source : TireCompound.js

  1. 'use strict';
  2. /**
  3. * This widget shows all your tire compounds and allows you to select the one you want.
  4. * <p>
  5. * Example(s):
  6. * <p><b>
  7. * <sra-tire-compound></sra-tire-compound><br />
  8. * </b>
  9. * <img src="../widgets/TireCompound/icon.png" />
  10. * @ngdoc directive
  11. * @name sra-tire-compound
  12. * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 50.
  13. * @author Jeffrey Gilliam
  14. * @since 1.22
  15. * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
  16. * @license Apache License 2.0
  17. */
  18. define(['SIMRacingApps'
  19. ,'css!widgets/TireCompound/TireCompound'
  20. ],function(SIMRacingApps) {
  21. var self = {
  22. name: "sraTireCompound",
  23. url: 'TireCompound',
  24. template: 'TireCompound.html',
  25. defaultWidth: 240,
  26. defaultHeight: 240,
  27. defaultInterval: 50 //initialize with the default interval
  28. };
  29. self.module = angular.module('SIMRacingApps'); //get the main module
  30. self.module.directive(self.name,
  31. ['sraDispatcher', '$filter', '$rootScope',
  32. function(sraDispatcher, $filter, $rootScope) {
  33. return {
  34. restrict: 'EA',
  35. scope: true,
  36. templateUrl: sraDispatcher.getWidgetUrl(self.url) + '/' + self.template,
  37. controller: [ '$scope', function($scope) {
  38. $scope.directiveName = self.name;
  39. $scope.defaultWidth = self.defaultWidth;
  40. $scope.defaultHeight = self.defaultHeight;
  41. $scope.defaultInterval = self.defaultInterval;
  42. /** your code goes here **/
  43. $scope.backgroundRow1Col1 = "none";
  44. $scope.backgroundRow1Col2 = "none";
  45. $scope.backgroundRow2Col1 = "none";
  46. $scope.backgroundRow2Col2 = "none";
  47. $scope.controller = false;
  48. $scope.row1col1Clicked = function($clickedScope,value) {
  49. console.log("Clicked("+$scope.data.Car.REFERENCE.Gauge.TireCompound.Value['0'].ValueFormatted+")");
  50. if ($scope.backgroundRow1Col1 != "active" && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['0'].ValueFormatted != "") {
  51. if ($scope.controller) {
  52. $scope.backgroundRow1Col1 = "clicked";
  53. sraDispatcher.sendCommand("Car/REFERENCE/Gauge/TireCompound/setValueNext/0");
  54. }
  55. }
  56. };
  57. $scope.row1col2Clicked = function($clickedScope,value) {
  58. console.log("Clicked("+$scope.data.Car.REFERENCE.Gauge.TireCompound.Value['1'].ValueFormatted+")");
  59. if ($scope.backgroundRow1Col2 != "active" && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['1'].ValueFormatted != "") {
  60. if ($scope.controller) {
  61. $scope.backgroundRow1Col2 = "clicked";
  62. sraDispatcher.sendCommand("Car/REFERENCE/Gauge/TireCompound/setValueNext/1");
  63. }
  64. }
  65. };
  66. $scope.row2col1Clicked = function($clickedScope,value) {
  67. console.log("Clicked("+$scope.data.Car.REFERENCE.Gauge.TireCompound.Value['2'].ValueFormatted+")");
  68. if ($scope.backgroundRow2Col1 != "active" && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['2'].ValueFormatted != "") {
  69. if ($scope.controller) {
  70. $scope.backgroundRow2Col1 = "clicked";
  71. sraDispatcher.sendCommand("Car/REFERENCE/Gauge/TireCompound/setValueNext/2");
  72. }
  73. }
  74. };
  75. $scope.row2col2Clicked = function($clickedScope,value) {
  76. console.log("Clicked("+$scope.data.Car.REFERENCE.Gauge.TireCompound.Value['3'].ValueFormatted+")");
  77. if ($scope.backgroundRow2Col2 != "active" && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['3'].ValueFormatted != "") {
  78. if ($scope.controller) {
  79. $scope.backgroundRow2Col2 = "clicked";
  80. sraDispatcher.sendCommand("Car/REFERENCE/Gauge/TireCompound/setValueNext/3");
  81. }
  82. }
  83. };
  84. $scope.updateState = function() {
  85. $scope.backgroundRow1Col1 = "none";
  86. $scope.backgroundRow1Col2 = "none";
  87. $scope.backgroundRow2Col1 = "none";
  88. $scope.backgroundRow2Col2 = "none";
  89. if ($scope.data.Car.REFERENCE.Gauge.TireCompound.Value['0'].ValueFormatted != ""
  90. && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['0'].ValueFormatted == $scope.data.Car.REFERENCE.Gauge.TireCompound.ValueNext.ValueFormatted)
  91. $scope.backgroundRow1Col1 = "active";
  92. if ($scope.data.Car.REFERENCE.Gauge.TireCompound.Value['1'].ValueFormatted != ""
  93. && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['1'].ValueFormatted == $scope.data.Car.REFERENCE.Gauge.TireCompound.ValueNext.ValueFormatted)
  94. $scope.backgroundRow1Col2 = "active";
  95. if ($scope.data.Car.REFERENCE.Gauge.TireCompound.Value['2'].ValueFormatted != ""
  96. && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['2'].ValueFormatted == $scope.data.Car.REFERENCE.Gauge.TireCompound.ValueNext.ValueFormatted)
  97. $scope.backgroundRow2Col1 = "active";
  98. if ($scope.data.Car.REFERENCE.Gauge.TireCompound.Value['3'].ValueFormatted != ""
  99. && $scope.data.Car.REFERENCE.Gauge.TireCompound.Value['3'].ValueFormatted == $scope.data.Car.REFERENCE.Gauge.TireCompound.ValueNext.ValueFormatted)
  100. $scope.backgroundRow2Col2 = "active";
  101. };
  102. }]
  103. , link: function($scope,$element,$attrs) {
  104. //copy arguments to our $scope. First if using attribute, second tag, else default to something.
  105. $attrs.sraArgsData = $attrs.sraArgsData || "";
  106. $scope.value =
  107. $scope[self.name] = sraDispatcher.getTruthy($scope.sraArgsVALUE, $attrs[self.name], $attrs.sraArgsValue, "DefaultValue");
  108. $scope.canControl = sraDispatcher.getBoolean($scope.sraArgsPITCOMMANDSSIMCONTROLLER,$attrs.sraArgsSIMController,$attrs.sraSIMController,false);
  109. $scope.controller = false;
  110. /** your code goes here **/
  111. if ($scope.canControl)
  112. $attrs.sraArgsData += ";Car/REFERENCE/HasAutomaticPitCommands";
  113. $scope.$watch("data.Car.REFERENCE.Gauge.TireCompound.ValueNext.ValueFormatted", $scope.updateState);
  114. $scope.$watch("data.Car.REFERENCE.HasAutomaticPitCommands.Value", function(value) {
  115. if (!value) {
  116. $scope.controller = false;
  117. }
  118. else
  119. if (value && $scope.canControl) {
  120. $scope.controller = true;
  121. }
  122. });
  123. /**standard code that should be in every directive **/
  124. $rootScope.$on('sraResize', sraDispatcher.resize($scope,$element,self.defaultWidth,self.defaultHeight));
  125. //register with the dispatcher
  126. $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
  127. }
  128. };
  129. }]);
  130. return self;
  131. });