Skip to content

Commit

Permalink
Admin tabs, Mailing Scheduler, Dropdown Menu all completed (#65)
Browse files Browse the repository at this point in the history
* Fixing Submitted and Creating new teams bugs

* fixed dropdown menu and boostrapped it and the warning -- SID M

* fixed dasols comments

* Mailing scheduling works

* accepted pending forming done

* Changed paths.rb for testing purposes

* wtf git log

* fixed dasol's pr

* moved the home link again

* made tests pass and rebased with master

* added in home link
  • Loading branch information
adnanhemani authored and dasolyoon committed Nov 16, 2016
1 parent fd651ed commit 2d513fe
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 22 deletions.
23 changes: 22 additions & 1 deletion app/controllers/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,31 @@ def update
return redirect_to admin_path(@admin.id)
end

def show
def show_all
@stat_loc = "Team List: Showing All Teams"
@teams_li = Team.all.each
render 'show'
end

def show_accepted
@stat_loc = "Team List: Showing Accepted Teams"
@teams_li = Team.where(approved: true)
render 'show'
end

def show_pending
@stat_loc = "Team List: Showing Pending Teams"
@teams_li = Team.where("approved = ? AND submitted = ?", false, true)
render 'show'
end

def forming
@stat_loc = "Team List: Showing Forming Teams"
@teams_li = Team.where("approved = ? AND submitted = ?", false, false)
render 'show'
end


def approve
@team = Team.find_by_id(params[:team_id])
@team.approved = true
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class SessionController < ApplicationController
skip_before_filter :authenticate, :except => ['destroy']
skip_before_filter :check_existence

def new
def new
id = session[:user_id]
if id.nil?
render 'new'
Expand Down
1 change: 1 addition & 0 deletions app/controllers/team_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

class TeamController < ApplicationController

before_filter :set_user, :set_team
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ def team_list_email(admin)
format.html
end
end

def look_at_submission(email)
mail(to: email, subject: "Teams are awaiting your approval!")
end

def self.send_look_at_submission
if !(Team.where("approved = ? AND submitted = ?", false, true).nil?)
Admin.all.each do |admin|
look_at_submission(admin.email).deliver
end
end
end
end
2 changes: 1 addition & 1 deletion app/views/admin_mailer/team_list_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<td>Members</td>
<td>Status</td>
</tr>
<% Team.all.each do |t| %>
<% Team.where("approved = ? AND submitted = ?", false, true).each do |t| %>
<tr>
<td><%= t.id %></td>
<td><% t.users.each do |u| %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/admins/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<%= button_to "Download Team Information", download_team_info_path, {method: 'get', class: "btn btn-primary btn-med"} %>
</div>
</div>

<h2>Team List</h2>
<h2> <%= @stat_loc %></h2>
</div>
<table class="table table-striped table-hover">
<tr>
Expand All @@ -48,7 +48,7 @@
<td>Status</td>
<td></td>
</tr>
<% Team.all.each do |t| %>
<% @teams_li.each do |t| %>
<tr>
<td><%= t.id %></td>
<td><% t.users.each do |u| %>
Expand All @@ -60,8 +60,8 @@
<div class="btn-group">
<a class="btn btn-info btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Change Status</a>
<ul class="dropdown-menu">
<li><%= link_to "Approve", approve_team_path(:team_id => t) %></li>
<li><%= link_to "Disapprove", disapprove_team_path(:team_id => t) %></li>
<li><%= link_to "Approve", admin_approve_team_path(:team_id => t) %></li>
<li><%= link_to "Disapprove", admin_disapprove_team_path(:team_id => t) %></li>
</ul>
</div>
</td>
Expand Down
6 changes: 5 additions & 1 deletion app/views/shared/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@

<div class="navbar-collapse collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href='/'>Home</a></li>
<li><a href='/'>Home</a></li>
<% if session[:user_id].nil? %>
<li><%= link_to "Sign up", new_user_path, {method: 'get'} %></li>
<% else %>
<% if session[:is_admin].nil? %>
<li><%= link_to "Edit My Info", edit_user_path(session[:user_id]), {method: 'get'} %></li>
<% else %>
<li><%= link_to "All", admin_show_all_path(session[:user_id]), {method: 'get'} %></li>
<li><%= link_to "Forming", admin_show_forming_path(session[:user_id]), {method: 'get'} %></li>
<li><%= link_to "Pending", admin_show_pending_path(session[:user_id]), {method: 'get'} %></li>
<li><%= link_to "Accepted", admin_show_accepted_path(session[:user_id]), {method: 'get'} %></li>
<li><%= link_to "Edit My Info", edit_admin_path(session[:user_id]), {method: 'get'} %></li>
<% end %>
<li><%= link_to "Logout", logout_path, {method: 'get'} %></li>
Expand Down
14 changes: 11 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
post 'login', to: 'session#create'
get 'logout', to: 'session#destroy'

resources :admins
get 'approve_team', to: 'admins#approve'
get 'disapprove_team', to: 'admins#disapprove'

resources :admins, except: :show
get '/admin', to: 'admins#show_all'
get '/admins/:id', to: 'admins#show_all'
get '/admin/approve_team', to: 'admins#approve'
get '/admin/disapprove_team', to: 'admins#disapprove'
get '/admin/show_accepted', to: 'admins#show_accepted'
get '/admin/show_pending', to: 'admins#show_pending'
get '/admin/show_forming', to: 'admins#forming'
get '/admin/show_all', to: 'admins#show_all'

post '/admin/email', to: "admins#team_list_email", as: 'admins_email'

get 'download_team_info', to: "file#download_approved_teams"
Expand Down
13 changes: 7 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@
add_index "teams", ["discussion_id"], name: "index_teams_on_discussion_id"

create_table "users", force: :cascade do |t|
t.string "name", null: false
t.string "email", null: false
t.string "password", null: false
t.string "major", null: false
t.string "sid", null: false
t.string "name"
t.string "email"
t.string "password"
t.string "team"
t.string "major"
t.string "sid"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "team_id"
end

add_index "users", ["team_id"], name: "index_users_on_team_id"

end
end
4 changes: 2 additions & 2 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def path_to(page_name)
when /^the removal page for "([^"]*)"$/i
edit_team_path(:id => @team, :unwanted_user=>User.find_by_name($1))
when /^the approve team "([^"]*)" page$/i
approve_team_path(:team_id=>$1)
admin_approve_team_path(:team_id=>$1)
when /^the disapprove team "([^"]*)" page$/i
disapprove_team_path(:team_id=>$1)
admin_disapprove_team_path(:team_id=>$1)
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
Expand Down
6 changes: 6 additions & 0 deletions lib/tasks/scheduler.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
desc "This task is called by the Heroku scheduler add-on"
task :admin_emails => :environment do
puts "Sending Emails to Admins..."
AdminMailer.send_look_at_submission
puts "done."
end
4 changes: 2 additions & 2 deletions spec/controllers/admins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
Admin.create!({:name => "admin", :email => "[email protected]", :password => "123"})
session[:user_id] = 1
session[:is_admin] = true
get :show, {:id => 1}
get :show_all, {:id => 1}
response.should render_template(:show)

Admin.find_by_id(1).destroy!
get :show, {:id => 1}
get :show_all, {:id => 1}
response.should redirect_to(logout_path)
end
end
Expand Down

0 comments on commit 2d513fe

Please sign in to comment.