mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Views for school and tournament delegates
This commit is contained in:
@@ -1,17 +1,40 @@
|
|||||||
class TournamentsController < ApplicationController
|
class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: [:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
before_action :set_tournament, only: [:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||||
before_filter :check_access_manage, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
before_filter :check_access_manage, only: [:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||||
before_filter :check_access_destroy, only: [:destroy,:delegate]
|
before_filter :check_access_destroy, only: [:destroy,:delegate]
|
||||||
|
|
||||||
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||||
|
|
||||||
|
def school_delegate
|
||||||
|
if params[:search]
|
||||||
|
@users = User.search(params[:search])
|
||||||
|
elsif params[:school_delegate]
|
||||||
|
@delegate = SchoolDelegate.new
|
||||||
|
@delegate.user_id = params[:school_delegate]["user_id"]
|
||||||
|
@delegate.school_id = params[:school_delegate]["school_id"]
|
||||||
|
respond_to do |format|
|
||||||
|
if @delegate.save
|
||||||
|
format.html { redirect_to "/tournaments/#{@tournament.id}/school_delegate", notice: 'Delegated permissions added successfully' }
|
||||||
|
else
|
||||||
|
format.html { redirect_to "/tournaments/#{@tournament.id}/school_delegate", notice: 'There was an issue delegating permissions please try again' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@users_delegates = []
|
||||||
|
@tournament.schools.each do |s|
|
||||||
|
s.delegates.each do |d|
|
||||||
|
@users_delegates << d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delegate
|
def delegate
|
||||||
if params[:search]
|
if params[:search]
|
||||||
@users = User.search(params[:search])
|
@users = User.search(params[:search])
|
||||||
elsif params[:user]
|
elsif params[:tournament_delegate]
|
||||||
@user = User.find(params[:user]["id"])
|
|
||||||
@delegate = TournamentDelegate.new
|
@delegate = TournamentDelegate.new
|
||||||
@delegate.user_id = @user.id
|
@delegate.user_id = params[:tournament_delegate]["user_id"]
|
||||||
@delegate.tournament_id = @tournament.id
|
@delegate.tournament_id = @tournament.id
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @delegate.save
|
if @delegate.save
|
||||||
|
|||||||
@@ -24,8 +24,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><%= user.email %></td>
|
<td><%= user.email %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= form_for user, :url => url_for(:controller => 'tournaments', :action => 'delegate', :method => "patch") do |f| %>
|
<%= form_for TournamentDelegate.new, :url => url_for(:controller => 'tournaments', :action => 'delegate', :method => "post") do |f| %>
|
||||||
<%= f.hidden_field :id, :value => user.id %>
|
<%= f.hidden_field :user_id, :value => user.id %>
|
||||||
<% if can? :manage, @tournament %>
|
<% if can? :manage, @tournament %>
|
||||||
<%= submit_tag "Give permissions", :class=>"btn btn-success"%>
|
<%= submit_tag "Give permissions", :class=>"btn btn-success"%>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
70
app/views/tournaments/school_delegate.html.erb
Normal file
70
app/views/tournaments/school_delegate.html.erb
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<% if @users %>
|
||||||
|
<h1>Search results</h1> <%= form_tag(school_delegate_path, :method => "get", id: "search-form") do %>
|
||||||
|
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
|
||||||
|
<%= submit_tag "Search" %>
|
||||||
|
<% end %>
|
||||||
|
<p>Search by email address</p>
|
||||||
|
</br>
|
||||||
|
</br>
|
||||||
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>User Email</th>
|
||||||
|
<th>School to delegate</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @users.each do |user| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= user.email %></td>
|
||||||
|
<%= form_for SchoolDelegate.new, :url => url_for(:controller => 'tournaments', :action => 'school_delegate', :method => "post") do |f| %>
|
||||||
|
<td><%= f.collection_select :school_id, @tournament.schools, :id, :name %></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
<%= f.hidden_field :user_id, :value => user.id %>
|
||||||
|
<% if can? :manage, @tournament %>
|
||||||
|
<%= submit_tag "Give permissions", :class=>"btn btn-success"%>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @users_delegates %>
|
||||||
|
<h1>Delegated users schools</h1> <%= form_tag(school_delegate_path, :method => "get", id: "search-form") do %>
|
||||||
|
<%= text_field_tag :search, params[:search], placeholder: "Search users" %>
|
||||||
|
<%= submit_tag "Search" %>
|
||||||
|
<% end %>
|
||||||
|
<p>Search by email address</p>
|
||||||
|
</br>
|
||||||
|
</br>
|
||||||
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>User Email</th>
|
||||||
|
<th>School</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @users_delegates.each do |delegate| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= delegate.user.email %></td>
|
||||||
|
<td><%= delegate.school.name %></td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -41,10 +41,9 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'tournaments/:id/no_matches' => 'tournaments#no_matches'
|
get 'tournaments/:id/no_matches' => 'tournaments#no_matches'
|
||||||
get 'tournaments/:id/matches' => 'tournaments#matches'
|
get 'tournaments/:id/matches' => 'tournaments#matches'
|
||||||
get 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :tournament_delegate
|
get 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :tournament_delegate
|
||||||
patch 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :set_tournament_delegate
|
post 'tournaments/:id/delegate' => 'tournaments#delegate', :as => :set_tournament_delegate
|
||||||
|
get 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :school_delegate
|
||||||
get 'schools/:id/delegate' => 'schools#delegate'
|
post 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :set_school_delegate
|
||||||
post 'schools/:id/delegate' => 'schools#delegate'
|
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|||||||
Reference in New Issue
Block a user