Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmesuere committed May 11, 2016
2 parents 8b9339c + 455487f commit e26f458
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta4', '< 5.1'
gem 'rails', '>= 5.0.0.rc1', '< 5.1'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ GEM
railties (>= 4.1.0, < 5.1)
responders
warden (~> 1.2.3)
devise_cas_authenticatable (1.8.0)
devise_cas_authenticatable (1.9.0)
devise (>= 1.2.0)
rubycas-client (>= 2.2.1)
erubis (2.7.0)
Expand Down Expand Up @@ -238,7 +238,7 @@ DEPENDENCIES
mysql2 (>= 0.3.18, < 0.5)
puma
pundit
rails (>= 5.0.0.beta4, < 5.1)
rails (>= 5.0.0.rc1, < 5.1)
rails-i18n (~> 5.0.0.beta3)
rouge
spring
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/exercises_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ExercisesController < ApplicationController
before_action :set_exercise, only: [:show, :edit, :update]
before_action :set_exercise, only: [:show, :edit, :update, :users]

rescue_from ActiveRecord::RecordNotFound do
redirect_to exercises_path, alert: "Sorry, we kunnen de oefening #{params[:name]} niet vinden."
Expand Down Expand Up @@ -31,6 +31,10 @@ def update
end
end

def users
@users = User.all.order(last_name: :asc)
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
15 changes: 14 additions & 1 deletion app/models/exercise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# updated_at :datetime not null
#

require 'action_view'
include ActionView::Helpers::DateHelper

class Exercise < ApplicationRecord
DATA_DIR = Rails.root.join('data', 'exercises').freeze
TESTS_FILE = 'tests.js'.freeze
Expand Down Expand Up @@ -61,6 +64,16 @@ def status_for(user)
:unknown
end

def number_of_submissions_for(user)
submissions.of_user(user).count
end

def solving_speed_for(user)
subs = submissions.of_user(user)
return '' if subs.count < 2
distance_of_time_in_words(subs.first.created_at, subs.last.created_at)
end

def self.refresh(changed)
msg = `cd #{DATA_DIR} && git pull 2>&1`
status = $CHILD_STATUS.exitstatus
Expand All @@ -70,7 +83,7 @@ def self.refresh(changed)

def self.process_directories(changed)
Dir.entries(DATA_DIR)
.select { |entry| File.directory?(File.join(DATA_DIR, entry)) && !entry.start_with?('.') && (changed.include?(entry) || changed.include?("UPDATE_ALL"))}
.select { |entry| File.directory?(File.join(DATA_DIR, entry)) && !entry.start_with?('.') && (changed.include?(entry) || changed.include?('UPDATE_ALL')) }
.each { |entry| Exercise.process_exercise_directory(entry) }
end

Expand Down
4 changes: 4 additions & 0 deletions app/policies/exercise_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def update?
user && user.admin?
end

def users?
user && user.admin?
end

def permitted_attributes
if user && user.admin?
[:visibility]
Expand Down
41 changes: 41 additions & 0 deletions app/views/exercises/users.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-xs-12">
<div class="card exercise-description">
<div class="card-title card-title-colored">
<h2 class="card-title-text">Overzicht <%= @exercise.name.titleize %></h2>
</div>
<div class="card-supporting-text">
<table class="table table-index table-resource">
<thead>
<tr>
<th>Gebruikersnaam</th>
<th>Naam</th>
<th>Status</th>
<th>Oplossingen</th>
<th>Tijd</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= link_to user.username, user %></td>
<td><%= user.full_name %></td>
<td>
<% if :correct == @exercise.status_for(user) %>
<%= link_to "correct", @exercise.last_correct_submission(user) %>
<% elsif :wrong == @exercise.status_for(user) %>
<%= link_to @exercise.last_submission(user).result, @exercise.last_submission(user) %>
<% else %>
niet opgelost
<% end %>
</td>
<td><%= @exercise.number_of_submissions_for(user) %></td>
<td><%= @exercise.solving_speed_for(user) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# config valid only for current version of Capistrano
lock '3.4.0'
lock '3.5.0'

set :application, 'dodona'
set :repo_url, '[email protected]:Scriptingtalen/dodona.git'
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

resources :exercises, only: [:index, :show, :edit, :update], param: :name do
resources :submissions, only: [:index, :create]
member do
get 'users' end
end

resources :submissions, only: [:index, :show, :create] do
Expand Down

0 comments on commit e26f458

Please sign in to comment.