got going...

This commit is contained in:
Joachim Nielandt 2015-09-03 22:36:35 +02:00
parent d07deb2fb3
commit ef407e5ff0
11 changed files with 278 additions and 69 deletions

View File

@ -27,8 +27,6 @@
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap-theme.min.css">
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="node_modules/bootstrap/js/tooltip.js"></script>
<script src="node_modules/bootstrap/js/popover.js"></script>
<!-- <script src="node_modules/angular-bootstrap/dist/ui-bootstrap.min.js"></script> -->
<!-- <script src="node_modules/angular-bootstrap/dist/ui-bootstrap-tpls.min.js"></script> -->
@ -39,69 +37,23 @@
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<!-- init all popovers -->
<script>
$(function () {
$('[data-toggle="popover"]').popover()
})
</script>
<script>
keypressCallback = function($event) {
alert('Voila!');
$event.preventDefault();
};
</script>
<style>
.angular-ui-tree-drag {
border-style:dashed;
}
.angular-ui-tree-handle {
padding:5px 5px;
/*background-color:#f8faff;*/
border: 1px solid #dae2ea;
color: #7c9eb2;
}
.angular-ui-tree-placeholder {
border:1px gray dashed;
}
#stopwatchcontainer {
text-align:center;
}
.stopwatchbutton {
height:32px;
}
.popover {
width:300px;
}
#leafcontainer {
margin-top:10px;
}
/*.stay-open {display:block !important;}*/
</style>
</head>
<body ng-controller="BodyCtrl">
<body>
<!-- the navbar on top ... -->
<nav class="navbar navbar-default" ng-controller="NavCtrl">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="">TimeY</a>
<a class="navbar-brand" href="">Race - title?</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ng-class="getActiveCss('/stopwatch');"><a href="#/stopwatch">Stopwatch</a></li>
<li ng-class="getActiveCss('/createtemplate');" ng-show="loggedIn();"><a href="#/createtemplate">Create template</a></li>
<li ng-class="getActiveCss('/championships');"><a href="#/championships">Championships</a></li>
<li ng-class="getActiveCss('/poules');"><a href="#/poules">Poules</a></li>
</ul>
<ul class="nav navbar-nav navbar-right" ng-controller="LoginCtrl">

View File

