From 916bef97e9987d457711104c39b2c56b05368336 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 9 May 2016 18:26:52 +0200 Subject: [PATCH 1/4] update to rails rc1 --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 2100b822dc..7a68711d2b 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 11e34e0367..22931d2f34 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 From e23d5c46b0712643f5410915a727f3ddee41ce2d Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Mon, 9 May 2016 18:27:14 +0200 Subject: [PATCH 2/4] update capistrano lock --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index f20d8fc950..7bc79b5a11 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -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, 'git@github.ugent.be:Scriptingtalen/dodona.git' From 87d4f7b4dcba5df21369f052a39ad975a0c80b19 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Wed, 11 May 2016 13:22:49 +0200 Subject: [PATCH 3/4] use devise_cas_authenticatable 1.9.0 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 22931d2f34..5c56b68ede 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) From 455487f7b1a8ddd695ca4ad13ee1a5aacef81243 Mon Sep 17 00:00:00 2001 From: Bart Mesuere Date: Wed, 11 May 2016 13:55:50 +0200 Subject: [PATCH 4/4] add overview page per exercise --- app/controllers/exercises_controller.rb | 6 +++- app/models/exercise.rb | 15 ++++++++- app/policies/exercise_policy.rb | 4 +++ app/views/exercises/users.html.erb | 41 +++++++++++++++++++++++++ config/routes.rb | 2 ++ 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 app/views/exercises/users.html.erb diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6a3e617678..c50c7dbc4b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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." @@ -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. diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 30ed4a353d..8c1cae70ba 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -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 @@ -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 @@ -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 diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index 93e1c5c03e..a10cadc717 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -25,6 +25,10 @@ def update? user && user.admin? end + def users? + user && user.admin? + end + def permitted_attributes if user && user.admin? [:visibility] diff --git a/app/views/exercises/users.html.erb b/app/views/exercises/users.html.erb new file mode 100644 index 0000000000..6c153bd879 --- /dev/null +++ b/app/views/exercises/users.html.erb @@ -0,0 +1,41 @@ +
+
+
+
+

Overzicht <%= @exercise.name.titleize %>

+
+
+ + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + <% end %> + +
GebruikersnaamNaamStatusOplossingenTijd
<%= link_to user.username, user %><%= user.full_name %> + <% 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 %> + <%= @exercise.number_of_submissions_for(user) %><%= @exercise.solving_speed_for(user) %>
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index a6e264b4d8..1978c30202 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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