Skip to content

Commit

Permalink
Added some keys to the en locale WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gorrillamcd committed Nov 12, 2012
1 parent 7ccb541 commit 5f3fab5
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 312 deletions.
3 changes: 2 additions & 1 deletion app/controllers/dashboard_controller.rb
Expand Up @@ -14,8 +14,9 @@ def show
when "teacher"
return true # TODO: Add Teacher Dashboard
when "student" # TODO: Expand Student dashboard to provide all needed info
@subscriptions = Subscription.where(:user_id => current_user.id).group_by(&:state)
#@subscriptions = Subscription.where(:user_id => current_user.id).group_by(&:state)
@courses = current_user.courses.select('courses.*, subscriptions.state').group_by(&:state)
@available = Course.limit(5).order("created_at DESC")
else
return false

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/payments_controller.rb
Expand Up @@ -22,7 +22,7 @@ def index

def new
@unpaid_subs = current_user.subscriptions.unpaid.includes(:course)
@payment = Payment.new
@payment = current_user.payments.new
end

def create
Expand All @@ -33,7 +33,7 @@ def create
@payment.kind = @payment.determine_kind
@payment.amount = @unpaid_subs.calculate_cost
if @payment.charge_and_save
redirect_to dashboard_url, :notice => "Thank you for Paying!"
redirect_to dashboard_url, :notice => t('ui.payments.create.success')
else
render :action => 'new'
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/payment.rb
Expand Up @@ -2,11 +2,11 @@ class Payment < ActiveRecord::Base
has_many :subscriptions
belongs_to :user

attr_accessor :stripe_card_token, :user_id, :email
attr_accessor :stripe_card_token

attr_accessible :kind, :stripe_card_token #, :card_type, :card_expires_on, :card_number, :card_verification
attr_accessible :kind, :stripe_card_token

validates_presence_of :kind, :stripe_card_token #, :card_type, :card_expires_on, :card_number, :card_verification
validates_presence_of :kind, :stripe_card_token

# TODO: Make Payment functionality more user friendly, allowing users to pick which courses they will pay for
# TODO: Make Payment method (Stripe or ActiveMerchant) a configurable option (default: Stripe)
Expand All @@ -31,7 +31,7 @@ def charge_and_save
end
rescue Stripe::InvalidRequestError => e
logger.error "Stripe error while creating charge: #{e.message}"
errors.add :base, "There was a problem with your credit card."
errors.add :base, t('ui.payments.stripe.card_error')
false
end

Expand Down
5 changes: 3 additions & 2 deletions app/models/subscription.rb
Expand Up @@ -8,9 +8,10 @@ class Subscription < ActiveRecord::Base
validates_presence_of :course_id, :user_id, :state
validates_uniqueness_of :user_id, :scope => :course_id

scope :paid, -> { joins(:payments).where('payments.completed_at'.lt(Time.now)) }
scope :unpaid, -> { where('subscriptions.payment_id' => nil)}
scope :paid, -> { joins(:payments).where('payments.completed_at'.lt(Time.now)) }
scope :unpaid, -> { where('subscriptions.payment_id' => nil) }
scope :with_course, -> { joins(:courses).where(:course_id => 'courses.id') }
scope :active, -> { where('subscriptions.state' => 'active') }

state_machine :initial => :pending do

Expand Down
8 changes: 2 additions & 6 deletions app/models/user.rb
Expand Up @@ -22,12 +22,8 @@ class User < ActiveRecord::Base

# Methods

def find_subscriptions
Subscription.where(:user_id => self.id)
end

def has_courses?
unless self.find_subscriptions.blank?
unless self.subscriptions.blank?
return false
else
return true
Expand All @@ -43,7 +39,7 @@ def is_admin?(user)
end

def full_name
self.first_name+" "+self.last_name
[self.first_name,self.last_name].join(' ')
end

end
1 change: 1 addition & 0 deletions app/views/dashboard/_admin.html.erb
@@ -0,0 +1 @@
You're an admin. Reports and such will appear here once they're written.
78 changes: 78 additions & 0 deletions app/views/dashboard/_student.html.erb
@@ -0,0 +1,78 @@
<aside class="span4">
<div class="module">
<h2><%= t 'ui.module.availablecourses' %></h2>
<div class="accordion" id="available-courses">

<% @available.each_with_index do |course, index| %>
<div class="accordion-group">
<div class="accordion-header">
<div class="accordion-toggle" data-toggle="collapse" data-target="#available<%= index %>" data-parent="#available-courses">
<span><%= course.name.capitalize %></span>
</div>
</div>
<div id="available<%= index %>" class="accordion-body collapse <%= index == 0 ? "in" : "" %>">
<div class="module-body">
<p><%= course.description %></p>
<div class="btn-group">
<%= link_to t('ui.subscribe'), subscriptions_path(:course_id => course.id), :class => "btn btn-small btn-primary pull-right" %>
<%= link_to t('ui.courseinfo'), course, :class => "btn btn-small btn-info pull-right" %>
</div>
</div>
</div>
</div>
<% end %>
</div>
</div>
</aside>
<article class="span8 content">

<div class="module">
<h2><%= t 'ui.module.usercourses.mycourses' %></h2>
<div class="accordion" id="active-courses">

<% if @courses.blank? %>
<div id="no-courses">
<p>
You don't have any active courses. Why don't you <%= link_to "have a look at the available courses.", courses_path %>
</p>
</div>
<% else %>
<% @courses.each_pair do |state, courses| %>
<% courses.each_with_index do |course, index| %>
<% # Just some code to simulate a production environment to better display the UI, will be removed once the real feature is written
grade = Random.rand(90+10)
completion = Random.rand(90+10)

if grade <= 45
type = "fail"
elsif grade >= 80
type = "good"
else
type = "warn"
end %>
<div class="accordion-group">
<div class="accordion-header <%= type %>">
<div class="accordion-toggle" data-toggle="collapse" data-target="#record<%= index %>" data-parent="#active-courses">
<span><%= course.name %></span>
<small><%= completion %>%&nbsp;<%= t 'ui.module.usercourses.completed' %></small>
</div>
</div>
<div id="record<%= index %>" class="accordion-body collapse <%= index == 0 ? "in" : "" %>">
<div class="module-body">
<p><%= t 'ui.module.usercourses.nextlesson' %>: <strong>Chapter 5</strong></p>

<div class="btn-group">
<a class="btn btn-small btn-primary" href="#"><%= t 'ui.module.usercourses.takelesson' %></a>
<a class="btn btn-small btn-info" href="#"><%= t 'ui.courseinfo' %></a>
</div>
<span class="average <%= type %> pull-right"><%= grade %></span>
</div>
</div>
</div>
<% end %>
<% end %>
<% end %>
</div>
</div>
</article>
<% # End student Case %>

0 comments on commit 5f3fab5

Please sign in to comment.