Skip to content

Commit

Permalink
Add admin panel
Browse files Browse the repository at this point in the history
Add a basic admin panel to add/remove queues and instructor for a pre-existing
coruse. Closes #30.
  • Loading branch information
mterwill committed Sep 7, 2016
1 parent e8d6ad7 commit ef7acc8
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/course_instructors.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/courses.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/course_instructors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the CourseInstructors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/courses.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Courses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
40 changes: 40 additions & 0 deletions app/controllers/course_instructors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class CourseInstructorsController < ApplicationController
before_action :set_course, :authorize_current_user

def new
@course_instructor = CourseInstructor.new
end

def create
@course_instructor = CourseInstructor.new
@course_instructor.course = @course
@course_instructor.instructor = User.find_or_create_by({
email: params[:instructor_email]
})

if @course_instructor.save
redirect_to @course
else
render :new
end
end

def destroy
@course_instructor = CourseInstructor.find(params[:id])

@course_instructor.destroy!

redirect_to @course
end

private
def set_course
@course = Course.find(params[:course_id])
end

def authorize_current_user
unless @course.instructors.include?(current_user)
redirect_to root_url
end
end
end
53 changes: 52 additions & 1 deletion app/controllers/course_queues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
class CourseQueuesController < ApplicationController
before_action :set_course_queue
ADMIN_ACTIONS = %w(new create destroy edit update)

before_action :set_course_queue, except: [:new, :create]
before_action :set_course, only: ADMIN_ACTIONS
before_action :authorize_current_user, only: ADMIN_ACTIONS

# GET /course_queues/1
# GET /course_queues/1.json
def show
end

def new
@course_queue = CourseQueue.new
end

def create
@course_queue = CourseQueue.new(course_queue_params)

@course_queue.course = @course

if @course_queue.save
redirect_to @course
else
render :new
end
end

def edit
end

def update
if @course_queue.update(course_queue_params)
redirect_to @course
else
render :edit
end
end

def destroy
@course_queue.destroy!

redirect_to @course
end

# GET /course_queues/1/outstanding_requests.json
def outstanding_requests
@outstanding_requests = @course_queue.outstanding_requests
Expand All @@ -20,4 +57,18 @@ def online_instructors
def set_course_queue
@course_queue = CourseQueue.find(params[:id])
end

def set_course
@course = Course.find(params[:course_id])
end

def course_queue_params
params.require(:course_queue).permit(:name, :location, :description)
end

def authorize_current_user
unless @course.instructors.include?(current_user)
redirect_to root_url
end
end
end
17 changes: 17 additions & 0 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CoursesController < ApplicationController
before_action :set_course, :authorize_current_user

def show
end

private
def set_course
@course = Course.find(params[:id])
end

def authorize_current_user
unless @course.instructors.include?(current_user)
redirect_to root_url
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/course_instructors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CourseInstructorsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/courses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CoursesHelper
end
1 change: 1 addition & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Course < ApplicationRecord
has_many :course_queues
has_many :course_instructors
has_many :instructors, through: :course_instructors


Expand Down
15 changes: 15 additions & 0 deletions app/views/course_instructors/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="six wide column">
<h1 class="ui header">
Add Instructor for <%= @course.name %>
</h1>

<%= form_for [@course, @course_instructor], html: {class: 'ui form'} do |f| %>
<div class="field">
<label>Email</label>
<input type="email" name="instructor_email" placeholder="instructor@umich.edu">
</div>

<%= f.submit 'Add', class: 'ui button' %>
<% end %>

</div>
3 changes: 2 additions & 1 deletion app/views/course_queues/_admin_panel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<h4 class="ui header">Instructor Queue Management</h4>

<div data-cable-action="queue_pop" class="ui huge bottom padded fluid primary button">Queue Pop</div>
<div data-cable-action="instructor_status_toggle" class="ui large fluid button"></div>
<div data-cable-action="instructor_status_toggle" class="ui large fluid bottom padded button"></div>
<a href="<%= url_for @course_queue.course %>" class="ui large fluid button">Admin Panel</a>
</script>
18 changes: 18 additions & 0 deletions app/views/course_queues/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%= form_for [@course, @course_queue], html: {class: 'ui form'} do |f| %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="field">
<%= f.label :location %>
<%= f.text_field :location %>
</div>

<div class="field">
<%= f.label :description %>
<%= f.text_field :description %>
</div>

<%= f.submit 'Submit', class: 'ui button' %>
<% end %>
7 changes: 7 additions & 0 deletions app/views/course_queues/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="six wide column">
<h1 class="ui header">
Edit Queue for <%= @course.name %>
</h1>

<%= render 'form' %>
</div>
7 changes: 7 additions & 0 deletions app/views/course_queues/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="six wide column">
<h1 class="ui header">
Add Queue for <%= @course.name %>
</h1>

<%= render 'form' %>
</div>
25 changes: 25 additions & 0 deletions app/views/courses/_instructors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<table class="ui table">
<thead>
<tr><th style="width: 50%">Name</th>
<th style="width: 50%">Email</th>
<th>
<a href="<%= new_course_course_instructor_url(@course) %>" class="ui primary fluid labeled icon button">
<i class="plus icon"></i>
Add
</a>
</th>
</tr></thead>
<tbody>
<% @course.course_instructors.each do |course_instructor| %>
<tr>
<td><%= course_instructor.instructor.name %></td>
<td><%= course_instructor.instructor.email %></td>
<td>
<div class="ui fluid basic buttons">
<%= link_to 'Delete', course_course_instructor_url(@course, course_instructor), method: :delete, data: { confirm: 'Are you sure?' }, class: 'ui button' %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
26 changes: 26 additions & 0 deletions app/views/courses/_queues.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<table class="ui table">
<thead>
<tr><th style="width: 50%">Course Queue Name</th>
<th style="width: 50%">Location</th>
<th>
<a href="<%= new_course_course_queue_url(@course) %>" class="ui primary labeled icon fluid button">
<i class="plus icon"></i>
New
</a>
</th>
</tr></thead>
<tbody>
<% @course.course_queues.each do |queue| %>
<tr>
<td><%= queue.name %></td>
<td><%= queue.location %></td>
<td>
<div class="ui fluid basic buttons">
<%= link_to 'Edit', edit_course_course_queue_url(@course, queue), class: 'ui button' %>
<%= link_to 'Delete', course_course_queue_url(@course, queue), method: :delete, data: { confirm: 'Are you sure?' }, class: 'ui button' %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
12 changes: 12 additions & 0 deletions app/views/courses/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="ten wide column">
<h1 class="ui header">
<%= @course.name %>
Course Administration
</h1>

<h2>Course Queues</h2>
<%= render 'queues' %>

<h2>Course Instructors</h2>
<%= render 'instructors' %>
</div>
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

root 'landing#index'


resources :courses do
resources :course_queues
resources :course_instructors
end

resources :course_queues, only: [:show] do
member do
get 'outstanding_requests'
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/course_instructors_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CourseInstructorsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/controllers/courses_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CoursesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit ef7acc8

Please sign in to comment.