did teams and pules

This commit is contained in:
Joachim Nielandt 2015-09-04 20:56:31 +02:00
parent ef407e5ff0
commit 235f2383c6
9 changed files with 238 additions and 5 deletions

View File

@ -54,6 +54,7 @@
<ul class="nav navbar-nav">
<li ng-class="getActiveCss('/championships');"><a href="#/championships">Championships</a></li>
<li ng-class="getActiveCss('/poules');"><a href="#/poules">Poules</a></li>
<li ng-class="getActiveCss('/teams');"><a href="#/teams">Teams</a></li>
</ul>
<ul class="nav navbar-nav navbar-right" ng-controller="LoginCtrl">

View File

@ -21,6 +21,7 @@ config(['$routeProvider', function($routeProvider) {
// $routeProvider.when('/news', {templateUrl: 'partials/news.html', controller: 'NewsCtrl'});
// $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.when('/championships', {templateUrl: 'partials/championships.html', controller: 'ChampionshipCtrl'});
$routeProvider.when('/teams/:idchampionship', {templateUrl: 'partials/teams.html', controller: 'TeamCtrl'});
$routeProvider.when('/poules/:idchampionship', {templateUrl: 'partials/poules.html', controller: 'PouleCtrl'});
$routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'LoginCtrl'});
$routeProvider.when('/register', {templateUrl: 'partials/register.html', controller: 'RegisterCtrl'});

View File

@ -90,9 +90,69 @@ mod.controller('PouleCtrl', ['$scope', '$routeParams', 'PouleService', function(
});
};
$scope.addPoule = function(newpoule) {
var idchampionship = $routeParams.idchampionship;
PouleService.addPoule(newpoule, idchampionship).
success(function(data, status, headers, config) {
console.log('addPoule successful...');
console.log(data);
if(data['ok']==true) {
$scope.refreshPoules();
newpoule.tier = "";
newpoule.poule = "";
}
}).
error(function(data, status, headers, config) {
console.log('addPoule failed...');
}
);;
};
$scope.refreshPoules();
}]);
mod.controller('TeamCtrl', ['$scope', '$routeParams', 'TeamService', function($scope, $routeParams, TeamService) {
//fetch all poules for the given championship
var teams = [];
$scope.refreshTeams = function() {
console.log('doing refreshTeams');
var idchampionship = $routeParams.idchampionship;
TeamService.getTeams(idchampionship).
success(function(data, status, headers, config) {
console.log('refreshTeams successful...');
console.log(data);
if(data['ok']==true) {
$scope.teams = data.teams;
} else {
}
}).
error(function(data, status, headers, config) {
console.log('refreshTeams failed...');
});
};
$scope.addTeam = function(newteam) {
var idchampionship = $routeParams.idchampionship;
TeamService.addTeam(newteam, idchampionship).
success(function(data, status, headers, config) {
console.log('addTeam successful...');
console.log(data);
if(data['ok']==true) {
$scope.refreshTeams();
newteam.name = "";
}
}).
error(function(data, status, headers, config) {
console.log('addTeam failed...');
}
);;
};
$scope.refreshTeams();
}]);
// STOPWATCH CONTROLLER

View File

@ -16,12 +16,27 @@ appServices.service('ChampionshipService', function($http) {
this.addChampionship = function(newchampionship) {
return $http.post('server/addchampionship.php', {name:newchampionship.name});
}
};
});
appServices.service('PouleService', function($http) {
this.getPoules = function(idchampionship) {
return $http.post('server/getpoules.php', {idchampionship:idchampionship});
return $http.post('server/getpoules.php', {idchampionship:idchampionship});
};
this.addPoule = function(newpoule, idchampionship) {
return $http.post('server/addpoule.php', {tier:newpoule.tier, poule:newpoule.poule, idchampionship:idchampionship});
};
});
appServices.service('TeamService', function($http) {
this.getTeams = function(idchampionship) {
return $http.post('server/getteams.php', {idchampionship:idchampionship});
};
this.addTeam = function(newteam, idchampionship) {
console.log('adding team');
return $http.post('server/addteam.php', {name:newteam.name, idchampionship:idchampionship});
};
});

