From 8eb58be172024e25a39555a2df689933aa15a6c4 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 1 Sep 2018 10:03:04 +0200 Subject: [PATCH] can now toggle publishresults in race --- js/controllers/poule.js | 6 + js/services.js | 119 +++++++++--------- partials/championship-poule-races.html | 160 +++++++++++++++---------- server/config.php | 44 +++---- server/getracesinpoule.php | 4 +- 5 files changed, 191 insertions(+), 142 deletions(-) diff --git a/js/controllers/poule.js b/js/controllers/poule.js index ccbea4f..9484add 100644 --- a/js/controllers/poule.js +++ b/js/controllers/poule.js @@ -143,6 +143,8 @@ angular.module('bananaraceApp.controllers').controller('PouleCtrl', ['$scope', ' console.log(data); if(data['ok']==true) { $scope.racesInPoule = data.races; + console.log('got races: '); + console.log(data.races); } else { console.log('getRacesInPoule call returned but wasnt ok: '+data['error']); } @@ -159,6 +161,10 @@ angular.module('bananaraceApp.controllers').controller('PouleCtrl', ['$scope', ' MainService.toggleActiveRace(race.idrace, tier, poule, idchampionship); }; + $scope.togglePublishResults = function(race) { + MainService.togglePublishResults(race); + }; + $scope.getActiveRace = function() { return MainService.getActiveRace(); }; diff --git a/js/services.js b/js/services.js index 30da6d0..9f56b4a 100644 --- a/js/services.js +++ b/js/services.js @@ -4,33 +4,33 @@ var appServices = angular.module('bananaraceApp.services', []); -appServices.service('ChampionshipService', function($http) { - this.getChampionships = function() { +appServices.service('ChampionshipService', function ($http) { + this.getChampionships = function () { console.log('service.getChampionships called'); return $http.post('server/getchampionships.php', {}); }; - this.deleteChampionship = function(championship) { + this.deleteChampionship = function (championship) { return $http.post('server/deletechampionship.php', { idchampionship: championship.idchampionship }); }; - this.addChampionship = function(newchampionship) { + this.addChampionship = function (newchampionship) { return $http.post('server/addchampionship.php', { name: newchampionship.name }); }; }); -appServices.service('PouleService', function($http) { - this.getPoules = function(idchampionship) { +appServices.service('PouleService', function ($http) { + this.getPoules = function (idchampionship) { return $http.post('server/getpoules.php', { idchampionship: idchampionship }); }; - this.addPoule = function(newpoule, idchampionship) { + this.addPoule = function (newpoule, idchampionship) { return $http.post('server/addpoule.php', { tier: newpoule.tier, poule: newpoule.poule, @@ -38,7 +38,7 @@ appServices.service('PouleService', function($http) { }); }; - this.deletePoule = function(tier, poule, idchampionship) { + this.deletePoule = function (tier, poule, idchampionship) { return $http.post('server/deletepoule.php', { tier: tier, poule: poule, @@ -46,7 +46,7 @@ appServices.service('PouleService', function($http) { }); }; - this.addTeam = function(team, idchampionship, tier, poule) { + this.addTeam = function (team, idchampionship, tier, poule) { return $http.post('server/addteamtopoule.php', { idteam: team.idteam, tier: tier, @@ -55,7 +55,7 @@ appServices.service('PouleService', function($http) { }); }; - this.removeTeam = function(team, idchampionship, tier, poule) { + this.removeTeam = function (team, idchampionship, tier, poule) { return $http.post('server/removeteamfrompoule.php', { idteam: team.idteam, tier: tier, @@ -64,7 +64,7 @@ appServices.service('PouleService', function($http) { }); }; - this.getRacesInPoule = function(idchampionship, tier, poule) { + this.getRacesInPoule = function (idchampionship, tier, poule) { return $http.post('server/getracesinpoule.php', { tier: tier, poule: poule, @@ -72,7 +72,7 @@ appServices.service('PouleService', function($http) { }); }; - this.addRace = function(idchampionship, tier, poule, idteam) { + this.addRace = function (idchampionship, tier, poule, idteam) { return $http.post('server/addracetopoule.php', { tier: tier, poule: poule, @@ -81,7 +81,7 @@ appServices.service('PouleService', function($http) { }); }; - this.deleteRace = function(idchampionship, tier, poule, idrace) { + this.deleteRace = function (idchampionship, tier, poule, idrace) { return $http.post('server/deleterace.php', { tier: tier, poule: poule, @@ -92,14 +92,14 @@ appServices.service('PouleService', function($http) { }); -appServices.service('TeamService', function($http) { - this.getTeams = function(idchampionship) { +appServices.service('TeamService', function ($http) { + this.getTeams = function (idchampionship) { return $http.post('server/getteams.php', { idchampionship: idchampionship }); }; - this.getTeamsInPoule = function(idchampionship, tier, poule) { + this.getTeamsInPoule = function (idchampionship, tier, poule) { return $http.post('server/getteams.php', { idchampionship: idchampionship, tier: tier, @@ -107,7 +107,7 @@ appServices.service('TeamService', function($http) { }); }; - this.deleteTeam = function(team, idchampionship) { + this.deleteTeam = function (team, idchampionship) { return $http.post('server/deleteteam.php', { idteam: team.idteam, idchampionship: idchampionship @@ -117,7 +117,7 @@ appServices.service('TeamService', function($http) { /** * Filters: teams that are from the given championship and haven't been used in another poule... */ - this.getTeamsAvailableForPoule = function(idchampionship, tier, poule) { + this.getTeamsAvailableForPoule = function (idchampionship, tier, poule) { return $http.post('server/getteams.php', { idchampionship: idchampionship, tier: tier, @@ -126,7 +126,7 @@ appServices.service('TeamService', function($http) { }); }; - this.addTeam = function(newteam, idchampionship) { + this.addTeam = function (newteam, idchampionship) { console.log('adding team'); return $http.post('server/addteam.php', { name: newteam.name, @@ -136,21 +136,21 @@ appServices.service('TeamService', function($http) { }); -appServices.service('RaceService', function($http) { - this.getDrives = function(idrace) { +appServices.service('RaceService', function ($http) { + this.getDrives = function (idrace) { return $http.post('server/getdrives.php', { idrace: idrace }); }; - this.getTeam = function(idrace) { + this.getTeam = function (idrace) { return $http.post('server/getraceteam.php', { idrace: idrace }); }; - this.addDrive = function(race, driver, laps) { - console.log('raceservice.adddrive got called: '+race+' '+driver.iddriver+' '+laps); + 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, @@ -158,21 +158,21 @@ appServices.service('RaceService', function($http) { }); }; - this.deleteDrive = function(drivenr, idrace) { + this.deleteDrive = function (drivenr, idrace) { return $http.post('server/deletedrive.php', { drivenr: drivenr, idrace: idrace }); }; - this.addMeasurementNow = function(idrace) { + this.addMeasurementNow = function (idrace) { return $http.post('server/addmeasurement.php', { type: 'now', idrace: idrace }); }; - this.addMeasurementRelative = function(idrace, timestamp) { + this.addMeasurementRelative = function (idrace, timestamp) { return $http.post('server/addmeasurement.php', { type: 'relative', idrace: idrace, @@ -180,20 +180,20 @@ appServices.service('RaceService', function($http) { }); }; - this.getMeasurements = function(idrace) { + this.getMeasurements = function (idrace) { return $http.post('server/getmeasurements.php', { idrace: idrace }); }; - this.updateMeasurement = function(measurement) { + this.updateMeasurement = function (measurement) { return $http.post('server/updatemeasurement.php', { idmeasurement: measurement.idmeasurement, valid: measurement.valid }); }; - this.deleteMeasurement = function(measurement) { + this.deleteMeasurement = function (measurement) { console.log('deleting measurement'); console.log(measurement); return $http.post('server/deletemeasurement.php', { @@ -203,15 +203,15 @@ appServices.service('RaceService', function($http) { }); -appServices.service('DriverService', function($http) { - this.getDrivers = function(idchampionship, idteam) { +appServices.service('DriverService', function ($http) { + this.getDrivers = function (idchampionship, idteam) { return $http.post('server/getdrivers.php', { idchampionship: idchampionship, idteam: idteam }); }; - this.addDriver = function(newdriver, idchampionship, idteam) { + this.addDriver = function (newdriver, idchampionship, idteam) { console.log('adding driver'); return $http.post('server/adddriver.php', { idchampionship: idchampionship, @@ -220,7 +220,7 @@ appServices.service('DriverService', function($http) { }); }; - this.deleteDriver = function(driver) { + this.deleteDriver = function (driver) { console.log('removing driver'); return $http.post('server/deletedriver.php', { iddriver: driver.iddriver @@ -228,8 +228,8 @@ appServices.service('DriverService', function($http) { }; }); -appServices.service('DriveService', function($http) { - this.getComments = function(idrace, drivenr) { +appServices.service('DriveService', function ($http) { + this.getComments = function (idrace, drivenr) { console.log('getting comments for: ' + idrace + ' ' + drivenr); return $http.post('server/getcomments.php', { idrace: idrace, @@ -237,7 +237,7 @@ appServices.service('DriveService', function($http) { }); }; - this.addComment = function(idrace, drivenr, comment, penaltyseconds) { + this.addComment = function (idrace, drivenr, comment, penaltyseconds) { return $http.post('server/addcomment.php', { idrace: idrace, drivenr: drivenr, @@ -246,13 +246,13 @@ appServices.service('DriveService', function($http) { }); }; - this.deleteComment = function(idcomment) { + this.deleteComment = function (idcomment) { return $http.post('server/deletecomment.php', { idcomment: idcomment }); }; - this.deleteDriver = function(driver) { + this.deleteDriver = function (driver) { console.log('removing driver'); return $http.post('server/deletedriver.php', { iddriver: driver.iddriver @@ -261,17 +261,17 @@ appServices.service('DriveService', function($http) { }); -appServices.service('OverviewService', function($http) { - this.getData = function(idchampionship) { +appServices.service('OverviewService', function ($http) { + this.getData = function (idchampionship) { return $http.post('server/getoverviewofchampionship.php', { idchampionship: idchampionship }); }; }); -appServices.service('ViewerService', function($http) { +appServices.service('ViewerService', function ($http) { - this.getTeamsForPoule = function(idchampionship, tier, poule) { + this.getTeamsForPoule = function (idchampionship, tier, poule) { return $http.post('server/getteamsforpoule.php', { tier: tier, poule: poule, @@ -280,15 +280,14 @@ appServices.service('ViewerService', function($http) { }; }); -appServices.service('MainService', function($http, $cookies) { +appServices.service('MainService', function ($http, $cookies) { var activerace = null; - this.refreshConfig = function() { + this.refreshConfig = function () { $http.post('server/config.php', { action: 'getConfig' - }). - success(function(data, status, headers, config) { + }).success(function (data, status, headers, config) { // console.log('refreshConfig successful...'); //refresh activerace if (data.activeidrace != null) { @@ -304,13 +303,12 @@ appServices.service('MainService', function($http, $cookies) { activerace = null; } // console.log(activerace); - }). - error(function(data, status, headers, config) { + }).error(function (data, status, headers, config) { console.log('getConfig failed...'); }); }; - this.setActiveRace = function(idrace, tier, poule, idchampionship) { + this.setActiveRace = function (idrace, tier, poule, idchampionship) { if (idrace == null) { activerace = null; } else { @@ -324,17 +322,16 @@ appServices.service('MainService', function($http, $cookies) { $http.post('server/config.php', { action: 'setActiveIdRace', idrace: idrace - }). - success(function(data, status, headers, config) { + }).success(function (data, status, headers, config) { //do something? }); }; - this.getActiveRace = function() { + this.getActiveRace = function () { return activerace; }; - this.toggleActiveRace = function(idrace, tier, poule, idchampionship) { + this.toggleActiveRace = function (idrace, tier, poule, idchampionship) { console.log('toggling active race' + idrace); //if the race is not the same as the currently active on: switch it if (activerace == null || activerace.idrace != idrace) { @@ -346,6 +343,20 @@ appServices.service('MainService', function($http, $cookies) { } }; + this.togglePublishResults = function (race) { + console.log('toggling publish results ' + race.idrace); + $http.post('server/config.php', { + action: 'togglePublishResults', + idrace: race.idrace + }).success(function (data, status, headers, config) { + if (race.publishresults === 'f') { + race.publishresults = 't'; + } else if (race.publishresults === 't') { + race.publishresults = 'f'; + } + }); + }; + //load the current config this.refreshConfig(); }); diff --git a/partials/championship-poule-races.html b/partials/championship-poule-races.html index 8ad33ac..d32aa4c 100644 --- a/partials/championship-poule-races.html +++ b/partials/championship-poule-races.html @@ -1,74 +1,102 @@
-
- -
+
+ +
+ -
+
-
-
-

Races

+
+
+

Races

+
+
+ + + + + + + + + + + + + + + +
TeamRaceidTotaaltijdRittenActies
{{race.name}}{{race.idrace}}{{race.totaltime | secondsToString}}{{race.lapagg}} + + Tijden {{race.measurementcount}} + + + Ritten {{race.drivecount}} + + + + +
+
-
- - - - - - - - - -
TeamRaceidTotaaltijdRittenActies
{{race.name}}{{race.idrace}}{{race.totaltime | secondsToString}}{{race.lapagg}} - - Tijden {{race.measurementcount}} - - - Ritten {{race.drivecount}} - - - -
-
-
-
-
-
-

Voeg race toe

+
+
+
+

Voeg race toe

+
+
+ + +
+
Met een team uit de poule...
+
+ + +
+
+ +
+
Met alle teams...
+
+ +
+
+
+
-
- - -
-
Met een team uit de poule...
-
- - -
-
- -
-
Met alle teams...
-
- -
-
-
-
-
diff --git a/server/config.php b/server/config.php index 515de2b..570847e 100644 --- a/server/config.php +++ b/server/config.php @@ -1,26 +1,30 @@ diff --git a/server/getracesinpoule.php b/server/getracesinpoule.php index 53935de..ab2152f 100644 --- a/server/getracesinpoule.php +++ b/server/getracesinpoule.php @@ -14,12 +14,12 @@ $poule = $post['poule']; //fetch the championships - $racefetch = pg_prepare($dbconn, "racefetch", "select team.*, race.idrace, (select string_agg(laps||'', ',') lapagg + $racefetch = pg_prepare($dbconn, "racefetch", "select team.*, race.publishresults, race.idrace, (select string_agg(laps||'', ',') lapagg from drive where drive.idrace = race.idrace), (select extract(epoch from max(case when sensortime is null then timestamp else sensortime end)-min(case when sensortime is null then timestamp else sensortime end)) from measurement where valid and idrace = race.idrace) as totaltime, (select count(*) from measurement where idrace = race.idrace) measurementcount, (select count(*) from drive where idrace = race.idrace) drivecount from team inner join race using (idteam, idchampionship) - where idchampionship = $1 and tier = $2 and poule = $3"); + where idchampionship = $1 and tier = $2 and poule = $3 order by race.idrace"); $racefetch = pg_execute($dbconn, "racefetch", array($idchampionship, $tier, $poule)); //build result object