fixed drivenr update when deleting one, added 1/1/... button

This commit is contained in:
Joachim Nielandt 2015-09-17 12:47:42 +02:00
parent 8bc6ab8750
commit e1bbb91f7a
9 changed files with 55 additions and 29 deletions

View File

@ -6,31 +6,6 @@ var mod = angular.module('bananaraceApp.controllers');
mod.controller('NavCtrl', ['$scope', '$location', 'MainService', function ($scope, $location, MainService) {
$scope.loggedIn = function() {

View File

@ -144,6 +144,48 @@ angular.module('bananaraceApp.controllers').controller('RaceCtrl', ['$scope', '$
});
};
$scope.addBatchDrives = function() {
//do the adddrive action for all the drivers and the selected lapamount
//if only one driver is there: trivial, call addDrive instead
if($scope.team.drivers.length==1) {
$scope.addDrive();
return;
}
//more than one driver present!
var finalpromise = undefined;
var team = $scope.team;
for(var i = 0; i<team.drivers.length; i++) {
var iddriver = team.drivers[i].iddriver;
console.log('adding batch drives for...'+iddriver);
(function(i) {
var icopy = i;
console.log('doing it for the icopy:'+icopy+' driver '+iddriver);
if (icopy == 0) {
//start up the sequence
console.log('queueing this: '+icopy);
finalpromise = RaceService.addDrive($scope.currentRace, team.drivers[icopy], $scope.selectedLapamount);
} else {
//the rest: this does not need to resolve, just add to the sequence of promises
finalpromise = finalpromise.then(function(data, status, headers, config) {
// console.log($scope.team.drivers[i].iddriver+'gets added to queue');
console.log('got success, queueing this: '+icopy);
console.log(data);
return RaceService.addDrive($scope.currentRace, team.drivers[icopy], $scope.selectedLapamount);
});
}
})(i);
}
//now listen to the end of the promise...
console.log('going to listen to the end...');
finalpromise.then(function(data, status, headers, config) {
console.log('wellllll, last one finished, will refresh now');
console.log(data);
$scope.refreshDrives();
});
};
$scope.deleteDrive = function(drivenr, idrace) {
RaceService.deleteDrive(drivenr, idrace).
success(function(data, status, headers, config) {

View File

@ -150,6 +150,7 @@ appServices.service('RaceService', function($http) {
};
this.addDrive = function(race, driver, laps) {
console.log('raceservice.adddrive got called: '+race+' '+driver.iddriver+' '+laps);
return $http.post('server/adddrive.php', {
idrace: race,
iddriver: driver.iddriver,
@ -346,4 +347,4 @@ appServices.service('MainService', function($http, $cookies) {
//load the current config
this.refreshConfig();
});
});

View File

@ -19,6 +19,7 @@
<!-- <span class="label label-primary">Poule {{poule.poule}}</span> -->
<!-- <a href="" type="button" class="btn btn-default btn-xs">Poule {{poule.poule}}</button> -->
<a href="#/championship/{{currentChampionship}}/poules" class="btn btn-default btn-xs" role="button">Poule {{poule.poule}}</a>
<a href="#/viewer/championship/{{currentChampionship}}/poule/{{tier.tier}}/{{poule.poule}}/overview" class="btn btn-default btn-xs glyphicon glyphicon-eye-open" role="button"></a>
</div>
<div class="col-xs-11" ng-show="poule.teams.length>0">
<div class="row" ng-repeat="team in poule.teams">

View File

@ -62,7 +62,7 @@
</div>
</div>
<button type="button" class="btn btn-default" ng-click="addDrive();" ng-disabled="selectedDriver == null">Voeg rit toe</button>
<button type="button" class="btn btn-default" ng-click="addBatchDrives(1,1);" ng-disabled="selectedDriver == null">Voeg 1/1/.. toe</button>
<button type="button" class="btn btn-default" ng-click="addBatchDrives();" ng-disabled="selectedDriver == null" tooltip="Voegt ritten van x lap(s) toe voor iedere chauffeur in deze race.">Voeg {{selectedLapamount}}/{{selectedLapamount}}/.. toe</button>
</div>
</div>
</div><!-- end row -->

View File

@ -68,7 +68,7 @@
<label for="pouleInput">Poule</label>
<input type="text" class="form-control" id="pouleInput" aria-describedby="sizing-addon2" ng-model="newpoule.poule" style="width:50px"/>
</div>
<button type="button" class="btn btn-sm btn-default btn-success" ng-click="addPoule(newpoule)">Toevoegen</button>
<button type="button" class="btn btn-sm btn-success" ng-click="addPoule(newpoule)">Toevoegen</button>
</form>
</div>
</div>

View File

@ -25,6 +25,12 @@
$result['ok'] = true;
}
$result['debug'] = array();
$result['debug']['laps'] = $laps;
$result['debug']['idrace'] = $idrace;
$result['debug']['iddriver'] = $iddriver;
//print message
$resultjson = json_encode($result);

View File

@ -24,6 +24,7 @@
$result['ok'] = true;
}
$result['post'] = $post;
//print message

View File

@ -27,7 +27,7 @@
}
//update drivenrs
$updatedrivenr= pg_prepare($dbconn, "updatedrivenr", "update drive set drivenr = sub.rnum from (select idrace, drivenr, row_number() OVER () as rnum from drive) sub where drive.drivenr = sub.drivenr and drive.idrace = $1");
$updatedrivenr= pg_prepare($dbconn, "updatedrivenr", "update drive set drivenr = sub.rnum from (select idrace, drivenr, row_number() OVER () as rnum from drive where idrace = $1) sub where drive.drivenr = sub.drivenr and drive.idrace = $1");
if($updatedrivenr===false)
$result['debug2'] = pg_last_error();
$updatedrivenr= pg_execute($dbconn, "updatedrivenr", array($idrace));