diff --git a/app/views/api/tournament.jbuilder b/app/views/api/tournament.jbuilder
index 09fe7aa..1027761 100644
--- a/app/views/api/tournament.jbuilder
+++ b/app/views/api/tournament.jbuilder
@@ -4,6 +4,7 @@ json.cache! ["api_tournament", @tournament] do
json.(@tournament, :id, :name, :address, :director, :director_email, :tournament_type, :created_at, :updated_at, :user_id)
json.schools @tournament.schools do |school|
+ json.id school.id
json.name school.name
json.score school.score
end
diff --git a/frontend/app/js/controllers/tournament-controller.js b/frontend/app/js/controllers/tournament-controller.js
index 21816bd..3871072 100644
--- a/frontend/app/js/controllers/tournament-controller.js
+++ b/frontend/app/js/controllers/tournament-controller.js
@@ -10,6 +10,14 @@ app.controller("tournamentController", function($scope, tournamentsService, $rou
$scope.tournament = data;
});
+ $scope.refreshTournamentData = function(){
+ tournamentsService.tournamentDetails($routeParams.id).then(function(data) {
+ //this will execute when the
+ //AJAX call completes.
+ $scope.tournament = data;
+ });
+ };
+
// refresh tournament data every 10 seconds
// setInterval(function(){
// tournamentsService.tournamentDetails($routeParams.id).then(function(data) {
@@ -33,6 +41,7 @@ app.controller("tournamentController", function($scope, tournamentsService, $rou
$scope.showWeightSeeds = !$scope.showWeightSeeds;
};
+
$scope.showBoutBoard = false;
$scope.toggleBoutBoard = function(){
@@ -48,5 +57,30 @@ app.controller("tournamentController", function($scope, tournamentsService, $rou
}
};
+
+ $scope.newSchool = null;
+
+ $scope.saveNewSchool = function(){
+ $scope.newSchool.tournament_id = $scope.tournament.id;
+ tournamentsService.saveNewSchool($scope.newSchool).then(function(data) {
+ $scope.tournament.schools.push(data);
+ });
+ $scope.newSchool = null;
+ $('#NewSchool').modal('hide');
+ };
+
+ $scope.deleteSchool = function(school){
+ if (confirm('Are you sure you want to delete ' + school.name + '?')) {
+ tournamentsService.deleteSchool(school).then(function(data) {
+ $scope.tournament.schools.splice( $scope.tournament.schools.indexOf(school), 1 );
+ });
+ }
+ };
+
+ $scope.updateSchool = function(school){
+ tournamentsService.updateSchool(school);
+ $('#EditSchool' + school.id).modal('hide');
+ };
+
});
\ No newline at end of file
diff --git a/frontend/app/js/services/tournaments-service.js b/frontend/app/js/services/tournaments-service.js
index ecba5fa..4f5db46 100644
--- a/frontend/app/js/services/tournaments-service.js
+++ b/frontend/app/js/services/tournaments-service.js
@@ -1,7 +1,7 @@
app.factory('tournamentsService', tournamentsService);
-function tournamentsService($http){
+function tournamentsService($http,$rootScope){
var service = {};
service.getMyTournaments = function(user){
@@ -34,16 +34,65 @@ function tournamentsService($http){
method: "GET"
}).then(successResponse, errorCallback);
};
+
+ service.saveNewSchool = function(newSchool){
+ return $http({
+ url: '/schools.json',
+ method: "POST",
+
+ data: {
+ school: {
+ 'name': newSchool.name,
+ 'tournament_id': newSchool.tournament_id
+ }
+ },
+ headers: {
+ "Content-Type": "application/json"
+ }
+ }).then(successResponse, errorCallback);
+ };
+
+ service.deleteSchool = function(school){
+ return $http({
+ url: '/schools/' + school.id + '/',
+ method: "DELETE"
+ }).then(successResponse, errorCallback);
+ };
+
+ service.updateSchool = function(schoolToEdit){
+ return $http({
+ url: '/schools/' + schoolToEdit.id,
+ method: "PATCH",
+ data: {
+ school: {
+ 'name': schoolToEdit.name,
+ 'tournament_id': schoolToEdit.tournament_id
+ }
+ },
+ headers: {
+ "Content-Type": "application/json"
+ }
+ }).then(successResponse, errorCallback);
+ };
function successResponse(response){
// console.log("success log below");
// console.log(response);
+ if(response.config.method == "POST" || response.config.method == "DELETE" || response.config.method == "PATCH"){
+ $rootScope.alertClass = "alert alert-success";
+ $rootScope.alertMessage = response.statusText;
+ }
return response.data;
}
function errorCallback(err){
// console.log("error log below");
// console.log(err);
+ if(err.status > 0){
+ $rootScope.alertClass = "alert alert-danger";
+ $rootScope.alertMessage = err.statusText;
+ }
+
return err;
}
diff --git a/frontend/app/pages/tournaments/tournaments-show.html b/frontend/app/pages/tournaments/tournaments-show.html
index 957890d..a0f2403 100644
--- a/frontend/app/pages/tournaments/tournaments-show.html
+++ b/frontend/app/pages/tournaments/tournaments-show.html
@@ -27,7 +27,7 @@
-
+
@@ -42,7 +42,10 @@
| {{ school.name }} |
{{ school.score }} |
- |
+
+
+
+ |
@@ -85,7 +88,8 @@
-
+ Matches have not been generated
+
- Matches not assigned
+ Matches not assigned
-
+
| Round |
@@ -132,7 +136,7 @@
-
+
+
+
+
+
+
+
+