added search intervention. search opens new tab with search in the java course (at least in chrome)
send only 3 interventions per exercise at maximum
This commit is contained in:
@ -618,7 +618,7 @@ configureEditors: function () {
|
||||
}, timeUntilBreak);
|
||||
|
||||
setTimeout(function() {
|
||||
$('#intervention-text').text(`Willst du eine Frage stellen?`);
|
||||
$('#intervention-text').html("Möchtest du eine Frage stellen?");
|
||||
$('#intervention-modal').modal('show');
|
||||
$.ajax({
|
||||
data: {
|
||||
@ -632,6 +632,13 @@ configureEditors: function () {
|
||||
});
|
||||
},
|
||||
|
||||
initializeSearchButton: function(){
|
||||
$('.btn-search').button().click(function(){
|
||||
var search = $('#search_search').val();
|
||||
window.open(`https://open.hpi.de/courses/javaeinstieg2017/pinboard?query=${search}`, '_blank', 'toolbar=yes, location=yes, status=yes, menubar=yes, scrollbars=yes');
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
initializeEverything: function() {
|
||||
this.initializeRegexes();
|
||||
@ -648,6 +655,7 @@ configureEditors: function () {
|
||||
this.initializeTooltips();
|
||||
if ($('#editor').data('show-interventions') == true){
|
||||
this.initializeInterventionTimer();
|
||||
this.initializeSearchButton();
|
||||
}
|
||||
this.initPrompt();
|
||||
this.renderScore();
|
||||
|
@ -156,11 +156,13 @@ class ExercisesController < ApplicationController
|
||||
def implement
|
||||
redirect_to(@exercise, alert: t('exercises.implement.no_files')) unless @exercise.files.visible.exists?
|
||||
@show_interventions =
|
||||
if UserExerciseIntervention.find_by(exercise: @exercise, user: current_user)
|
||||
if UserExerciseIntervention.where(exercise: @exercise, user: current_user).count >= 3
|
||||
"false"
|
||||
else
|
||||
"true"
|
||||
end
|
||||
@search = Search.new
|
||||
@search.exercise = @exercise
|
||||
@submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first
|
||||
@files = (@submission ? @submission.collect_files : @exercise.files).select(&:visible).sort_by(&:name_with_extension)
|
||||
@paths = collect_paths(@files)
|
||||
|
34
app/controllers/searches_controller.rb
Normal file
34
app/controllers/searches_controller.rb
Normal file
@ -0,0 +1,34 @@
|
||||
class SearchesController < ApplicationController
|
||||
include CommonBehavior
|
||||
|
||||
def authorize!
|
||||
authorize(@search || @searchs)
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
|
||||
def create
|
||||
@search = Search.new(search_params)
|
||||
@search.user = current_user
|
||||
authorize!
|
||||
|
||||
respond_to do |format|
|
||||
if @search.save
|
||||
path = implement_exercise_path(@search.exercise)
|
||||
respond_with_valid_object(format, path: path, status: :created)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def search_params
|
||||
params[:search].permit(:search, :exercise_id)
|
||||
end
|
||||
private :search_params
|
||||
|
||||
def index
|
||||
@search = policy_scope(ProxyExercise).search(params[:q])
|
||||
@searches = @search.result.order(:title).paginate(page: params[:page])
|
||||
authorize!
|
||||
end
|
||||
|
||||
end
|
4
app/models/search.rb
Normal file
4
app/models/search.rb
Normal file
@ -0,0 +1,4 @@
|
||||
class Search < ActiveRecord::Base
|
||||
belongs_to :user, polymorphic: true
|
||||
belongs_to :exercise
|
||||
end
|
34
app/policies/search_policy.rb
Normal file
34
app/policies/search_policy.rb
Normal file
@ -0,0 +1,34 @@
|
||||
class SearchPolicy < AdminOrAuthorPolicy
|
||||
def author?
|
||||
@user == @record.author
|
||||
end
|
||||
private :author?
|
||||
|
||||
def batch_update?
|
||||
admin?
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||
define_method(action) { admin? || author?}
|
||||
end
|
||||
|
||||
[:reload?].each do |action|
|
||||
define_method(action) { everyone }
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -23,4 +23,4 @@
|
||||
|
||||
|
||||
= render('shared/modal', id: 'comment-modal', title: t('exercises.implement.comment.request'), template: 'exercises/_request_comment_dialogcontent')
|
||||
= render('shared/modal', id: 'intervention-modal', title: 'Leg mal eine Pause ein', template: 'interventions/_intervention_modal')
|
||||
= render('shared/modal', id: 'intervention-modal', title: 'Hinweis', template: 'interventions/_intervention_modal')
|
@ -1,9 +1,14 @@
|
||||
/h5 = t('exercises.implement.comment.question')
|
||||
|
||||
h5 = 'Hinweis'
|
||||
/textarea.form-control#question(style='resize:none;')
|
||||
#intervention-text
|
||||
= form_for(@search, multipart: true, target: "_blank") do |f|
|
||||
.form-group
|
||||
= f.text_field(:search, class: 'form-control', required: true)
|
||||
= f.hidden_field :exercise_id
|
||||
|
||||
.actions
|
||||
= f.submit(class: 'btn btn-default btn-search', value: 'Suche', model: @search.class.model_name.human)
|
||||
/p = "AVG: #{@working_time_avg}"
|
||||
/p = "ACCUMULATED: #{@working_time_accumulated}"
|
||||
|
||||
|
0
app/views/searches/destroy.html.erb
Normal file
0
app/views/searches/destroy.html.erb
Normal file
@ -84,6 +84,14 @@ Rails.application.routes.draw do
|
||||
end
|
||||
end
|
||||
|
||||
resources :searches do
|
||||
member do
|
||||
post :clone
|
||||
get :reload
|
||||
post :submit
|
||||
end
|
||||
end
|
||||
|
||||
resources :interventions do
|
||||
member do
|
||||
post :clone
|
||||
|
10
db/migrate/20170228165741_add_search.rb
Normal file
10
db/migrate/20170228165741_add_search.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class AddSearch < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :searches do |t|
|
||||
t.belongs_to :exercise, null: false
|
||||
t.belongs_to :user, polymorphic: true, null: false
|
||||
t.string :search
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user