From 81d2d69d111e84f56720aaff1a9c39c56f69cc4d Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Thu, 9 Jul 2015 12:03:03 +0200 Subject: [PATCH] Display request for comments button if we are working on a non binary submission. Introduced needed data attributes for that and assigned them to the frame (instead of the editor). Data Attributes get updated by the CreateSubmissionCallback. Adjusted comment checks to also use the attributes of the frame. --- app/assets/javascripts/editor.js | 22 ++++++++++++++++--- .../exercises/_editor_file_tree.html.slim | 2 +- app/views/exercises/_editor_frame.html.slim | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index 93267501..045e03ae 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -125,12 +125,16 @@ $(function() { }; var createSubmissionCallback = function(data){ + // set all frames context types to submission + $('.frame').each(function(index, element) { + $(element).data('context-type', 'Submission'); + }); + // update the ids of the editors and reload the annotations for (var i = 0; i < editors.length; i++) { // set the data attribute to submission - $(editors[i].container).data('context-type', 'Submission'); - + //$(editors[i].container).data('context-type', 'Submission'); var file_id_old = $(editors[i].container).data('file-id'); @@ -150,6 +154,8 @@ $(function() { } setAnnotations(editors[i], $(editors[i].container).data('id')); } + // toggle button states (it might be the case that the request for comments button has to be enabled + toggleButtonStates(); }; @@ -373,7 +379,8 @@ $(function() { var target = e.domEvent.target; // only allow comments on submissions, not on the template - if ($(editor.container).data('context-type') != 'Submission') return; + if(active_frame.data('context-type') != 'Submission') return; + //if ($(editor.container).data('context-type') != 'Submission') return; if (target.className.indexOf("ace_gutter-cell") == -1) return; if (!editor.isFocused()) return; if (e.clientX > 25 + target.getBoundingClientRect().left) return; @@ -573,6 +580,10 @@ $(function() { $('#start-over').on('click', confirmReset); }; + var isActiveFileBinary = function() { + return 'binary' in active_frame.data(); + }; + var isActiveFileExecutable = function() { return 'executable' in active_frame.data(); }; @@ -596,6 +607,10 @@ $(function() { return isActiveFileRunnable() && running; }; + var isActiveFileSubmission = function() { + return ['Submission'].includes(active_frame.data('contextType')); + }; + var isActiveFileTestable = function() { return isActiveFileExecutable() && ['teacher_defined_test', 'user_defined_test'].includes(active_frame.data('role')); }; @@ -960,6 +975,7 @@ $(function() { $('#run').toggle(isActiveFileRunnable() && !running); $('#stop').toggle(isActiveFileStoppable()); $('#test').toggle(isActiveFileTestable()); + $('#request-for-comments').toggle(isActiveFileSubmission() && !isActiveFileBinary()); }; var requestComments = function(e) { diff --git a/app/views/exercises/_editor_file_tree.html.slim b/app/views/exercises/_editor_file_tree.html.slim index 627d5e02..ac8c91d0 100644 --- a/app/views/exercises/_editor_file_tree.html.slim +++ b/app/views/exercises/_editor_file_tree.html.slim @@ -5,6 +5,6 @@ hr = render('editor_button', classes: 'btn-block btn-primary btn-xs', data: {:'data-cause' => 'file'}, icon: 'fa fa-plus', id: 'create-file', label: t('exercises.editor.create_file')) = render('editor_button', classes: 'btn-block btn-warning btn-xs', data: {:'data-cause' => 'file', :'data-message-confirm' => t('shared.confirm_destroy')}, icon: 'fa fa-times', id: 'destroy-file', label: t('exercises.editor.destroy_file')) = render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-download', id: 'download', label: t('exercises.editor.download')) -/= render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-bullhorn', id: 'request-for-comments', label: 'Request comments') += render('editor_button', classes: 'btn-block btn-primary btn-xs', icon: 'fa fa-bullhorn', id: 'request-for-comments', label: 'Request comments') = render('shared/modal', id: 'modal-file', template: 'code_ocean/files/_form', title: t('exercises.editor.create_file')) diff --git a/app/views/exercises/_editor_frame.html.slim b/app/views/exercises/_editor_frame.html.slim index e1596c42..dc077e02 100644 --- a/app/views/exercises/_editor_frame.html.slim +++ b/app/views/exercises/_editor_frame.html.slim @@ -1,4 +1,4 @@ -.frame data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role +.frame data-executable=file.file_type.executable? data-filename=file.name_with_extension data-renderable=file.file_type.renderable? data-role=file.role data-binary=file.file_type.binary? data-context-type=file.context_type - if file.file_type.binary? .binary-file data-file-id=file.ancestor_id - if file.file_type.renderable? @@ -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 data-context-type=file.context_type + .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