Skip to content

Commit c680ed8

Browse files
committed
integration from clubs to teams
1 parent 31c3ab4 commit c680ed8

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

app/controllers/teams_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TeamsController < ApplicationController
77
# GET /teams
88
# GET /teams.json
99
def index
10-
@teams = Team.all
10+
@teams = Team.joins('LEFT OUTER JOIN clubs on teams.club_id = clubs.id').select('teams.*, clubs.name as club_name')
1111
render_with_protection @teams
1212
end
1313

src/app/club/club.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ angular.module( 'league.club', [
4646
{field: 'name', displayName: 'Club Name'},
4747
{field: 'contact_officer', displayName: 'Contact Officer'},
4848
{displayName: 'Edit', cellTemplate: '<button id="editBtn" type="button" class="btn-small" ng-click="editClub(row.entity)" >Edit</button> '},
49-
{displayName: 'Delete', cellTemplate: '<button id="deleteBtn" type="button" class="btn-small" ng-click="deleteClub(row.entity)" >Delete</button> '}
49+
{displayName: 'Delete', cellTemplate: '<button id="deleteBtn" type="button" class="btn-small" ng-click="deleteClub(row.entity)" >Delete</button> '},
50+
{displayName: 'Show Teams', cellTemplate: '<button id="showBtn" type="button" class="btn-small" ng-click="showTeams(row.entity)" >Show Teams</button> '}
5051
],
5152
multiSelect: false
5253
};
@@ -66,6 +67,10 @@ angular.module( 'league.club', [
6667
$scope.newClub = function() {
6768
$state.transitionTo('club');
6869
};
70+
71+
$scope.showTeams = function(club) {
72+
$state.transitionTo('teams', {clubId: club.id});
73+
};
6974

7075
})
7176

