diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index bd2dc69b..57e94263 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -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(); diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 97910b18..3742de4d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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) diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb new file mode 100644 index 00000000..8af6b364 --- /dev/null +++ b/app/controllers/searches_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/search.rb b/app/models/search.rb new file mode 100644 index 00000000..f22dbc3e --- /dev/null +++ b/app/models/search.rb @@ -0,0 +1,4 @@ +class Search < ActiveRecord::Base + belongs_to :user, polymorphic: true + belongs_to :exercise +end \ No newline at end of file diff --git a/app/policies/search_policy.rb b/app/policies/search_policy.rb new file mode 100644 index 00000000..9da9a641 --- /dev/null +++ b/app/policies/search_policy.rb @@ -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 diff --git a/app/views/exercises/_editor.html.slim b/app/views/exercises/_editor.html.slim index b4cf7bb8..bae90a13 100644 --- a/app/views/exercises/_editor.html.slim +++ b/app/views/exercises/_editor.html.slim @@ -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') \ No newline at end of file += render('shared/modal', id: 'intervention-modal', title: 'Hinweis', template: 'interventions/_intervention_modal') \ No newline at end of file diff --git a/app/views/interventions/_intervention_modal.html.slim b/app/views/interventions/_intervention_modal.html.slim index 027e4f97..a432751d 100644 --- a/app/views/interventions/_intervention_modal.html.slim +++ b/app/views/interventions/_intervention_modal.html.slim @@ -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}" diff --git a/app/views/searches/destroy.html.erb b/app/views/searches/destroy.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/config/routes.rb b/config/routes.rb index 79f57fe5..a33369d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20170228165741_add_search.rb b/db/migrate/20170228165741_add_search.rb new file mode 100644 index 00000000..a36d94ff --- /dev/null +++ b/db/migrate/20170228165741_add_search.rb @@ -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