Skip to content

Commit

Permalink
fixed merge conflicts for UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ingridh committed Apr 27, 2015
2 parents 178b17f + d0ea434 commit 2c6b5ff
Show file tree
Hide file tree
Showing 55 changed files with 365 additions and 76 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ gem 'rails', '3.2.16'

gem 'ruql', :git =>'https://github.com/zhangaaron/ruql.git'
gem 'omniauth'
gem 'cancan'
gem 'omniauth-github'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'barista'
gem 'cucumber-rails'
gem 'sunspot_rails', :git => 'https://github.com/sunspot/sunspot.git'
gem 'progress_bar'
gem 'json'
gem 'will_paginate', '~> 3.0.6'

group :development, :test do
gem 'sqlite3'
Expand All @@ -37,7 +39,6 @@ group :assets do
gem 'therubyracer'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

gem 'uglifier', '>= 1.0.3'
end

Expand Down
20 changes: 11 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GEM
multi_json (~> 1.0)
archive-tar-minitar (0.5.2)
arel (3.0.3)
autoprefixer-rails (5.1.9)
autoprefixer-rails (5.1.11)
execjs
json
barista (1.3.0)
Expand All @@ -60,6 +60,7 @@ GEM
autoprefixer-rails (>= 5.0.0.1)
sass (>= 3.2.19)
builder (3.0.4)
cancan (1.6.10)
capybara (2.4.4)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
Expand Down Expand Up @@ -134,9 +135,7 @@ GEM
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
omniauth-oauth2 (1.3.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
options (2.3.2)
Expand Down Expand Up @@ -204,11 +203,11 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simplecov (0.9.2)
simplecov (0.10.0)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.9.0)
simplecov-html (0.9.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
sprockets (2.2.3)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -223,10 +222,11 @@ GEM
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.43)
tzinfo (0.3.44)
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
will_paginate (3.0.7)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -236,6 +236,7 @@ PLATFORMS
DEPENDENCIES
barista
bootstrap-sass (~> 3.3.3)
cancan
coffee-rails (~> 3.2.1)
cucumber-rails
database_cleaner
Expand All @@ -258,3 +259,4 @@ DEPENDENCIES
sunspot_solr!
therubyracer
uglifier (>= 1.0.3)
will_paginate (~> 3.0.6)
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

require File.expand_path('../config/application', __FILE__)

Saasquizes::Application.load_tasks
Coursequestionbank::Application.load_tasks

task :default => [:test]
16 changes: 14 additions & 2 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
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
@collection = Collection.new
end
Expand All @@ -18,6 +27,11 @@ def create
redirect_to profile_path
end

def show
@collection = Collection.find(params[:id])
@problems = @collection.problems
end

def update
if not (collection = Collection.update(params[:id], params[:collection])).valid?
flash[:notice] = collection.errors.messages.map {|key, value| key.to_s + ' ' + value.to_s}.join ' ,'
Expand Down Expand Up @@ -45,6 +59,4 @@ def export
def finalize_upload
@collections = params[:ids].map{|collection_id| Collection.find(collection_id)}
end


end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class InstructorController < ApplicationController
class InstructorsController < ApplicationController

def show
@instructor = Instructor.find_by_id(@current_user)
Expand Down
21 changes: 12 additions & 9 deletions app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
class ProblemsController < ApplicationController
# before_filter :set_filter_options
#@@defaults = {tags: "", collections: "", last_exported_begin: "", last_exported_end: "", page: 1, page_count: 5 } #default arguments hash, not sure about the proper styling for this

def set_filter_options
session[:filter ] = @@defaults.merge params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :page_count)
puts "SESSION SET TO : #{session[:filter]} ----------------------------------------------------------------------------------------"
end

def home
redirect_to problems_path
end

def index
if @current_user
@collections = @current_user.collections
else
@collections = []
end

