source : Incidents.js

  1. 'use strict';
  2. /**
  3. * This widget displays your incident counts.
  4. * <p>
  5. * Example:
  6. * <p><b>
  7. * <sra-incidents></sra-incidents><br />
  8. * </b>
  9. * <img src="../widgets/Incidents/icon.png" alt="Image goes here"/>
  10. * @ngdoc directive
  11. * @name sra-incidents
  12. * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 500.
  13. * @author Jeffrey Gilliam
  14. * @since 1.13
  15. * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
  16. * @license Apache License 2.0
  17. */
  18. define(['SIMRacingApps','css!widgets/Incidents/Incidents'],
  19. function(SIMRacingApps) {
  20. var self = {
  21. name: "sraIncidents",
  22. url: 'Incidents',
  23. template: 'Incidents.html',
  24. defaultWidth: 800,
  25. defaultHeight: 280,
  26. defaultInterval: 500 //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. //load translations, if you have any comment out if you do not so it will not look for them
  42. // $scope.translations = {};
  43. // sraDispatcher.loadTranslations(sraDispatcher.getWidgetUrl(self.url),'text',function(path) {
  44. // $scope.translations = sraDispatcher.getTranslation(path);
  45. // });
  46. /** your code goes here **/
  47. }]
  48. , link: function($scope,$element,$attrs) {
  49. //copy arguments to our scope. First if using attribute, second tag, else default to something.
  50. $attrs.sraArgsData = $attrs.sraArgsData || "";
  51. $scope.value =
  52. $scope[self.name] = sraDispatcher.getTruthy($scope.sraArgsVALUE, $attrs[self.name], $attrs.sraArgsValue, "DefaultValue");
  53. /** your code goes here **/
  54. $attrs.sraArgsData += ";Session/IncidentLimit;Car/REFERENCE/Incidents;Car/REFERENCE/IncidentsTeam";
  55. /**standard code that should be in every directive **/
  56. $rootScope.$on('sraResize', sraDispatcher.resize($scope,$element,self.defaultWidth,self.defaultHeight));
  57. //register with the dispatcher
  58. $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
  59. /**watches go here **/
  60. $scope.$watch("data.Car.REFERENCE.Incidents.Value",function(value,oldvalue) {
  61. if ($scope.data.Car.REFERENCE.IncidentsTeam.State == 'NORMAL')
  62. $scope.incidents = $scope.data.Car.REFERENCE.Incidents.Value + '/' + $scope.data.Car.REFERENCE.IncidentsTeam.Value + '/' + $scope.data.Session.IncidentLimit.Value + $scope.data.Session.IncidentLimit.UOMDesc;
  63. else
  64. $scope.incidents = $scope.data.Car.REFERENCE.Incidents.Value + '/' + $scope.data.Session.IncidentLimit.Value + $scope.data.Session.IncidentLimit.UOMDesc;
  65. //$scope.incidents = '99/99/9999x';
  66. });
  67. $scope.$watch("data.Session.IncidentLimit.Value",function(value,oldvalue) {
  68. if ($scope.data.Car.REFERENCE.IncidentsTeam.State == 'NORMAL')
  69. $scope.incidents = $scope.data.Car.REFERENCE.Incidents.Value + '/' + $scope.data.Car.REFERENCE.IncidentsTeam.Value + '/' + $scope.data.Session.IncidentLimit.Value + $scope.data.Session.IncidentLimit.UOMDesc;
  70. else
  71. $scope.incidents = $scope.data.Car.REFERENCE.Incidents.Value + '/' + $scope.data.Session.IncidentLimit.Value + $scope.data.Session.IncidentLimit.UOMDesc;
  72. //$scope.incidents = '99/99/9999x';
  73. });
  74. }
  75. };
  76. }]);
  77. return self;
  78. });