Skip to content
Browse files

Merge branch 'master' of github.com:elpassion/elranks

  • Loading branch information...
2 parents 22be53e + 32a8aab commit 36a8131816b9bc48a224429ad4d28a9012ab09bb @aserafin aserafin committed Jan 3, 2014
View
14 app/assets/javascripts/app.js
@@ -1,4 +1,9 @@
var myAppModule = angular.module('MyApp', ['ui.select2','rails'])
+ .config([
+ "$httpProvider", function($httpProvider) {
+ $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
+ }
+ ])
.factory('Book', ['railsResourceFactory', function (railsResourceFactory) {
return railsResourceFactory({
@@ -20,13 +25,20 @@ var myAppModule = angular.module('MyApp', ['ui.select2','rails'])
name: 'team'
});
}])
+ .factory('Match', ['railsResourceFactory', function (railsResourceFactory) {
+ return railsResourceFactory({
+ url: '/matches',
+ name: 'match'
+ });
+ }])
- .controller('PlayersCtrl', ['Player','Team','$scope', function(Player,Team,$scope) {
+ .controller('PlayersCtrl', ['Player','Team','Match','$scope', function(Player,Team,Match,$scope) {
$scope.home = { score: 0 };
$scope.away = { score: 0 };
$scope.save = function() {
console.log($scope.home, $scope.away);
+ new Match({ match: { home: $scope.home, away: $scope.away }}).create().then(function(){ window.location = '/'; });
};
Player.query().then(function(data){
View
4 app/assets/stylesheets/main.css.scss
@@ -38,7 +38,7 @@ tbody {
height: 15px;
position: absolute;
left: 10px;
- top: 33%;
+ top: 37%;
display: none;
background: transparent url('stars.png') top left no-repeat;
}
@@ -191,7 +191,7 @@ h1 {
.table-container {
max-height: 250px;
height: auto;
- overflow-y: scroll;
+ overflow-y: auto;
}
View
36 app/controllers/matches_controller.rb
@@ -1,2 +1,36 @@
-class MatchesController < ApplicationController
+class MatchesController < InheritedResources::Base
+
+ def create
+ build_resource.save
+ build_resource.finish!
+
+ create!
+ end
+
+
+ protected
+ def build_resource
+ return Match.new if params['match'].blank?
+
+
+ @match ||= tournament.matches.build do |m|
+ m.competitors.build player_id: home['player_id'], team_id: home['team_id'], side: 'home'
+ m.competitors.build player_id: away['player_id'], team_id: away['team_id'], side: 'away'
+
+ m.build_score home: home['score'], away: away['score'], played_at: Time.now
+ end
+ end
+
+ def tournament
+ Tournament.first
+ end
+
+ def away
+ params['match'] && params['match']['away']
+ end
+
+ def home
+ params['match'] && params['match']['home']
+ end
+
end
View
3 app/models/competitor.rb
@@ -6,7 +6,6 @@ class Competitor < ActiveRecord::Base
belongs_to :player
belongs_to :team
- validates :match, :player, :team, presence: true
+ validates :player, :team, presence: true
validates :side, inclusion: { in: %w(home away) }
- #validates :match, uniqueness: { scope: [:player_id, :team_id] }
end
View
24 app/views/matches/new.html.slim
@@ -1,43 +1,43 @@
-
.new-match(ng-controller="PlayersCtrl")
.preview.clearfix
.hometeam
- img(ng-src="{{logoUrl(home.team.id)}}" ng-show="home.team.id" width="60" height="37")
+ img(ng-src="{{logoUrl(home.team_id)}}" ng-show="home.team_id" width="60" height="37")
.score
input(type='number' step="1" min="0" ng-model="home.score" autofocus)
input(type='number' step="1" min="0" ng-model="away.score")
.awayteam
- img(ng-src="{{logoUrl(away.team.id)}}" ng-show="away.team.id" width="60" height="37")
+ img(ng-src="{{logoUrl(away.team_id)}}" ng-show="away.team_id" width="60" height="37")
hr.c-b
.teams
-
+
.team
h4 Choose team
- select(name='home' ui-select2="" ng-model="home.team.id" required)
+ select(name='home' ui-select2="" ng-model="home.team_id" required)
option(ng-repeat="team in teams" value="{{team.id}}")
| {{team.name}}
.team
h4 Choose team
- select(name='home' ui-select2="" ng-model="away.team.id" required)
+ select(name='home' ui-select2="" ng-model="away.team_id" required)
option(ng-repeat="team in teams" value="{{team.id}}")
| {{team.name}}
-
+
.players
.player
h4 Choose player
- select(name='home' ui-select2="" ng-model="home.player_ids" required)
- option(ng-repeat="player in players" value="{{player.id}}")
- | {{player.name}}
+ select(name='home' ui-select2="" ng-model="home.player_id" required)
+ option(ng-repeat="player in players" value="{{player.id}}")
+ | {{player.name}}
+
+
.player
h4 Choose player
- select(name='away' ui-select2="" ng-model="away.player_ids" required)
+ select(name='away' ui-select2="" ng-model="away.player_id" required)
option(ng-repeat="player in players" value="{{player.id}}")
| {{player.name}}
.actions.clearfix
button.btn.btn-lg.btn-success.save(ng-click="save()") Save match
-
View
2 app/views/welcome/index.html.slim
@@ -24,7 +24,7 @@ section.table.standings
span.award
= idx + 1
td.avatar
- = image_tag rating.player.avatar_url, size: '32'
+ = image_tag rating.player.avatar_url, size: '48'
td.playername
= rating.player.name

0 comments on commit 36a8131

Please sign in to comment.
Something went wrong with that request. Please try again.