diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index ebdcc08d..ccf8ce15 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -24,4 +24,5 @@ //= require bootstrap_pagedown //= require markdown.converter //= require markdown.sanitizer -//= require markdown.editor \ No newline at end of file +//= require markdown.editor +//= require ../../../vendor/assets/javascripts/ace/ext-language_tools \ No newline at end of file diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index 3d89bada..7a0a3a7e 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -221,6 +221,17 @@ var CodeOceanEditor = { editor.setReadOnly($(element).data('read-only') !== undefined); editor.setShowPrintMargin(false); editor.setTheme(this.THEME); + + // set options for autocompletion + if($(element).data('allow-auto-completion')){ + editor.setOptions({ + enableBasicAutocompletion: true, + enableSnippets: false, + enableLiveAutocompletion: true + }); + } + + editor.commands.bindKey("ctrl+alt+0", null); this.editors.push(editor); this.editor_for_file.set($(element).parent().data('filename'), editor); diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 45fd04d9..1e97d625 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -118,7 +118,7 @@ class ExercisesController < ApplicationController private :user_by_code_harbor_token def exercise_params - params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :public, :hide_file_tree, :allow_file_creation, :title, files_attributes: file_attributes).merge(user_id: current_user.id, user_type: current_user.class.name) + params[:exercise].permit(:description, :execution_environment_id, :file_id, :instructions, :public, :hide_file_tree, :allow_file_creation, :allow_auto_completion, :title, files_attributes: file_attributes).merge(user_id: current_user.id, user_type: current_user.class.name) end private :exercise_params diff --git a/app/views/exercises/_editor_frame.html.slim b/app/views/exercises/_editor_frame.html.slim index 94b43ab0..eff1541c 100644 --- a/app/views/exercises/_editor_frame.html.slim +++ b/app/views/exercises/_editor_frame.html.slim @@ -12,4 +12,4 @@ = link_to(file.native_file.file.name_with_extension, file.native_file.url) - else .editor-content.hidden data-file-id=file.ancestor_id = file.content - .editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-id=file.id \ No newline at end of file + .editor data-file-id=file.ancestor_id data-indent-size=file.file_type.indent_size data-mode=file.file_type.editor_mode data-read-only=file.read_only data-allow-auto-completion=exercise.allow_auto_completion.to_s data-id=file.id \ No newline at end of file diff --git a/app/views/exercises/_form.html.slim b/app/views/exercises/_form.html.slim index a640f0c2..c4159254 100644 --- a/app/views/exercises/_form.html.slim +++ b/app/views/exercises/_form.html.slim @@ -28,6 +28,10 @@ label = f.check_box(:allow_file_creation) = t('activerecord.attributes.exercise.allow_file_creation') + .checkbox + label + = f.check_box(:allow_auto_completion) + = t('activerecord.attributes.exercise.allow_auto_completion') h2 = t('activerecord.attributes.exercise.files') ul#files.list-unstyled.panel-group = f.fields_for :files do |files_form| diff --git a/app/views/exercises/show.html.slim b/app/views/exercises/show.html.slim index 5c554da8..902f8135 100644 --- a/app/views/exercises/show.html.slim +++ b/app/views/exercises/show.html.slim @@ -16,6 +16,7 @@ h1 = row(label: 'exercise.public', value: @exercise.public?) = row(label: 'exercise.hide_file_tree', value: @exercise.hide_file_tree?) = row(label: 'exercise.allow_file_creation', value: @exercise.allow_file_creation?) += row(label: 'exercise.allow_auto_completion', value: @exercise.allow_auto_completion?) = row(label: 'exercise.embedding_parameters') do = content_tag(:input, nil, class: 'form-control', readonly: true, value: embedding_parameters(@exercise)) diff --git a/config/locales/de.yml b/config/locales/de.yml index b12db0ad..8404ff3a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -36,6 +36,7 @@ de: public: Öffentlich title: Titel user: Autor + allow_auto_completion: "Autovervollständigung aktivieren" allow_file_creation: "Dateierstellung erlauben" external_user: consumer: Konsument diff --git a/config/locales/en.yml b/config/locales/en.yml index b70997e3..2fe2379a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,6 +36,7 @@ en: public: Public title: Title user: Author + allow_auto_completion: "Allow auto completion" allow_file_creation: "Allow file creation" external_user: consumer: Consumer diff --git a/db/migrate/20160907123009_add_allow_auto_completion_to_exercises.rb b/db/migrate/20160907123009_add_allow_auto_completion_to_exercises.rb new file mode 100644 index 00000000..99941e36 --- /dev/null +++ b/db/migrate/20160907123009_add_allow_auto_completion_to_exercises.rb @@ -0,0 +1,5 @@ +class AddAllowAutoCompletionToExercises < ActiveRecord::Migration + def change + add_column :exercises, :allow_auto_completion, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index b2c3b8a4..330f99d6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160704143402) do +ActiveRecord::Schema.define(version: 20160907123009) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -74,7 +74,6 @@ ActiveRecord::Schema.define(version: 20160704143402) do t.integer "file_type_id" t.integer "memory_limit" t.boolean "network_enabled" - end create_table "exercises", force: true do |t| @@ -90,6 +89,7 @@ ActiveRecord::Schema.define(version: 20160704143402) do t.string "token" t.boolean "hide_file_tree" t.boolean "allow_file_creation" + t.boolean "allow_auto_completion", default: false end create_table "external_users", force: true do |t|