mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a search to both api and frontend
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -36,24 +36,27 @@
|
||||
</div>
|
||||
<div class="col-md-8" style="padding-left: 2%;">
|
||||
<div class="container" ui-view="main" ng-controller="tournamentsController">
|
||||
<h2>All Tournaments</h2>
|
||||
<h2>Upcoming Tournaments</h2>
|
||||
<br>
|
||||
<form ng-submit="searchTournaments()">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Search by name or date YYYY-MM-DD" ng-model="searchTerms">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="submit" id="submit">Search</button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
<br>
|
||||
<table class="table">
|
||||
<thead class="font-spot-color">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Address</th>
|
||||
<th>Director</th>
|
||||
<th>Director Email</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="tournament in allTournaments">
|
||||
<td>{{ tournament.name }}</td>
|
||||
<td>{{ tournament.address }}</td>
|
||||
<td>{{ tournament.director }}</td>
|
||||
<td>{{ tournament.director_email }}</td>
|
||||
<td>{{ tournament.date }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user