From 04f2fd77ff6101e68a05aa2362197156d519cc55 Mon Sep 17 00:00:00 2001 From: Absurdon Date: Thu, 11 May 2017 22:26:18 +0200 Subject: [PATCH] Added view for creating proposals and added some controller functionality --- app/controllers/match_proposals_controller.rb | 21 +++++++++++++++++++ app/models/match_proposal.rb | 17 ++++++++++++--- app/views/match_proposals/index.html.erb | 2 +- app/views/match_proposals/new.html.erb | 13 ++++++++++-- config/routes.rb | 2 +- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb index 79e5773..8d02ece 100644 --- a/app/controllers/match_proposals_controller.rb +++ b/app/controllers/match_proposals_controller.rb @@ -1,11 +1,32 @@ class MatchProposalsController < ApplicationController + def index @match = Match.find(params[:match_id]) end def new + match = Match.find(params[:match_id]) + @proposal = MatchProposal.new(match: match) + raise AccessError unless @proposal.can_create? cuser end 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 + + def update + end + end diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index c662420..56c3412 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -3,7 +3,7 @@ class MatchProposal < ActiveRecord::Base STATUS_PENDING = 0 STATUS_REVOKED = 1 STATUS_REJECTED = 2 - STATUS_ACCEPTED = 3 + STATUS_CONFIRMED = 3 belongs_to :match belongs_to :team @@ -11,8 +11,19 @@ class MatchProposal < ActiveRecord::Base validates_presence_of :match, :team, :proposed_time - def can_create? (match, cuser) - match && cuser && cuser.team.is_leader?(cuser) && (match.of_team cuser.team) + def status_strings + {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 def can_destroy? diff --git a/app/views/match_proposals/index.html.erb b/app/views/match_proposals/index.html.erb index 726f1da..d89fe99 100644 --- a/app/views/match_proposals/index.html.erb +++ b/app/views/match_proposals/index.html.erb @@ -15,7 +15,7 @@ <%= proposal.team.name %> <%= longtime proposal.proposed_time %> - <%= proposal.status %> + <%= proposal.status_strings[proposal.status] %> test <% end %> diff --git a/app/views/match_proposals/new.html.erb b/app/views/match_proposals/new.html.erb index a67703b..b0f0e13 100644 --- a/app/views/match_proposals/new.html.erb +++ b/app/views/match_proposals/new.html.erb @@ -1,2 +1,11 @@ -

MatchProposals#new

-

Find me in app/views/match_proposals/new.html.erb

+

New Proposal

+<%= form_for @proposal, html: { class: 'square' } do |f| %> + <%= render 'shared/errors', messages: @proposal.errors.full_messages %> +
+ <%= f.label :proposed_time %> + <%= f.datetime_select :proposed_time, minute_step: 15 %> +
+
+ <%= f.submit 'Propose' %> +
+<% end %> diff --git a/config/routes.rb b/config/routes.rb index 1917806..1ed9989 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -61,7 +61,7 @@ Ensl::Application.routes.draw do get "matches/ref/:id" => "matches#ref", as: :match_ref resources :matches do 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 resources :maps