diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index 7221c38e..ddbe2e54 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -640,9 +640,18 @@ configureEditors: function () { initializeSearchButton: function(){ $('#btn-search-col').button().click(function(){ - var search = $('#search-col').val(); - var course_token = $('#sidebar-collapsed').data('course_token') + var search = $('#search-input-text').val(); + var course_token = $('#editor').data('course_token') + var save_search_url = $('#editor').data('search-save-url') window.open("https://open.hpi.de/courses/" + course_token + "/pinboard?query=" + search, '_blank'); + // save search + $.ajax({ + data: { + search_text: search + }, + dataType: 'json', + type: 'POST', + url: save_search_url}); }) $('#sidebar-search-collapsed').on('click',this.handleSideBarToggle.bind(this)); diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 5c536a0e..25361125 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -6,7 +6,7 @@ class ExercisesController < ApplicationController before_action :handle_file_uploads, only: [:create, :update] before_action :set_execution_environments, only: [:create, :edit, :new, :update] - before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :run, :statistics, :submit, :reload] + before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload] before_action :set_external_user, only: [:statistics] before_action :set_file_types, only: [:create, :edit, :new, :update] before_action :set_course_token, only: [:implement] @@ -223,7 +223,17 @@ class ExercisesController < ApplicationController else render(json: {success: 'false', error: "undefined intervention #{params[:intervention_type]}"}) end + end + def search + search_text = params[:search_text] + search = Search.new(user: current_user, exercise: @exercise, search: search_text) + + begin search.save + render(json: {success: 'true'}) + rescue + render(json: {success: 'false', error: "could not save search: #{$!}"}) + end end def index diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb deleted file mode 100644 index 8af6b364..00000000 --- a/app/controllers/searches_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -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/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index 6377488b..54d22b87 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -16,7 +16,7 @@ class ExercisePolicy < AdminOrAuthorPolicy define_method(action) { admin? || author?} end - [:implement?, :working_times?, :intervention?, :submit?, :reload?].each do |action| + [:implement?, :working_times?, :intervention?, :search?, :submit?, :reload?].each do |action| define_method(action) { everyone } end diff --git a/app/views/exercises/_editor.html.slim b/app/views/exercises/_editor.html.slim index 8a43b613..5b3c3478 100644 --- a/app/views/exercises/_editor.html.slim +++ b/app/views/exercises/_editor.html.slim @@ -2,7 +2,7 @@ - external_user_id = @current_user.respond_to?(:external_id) ? @current_user.id : '' #'tests' #(@current_user.uuid.present? ? @current_user.uuid : '') - consumer_id = @current_user.respond_to?(:external_id) ? @current_user.consumer_id : '' #'tests' #(@current_user.uuid.present? ? @current_user.uuid : '') - show_interventions = @show_interventions || "false" -#editor.row data-exercise-id=exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-errors-url=execution_environment_errors_path(exercise.execution_environment) data-submissions-url=submissions_path data-user-id=@current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path data-intervention-save-url=intervention_exercise_path data-show-interventions=show_interventions +#editor.row data-exercise-id=exercise.id data-message-depleted=t('exercises.editor.depleted') data-message-timeout=t('exercises.editor.timeout', permitted_execution_time: @exercise.execution_environment.permitted_execution_time) data-errors-url=execution_environment_errors_path(exercise.execution_environment) data-submissions-url=submissions_path data-user-id=@current_user.id data-user-external-id=external_user_external_id data-working-times-url=working_times_exercise_path data-intervention-save-url=intervention_exercise_path data-show-interventions=show_interventions data-course_token=@course_token data-search-save-url=search_exercise_path div id="sidebar" class=(@exercise.hide_file_tree ? 'sidebar-col-collapsed' : 'sidebar-col') = render('editor_file_tree', exercise: @exercise, files: @files) div id='output_sidebar' class='output-col-collapsed' = render('exercises/editor_output', external_user_id: external_user_id, consumer_id: consumer_id ) div id='frames' class='editor-col' diff --git a/app/views/exercises/_editor_file_tree.html.slim b/app/views/exercises/_editor_file_tree.html.slim index 2c287eba..3f8334dc 100644 --- a/app/views/exercises/_editor_file_tree.html.slim +++ b/app/views/exercises/_editor_file_tree.html.slim @@ -1,4 +1,4 @@ -div id='sidebar-collapsed' class=(@exercise.hide_file_tree ? '' : 'hidden') data-course_token=@course_token +div id='sidebar-collapsed' class=(@exercise.hide_file_tree ? '' : 'hidden') = render('editor_button', classes: 'btn-block btn-primary btn-sm', data: {:'data-toggle' => 'tooltip', :'data-placement' => 'right'}, icon: 'fa fa-plus-square', id: 'sidebar-collapse-collapsed', label:'', title:t('exercises.editor.expand_action_sidebar')) - if @exercise.allow_file_creation and not @exercise.hide_file_tree? @@ -27,15 +27,12 @@ div id='sidebar-uncollapsed' class=(@exercise.hide_file_tree ? 'hidden' : '') = render('editor_button', classes: 'btn-block btn-primary btn-sm', data: {:'data-message-confirm' => t('exercises.editor.confirm_start_over'), :'data-url' => reload_exercise_path(@exercise)}, icon: 'fa fa-history', id: 'start-over', label: t('exercises.editor.start_over')) - if !@course_token.blank? - = form_for(@search, multipart: true, target: "_blank") do |f| .input-group.enforce-top-margin - = f.hidden_field :exercise_id .enforce-right-margin - = f.text_field(:search, class: 'form-control', id: "search-col", required: true, placeholder: t('search.search_in_forum')) + = text_field_tag 'search-input-text', nil, placeholder: t('search.search_in_forum'), class: 'form-control' .input-group-btn - = button_tag(class: 'btn btn-primary', id: 'btn-search-col', model: @search.class.model_name.human) do + = button_tag(class: 'btn btn-primary', id: 'btn-search-col') do i.fa.fa-search - - if @exercise.allow_file_creation? = render('shared/modal', id: 'modal-file', template: 'code_ocean/files/_form', title: t('exercises.editor.create_file')) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a33369d4..4c8c18eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,6 +62,7 @@ Rails.application.routes.draw do get :implement get :working_times post :intervention + post :search get :statistics get :reload post :submit @@ -84,14 +85,6 @@ 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