Merge pull request #130 from openHPI/exercise-collections-ui
Exercise Collections UI
This commit is contained in:
51
app/controllers/exercise_collections_controller.rb
Normal file
51
app/controllers/exercise_collections_controller.rb
Normal file
@ -0,0 +1,51 @@
|
||||
class ExerciseCollectionsController < ApplicationController
|
||||
include CommonBehavior
|
||||
|
||||
before_action :set_exercise_collection, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@exercise_collections = ExerciseCollection.all.paginate(:page => params[:page])
|
||||
authorize!
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@exercise_collection = ExerciseCollection.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
def create
|
||||
@exercise_collection = ExerciseCollection.new(exercise_collection_params)
|
||||
authorize!
|
||||
create_and_respond(object: @exercise_collection)
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize!
|
||||
destroy_and_respond(object: @exercise_collection)
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
update_and_respond(object: @exercise_collection, params: exercise_collection_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_exercise_collection
|
||||
@exercise_collection = ExerciseCollection.find(params[:id])
|
||||
authorize!
|
||||
end
|
||||
|
||||
def authorize!
|
||||
authorize(@exercise_collection || @exercise_collections)
|
||||
end
|
||||
|
||||
def exercise_collection_params
|
||||
params[:exercise_collection].permit(:name, :exercise_ids => [])
|
||||
end
|
||||
end
|
@ -2,4 +2,8 @@ class ExerciseCollection < ActiveRecord::Base
|
||||
|
||||
has_and_belongs_to_many :exercises
|
||||
|
||||
def to_s
|
||||
"#{I18n.t('activerecord.models.exercise_collection.one')}: #{name} (#{id})"
|
||||
end
|
||||
|
||||
end
|
3
app/policies/exercise_collection_policy.rb
Normal file
3
app/policies/exercise_collection_policy.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class ExerciseCollectionPolicy < AdminOnlyPolicy
|
||||
|
||||
end
|
@ -8,7 +8,7 @@
|
||||
- if current_user.admin?
|
||||
li = link_to(t('breadcrumbs.dashboard.show'), admin_dashboard_path)
|
||||
li.divider
|
||||
- models = [ExecutionEnvironment, Exercise, ProxyExercise, Tag, Consumer, CodeHarborLink, ExternalUser, FileType, FileTemplate, InternalUser].sort_by { |model| model.model_name.human(count: 2) }
|
||||
- models = [ExecutionEnvironment, Exercise, ExerciseCollection, ProxyExercise, Tag, Consumer, CodeHarborLink, ExternalUser, FileType, FileTemplate, InternalUser].sort_by { |model| model.model_name.human(count: 2) }
|
||||
- models.each do |model|
|
||||
- if policy(model).index?
|
||||
li = link_to(model.model_name.human(count: 2), send(:"#{model.model_name.collection}_path"))
|
||||
|
11
app/views/exercise_collections/_form.html.slim
Normal file
11
app/views/exercise_collections/_form.html.slim
Normal file
@ -0,0 +1,11 @@
|
||||
- exercises = Exercise.order(:title)
|
||||
|
||||
= form_for(@exercise_collection, data: {exercises: exercises}, multipart: true) do |f|
|
||||
= render('shared/form_errors', object: @exercise_collection)
|
||||
.form-group
|
||||
= f.label(:name)
|
||||
= f.text_field(:name, class: 'form-control', required: true)
|
||||
.form-group
|
||||
= f.label(:exercises)
|
||||
= f.collection_select(:exercise_ids, exercises, :id, :title, {}, {class: 'form-control', multiple: true})
|
||||
.actions = render('shared/submit_button', f: f, object: @exercise_collection)
|
3
app/views/exercise_collections/edit.html.slim
Normal file
3
app/views/exercise_collections/edit.html.slim
Normal file
@ -0,0 +1,3 @@
|
||||
h1 = @exercise_collection
|
||||
|
||||
= render('form')
|
24
app/views/exercise_collections/index.html.slim
Normal file
24
app/views/exercise_collections/index.html.slim
Normal file
@ -0,0 +1,24 @@
|
||||
h1 = ExerciseCollection.model_name.human(count: 2)
|
||||
|
||||
.table-responsive
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
th = t('activerecord.attributes.exercise_collections.id')
|
||||
th = t('activerecord.attributes.exercise_collections.name')
|
||||
th = t('activerecord.attributes.exercise_collections.updated_at')
|
||||
th = t('activerecord.attributes.exercise_collections.exercises')
|
||||
th colspan=3 = t('shared.actions')
|
||||
tbody
|
||||
- @exercise_collections.each do |collection|
|
||||
tr
|
||||
td = collection.id
|
||||
td = link_to(collection.name, collection)
|
||||
td = collection.updated_at
|
||||
td = collection.exercises.size
|
||||
td = link_to(t('shared.show'), collection)
|
||||
td = link_to(t('shared.edit'), edit_exercise_collection_path(collection))
|
||||
td = link_to(t('shared.destroy'), collection, data: {confirm: t('shared.confirm_destroy')}, method: :delete)
|
||||
|
||||
= render('shared/pagination', collection: @exercise_collections)
|
||||
p = render('shared/new_button', model: ExerciseCollection)
|
3
app/views/exercise_collections/new.html.slim
Normal file
3
app/views/exercise_collections/new.html.slim
Normal file
@ -0,0 +1,3 @@
|
||||
h1 = t('shared.new_model', model: ExerciseCollection.model_name.human)
|
||||
|
||||
= render('form')
|
11
app/views/exercise_collections/show.html.slim
Normal file
11
app/views/exercise_collections/show.html.slim
Normal file
@ -0,0 +1,11 @@
|
||||
h1
|
||||
= @exercise_collection
|
||||
= render('shared/edit_button', object: @exercise_collection)
|
||||
|
||||
= row(label: 'exercise_collections.name', value: @exercise_collection.name)
|
||||
= row(label: 'exercise_collections.updated_at', value: @exercise_collection.updated_at)
|
||||
|
||||
h4 = t('activerecord.attributes.exercise_collections.exercises')
|
||||
ul.list-unstyled
|
||||
- @exercise_collection.exercises.sort_by{|c| c.title}.each do |exercise|
|
||||
li = link_to(exercise, exercise)
|
@ -111,6 +111,11 @@ de:
|
||||
name: "Name"
|
||||
file_type: "Dateityp"
|
||||
content: "Code"
|
||||
exercise_collections:
|
||||
id: "ID"
|
||||
name: "Name"
|
||||
updated_at: "Letzte Änderung"
|
||||
exercises: "Aufgaben"
|
||||
models:
|
||||
code_harbor_link:
|
||||
one: CodeHarbor-Link
|
||||
@ -127,6 +132,9 @@ de:
|
||||
exercise:
|
||||
one: Aufgabe
|
||||
other: Aufgaben
|
||||
exercise_collection:
|
||||
one: Aufgabesammlung
|
||||
other: Aufgabensammlungen
|
||||
proxy_exercise:
|
||||
one: Proxy Aufgabe
|
||||
other: Proxy Aufgaben
|
||||
|
@ -111,6 +111,11 @@ en:
|
||||
name: "Name"
|
||||
file_type: "File Type"
|
||||
content: "Content"
|
||||
exercise_collections:
|
||||
id: "ID"
|
||||
name: "Name"
|
||||
updated_at: "Last Update"
|
||||
exercises: "Exercises"
|
||||
models:
|
||||
code_harbor_link:
|
||||
one: CodeHarbor Link
|
||||
@ -127,6 +132,9 @@ en:
|
||||
exercise:
|
||||
one: Exercise
|
||||
other: Exercises
|
||||
exercise_collection:
|
||||
one: Exercise Collection
|
||||
other: Exercise Collections
|
||||
proxy_exercise:
|
||||
one: Proxy Exercise
|
||||
other: Proxy Exercises
|
||||
|
@ -74,6 +74,8 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :exercise_collections
|
||||
|
||||
resources :proxy_exercises do
|
||||
member do
|
||||
post :clone
|
||||
|
14
test/controllers/exercise_collections_controller_test.rb
Normal file
14
test/controllers/exercise_collections_controller_test.rb
Normal file
@ -0,0 +1,14 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ExerciseCollectionsControllerTest < ActionController::TestCase
|
||||
test "should get index" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
get :show
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user