added comments

This commit is contained in:
Joachim Nielandt 2015-09-14 23:33:56 +02:00
parent 4072460aa1
commit 1b84657029
10 changed files with 239 additions and 2 deletions

View File

@ -26,6 +26,7 @@ config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/championship/:idchampionship/poule/:tier/:poule/races', {templateUrl: 'partials/championship-poule-races.html', controller: 'PouleCtrl'});
$routeProvider.when('/championship/:idchampionship/poule/:tier/:poule/teams', {templateUrl: 'partials/championship-poule-teams.html', controller: 'PouleCtrl'});
$routeProvider.when('/championship/:idchampionship/poule/:tier/:poule/race/:idrace/drives', {templateUrl: 'partials/championship-poule-race-drives.html', controller: 'RaceCtrl'});
$routeProvider.when('/championship/:idchampionship/poule/:tier/:poule/race/:idrace/drive/:drivenr/comments', {templateUrl: 'partials/championship-poule-race-comments.html', controller: 'DriveCtrl'});
$routeProvider.when('/championship/:idchampionship/poule/:tier/:poule/race/:idrace/measurements', {templateUrl: 'partials/championship-poule-race-measurements.html', controller: 'RaceCtrl'});
$routeProvider.when('/championship/:idchampionship/teams', {templateUrl: 'partials/championship-teams.html', controller: 'TeamCtrl'});
$routeProvider.when('/championship/:idchampionship/team/:idteam/drivers', {templateUrl: 'partials/championship-team-drivers.html', controller: 'DriverCtrl'});

View File

@ -689,3 +689,69 @@ mod.controller('TimepickerDemoCtrl', ['$scope', function ($scope, $log) {
$scope.mytime = null;
};
}]);
mod.controller('DriveCtrl', ['$scope', 'RaceService', 'DriveService', '$routeParams', function ($scope, RaceService, DriveService, $routeParams) {
//set route params in scope variables
$scope.currentChampionship = $routeParams.idchampionship;
$scope.currentTier = $routeParams.tier;
$scope.currentPoule = $routeParams.poule;
$scope.currentRace = $routeParams.idrace;
$scope.currentDrive = $routeParams.drivenr;
$scope.refreshComments = function() {
DriveService.getComments($scope.currentRace, $scope.currentDrive).
success(function(data, status, headers, config) {
console.log('refreshComments successful...');
console.log(data);
if(data['ok']==true) {
$scope.comments = data.comments;
} else {
console.log('shit hit the fan with refreshComments');
}
}).
error(function(data, status, headers, config) {
console.log('refreshComments failed...');
});
};
$scope.deleteComment = function(idcomment) {
DriveService.deleteComment(idcomment).
success(function(data, status, headers, config) {
console.log('deleteComment successful...');
console.log(data);
if(data['ok']==true) {
$scope.refreshComments();
} else {
console.log('shit hit the fan with deleteComment');
}
}).
error(function(data, status, headers, config) {
console.log('deleteComment failed...');
});
};
$scope.addComment = function(newcomment, newpenaltyseconds) {
console.log('comment: '+newcomment);
console.log('penaltyseconds: '+newpenaltyseconds);
// this.addComment = function(idrace, drivenr, comment, penaltyseconds) {
DriveService.addComment($scope.currentRace, $scope.currentDrive, newcomment, newpenaltyseconds).
success(function(data, status, headers, config) {
console.log('addComment successful...');
console.log(data);
if(data['ok']==true) {
$scope.refreshComments();
} else {
console.log('shit hit the fan with addComment')
}
}).
error(function(data, status, headers, config) {
console.log('addcomment failed...');
});
};
$scope.refreshComments();
}]);

View File

