Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ingridh committed May 2, 2015
2 parents 23faf3e + 2939dca commit fe2bb6e
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 85 deletions.
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
# load_and_authorize_resource
#alias_method :current_user, :set_current_user

before_filter :set_current_user
Expand All @@ -16,7 +17,7 @@ def current_ability
end

rescue_from CanCan::AccessDenied do |exception|
flash[:notice] = "You have successfully logged in but don't have persmission to access the site at the moment. Please wait until you have been authorized by one of our administrators."
flash[:notice] = "You don't have permission to access this site. Ask an administrator to be granted permission first."
redirect_to login_path, :alert => exception.message
end

Expand Down
19 changes: 10 additions & 9 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ class CollectionsController < ApplicationController
after_filter :set_current_collection

def set_current_collection
# if not @current_user.current_collection
# flash[:notice] = 'NO CURRENT COLLECTION'
# puts 'NO CURRENT COLLECTION ------------------------------------'
# end
end

def new
Expand Down Expand Up @@ -78,11 +74,16 @@ def finalize_upload
def checked_problems
collection = Collection.find(params[:dropdown])
collection_size = collection.problems.size
# make explicit call to this route so that CanCan authorization is used
# params[:problems].each {|problem_id| add_problem_path({collection_id: collection.id, id: problem_id})}
params[:problems].each {|problem_id, value| collection.problems << Problem.find(problem_id)}
flash[:notice] = "#{collection.problems.size - collection_size} of #{params[:problems].size } problems added to collection: #{collection.name}. If not all were added, you are trying to add a duplicate to the collection"
flash.keep
if params['add_problems'] and params[:problems].present?
params[:problems].each {|problem_id, value| collection.problems << Problem.find(problem_id)}
flash[:notice] = "#{collection.problems.size - collection_size} of #{params[:problems].size } problems added to collection: #{collection.name}. If not all were added, you are trying to add a duplicate to the collection"
flash.keep
end
if params[:problems].present? #for delete route
params[:problems].each {|problem_id, value| Problem.find(problem_id).destroy}
flash[:notice] = 'Problems successfully deleted'
flash.keep
end
redirect_to problems_path
end

Expand Down
3 changes: 1 addition & 2 deletions app/controllers/instructors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class InstructorsController < ApplicationController

def show
@instructor = Instructor.find_by_id(@current_user)
@collections = @instructor.collections
Expand All @@ -26,7 +26,6 @@ def authorize
end

def add_to_whitelist
puts "blah blah ", params
Whitelist.create(username: params["username"], privilege: params["access"])
@user = Instructor.find_by_username(params["username"])
@user.update_attributes(privilege: params["access"]) if @user
Expand Down
37 changes: 7 additions & 30 deletions app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
class ProblemsController < ApplicationController
before_filter :set_filter_options
@@defaults = {'tags' => "", 'collections' => {}, 'last_exported_begin' => "", 'last_exported_end' => '', 'per_page' => 5 } #default arguments hash, not sure about the proper styling for this
load_and_authorize_resource
@@defaults = HashWithIndifferentAccess.new({'tags' => "", 'collections' => {}, 'last_exported_begin' => "", 'last_exported_end' => '', 'per_page' => 5 }) #default arguments hash, not sure about the proper styling for this

def set_filter_options
# if not session[:filters]
session[:filters] = @@defaults.merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)
# else
# session[:filters] = session[:filters].merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)
# end
puts "SESSION IS : #{session[:filters]} ----------------------------------------------------------------------------------------"
session[:filters] ||= @@defaults
session[:filters] = @@defaults.merge session[:filters].merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)
puts "SESSION SET TO : #{session[:filters]} ----------------------------------------------------------------------------------------"
puts "SESSION FILTERS ----------------------------------------------------------------------------------------"
# session[:filters] = {}
puts "PARAMS SLICE: #{params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :per_page)}"
end

def home
Expand All @@ -19,30 +17,9 @@ def home

def index
@collections = @current_user.collections
@chosen_collections = @collections.map { |c| c.name }
if params[:collections]
@chosen_collections = params[:collections].keys
end
problems = Problem.filter(@current_user, session[:filters])
@problems = problems.results
@problems = Problem.filter(@current_user, session[:filters].clone).results #for some reason session[:filters] was being passed by reference? i have no clue why wtf
end

#eventually this will be an AJAX call. ALSO WE NEED TO CHANGE OUR HABTM ASSOCIATION TO HAS_MANY: THROUGH SO WE CAN USE VALIDATIONS AND STUFF
# def add_to_collection
# collection = Collection.find(params[:collection_id])
# if not collection
# render :json => {:status => false}
# return
# end
# problem_to_add = Problem.find(params[:id])
# if not collection.problems.include? problem_to_add
# collection.problems << problem_to_add
# render :json => {:status => true}
# else
# render :json => {:status => false}
# end
# end

def remove_from_collection
collection = Collection.find(params[:collection_id])
problem_to_remove = Problem.find(params[:id])
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SessionsController < ApplicationController
skip_load_resource
skip_authorize_resource
skip_before_filter :set_current_user

