Skip to content

Commit

Permalink
Show example code on completed exercises, show completed code on dash…
Browse files Browse the repository at this point in the history
…board
  • Loading branch information
vosechu committed Jun 16, 2013
1 parent 4b15210 commit 97744ee
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 23 deletions.
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ GEM
nokogiri
thor
builder (3.0.4)
coderay (1.0.9)
faraday (0.8.7)
multipart-post (~> 1.1)
i18n (0.6.1)
metaclass (0.0.1)
method_source (0.8.1)
mocha (0.14.0)
metaclass (~> 0.0.1)
mongoid (3.1.4)
Expand All @@ -27,6 +29,10 @@ GEM
multipart-post (1.2.0)
nokogiri (1.5.9)
origin (1.1.0)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
puma (2.0.1)
rack (>= 1.1, < 2.0)
rack (1.5.2)
Expand All @@ -44,6 +50,7 @@ GEM
rack (~> 1.5, >= 1.5.2)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.4.5)
thor (0.18.1)
tilt (1.4.1)
tzinfo (0.3.37)
Expand All @@ -56,6 +63,7 @@ DEPENDENCIES
faraday
mocha
mongoid
pry
puma
rack-flash3
rack-test
Expand Down
5 changes: 3 additions & 2 deletions lib/app/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ class ExercismApp < Sinatra::Base
pending = Submission.pending.select do |submission|
current_user.may_nitpick?(submission.exercise)
end
unstarted = Exercism.current_curriculum.unstarted_trails(current_user.current_languages)
if current_user.admin?
erb :admin, locals: {pending: pending}
erb :admin, locals: {pending: pending, unstarted: unstarted}
else
erb :dashboard, locals: {pending: pending}
erb :dashboard, locals: {pending: pending, unstarted: unstarted}
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/app/views/current_submission.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<div class="row">
<div class="span6">
<%= Markdown.render("```#{submission.language}\n#{submission.code}\n```") %>
<h2>Code</h2>
<%= Markdown.render("```#{submission.language}\n#{submission.code}\n```") %>
<% if submission.approved? %>
<h2>Example</h2>
<%= Markdown.render("```#{submission.language}\n#{Exercism.current_curriculum.in(submission.language).assign(submission.slug).example}\n```") %>
<% end %>
</div>

<div class="span6">
Expand Down
58 changes: 42 additions & 16 deletions lib/app/views/dashboard.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
<% current_user.ongoing.each do |work| %>
<div class="row">
<% if (ongoing = current_user.ongoing) %>
<div class="span4">
<%= work.language %>: <%= work.slug %>
<% if work.submitted? %>
(<%= work.nits.count %>) <a href="/user/submissions/<%= work.id %>">view</a>
<% else %>
You haven't submitted anything on this yet.
<h2>Pending Work</h2>
<% ongoing.each do |work| %>
<div>
<%= work.language %>: <%= work.slug %>
<% if work.submitted? %>
(<%= work.nits.count %>) <a href="/user/submissions/<%= work.id %>">view</a>
<% else %>
You haven't submitted anything on this yet.
<% end %>
</div>
<% end %>
</div>
<% end %>
<% unstarted = Exercism.current_curriculum.unstarted_trails(current_user.current_languages) %>
<% unstarted.each do |language| %>
<form action="/user/<%= language %>/start" method="POST">
<input type="submit" value="start <%= language %>" />
</form>
<% end %>
<% end %>
<% if (submitted = current_user.submitted) %>
<div class="span4">
<h2>Completed Work</h2>
<% submitted.each do |work| %>
<div>
<%= work.language %>: <%= work.slug %>
<% if work.submitted? %>
(<%= work.nits.count %>) <a href="/user/submissions/<%= work.id %>">view</a>
<% else %>
You haven't submitted anything on this yet.
<% end %>
</div>
<% end %>
</div>
<% end %>
<% unless unstarted.empty? %>
<div class="span4">
<h2>Unstarted Trails</h2>
<% unstarted.each do |language| %>
<form action="/user/<%= language %>/start" method="POST">
<input type="submit" value="start <%= language %>" />
</form>
<% end %>
</div>
<% end %>

<div class="span3">
<%= erb :pending, locals: {pending: pending} %>
</div>
<div class="span4">
<%= erb :pending, locals: {pending: pending} %>
</div>
</div>
4 changes: 0 additions & 4 deletions lib/app/views/nitpick.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
<div class="span6">
<h2>Code</h2>
<%= Markdown.render("```#{submission.language}\n#{submission.code}\n```") %>
<% if current_user.completed?(submission.exercise) %>
<h2>Example</h2>
<%= Markdown.render("```#{submission.language}\n#{Exercism.current_curriculum.in(submission.language).assign(submission.slug).example}\n```") %>
<% end %>
</div>

<div class="span6">
Expand Down
8 changes: 8 additions & 0 deletions lib/exercism/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def ongoing
end
end

def submitted
@submitted ||= completed_exercises.map do |lang, exercises|
exercises.map do |exercise|
submissions_on(exercise).last || NullSubmission.new(exercise)
end
end.flatten
end

def latest_submission_on(exercise)
submissions_on(exercise).where(state: 'pending').last
end
Expand Down

0 comments on commit 97744ee

Please sign in to comment.