source : StandingsTop10.js

'use strict';
/**
 * This widget displays the official standings of the top 10 cars in a larger view so more data can be displayed than the Standings widget. 
 * These usually only change as you cross the start/finish line.
 * The cars are color coded as Red(At least a lap ahead), Blue (At least a lap behind), White (Same lap as you), Cyan (Off track).
 * In the header the Strength of Field (SOF) and current lap for the leader are displayed.
 * 
 * Column values displayed are: Position, Number, Name, Club, Blk(Blink Counter), Rating, Lap, Pit/Run(Pit Time/Laps since pitting), Behind Leader, Best, Last times.
 * 
 * Red box around the name indicates below minimum speed. 
 * Green box around Best is fastest lap overall and Last is fastest last lap if you are within 2 laps of the leader.
 * <p>
 * Example:
 * <p><b>
 * <sra-standings-top-10></sra-standings-top-10><br />
 * </b>
 * <img src="../widgets/StandingsTop10/icon.png" />
 * @ngdoc directive
 * @name sra-standings-top-10
 * @param {integer} data-sra-args-interval The interval, in milliseconds, that this widget will update from the server. Default is 1000.
 * @author Jeffrey Gilliam
 * @since 1.0
 * @copyright Copyright (C) 2015 - 2024 Jeffrey Gilliam
 * @license Apache License 2.0
 */
define(['SIMRacingApps','css!widgets/StandingsTop10/StandingsTop10','widgets/CarNumber/CarNumber'],
function(SIMRacingApps) {
    var self = {
        name:            'sraStandingsTop10',
        url:             'StandingsTop10',
        template:        'StandingsTop10.html',
        defaultWidth:    800,
        defaultHeight:   315,
        defaultInterval: 300, //initialize with the default interval
        module:          angular.module('SIMRacingApps') //get the main module
    };
    self.module.directive(self.name,
           ['sraDispatcher',
    function(sraDispatcher) {
        return {
            restrict: 'EA',
            scope: true,
            templateUrl: sraDispatcher.getWidgetUrl(self.url) + '/' + self.template,
            controller: ['$scope', function($scope) {
                $scope.directiveName   = self.name;
                $scope.defaultWidth    = self.defaultWidth;
                $scope.defaultHeight   = self.defaultHeight;
                $scope.defaultInterval = self.defaultInterval;
                $scope.positions = ['P1','P2','P3','P4','P5','P6','P7','P8','P9','P10','REFERENCE'];
                //load translations
                sraDispatcher.loadTranslations(sraDispatcher.getWidgetUrl(self.url),'text',function(path) {
                    $scope.translations = sraDispatcher.getTranslation(path);
                });
            }]
            , link: function($scope,$element,$attrs) {
                $attrs.sraArgsData = $attrs.sraArgsData || ""; 
                $attrs.sraArgsData += ";Car/REFERENCE/Position";
                $scope.names = sraDispatcher.subscribe($scope,$attrs,self.defaultInterval); //register subscriptions and options to the dispatcher
                //if the reference car is out of view, put them at the bottom
                $scope.$watch("data.Car.REFERENCE.Position.Value", function(value) {
                    if (value)
                        $scope.positions[10] = (value > 10 ? 'REFERENCE' : 'P99');
                });
            }
        };
    }]);
    return self;
});