def create
Expand Down
4 changes: 1 addition & 3 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def initialize(user)
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
user ||= Instructor.new
if user.admin?
can :manage, Instructor
can :manage, Problem
can :manage, Collection
can :manage, :all
end
if user.instructor?
can :manage, Problem, :instructor_id => user.id
Expand Down
1 change: 0 additions & 1 deletion app/models/problem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def self.filter(user, filters = {})
fulltext filters['search']
paginate :page => filters['page'], :per_page => filters['per_page']
end
puts "#{problems.results} ----------------------------------------------------------"
problems
end
end
4 changes: 1 addition & 3 deletions app/views/collections/_collections_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
%table.table.table-striped#problems
%thead
%tr
%th
%th Question Text
%th Collections
%th Tags
%th Remove from collection
%th Remove Problem
%tbody
- problems.each do |problem|
%tr
%tr{:id => "q#{problem.id - 1}"}
%td= check_box_tag "problems[#{problem.id}]", 1
%td
= problem.html5.html_safe
= "Created Date: " + problem.created_date.to_s + " | "
Expand Down
1 change: 1 addition & 0 deletions app/views/collections/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
%span.glyphicon.glyphicon-export
Export


4 changes: 2 additions & 2 deletions app/views/collections/finalize_upload.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%div.col-md-12
%p{:style=>"color: green; font-style: italic; padding:0px;margin:0px;"}
= "Your quiz was successfully uploaded! We found #{@collections.size} collections in your quiz. Review them below:"
%h3{:style=>"color: blue; padding:0px;margin:0px;"}
= "Your quiz was successfully uploaded! We found #{@collections.size} collections with #{collections.reduce{|collection, n| collection.size + n}} problems in your quiz. Review them below:"

-@collections.each do |collection|
%tr
Expand Down
19 changes: 12 additions & 7 deletions app/views/problems/_filter.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

= form_tag problems_path, :method => :get, :id => "filter_form" do

%div.form-group
= label_tag(:search, "Search Keywords:")
= text_field_tag(:search, params[:search], class: 'form-control', placeholder: "Search")
= text_field_tag(:search, session[:filters][:search], class: 'form-control', placeholder: "Search")

%div.form-group
= label_tag(:tags, "Tags:")
= text_field_tag(:tags, params[:tags], class: 'form-control', placeholder: "e.g.: tag 1,tag 2")
= text_field_tag(:tags, session[:filters][:tags], class: 'form-control', placeholder: "e.g.: tag 1,tag 2")

%div.form-group
= label_tag(:last_exported, "Last Exported:")
= text_field_tag(:last_exported_begin, params[:last_exported_begin], class: 'form-control', placeholder: "dd/mm/yyyy")
= text_field_tag(:last_exported_end, params[:last_exported_end], class: 'form-control', placeholder: "dd/mm/yyyy")
= text_field_tag(:last_exported_begin, session[:filters][:last_exported_begin], class: 'form-control', placeholder: "dd/mm/yyyy")
= text_field_tag(:last_exported_end, session[:filters][:last_exported_end], class: 'form-control', placeholder: "dd/mm/yyyy")
%div.form-group
= label_tag(:collections, "Collections:")
-@collections.each do |collection|
=check_box_tag "collections[#{collection.id}]", 1, !!(session[:filters][:collections].include? collection.id), class: "checkbox", id: "collections[#{collection.id}]"
=collection.name
=check_box_tag "collections[0]", 1, !!(session[:filters][:collections].include? 0), class: "checkbox", id: "collections[0]"
All Collections

%div.form-group
= submit_tag 'Apply', :id => "filter_submit", :class => 'btn btn-info'
= submit_tag 'Apply', :id => "filter_submit", :class => 'btn btn-info'
58 changes: 31 additions & 27 deletions app/views/problems/_problems_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,39 @@
/ - problem.tags.each do |tag|
/ %span= tag
/ = text_field_tag(:username, params[:username], class: 'form-control', id: 'add_tags', placeholder: "Add tags")
/ =======
=form_tag checked_problems_path, class: 'form-inline' do
%div.form-group
=select_tag 'dropdown', options_from_collection_for_select(Collection.where(instructor_id: @current_user), "id","name"), class: 'form-control'
=submit_tag 'Add problems to the collection', class: 'btn btn-primary'
%div{:class => "maintable"}
%div.table-responsive
%table.table.table-striped#problems
%thead
%tr
%th
%th Question Text
%th Collections
%th Tags
%th
%tbody
- problems.each do |problem|
%tr{:id => "q#{problem.id - 1}"}
%td= check_box_tag "problems[#{problem.id}]", 1
%td
%li.glyphicon.glyphicon-chevron-right{:class => 'icon', :id => "#{problem.id - 1}"}
= problem.html5.html_safe
%div{:class => "additional"}
= "Created Date: " + problem.created_date.to_s + " | "
= "Created By: " + problem.instructor.name

%td
- problem.collections.each do |collection|
%p{:class => "colname"}
= link_to "#{collection.name} \n", collection_path(:id => collection.id)
%td= problem.tags.map {|tags| tags.name + ', '}.join
=submit_tag 'Add problems to the collection', name: 'add_problems', class: 'btn btn-default'
=submit_tag 'Delete problems', class: 'btn btn-default'
%br
%br
%div{:class => "maintable"}
%div.table-responsive
%table.table.table-striped#problems
%thead
%tr
%th
%th Question Text
%th Collections
%th Tags
%th
%tbody
- problems.each do |problem|
%tr{:id => "q#{problem.id - 1}"}
%td= check_box_tag "problems[#{problem.id}]", 1
%td
%li.glyphicon.glyphicon-chevron-right{:class => 'icon', :id => "#{problem.id - 1}"}
= problem.html5.html_safe
%div{:class => "additional"}
= "Created Date: " + problem.created_date.to_s + " | "
= "Created By: " + problem.instructor.name

%td
- problem.collections.each do |collection|
%p{:class => "colname"}
= link_to "#{collection.name} \n", collection_path(:id => collection.id)
%td= problem.tags.map {|tags| tags.name + ', '}.join
/ >>>>>>> truncate

0 comments on commit fe2bb6e

Please sign in to comment.