Skip to content

Commit

Permalink
Add missing files from previous version
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Mar 9, 2012
1 parent 2337162 commit f781301
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 0 deletions.
63 changes: 63 additions & 0 deletions app/controllers/learnings_controller.rb
@@ -0,0 +1,63 @@
require 'common/workflow'

class LearningsController < ApplicationController

include Ptls::Workflow

before_filter :expose_subject_from_unit, :only => [:new, :create]
before_filter :expose_subject_from_learning, :only => [:edit, :update, :review]

make_resourceful do

belongs_to :unit, :subject
actions :edit, :update, :new, :create, :today, :review

response_for :create, :defer do |wants|
wants.html { redirect_to_next_learning }
end

response_for :today_complete do |wants|
wants.html do
flash[:notice] = "You've finished going through today's new material"
redirect_to subject_path(@subject)
end
end
end

def new
@learning = current_user.learnings.new(:unit => @unit)
end

def create
@learning = current_user.learnings.create(object_parameters)
@learning.deferred? ? response_for(:defer) : response_for(:create)
end

def review
current_object.update_attributes(object_parameters)
redirect_to today_subject_learnings_path(@subject, :page => (params[:page].to_i + 1))
end

# Iterate through today's newly learned items
def today
@learnings = current_user.learnings_for(@subject).paginate(:select => 'learnings.*', :page => params[:page], :per_page => 1)
response_for(@learnings.empty? ? :today_complete : :today)
end

private

def parent_object
@parent_object ||=
parent_model == Subject ?
parent_model.find_by_permalink(params["#{parent_name}_id"]) :
parent_model.find(params["#{parent_name}_id"])
end

def expose_subject_from_learning
@subject = current_object.subject
end

def expose_subject_from_unit
@subject = parent_object.subject
end
end
63 changes: 63 additions & 0 deletions app/controllers/reviews_controller.rb
@@ -0,0 +1,63 @@
require 'common/workflow'

class ReviewsController < ApplicationController

include Ptls::Workflow

before_filter :expose_subject_from_review, :only => [:edit, :update, :review]

include ActionView::Helpers::UrlHelper

make_resourceful do

belongs_to :subject

actions :edit, :update, :missed, :shift

response_for :update do |wants|
wants.html { redirect_to_next_review }
end

response_for :missed_complete do |wants|
wants.html do
flash[:notice] = "You've finished going through the reviews that you missed during today's review cycle. " +
"<a href=\"#{missed_subject_reviews_path(@subject)}\">Click here</a> if you would like to do so again."
redirect_to subject_path(@subject)
end
end

response_for :shift do |wants|
wants.html do
flash[:notice] = "Your reviews have been successfully shifted."
redirect_to subjects_path
end
end
end

def review
current_object.update_attributes(object_parameters)
redirect_to missed_subject_reviews_path(@subject, :page => (params[:page].to_i + 1))
end

# Iterate through reviews that were missed during today's review cycle
def missed
@reviews = current_user.missed(@subject).paginate(:select => 'reviews.*', :page => params[:page], :per_page => 1)
response_for(@reviews.empty? ? :missed_complete : :missed)
end

def shift
current_user.shift_reviews
response_for :shift
end

# Need to get subject by permalink
def parent_object
@parent_object ||= parent_model.find_by_permalink(params["#{parent_name}_id"])
end

private

def expose_subject_from_review
@subject = current_object.subject
end
end
5 changes: 5 additions & 0 deletions app/views/associations/_association.html.haml
@@ -0,0 +1,5 @@
#association
- if association.new_record?
= render :partial => '/associations/edit', :locals => { :association => association }
- else
= render :partial => '/associations/show', :locals => { :association => association }
4 changes: 4 additions & 0 deletions app/views/associations/_edit.html.haml
@@ -0,0 +1,4 @@
- remote_form_for association do |f|
= f.hidden_field :unit_id
= f.text_field :body, :class => :field
= image_submit_tag 'set_hint.png', :class => :button
2 changes: 2 additions & 0 deletions app/views/associations/_show.html.haml
@@ -0,0 +1,2 @@
%p
= link_to_remote h(association.body), :url => edit_association_path(association), :method => :get, :html => { :key => 'a', :id => 'edit_hint' }
15 changes: 15 additions & 0 deletions app/views/shared/_question.html.haml
@@ -0,0 +1,15 @@
- expanded = false if not defined?(expanded)

#question_wrapper
%em#progress
= progress
.clear
#question
%p#question_content= render :partial => 'units/show_question', :locals => { :unit => unit }
.clear
#hint{:class => (expanded ? 'expanded' : 'collapsed')}
= hint_bar_for(unit)
.clear
- if current_user.owns?(@subject)
%span#owner_actions
= link_to image_tag('delete_faded.png'), unit_path(unit), :method => :delete, :confirm => "Are you sure you want to delete this item AND all the progress made in relation to it?"
19 changes: 19 additions & 0 deletions app/views/subjects/_callout.html.haml
@@ -0,0 +1,19 @@
- content_for :callout do

#todays_progress
%h3 Todays highlights
%p.highlight
= todays_review_callout(@subject)
= review_shift_callout
%p.highlight= todays_learning_callout(@subject)
%a.swap{:href => '#overall_progress', :from => '#todays_progress'} see overall highlights
.clear

#overall_progress.hidden
%h3 Overall highlights
- if current_user.started?(@subject)
%p.highlight= subject_progress(@subject)
- if current_user.reviewing_yet?(@subject)
%p.highlight= subject_retention(@subject)
%a.swap{:href => '#todays_progress', :from => '#overall_progress'} see today's highlights
.clear
8 changes: 8 additions & 0 deletions app/views/subjects/_instructions.html.haml
@@ -0,0 +1,8 @@
- content_for :instructions do
%p
Please both review already learned material and learn new material on a
daily basis. This repetition ensures long term memory retention.
%p
You can always change the number of items you learn per day by adjusting
your
%a{:href => edit_user_path(current_user)} account settings.
2 changes: 2 additions & 0 deletions app/views/units/_edit_answer.html.haml
@@ -0,0 +1,2 @@
- remote_form_for unit do |f|
= f.text_field :answer, :class => :field
2 changes: 2 additions & 0 deletions app/views/units/_edit_question.html.haml
@@ -0,0 +1,2 @@
- remote_form_for unit do |f|
= f.text_field :question, :class => :field
4 changes: 4 additions & 0 deletions app/views/units/_show_answer.html.haml
@@ -0,0 +1,4 @@
- if current_user.owns?(@subject)
= link_to_remote unit.answer, :url => edit_answer_unit_path(unit), :method => :get, :html => { :id => 'unit_answer' }
- else
= unit.answer
4 changes: 4 additions & 0 deletions app/views/units/_show_question.html.haml
@@ -0,0 +1,4 @@
- if current_user.owns?(@subject)
= link_to_remote unit.question, :url => edit_question_unit_path(unit), :method => :get, :html => { :id => 'unit_question' }
- else
= unit.question

0 comments on commit f781301

Please sign in to comment.