@ -135,6 +135,27 @@ appServices.service('DriverService', function($http) {
};
});
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, drivenr:drivenr});
};
this.addComment = function(idrace, drivenr, comment, penaltyseconds) {
return $http.post('server/addcomment.php', {idrace:idrace, drivenr:drivenr, comment:comment, penaltyseconds:penaltyseconds});
};
this.deleteComment = function(idcomment) {
return $http.post('server/deletecomment.php', {idcomment:idcomment});
};
this.deleteDriver = function(driver) {
console.log('removing driver');
return $http.post('server/deletedriver.php', {iddriver:driver.iddriver});
};
});
appServices.service('MainService', function($http, $cookies) {
var activerace = null;

View File

@ -0,0 +1,50 @@
<ol class="breadcrumb">
<li><a href="#/championships/">Kampioenschappen</a></li>
<li><a href="#/championship/{{currentChampionship}}/poules">Poules voor {{currentChampionship}}</a></li>
<li><a href="#/championship/{{currentChampionship}}/poule/{{currentTier}}/{{currentPoule}}/races">Races voor poule {{currentTier}}/{{currentPoule}}</a></li>
<li><a href="#/championship/{{currentChampionship}}/poule/{{currentTier}}/{{currentPoule}}/race/{{currentRace}}/drives">Ritten voor race {{currentRace}}</a></li>
<li class="active">Commentaar voor rit {{currentDrive}}</li>
</ol>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Comments</h3>
</div>
<div class="panel-body">
<table class="table">
<tr><th>Commentaar</th><th>Penalty</th><th>Acties</th></tr>
<tr ng-repeat="comment in comments">
<td>{{comment.comment}}</td>
<td>{{comment.penaltyseconds}} <small ng-show="comment.penaltyseconds > 0">secs</small></td>
<td>
<a class="btn btn-danger btn-sm" href="" ng-click="deleteComment(comment.idcomment)">Verwijder</a>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Voeg rit toe</h3>
</div>
<div class="panel-body">
<div class="panel panel-default">
<div class="panel-heading">Opties en acties</div>
<div class="panel-body">
<textarea ng-model="newcomment" class="form-control" style="resize: none;"></textarea>
<div class="input-group">
<input type="number" class="form-control" placeholder="Extra seconds" aria-describedby="basic-addon2" ng-model="newpenaltyseconds">
<span class="input-group-addon" id="basic-addon2">penalty seconden</span>
</div>
<button type="button" class="btn btn-default" ng-disabled="newpenaltyseconds==null && newcomment==null" ng-click="addComment(newcomment, newpenaltyseconds);" ng-disabled="selectedDriver == null">Voeg commentaar toe</button>
</div>
</div>
</div><!-- end row -->
</div>
</div>
</div>

View File

@ -19,6 +19,9 @@
<td>{{drive.laps}}</td>
<td>{{drive.drivername}}</td>
<td>
<a class="btn btn-info btn-sm" href="#/championship/{{currentChampionship}}/poule/{{currentTier}}/{{currentPoule}}/race/{{drive.idrace}}/drive/{{drive.drivenr}}/comments">
Commentaar
</a>
<a class="btn btn-danger btn-sm" href="" ng-click="deleteDrive(drive.drivenr, drive.idrace)">Verwijder</a>
</td>
</tr>

View File

@ -15,10 +15,11 @@
</div>
<div class="panel-body">
<table class="table">
<tr><th>Team</th><th>Raceid</th><th>Laps</th><th>Acties</th></tr>
<tr><th>Team</th><th>Raceid</th><th>Totaaltijd</th><th>Laps</th><th>Acties</th></tr>
<tr ng-repeat="race in racesInPoule">
<td>{{race.name}}</td>
<td>{{race.idrace}}</td>
<td>{{race.totaltime}} <small ng-show="race.totaltime>0">secs</small></td>
<td>{{race.lapagg}}</td>
<td>
<a class="btn btn-info btn-sm" href="#/championship/{{currentChampionship}}/poule/{{currentTier}}/{{currentPoule}}/race/{{race.idrace}}/measurements">

31
server/addcomment.php Normal file
View File

@ -0,0 +1,31 @@
<?php
include_once("db.php");
//make result object
$result = array();
$result['ok'] = false;
//get post data
$postdata = file_get_contents("php://input");
$post = json_decode($postdata, true);
$idrace = $post['idrace'];
$drivenr = $post['drivenr'];
$comment = $post['comment'];
$penaltyseconds = $post['penaltyseconds'];
$addcomment= pg_prepare($dbconn, "addcomment", "insert into comment (idrace, drivenr, comment, penaltyseconds) values ($1, $2, $3, $4)");
$addcomment= pg_execute($dbconn, "addcomment", array($idrace, $drivenr, $comment, $penaltyseconds));
if($addcomment===FALSE) {
$result['ok'] = false;
$result['error'] = 'insert comment failed: '.pg_last_error($dbconn);
} else {
$result['ok'] = true;
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

30
server/deletecomment.php Normal file
View File

@ -0,0 +1,30 @@
<?php
include_once("db.php");
//make result object
$result = array();
$result['ok'] = false;
//get post data
$postdata = file_get_contents("php://input");
$post = json_decode($postdata, true);
$idcomment = $post['idcomment'];
$commentdelete = pg_prepare($dbconn, "commentdelete", "delete from comment where idcomment = $1");
$commentdelete = pg_execute($dbconn, "commentdelete", array($idcomment));
if($commentdelete===FALSE) {
$result['ok'] = false;
$result['error'] = pg_last_error($dbconn);
} else {
//return data
$result['ok'] = true;
$result['debug'] = 'deleted comment '.$post['idcomment'];
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

34
server/getcomments.php Normal file
View File

@ -0,0 +1,34 @@
<?php
include_once("db.php");
//make result object
$result = array();
$result['ok'] = false;
//get post data
$postdata = file_get_contents("php://input");
$post = json_decode($postdata, true);
$idrace = $post['idrace'];
$drivenr = $post['drivenr'];
//fetch the comments
$commentfetch = pg_prepare($dbconn, "commentfetch", "select * from comment where idrace = $1 and drivenr = $2");
$commentfetch = pg_execute($dbconn, "commentfetch", array($idrace, $drivenr));
//build result object
$comments = array();
while($row = pg_fetch_assoc($commentfetch)) {
$comments[] = $row;
}
$result['comments'] = $comments;
//return data
$result['ok'] = true;
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

View File

@ -14,7 +14,7 @@
$poule = $post['poule'];
//fetch the championships
$racefetch = pg_prepare($dbconn, "racefetch", "select team.*, race.idrace, (select string_agg(laps||'', ',') lapagg from drive where drive.idrace = race.idrace) from team inner join race using (idteam, idchampionship) where idchampionship = $1 and tier = $2 and poule = $3");
$racefetch = pg_prepare($dbconn, "racefetch", "select team.*, race.idrace, (select string_agg(laps||'', ',') lapagg from drive where drive.idrace = race.idrace), (select extract(epoch from max(timestamp)-min(timestamp)) from measurement where idrace = race.idrace) as totaltime from team inner join race using (idteam, idchampionship) where idchampionship = $1 and tier = $2 and poule = $3");
$racefetch = pg_execute($dbconn, "racefetch", array($idchampionship, $tier, $poule));
//build result object