mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-02-03 15:01:11 +00:00
Added view for creating proposals and added some controller functionality
This commit is contained in:
parent
0f05829bcc
commit
04f2fd77ff
5 changed files with 48 additions and 7 deletions
|
@ -1,11 +1,32 @@
|
||||||
class MatchProposalsController < ApplicationController
|
class MatchProposalsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@match = Match.find(params[:match_id])
|
@match = Match.find(params[:match_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
match = Match.find(params[:match_id])
|
||||||
|
@proposal = MatchProposal.new(match: match)
|
||||||
|
raise AccessError unless @proposal.can_create? cuser
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
match = Match.find(params[:match_id])
|
||||||
|
@proposal = MatchProposal.new(match: match)
|
||||||
|
raise AccessError unless @ban.can_create? cuser
|
||||||
|
@proposal.team = cuser.team
|
||||||
|
@proposal.status = MatchProposal::STATUS_PENDING
|
||||||
|
@proposal.proposed_time = params[:match_proposal][:proposed_time]
|
||||||
|
|
||||||
|
if @proposal.save
|
||||||
|
flash[:notice] = 'Created new proposal'
|
||||||
|
redirect_to(match)
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ class MatchProposal < ActiveRecord::Base
|
||||||
STATUS_PENDING = 0
|
STATUS_PENDING = 0
|
||||||
STATUS_REVOKED = 1
|
STATUS_REVOKED = 1
|
||||||
STATUS_REJECTED = 2
|
STATUS_REJECTED = 2
|
||||||
STATUS_ACCEPTED = 3
|
STATUS_CONFIRMED = 3
|
||||||
|
|
||||||
belongs_to :match
|
belongs_to :match
|
||||||
belongs_to :team
|
belongs_to :team
|
||||||
|
@ -11,8 +11,19 @@ class MatchProposal < ActiveRecord::Base
|
||||||
|
|
||||||
validates_presence_of :match, :team, :proposed_time
|
validates_presence_of :match, :team, :proposed_time
|
||||||
|
|
||||||
def can_create? (match, cuser)
|
def status_strings
|
||||||
match && cuser && cuser.team.is_leader?(cuser) && (match.of_team cuser.team)
|
{STATUS_PENDING => 'Pending',
|
||||||
|
STATUS_REVOKED => 'Revoked',
|
||||||
|
STATUS_REJECTED => 'Rejected',
|
||||||
|
STATUS_CONFIRMED => 'Confirmed'}
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_create? cuser
|
||||||
|
cuser && cuser.team.is_leader?(cuser) && match.of_team(cuser.team)
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_update? cuser
|
||||||
|
cuser && cuser.team.is_leader?(cuser) && match.of_team (cuser.team)
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_destroy?
|
def can_destroy?
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<tr class="<%=cycle('even', 'odd') %>">
|
<tr class="<%=cycle('even', 'odd') %>">
|
||||||
<td><%= proposal.team.name %></td>
|
<td><%= proposal.team.name %></td>
|
||||||
<td><%= longtime proposal.proposed_time %> </td>
|
<td><%= longtime proposal.proposed_time %> </td>
|
||||||
<td><%= proposal.status %></td>
|
<td><%= proposal.status_strings[proposal.status] %></td>
|
||||||
<td>test</td>
|
<td>test</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,2 +1,11 @@
|
||||||
<h1>MatchProposals#new</h1>
|
<h1>New Proposal</h1>
|
||||||
<p>Find me in app/views/match_proposals/new.html.erb</p>
|
<%= form_for @proposal, html: { class: 'square' } do |f| %>
|
||||||
|
<%= render 'shared/errors', messages: @proposal.errors.full_messages %>
|
||||||
|
<div class="fields horizontal">
|
||||||
|
<%= f.label :proposed_time %>
|
||||||
|
<%= f.datetime_select :proposed_time, minute_step: 15 %>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.submit 'Propose' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -61,7 +61,7 @@ Ensl::Application.routes.draw do
|
||||||
get "matches/ref/:id" => "matches#ref", as: :match_ref
|
get "matches/ref/:id" => "matches#ref", as: :match_ref
|
||||||
resources :matches do
|
resources :matches do
|
||||||
get :admin, to: "matches#admin", on: :collection
|
get :admin, to: "matches#admin", on: :collection
|
||||||
resources :match_proposals, path: "proposals", as: "proposals", only: [:index, :new, :create]
|
resources :match_proposals, path: "proposals", as: :proposals, only: [:index, :new, :create, :update]
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :maps
|
resources :maps
|
||||||
|
|
Loading…
Reference in a new issue