Bus Driving

by Avi Algaly

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<div ng-controller="driveCtrl">
    <div class="input-prepend" style="text-align:left">
        <div class="btn-group">
            <button class="btn dropdown-toggle" data-toggle="dropdown">הצג מצב עבור <span class="caret"></span>

            </button>
            <ul class="dropdown-menu">
                <li>אלעד אלגאלי</li>
                <li>עדן אלגאלי</li>
            </ul>
        </div>
    </div>
    <br />
    <button type="button" ng-click="tic()" class="btn btn-warning mtf">התחל</button>
    <button type="button" ng-click="addvanceTime()" class="btn btn-warning mtf">הרץ זמן</button>
    <button type="button" ng-click="madeItToNextStation()" class="btn btn-warning mtf">לתחנה הבאה</button>{{currentTime | date:"HH:mm:ss"}} | gap : {{minutes}}
    <table class="table">
        <thead>
            <tr class="info">
                <th>תחנה</th>
                <th>זמן הגעה</th>
                <th>איחור בדקות</th>
                <th>סטטוס</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="station in stations" ng-class="getCurrentClass()">
                <td ng-bind="station.stopName"></td>
                <td ng-bind="station.exitTime"></td>
                <td ng-bind="getMinutesLate(station)"></td>
                <td ng-bind="station.status"></td>
            </tr>
        </tbody>
    </table> <pre>{{stations|json}}</pre>

</div>

CSS

body {
    font-size:13px;
}
h1 {
    direction:rtl;
}
.table thead tr th {
    text-align:right;
}
.table {
    direction:rtl;
}
.mtf {
    float:right;
}
button {
    margin:5px;
}
.table tr td:last-child {
    text-transform:capitalize;
}

JavaScript

var app = angular.module('driveApp', []);

app.controller('driveCtrl', function ($scope, $timeout) {

    $scope.routeStartTime = new Date();
    var d2 = new Date($scope.routeStartTime);

    $scope.currentStation = 0;
    var diff = Math.abs($scope.routeStartTime - $scope.routeStartTime); // ?? always 0
    //var diff = Math.abs(d2 - $scope.routeStartTime); // ???
    $scope.minutes = Math.floor((diff / 1000) / 60);

    $scope.getExitTime = function (st) {
        return 2;
    };

    var status = {
        DRIVING: "בדרך",
        STOP: "עוצר",
        LEFT: "עזב",
        WAIT: "בהמתנה"
    };

    $scope.getMinutesLate = function (st) {
        return 1;
    };

    $scope.getStatus = function (st) {
        return 3;
    };
    $scope.madeItToNextStation = function () {
        $scope.stations[$scope.currentStation].imageUrl = "";
        $scope.stations[$scope.currentStation].status = status.LEFT;
        $scope.currentStation++;
        $scope.stations[$scope.currentStation].status = status.DRIVING;
        $scope.stations[$scope.currentStation].eta = $scope.currentTime;
    };

    // lets think
    /*
        var globalTimer = {
            getCurrentTime: function() { return ""; }
            start: function() { 
                // start the timer
            },
            stop: function() {
                // start the timer
            }
        };
    
        var station1 = {
            name: "Station 1",
            timeFromPrevStation: 0
        };
        var station2 = {
            name: "Station 2",
            timeFromPrevStation: 10
        };
        
        var Bus = (function() {
            function Bus(path, timeService) {
                // path -- array of stations
                this.stations = path;
                this.timeService = timeService;
                this.currentStationIndex = 0;
                this.prevStation = null;
                this.nextStation = this.stations[this.currentStationIndex];
               ...