@collections = @current_user.collections
@chosen_collections = @collections.map { |c| c.name }
if params[:collections]
@chosen_collections = params[:collections].keys
end
filter_options = params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search)
end
# filter_options = session[:filter]
filter_options = params.slice(:tags, :collections, :last_exported_begin, :last_exported_end, :search, :page, :page_count)
@problems = Problem.filter(@current_user, filter_options)
end

Expand All @@ -27,7 +30,7 @@ def add_to_collection
return
end
problem_to_add = Problem.find(params[:id])
if not collection.problems.include? problem_to_add
if not collection.problems.include? problem_to_add
collection.problems << problem_to_add
render :json => {:status => true}
else
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class SessionsController < ApplicationController
skip_before_filter :set_current_user

def create
auth = request.env["omniauth.auth"]
user = Instructor.find_by_provider_and_uid(auth["provider"],auth["uid"]) ||
Instructor.create_with_omniauth(auth)
session[:user_id] = user.id
if Rails.env.development? or Rails.env.test?
session[:user_id] = Instructor.find_by_uid("1234").id
end
redirect_to problems_path
end

Expand Down
32 changes: 32 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Ability
include CanCan::Ability

def initialize(user)
# Define abilities for the passed in user here. For example:
#
# user ||= User.new # guest user (not logged in)
# if user.admin?
# can :manage, :all
# else
# can :read, :all
# end
#
# The first argument to `can` is the action you are giving the user
# permission to do.
# If you pass :manage it will apply to every action. Other common actions
# here are :read, :create, :update and :destroy.
#
# The second argument is the resource the user can perform the action on.
# If you pass :all it will apply to every resource. Otherwise pass a Ruby
# class of the resource.
#
# The third argument is an optional hash of conditions to further filter the
# objects.
# For example, here the user can only update published articles.
#
# can :update, Article, :published => true
#
# See the wiki for details:
# https://github.com/ryanb/cancan/wiki/Defining-Abilities
end
end
6 changes: 6 additions & 0 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin < Instructor
# attr_accessible :title, :body
def is_admin?
false
end
end
9 changes: 7 additions & 2 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Collection < ActiveRecord::Base
attr_accessible :last_used, :name, :description
attr_accessible :last_used, :name, :description, :is_public
validates :name, presence: true, uniqueness: true
has_and_belongs_to_many :problems
belongs_to :instructor
scope :collection, ->(collection_name) { where(name: collection_name) }
# scope :collection, ->(collection_name) { where(name: collection_name) }
scope :mine_or_public, ->(user) {where('instructor_id=? OR is_public=?', "#{user.id}", 'true')}

def add_to_collection(problem)
if problems.include? problem
Expand All @@ -21,4 +22,8 @@ def export
export_quiz.render_with('Html5')
end
end

def public?
self.is_public
end
end
8 changes: 5 additions & 3 deletions app/models/instructor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def self.create_with_omniauth(auth)
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
user.privilege = "admin"
user.privilege = "instructor"
end
end

end

def is_admin?
false
end
end
3 changes: 3 additions & 0 deletions app/models/null_collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class NullCollection < Collection
# attr_accessible :title, :body
end
19 changes: 7 additions & 12 deletions app/models/problem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ def html5
end
end

def self.filter(user, filters = {})
def self.filter(user, filters = {}, page)

if !filters[:tags]
filters[:tags] = ""
end

if !filters[:collections]
filters[:collections] = {}
end
filters[:tags] ||= ''
filters[:tags] = filters[:tags].strip.split(',')
filters[:collections] ||= {}

if !filters[:last_exported_begin] or filters[:last_exported_end].empty?
filters[:last_exported_begin] = nil
Expand All @@ -67,9 +63,7 @@ def self.filter(user, filters = {})
with(:instructor_id, user.id)
with(:is_public, true)
end

with(:tag_names, filters[:tags].split(",")) if !filters[:tags].empty?

with(:tag_names, filters[:tags]) if filters[:tags].present? #I THOUGHT SUNSPOT SAID THE PRESENCE CHECK WAS UNNECESARY
with(:coll_names, filters[:collections].keys)