@ -20,12 +20,12 @@ angular.module('bananaraceApp', [
config(['$routeProvider', function($routeProvider) {
// $routeProvider.when('/news', {templateUrl: 'partials/news.html', controller: 'NewsCtrl'});
// $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'});
$routeProvider.when('/createtemplate', {templateUrl: 'partials/createtemplate.html', controller: 'TimerTemplateCtrl'});
$routeProvider.when('/championships', {templateUrl: 'partials/championships.html', controller: 'ChampionshipCtrl'});
$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'});
$routeProvider.when('/stopwatch', {templateUrl: 'partials/stopwatch.html', controller: 'StopwatchCtrl'});
// $routeProvider.when('/member', {templateUrl: 'partials/member.html', controller: 'MemberCtrl'});
$routeProvider.otherwise({redirectTo: '/stopwatch'});
$routeProvider.otherwise({redirectTo: '/unknown'});
}]);
//$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

View File

@ -6,27 +6,92 @@ var mod = angular.module('bananaraceApp.controllers', ['bananaraceApp.services']
mod.controller('ChampionshipCtrl', ['$scope', 'ChampionshipService', function($scope, ChampionshipService) {
var championships = [];
mod.controller('BodyCtrl', ['$scope', 'StopwatchService', 'LoginService', function($scope, StopwatchService, LoginService) {
console.log('body controller loaded?');
$scope.name = 'World';
$scope.keyCode = "";
$scope.keyPressed = function(e) {
console.log('KEY PRESSED');
$scope.keyCode = e.which;
$scope.refreshChampionships = function() {
console.log('doing refreshChampionships');
ChampionshipService.getChampionships().
success(function(data, status, headers, config) {
console.log('refreshChampionships successful...');
console.log(data);
if(data['ok']==true) {
$scope.championships = data.championships;
} else {
}
}).
error(function(data, status, headers, config) {
console.log('refreshChampionships failed...');
});
};
$scope.isLoggedIn = function() {
return LoginService.isLoggedIn();
}
$scope.setSelectedChampionship = function(championship) {
$scope.selectedChampionship = championship;
console.log('selected: '+championship.name);
};
$scope.isSelectedChampionship = function(championship) {
return championship == $scope.selectedChampionship;
};
$scope.deleteChampionship = function(championship) {
ChampionshipService.deleteChampionship(championship).
success(function(data, status, headers, config) {
console.log('refreshChampionships successful...');
if(data['ok']==true) {
$scope.refreshChampionships();
} else {
}
}).
error(function(data, status, headers, config) {
console.log('refreshChampionships failed...');
});
};
$scope.addChampionship = function(newchampionship) {
console.log("adding: "+newchampionship);
ChampionshipService.addChampionship(newchampionship).
success(function(data, status, headers, config) {
console.log('addChampionships successful...');
console.log(data);
if(data['ok']==true) {
$scope.refreshChampionships();
newchampionship.name = "";
}
}).
error(function(data, status, headers, config) {
console.log('addChampionships failed...');
}
);
};
//initial refresh championships when building the controller
$scope.refreshChampionships();
}]);
mod.controller('PouleCtrl', ['$scope', '$routeParams', 'PouleService', function($scope, $routeParams, PouleService) {
//fetch all poules for the given championship
var poules = [];
$scope.refreshPoules = function() {
var idchampionship = $routeParams.idchampionship;
console.log('doing refreshPoules');
PouleService.getPoules(idchampionship).
success(function(data, status, headers, config) {
console.log('refreshPoules successful...');
console.log(data);
if(data['ok']==true) {
$scope.poules = data.poules;
} else {
}
}).
error(function(data, status, headers, config) {
console.log('refreshChampionships failed...');
});
};
$scope.refreshPoules();
}]);

View File

@ -4,6 +4,28 @@
var appServices = angular.module('bananaraceApp.services', []);
appServices.service('ChampionshipService', function($http) {
this.getChampionships = function() {
console.log('service.getChampionships called');
return $http.post('server/getchampionships.php', {});
};
this.deleteChampionship = function(championship) {
return $http.post('server/deletechampionship.php', {idchampionship:championship.idchampionship});
};
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});
};
});
appServices.service('StopwatchService', ['TemplateBackendService', function(TemplateBackendService) {
//init the stopwatch value in ms
var intervalMs = 0;

View File

@ -0,0 +1,36 @@
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Kampioenschappen</h3>
</div>
<div class="panel-body">
<table class="table">
<tr><th>Selected</th><th>Naam</th></tr>
<tr ng-repeat="championship in championships">
<td><button ng-click="setSelectedChampionship(championship);" ng-disabled="isSelectedChampionship(championship)" ng-show="!isSelectedChampionship(championship)">
Select
</button>
<button ng-click="deleteChampionship(championship);">
Delete
</button>
<a href="#/poules/{{championship.idchampionship}}">Bekijk poules</a>
</td>
<td>{{championship.name}}</td>
</tr>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Voeg kampioenschap 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="newchampionship.name">
</div>
<button type="button" class="btn btn-default" ng-click="addChampionship(newchampionship);">Voeg toe!</button>
</div>
</div>

11
partials/poules.html Normal file
View File

@ -0,0 +1,11 @@
<div class="row">
<div class="btn-group col-lg-4">
<table class="table">
<tr><th>Tier</th><th>Poule</th></tr>
<tr ng-repeat="poule in poules">
<td>{{poule.tier}}</td>
<td>{{poule.poule}}</td>
</tr>
</table>
</div>
</div>

View File

@ -0,0 +1,27 @@
<?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);
$addchamp= pg_prepare($dbconn, "addchamp", "insert into championship (name) values ($1)");
$addchamp= pg_execute($dbconn, "addchamp", array($post['name']));
if($addchamp===FALSE) {
$result['ok'] = false;
$result['error'] = pg_last_error($dbconn);
} else {
//return data
$result['ok'] = true;
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

4
server/db.php Normal file
View File

@ -0,0 +1,4 @@
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=race user=postgres password=915015");
echo pg_last_error($dbconn);
?>

View File

@ -0,0 +1,28 @@
<?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);
//fetch the championships
$champdelete = pg_prepare($dbconn, "champdelete", "delete from championship where idchampionship = $1");
$champdelete = pg_execute($dbconn, "champdelete", array($post['idchampionship']));
if($champdelete===FALSE) {
$result['ok'] = false;
$result['error'] = pg_last_error($dbconn);
} else {
//return data
$result['ok'] = true;
}
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

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);
//fetch the championships
$champfetch = pg_prepare($dbconn, "champfetch", "select * from championship");
$champfetch = pg_execute($dbconn, "champfetch", array());
//build result object
$championships = array();
while($row = pg_fetch_assoc($champfetch)) {
$championships[] = $row;
}
$result['championships'] = $championships;
//return data
$result['ok'] = true;
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>

33
server/getpoules.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
$poulefetch = pg_prepare($dbconn, "poulefetch", "select * from poule where idchampionship = $1");
$poulefetch = pg_execute($dbconn, "poulefetch", array($idchampionship));
//build result object
$poules = array();
while($row = pg_fetch_assoc($poulefetch)) {
$poules[] = $row;
}
$result['poules'] = $poules;
//return data
$result['ok'] = true;
//print message
$resultjson = json_encode($result);
echo $resultjson;
?>