View File

@ -1,11 +1,34 @@
<div class="row">
<div class="btn-group col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Poules</h3>
</div>
<div class="panel-body">
<table class="table">
<tr><th>Tier</th><th>Poule</th></tr>
<tr ng-repeat="poule in poules">
<td>{{poule.tier}}</td>
<td>{{poule.tier}}</td>
<td>{{poule.poule}}</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Voeg poule toe</h3>
</div>
<div class="panel-body">
<div class="input-group">
<span class="input-group-addon" id="sizing-addon2">Tier</span>
<input type="text" class="form-control" aria-describedby="sizing-addon2" ng-model="newpoule.tier">
</div>
<div class="input-group">
<span class="input-group-addon" id="sizing-addon2">Poule</span>
<input type="text" class="form-control" aria-describedby="sizing-addon2" ng-model="newpoule.poule">
</div>
<button type="button" class="btn btn-default" ng-click="addPoule(newpoule);">Voeg toe!</button>
</div>
</div>

27
partials/teams.html Normal file
View File

@ -0,0 +1,27 @@
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Teams</h3>
</div>
<div class="panel-body">
<table class="table">
<tr><th>Naam</th></tr>
<tr ng-repeat="team in teams">
<td>{{team.name}}</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Voeg team toe</h3>
</div>
<div class="panel-body">
<div class="input-group">
<span class="input-group-addon" id="sizing-addon2">Naam</span>
<input type="text" class="form-control" aria-describedby="sizing-addon2" ng-model="newteam.name">
</div>
<button type="button" class="btn btn-default" ng-click="addTeam(newteam);">Voeg toe!</button>
</div>
</div>

31
server/addpoule.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);
$idchampionship = $post['idchampionship'];
$poule = $post['poule'];
$tier = $post['tier'];
$addpoule= pg_prepare($dbconn, "addpoule", "insert into poule (poule, tier, idchampionship) values ($1, $2, $3)");
$addpoule= pg_execute($dbconn, "addpoule", array($poule, $tier, $idchampionship));
if($addpoule===FALSE) {
$result['ok'] = false;
$result['error'] = pg_last_error($dbconn);
} else {
//return data
$result['ok'] = true;
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

42
server/addteam.php Normal file
View File

@ -0,0 +1,42 @@
<?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);
$idchampionship = $post['idchampionship'];
$teamname = $post['name'];
$addteam= pg_prepare($dbconn, "addteam", "insert into team (name) values ($1) returning idteam");
$addteam= pg_execute($dbconn, "addteam", array($teamname));
if($addpoule===FALSE) {
$result['ok'] = false;
$result['error'] = 'insert team failed: '.pg_last_error($dbconn);
} else {
//inserted team, now the link
$insertedteam = pg_fetch_assoc($addteam);
$insertedidteam = $insertedteam['idteam'];
$addteamlinks= pg_prepare($dbconn, "addteamlink", "insert into team_championship (idteam, idchampionship) values ($1, $2)");
$addteamlinks= pg_execute($dbconn, "addteamlink", array($insertedidteam, $idchampionship));
//check
if($addteamlinks===FALSE) {
$result['ok'] = false;
$result['error'] = "inserted team, couldn't insert the link to championship...";
} else {
//all went well
$result['ok'] = true;
}
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

33
server/getteams.php Normal file
View File

@ -0,0 +1,33 @@
<?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);
$idchampionship = $post['idchampionship'];
//fetch the championships
$teamfetch = pg_prepare($dbconn, "teamfetch", "select team.* from team inner join team_championship using (idteam) where idchampionship = $1");
$teamfetch = pg_execute($dbconn, "teamfetch", array($idchampionship));
//build result object
$teams = array();
while($row = pg_fetch_assoc($teamfetch)) {
$teams[] = $row;
}
$result['teams'] = $teams;
//return data
$result['ok'] = true;
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>