Expand All @@ -83,8 +77,9 @@ def self.filter(user, filters = {})
end

fulltext filters[:search]
paginate :page => filters[:page], :per_page => filters[:page_count]
end

return problems.results
problems.results
end
end
6 changes: 4 additions & 2 deletions app/models/ruql_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def self.store_as_json(user, file)
puts Quiz.quizzes.uniq.map{|q| q.title + ' ,'}.join
Quiz.quizzes.uniq.each do |quiz|
problems_json = quiz.render_with("JSON", {})
collection = if Collection.find_by_name(quiz.title) then false else user.collections.create(:name => quiz.title) end
collection = if Collection.find_by_name(quiz.title) then false else user.collections.new(:name => quiz.title) end
if collection
collections.append collection

problems_json.each do |problem_json|
json_hash = JSON.parse(problem_json)
problem = Problem.new(text: "",
Expand All @@ -26,6 +26,8 @@ def self.store_as_json(user, file)
end
problem.save
end
collection.save!
collections.append collection
else
raise 'Quiz with that name already exists in your list of collections. You probably didn\'t mean to upload the same quiz again. Try deleting the old collection and upload again if you really meant to do that '
end
Expand Down
4 changes: 3 additions & 1 deletion app/views/collections/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
= form_for collection do |f|
= form_for(collection, :remote => !!remote) do |f| #magical hacks to set remote to be true when called from finalize_upload
= f.label :name
= f.text_field :name
= f.label :description
= f.text_field :description
= f.label 'Mark as public?'
= f.check_box :is_public
= f.submit
14 changes: 13 additions & 1 deletion app/views/collections/edit.html.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<<<<<<< HEAD
%h3= "Your collection: #{@collection.name}"
=render :partial=> 'form', locals: {collection: @collection}
%p.collectioncontrols
=link_to "Delete Collection", collection_path(@collection), :class => 'btn btn-danger', method: :delete, :confirm => 'Delete this collection?'
%p.collectioncontrols
=link_to "Export Collection", export_path(:id => @collection), :class => 'btn btn-info'

= render :partial => "shared/problems_table", locals: {problems_index: false, collection: @collection, problems: @collection.problems}
= render :partial => "shared/problems_table", locals: {problems_index: false, collection: @collection, problems: @collection.problems}
=======
%h3= "Your collection #{@collection.name}"
=render :partial=> 'form', locals: {collection: @collection, remote: false}
%p
Delete this collection?
=link_to 'trash_can_icon', collection_path(@collection), method: :delete, :confirm => 'Delete this collection?'
%p
Export this collection:
=link_to 'export button', export_path(:id => @collection)
= render :partial => "shared/problems_table", locals: {problems_index: false, collection: @collection, problems: @collection.problems}
>>>>>>> d0ea43498e3f0a2e8de3fcb02232d15b7b51459a
5 changes: 4 additions & 1 deletion app/views/collections/finalize_upload.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%h3= "Quiz successfully uploaded! Finalize changes or discard this upload"
%p{:style=>"color: green; font-style: italic"}
= "Your quiz was successfully uploaded! We found #{@collections.size} collections in your quiz. Review them below here:"


%div.col-md-10
%div.table-responsive
Expand All @@ -12,6 +14,7 @@
%p.collectioncontrols
=link_to(image_tag('trashcan.png', width: 21), collection_path(@collection), method: :delete, :confirm => 'Delete this collection?')
%p.collectioncontrols

Export this collection:
=link_to 'export button', export_path(:id => collection)
= render :partial => "shared/problems_table", locals: {problems_index: false, collection: collection, problems: collection.problems}
3 changes: 3 additions & 0 deletions app/views/collections/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- if @collection.instructor == @current_user
= link_to "Click here to edit this collection", edit_collection_path(id: @collection)
= render :partial => "shared/problems_table", locals: {problems_index: false, collection: @collection, problems: @collection.problems}
Loading

0 comments on commit 2c6b5ff

Please sign in to comment.