Skip to content

Commit

Permalink
Merge pull request #550 from makeitrealcamp/quizzes-resources
Browse files Browse the repository at this point in the history
Move quizzes to resources
  • Loading branch information
germanescobar committed Oct 19, 2016
2 parents fa0bb88 + 9722b03 commit b66e8a9
Show file tree
Hide file tree
Showing 162 changed files with 1,725 additions and 1,165 deletions.
20 changes: 19 additions & 1 deletion app/assets/javascripts/quizer/questions.coffee
@@ -1,5 +1,4 @@
class MultiAnswerQuestionForm extends Backbone.View

events:
"click .add-correct-answer" : "add_correct_answer"
"click .add-wrong-answer" : "add_wrong_answer"
Expand All @@ -20,4 +19,23 @@ class MultiAnswerQuestionForm extends Backbone.View
$remove_btn = $(event.currentTarget)
$remove_btn.parents(".answer").remove()

class SingleAnswerQuestionForm extends Backbone.View
events:
"click .add-wrong-answer" : "add_wrong_answer"
"click .remove-answer" : "remove_answer"

add_wrong_answer: ->
@add_answer("wrong_answers")

add_answer: (type)->
type_class = type.replace(/_/g,'-')
template = _.template($("#single-answer-question-answer-template").html())
@$el.find(".#{type_class}").append(template({ type: type, answer:"" }))

remove_answer: (event)->
$remove_btn = $(event.currentTarget)
$remove_btn.parents(".answer").remove()


window.MultiAnswerQuestionForm = MultiAnswerQuestionForm
window.SingleAnswerQuestionForm = SingleAnswerQuestionForm
Expand Up @@ -54,4 +54,4 @@ class ProfileQuestionsView extends Backbone.View
@.$('.next').show()
@.$('.finish').hide()

