Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup Courses' CRUD

  • Loading branch information...
commit 79f49774a3de077fcbbadff0d67997bbaf447872 1 parent 5ae66d5
@ryansouza ryansouza authored
View
9 app/assets/stylesheets/bootstrap_and_overrides.css.less
@@ -92,3 +92,12 @@ abbr {
text-transform: uppercase;
}
}
+
+table.table {
+ tr.head {
+ border: none;
+ td,th { border: none;}
+ }
+ tbody.noborder { border: none; }
+}
+
View
34 app/controllers/courses_controller.rb
@@ -29,13 +29,14 @@ def edit
end
def create
- @course = Course.new(params[:course])
+ @course = Course.new
+ @course.assign_attributes(params[:course])
+ @course.created_term = @term
if @course.save
flash[:success] = 'Course was successfully created.'
- redirect_to [@term, @course]
+ redirect_to [@term, :courses]
else
- flash[:error] = @course.errors.full_messages.to_sentence
render action: :new
end
end
@@ -43,28 +44,23 @@ def create
def update
@course = Course.find(params[:id])
- respond_to do |format|
- if @course.update_attributes(params[:course])
- format.html {
- redirect_to [@term, @course],
- success: 'Course was successfully updated.'
- }
- else
- format.html {
- flash[:error] = @course.errors.full_messages.to_sentence
- render action: "edit"
- }
- end
+ if @course.update_attributes(params[:course])
+ flash[:success] = 'Course was successfully updated.'
+ redirect_to [@term, :courses]
+ else
+ render action: :edit
end
end
def destroy
@course = Course.find(params[:id])
- @course.destroy
- respond_to do |format|
- format.html { redirect_to [@term, :courses] }
- format.json { head :ok }
+ if @course.destroy
+ flash[:success] = 'Course successfully destroyed'
+ redirect_to [@term, :courses]
+ else
+ flash[:error] = 'Could not delete course'
+ redirect_to [:edit, @term, @course]
end
end
end
View
2  app/form_builders/fancy_form_builder.rb
@@ -47,7 +47,7 @@ def help_tooltip(content, options = {} )
options = args.extract_options!
options[:rel] = 'tooltip'
options[:title] = errors.join.humanize
- options['data-trigger'] = 'focus'
+ #options['data-trigger'] = 'focus'
args.unshift options
super attribute, *args
else
View
42 app/views/courses/_form.html.erb
@@ -1,20 +1,32 @@
-<%= bs_form_for([@term, @course]) do |f| %>
- <% if @course.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved:</h2>
+<%= form_for [@term, @course],
+ builder: FancyFormBuilder,
+ html: {class: 'form-horizontal'} do |f| %>
- <ul>
- <% @course.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
+
+ <legend>
+ <% if @course.new_record? %>
+ New Course for <%= @term %>
+ <% else %>
+ Editing: <%= @course %>
+ <% end %>
+ </legend>
+
+ <%= render partial: 'misc/errors', object: @course.errors %>
+
+ <%= f.control_group :dept_code, label: 'Subject Code' do %>
+ <%= f.text_field :dept_code %>
+ <% end %>
+
+ <%= f.control_group :course_num, label: 'Course Number' do %>
+ <%= f.text_field :course_num %>
+ <% end %>
+
+ <%= f.control_group :title, label: 'Course Title' do %>
+ <%= f.text_field :title %>
<% end %>
- <%= f.text_field :dept_code, label: 'Department Code' %>
- <%= f.text_field :course_num, label: 'Course Number' %>
- <%= f.text_field :title, label: 'Course Title' %>
- <div class="actions">
- <%= f.submit %>
+ <div class="form-actions">
+ <%= f.submit 'Save', class: 'btn btn-primary' %>
+ <%= link_to 'Cancel', [@term, :courses], class: 'btn' %>
</div>
<% end %>
View
10 app/views/courses/edit.html.erb
@@ -1,5 +1,5 @@
-<h1>Editing course</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', [@term, @course] %> |
+<div class="row">
+ <div class="span12">
+ <%= render 'form' %>
+ </div>
+</div>
View
47 app/views/courses/index.html.erb
@@ -1,5 +1,42 @@
<div class="row">
<div class="span10 offset1">
+ <table class="courses table" cellspacing="5px">
+ <thead>
+ <tr>
+ <th class="subject-num">Course</th>
+ <th class="title">Title</th>
+ <th colspan="2">
+ </tr>
+ </thead>
+ <% @courses.group_by(&:group).each do |group, courses| %>
+ <tbody class="noborder">
+ <tr class="head">
+ <th colspan="4">Group: <%= group %></th>
+ </tr>
+ <% courses.each do |course| %>
+ <tr class="">
+ <td class="subject-num"><%= course.short %></td>
+ <td class="title"><%= course.title %></td>
+ <td class="status">
+ <div><%= course_status_label(course) %></div>
+ </td>
+ <td class="actions">
+ <% if can? :edit, course %>
+ <a class="btn btn-tiny btn-success"
+ href="<%= url_for [:edit, @term, course] %>"
+ >Edit</a>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ <% end %>
+ </table>
+ </div>
+</div>
+
+<!--
+
<% @courses.group_by(&:group).each do |group, courses| %>
<div class="span3"><b>Group: <%= group %></b></div>
<table class="courses-index table" cellspacing="5px">
@@ -12,11 +49,6 @@
<tbody class="no-first-border">
<% courses.each do |course| %>
<tr class="">
- <td class="select">
- <input type="checkbox"
- id="course_check_<%= course.id %>"
- value="option1">
- </td>
<td class="subject-num"><%= course.short %></td>
<td class="title"><%= course.title %></td>
<td class="status">
@@ -29,7 +61,6 @@
>Edit
<% end %>
</a>
- <!--TODO:dkf when in retire mode change to icon-refresh -->
<% if can? :edit, course %>
<a class="btn btn-tiny btn-danger"
><i class="icon-trash icon-white"></i></a>
@@ -43,3 +74,7 @@
</div>
</div>
+-->
+
+<%= link_to 'New Course', [:new, @term, :course], class: 'btn' %>
+
View
4 app/views/courses/new.html.erb
@@ -1,5 +1 @@
-<h1>New course</h1>
-
<%= render 'form' %>
-
-<%= link_to 'Back', [@term, :courses] %>
View
6 test/controllers/courses_controller_test.rb
@@ -22,12 +22,11 @@
lambda do
post :create, academic_term_id: @term, course: attributes
end.must_change 'Course.count'
- must_redirect_to [@term, assigns(:course)]
end
describe 'an existing course' do
before do
- @course = Factory :course
+ @course = Factory :course, created_term: @term
end
it 'must display show page' do
@@ -44,7 +43,6 @@
lambda do
delete :destroy, academic_term_id: @term, id: @course.id
end.must_change 'Course.count', -1
- must_redirect_to [@term, :courses]
end
it 'should update title' do
@@ -53,9 +51,7 @@
academic_term_id: @term,
id: @course.id,
course: { title: new_title }
-
assigns(:course).title.must_equal new_title
- must_redirect_to [@term, assigns(:course)]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.