diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 50d6e89..679c84f 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -6,7 +6,11 @@ class ApiController < ApplicationController end def tournaments - @tournaments = Tournament.all + if params[:search] + @tournaments = Tournament.search(params[:search]).order("created_at DESC") + else + @tournaments = Tournament.all.sort_by{|t| t.daysUntil}.first(20) + end end def tournament diff --git a/frontend/app/js/tournaments-controller.js b/frontend/app/js/tournaments-controller.js index bc79971..92bf66f 100644 --- a/frontend/app/js/tournaments-controller.js +++ b/frontend/app/js/tournaments-controller.js @@ -1,10 +1,21 @@ app.controller("tournamentsController", function($scope, tournamentsService) { $scope.message = "Test message in scope."; + tournamentsService.getAllTournaments().then(function(data) { //this will execute when the //AJAX call completes. console.log(data); $scope.allTournaments = data; - }); + }); + + $scope.searchTournaments = function (){ + console.log("Tried search"); + tournamentsService.searchTournaments($scope.searchTerms).then(function(data) { + //this will execute when the + //AJAX call completes. + console.log(data); + $scope.allTournaments = data; + }); + } }); \ No newline at end of file diff --git a/frontend/app/js/tournaments-service.js b/frontend/app/js/tournaments-service.js index b301cf6..6f2e0e8 100644 --- a/frontend/app/js/tournaments-service.js +++ b/frontend/app/js/tournaments-service.js @@ -1,6 +1,6 @@ app.factory('tournamentsService', function($http){ - + return { getAllTournaments: function() { //since $http.get returns a promise, @@ -10,6 +10,24 @@ app.factory('tournamentsService', function($http){ return $http.get('/api/tournaments/').then(function(result) { return result.data; }); + }, + + searchTournaments: function(search){ + return $http({ + method: 'GET', + url: '/api/tournaments/', + params: { + search: search + } + }).then(function successCallback(response) { + // this callback will be called asynchronously + // when the response is available + return response.data + }, function errorCallback(response) { + // called asynchronously if an error occurs + // or server returns response with an error status. + return response; + }); } }; diff --git a/frontend/app/pages/index.us b/frontend/app/pages/index.us index 3693a53..23a13d6 100644 --- a/frontend/app/pages/index.us +++ b/frontend/app/pages/index.us @@ -36,24 +36,27 @@
-

All Tournaments

+

Upcoming Tournaments

+
+
+
+ + + + +
+

- - - - - -
NameAddressDirectorDirector Email Date
{{ tournament.name }}{{ tournament.address }}{{ tournament.director }}{{ tournament.director_email }} {{ tournament.date }}