window.ProfileQuestionsView = ProfileQuestionsView
window.ProfileQuestionsView = ProfileQuestionsView
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Expand Up @@ -15,7 +15,7 @@ $grid-float-breakpoint: 810px;
@import "sessions";
@import "users";
@import "dashboard";
@import "courses";
@import "subjects";
@import "challenges";
@import "resources";
@import "comments";
Expand Down
Expand Up @@ -212,7 +212,7 @@ blockquote {
.nav-tabs {
li {
text-align: center;
width: 25%;
width: 33%;
}
.glyphicon {
margin-right: 7px;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/badges_controller.rb
Expand Up @@ -41,7 +41,7 @@ def destroy

def badge_params
params.require(:badge).permit(:name, :description, :image_url,
:giving_method, :required_points, :course_id)
:giving_method, :required_points, :subject_id)
end

end
12 changes: 0 additions & 12 deletions app/controllers/admin/courses_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/admin/project_solutions_controller.rb
Expand Up @@ -21,7 +21,7 @@ def assign_points
@user = @project_solution.user

@user.points.create(
course: @project_solution.project.course,
subject: @project_solution.project.subject,
points: assign_points_params[:points],
pointable: @project_solution.project
)
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/admin/subjects_controller.rb
@@ -0,0 +1,12 @@
class Admin::SubjectsController < ApplicationController
before_action :admin_access

def index
@subjects = Subject.all
end

def update_position
@subject = Subject.update(params[:id], row_position: params[:position])
render nothing: true, status: 200
end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Expand Up @@ -65,7 +65,7 @@ def update

def show
@user = User.find(params[:id])
@courses = Course.all
@subjects = Subject.all
end

private
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/challenges_controller.rb
Expand Up @@ -3,13 +3,13 @@ class ChallengesController < ApplicationController
before_action :admin_access, except:[:show, :discussion]

def new
course = Course.friendly.find(params[:course_id])
@challenge = course.challenges.new
subject = Subject.friendly.find(params[:subject_id])
@challenge = subject.challenges.new
end

def create
@challenge = Challenge.create(challenge_params)
redirect_to course_path(@challenge.course), notice: "El reto <strong>#{@challenge.name}</strong> ha sido creado"
redirect_to subject_path(@challenge.subject), notice: "El reto <strong>#{@challenge.name}</strong> ha sido creado"
end

def edit
Expand All @@ -18,7 +18,7 @@ def edit

def update
@challenge = Challenge.friendly.update(params[:id], challenge_params)
redirect_to course_challenge_path(@challenge.course,@challenge), notice: "El reto <strong>#{@challenge.name}</strong> ha sido actualizado"
redirect_to subject_challenge_path(@challenge.subject,@challenge), notice: "El reto <strong>#{@challenge.name}</strong> ha sido actualizado"
end

def update_position
Expand All @@ -43,7 +43,7 @@ def discussion
solution = load_solution
if (solution.nil? || solution.completed_at.blank?) && !current_user.is_admin?
flash[:error] = "Debes completar el reto para poder ver la discusión"
redirect_to course_challenge_path(@challenge.course, @challenge)
redirect_to subject_challenge_path(@challenge.subject, @challenge)
end
end

Expand All @@ -54,7 +54,7 @@ def load_solution

def challenge_params
params.require(:challenge).permit(
:course_id, :name, :instructions, :evaluation_strategy, :published, :timeout,
:subject_id, :name, :instructions, :evaluation_strategy, :published, :timeout,
:evaluation, :solution_text, :solution_video_url,:difficulty_bonus, :restricted, :preview, :pair_programming,
documents_attributes: [:id, :name, :content, :_destroy])
end
Expand Down
54 changes: 0 additions & 54 deletions app/controllers/courses_controller.rb

This file was deleted.

16 changes: 8 additions & 8 deletions app/controllers/lessons_controller.rb
Expand Up @@ -11,22 +11,22 @@ def create
@section = Section.find(params[:section_id])
@lesson = @section.lessons.new(lesson_params)
if @lesson.save
redirect_to course_resource_path(@lesson.resource.course, @lesson.resource), notice: "La Lección <strong>#{@lesson.name}</strong> ha sido creado"
redirect_to subject_resource_path(@lesson.resource.subject, @lesson.resource), notice: "La Lección <strong>#{@lesson.name}</strong> ha sido creado"
else
render :new
end
end

# GET /courses/:course_id/resources/:resource_id/sections/:section_id/lessons/:id
# GET /subjects/:subject_id/resources/:resource_id/sections/:section_id/lessons/:id
def show
@lesson = Lesson.find(params[:id])
@course = @lesson.section.resource.course
@subject = @lesson.section.resource.subject
@resource = @lesson.section.resource
if @lesson.free_preview? || current_user.has_access_to?(@lesson.resource)
render :show
else
flash[:error] = "Debes suscribirte para tener acceso a todas las lecciones"
redirect_to course_resource_path(@lesson.resource.course,@lesson.resource)
redirect_to subject_resource_path(@lesson.resource.subject,@lesson.resource)
end
end

Expand All @@ -39,13 +39,13 @@ def update
@lesson = Lesson.find(params[:id])
@section = Section.find(params[:section_id])
if @lesson && @lesson.update(lesson_params)
redirect_to course_resource_path(@lesson.resource.course, @lesson.resource), notice: "La Lección <strong>#{@lesson.name}</strong> ha sido actualizado"
redirect_to subject_resource_path(@lesson.resource.subject, @lesson.resource), notice: "La Lección <strong>#{@lesson.name}</strong> ha sido actualizado"
else
render :edit
end
end

# POST /courses/:course_id/resources/:resource_id/sections/:section_id/lessons/:id/complete
# POST /subjects/:subject_id/resources/:resource_id/sections/:section_id/lessons/:id/complete
def complete
@lesson = Lesson.find(params[:id])
unless current_user.has_completed_lesson?(@lesson)
Expand Down Expand Up @@ -74,9 +74,9 @@ def lesson_params
def next_path(lesson)
next_lesson = lesson.next(current_user)
if next_lesson
course_resource_section_lesson_path(next_lesson.section.resource.course, next_lesson.section.resource, next_lesson.section, next_lesson)
subject_resource_section_lesson_path(next_lesson.section.resource.subject, next_lesson.section.resource, next_lesson.section, next_lesson)
else
course_resource_path(lesson.resource.course, lesson.resource)
subject_resource_path(lesson.resource.subject, lesson.resource)
end
end
end
14 changes: 7 additions & 7 deletions app/controllers/project_solutions_controller.rb
Expand Up @@ -3,34 +3,34 @@ class ProjectSolutionsController < ApplicationController
before_action :paid_access
before_action :set_project

# GET /courses/:course_id/projects/:project_id/project_solutions/:id
# GET /subjects/:subject_id/projects/:project_id/project_solutions/:id
def show
@project_solution = ProjectSolution.find(params[:id])
if !current_user.is_admin? && !current_user.has_completed_project?(@project)
flash[:notice] = "Debes publicar tu solución para ver las soluciones de la comunidad."
redirect_to course_project_path(@project.course,@project)
redirect_to subject_project_path(@project.subject,@project)
end
end

# GET /courses/:course_id/projects/:project_id/project_solutions
# GET /subjects/:subject_id/projects/:project_id/project_solutions
def index
if current_user.is_admin? || current_user.has_completed_project?(@project)
@own_project_solution = @project.project_solutions.find_by_user_id(current_user.id)
@project_solutions = @project.project_solutions.where.not(user_id: current_user.id)
else
flash[:notice] = "Debes publicar tu solución para ver las soluciones de la comunidad."
redirect_to course_project_path(@project.course,@project)
redirect_to subject_project_path(@project.subject,@project)
end
end

# POST /courses/:course_id/projects/:project_id/project_solutions
# POST /subjects/:subject_id/projects/:project_id/project_solutions
def create
@project_solution = @project.project_solutions.build(project_solution_params)
@project_solution.user = current_user

if @project_solution.save
flash[:notice] = "Tu solución ha sido publicada, ahora ayuda a los demás con tu opinión"
redirect_to course_project_project_solutions_path(@project.course,@project)
redirect_to subject_project_project_solutions_path(@project.subject,@project)
else
render "projects/show"
end
Expand All @@ -41,7 +41,7 @@ def update

if @project_solution.update(project_solution_params)
flash[:notice] = "Tu solución ha sido actualizada"
redirect_to course_project_project_solutions_path(@project.course,@project)
redirect_to subject_project_project_solutions_path(@project.subject,@project)
else
render "projects/show"
end
Expand Down
24 changes: 12 additions & 12 deletions app/controllers/projects_controller.rb
Expand Up @@ -4,44 +4,44 @@ class ProjectsController < ApplicationController
before_action :paid_access, only:[:show]
before_action :set_project, only: [:show,:edit,:update,:destroy]

# GET /courses/:course_id/projects/:id
# GET /subjects/:subject_id/projects/:id
def show
@project_solution = @project.project_solutions.find_or_initialize_by(user_id: current_user.id)
end

# GET /courses/:course_id/projects/new
# GET /subjects/:subject_id/projects/new
def new
course = Course.friendly.find(params[:course_id])
@project = course.projects.new
subject = Subject.friendly.find(params[:subject_id])
@project = subject.projects.new
end

# POST /courses/:course_id/projects
# POST /subjects/:subject_id/projects
def create
@course = Course.friendly.find(params[:course_id])
@project = @course.projects.new(project_params)
@subject = Subject.friendly.find(params[:subject_id])
@project = @subject.projects.new(project_params)

if @project.save
redirect_to @course, anchor: "projects"
redirect_to @subject, anchor: "projects"
else
render :new
end
end

# GET /courses/:course_id/projects/:id/edit
# GET /subjects/:subject_id/projects/:id/edit
def edit
end

# PATCH /courses/:course_id/projects/:id
# PATCH /subjects/:subject_id/projects/:id
def update
@project = Project.find(params[:id])
if @project.update(project_params)
redirect_to course_project_path(@project.course,@project), anchor: "projects", notice: "Proyecto actualizado"
redirect_to subject_project_path(@project.subject,@project), anchor: "projects", notice: "Proyecto actualizado"
else
render :edit
end
end

# DELETE /courses/:course_id/projects/:id
# DELETE /subjects/:subject_id/projects/:id
def destroy
@project.destroy
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/quizer/question_attempts_controller.rb
@@ -1,6 +1,6 @@
module Quizer
class QuestionAttemptsController < ApplicationController
before_action :set_course
before_action :set_subject
before_action :set_quiz
before_action :set_quiz_attempt
before_action :set_question_attempt, only: [:update]
Expand All @@ -18,12 +18,12 @@ def update

private

def set_course
@course = Course.friendly.find(params[:course_id])
def set_subject
@subject = Subject.friendly.find(params[:subject_id])
end

def set_quiz
@quiz = Quiz.friendly.find(params[:quiz_id])
@quiz = Quiz.friendly.find(params[:resource_id])
end

def set_quiz_attempt
Expand Down

0 comments on commit b66e8a9

Please sign in to comment.