src/app/team/team.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
angular.module( 'league.team', [
55
'ui.state',
6+
'league.club',
67
'ngResource',
78
'ngGrid'
89
])
@@ -12,7 +13,7 @@ angular.module( 'league.team', [
1213
*/
1314
.config(function config( $stateProvider ) {
1415
$stateProvider.state( 'teams', {
15-
url: '/teams',
16+
url: '/teams?clubId',
1617
views: {
1718
"main": {
1819
controller: 'TeamsCtrl',
@@ -37,18 +38,37 @@ angular.module( 'league.team', [
3738
/**
3839
* And of course we define a controller for our route.
3940
*/
40-
.controller( 'TeamsCtrl', function TeamsController( $scope, TeamRes, $state ) {
41+
.controller( 'TeamsCtrl', function TeamsController( $scope, TeamRes, $state, $stateParams ) {
4142
$scope.teams = TeamRes.query();
43+
44+
$scope.clubId = $stateParams.clubId;
45+
46+
if($scope.clubId) {
47+
$scope.filterOptions = {
48+
filterText: 'club_id:' + $scope.clubId
49+
};
50+
}
51+
else {
52+
$scope.filterOptions = {
53+
filterText: ''
54+
};
55+
}
56+
4257
$scope.gridOptions = {
4358
data: 'teams',
4459
columnDefs: [
4560
{field: 'id', displayName: 'Id'},
61+
{field: 'club_id', displayName: 'Club Id', visible: false},
62+
{field: 'club_name', displayName: 'Club Name'},
4663
{field: 'name', displayName: 'Team Name'},
4764
{field: 'captain', displayName: 'Captain'},
65+
{field: 'date_created', displayName: 'Date Created', cellFilter: "date:mediumDate"},
4866
{displayName: 'Edit', cellTemplate: '<button id="editBtn" type="button" class="btn-small" ng-click="editTeam(row.entity)" >Edit</button> '},
4967
{displayName: 'Delete', cellTemplate: '<button id="deleteBtn" type="button" class="btn-small" ng-click="deleteTeam(row.entity)" >Delete</button> '}
5068
],
51-
multiSelect: false
69+
multiSelect: false,
70+
filterOptions: $scope.filterOptions,
71+
showColumnMenu: true
5272
};
5373

5474
$scope.editTeam = function(team) {
@@ -69,15 +89,16 @@ angular.module( 'league.team', [
6989

7090
})
7191

72-
.controller('TeamCtrl', function TeamController( $scope, TeamRes, $state, $stateParams ) {
92+
.controller('TeamCtrl', function TeamController( $scope, TeamRes, ClubRes, $state, $stateParams ) {
7393
$scope.teamId = parseInt($stateParams.teamId, 10);
7494

7595
if ($scope.teamId) {
7696
$scope.team = TeamRes.get({id: $scope.teamId});
7797
} else {
7898
$scope.team = new TeamRes();
7999
}
80-
100+
$scope.clubs = ClubRes.query();
101+
81102
$scope.submit = function() {
82103
if ($scope.teamId) {
83104
$scope.team.$update(function(response) {

src/app/team/team.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe( 'Team functionality', function() {
111111
expect(scope.teamId).toEqual(2);
112112

113113
scope.httpBackend.expectGET('../teams/2.json').respond({"captain":"Captain 2","created_at":"2012-02-02T00:00:00Z","date_created":"2012-01-01T00:00:00Z","id":2,"name":"Team 2","updated_at":"2012-03-03T00:00:00Z"});
114+
scope.httpBackend.expect('GET', '../clubs.json').respond([]);
114115

115116
scope.$digest();
116117
scope.httpBackend.flush();
@@ -122,6 +123,10 @@ describe( 'Team functionality', function() {
122123
scope.fakeStateParams.teamId = null;
123124

124125
$controller('TeamCtrl', { $scope: scope, $stateParams: scope.fakeStateParams });
126+
scope.httpBackend.expect('GET', '../clubs.json').respond([]);
127+
128+
scope.$digest();
129+
scope.httpBackend.flush();
125130
expect(scope.teamId).toBeNaN();
126131
}));
127132
});
@@ -132,6 +137,7 @@ describe( 'Team functionality', function() {
132137

133138
// The initial render triggers a get, drain that before we start the test proper
134139
scope.httpBackend.expectGET('../teams/2.json').respond({"captain":"Captain 2","created_at":"2012-02-02T00:00:00Z","date_created":"2012-01-01T00:00:00Z","id":2,"name":"Team 2","updated_at":"2012-03-03T00:00:00Z"});
140+
scope.httpBackend.expect('GET', '../clubs.json').respond([]);
135141

136142
scope.$digest();
137143
scope.httpBackend.flush();
@@ -167,6 +173,10 @@ describe( 'Team functionality', function() {
167173
beforeEach(angular.mock.inject(function($controller){
168174
scope.fakeStateParams.teamId = null;
169175
$controller('TeamCtrl', {$scope: scope, $stateParams: scope.fakeStateParams});
176+
scope.httpBackend.expect('GET', '../clubs.json').respond([]);
177+
178+
scope.$digest();
179+
scope.httpBackend.flush();
170180
}));
171181

172182
it('Submit with teamId calls post on server, post succeeds', function(){

src/app/team/team.tpl.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<div class="body">
22
<div class="form-horizontal">
3+
<div class="control-group" ng-class="error.club ? 'error' : ''">
4+
<label class="control-label">Club:</label>
5+
<div class="controls">
6+
<select ng-model="team.club_id" ng-options="club.id as club.name for club in clubs"></select>
7+
</div>
8+
<div field_error errors="error" field="club"></div>
9+
</div>
10+
311
<div class="control-group" ng-class="error.name ? 'error' : ''">
412
<label class="control-label">Team name:</label>
513
<div class="controls">

src/app/team/teams.tpl.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ <h1 id="title">Team functions</h1>
88
</div>
99

1010
<div>
11+
<strong>Filter:</strong><input type="text" ng-model="filterOptions.filterText" />
1112
<div class="gridStyle" ng-grid="gridOptions"></div>
1213
<button ng-click="newTeam()" class="btn btn-primary" >New</button>
1314
</div>

0 commit comments

Comments
 (0)