From 33a94a9aa5c710ff806310b858b0eeb26d3b8f3c Mon Sep 17 00:00:00 2001 From: Splines <37160523+Splines@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:22:19 +0100 Subject: [PATCH 1/3] Fix discard in quiz editor (#600) * Fix discard behavior in quiz editor -> edit answer * Clean up code comments --- app/abilities/answer_ability.rb | 4 +- app/assets/javascripts/answers.coffee | 69 ----------------- app/assets/javascripts/answers.coffee.erb | 90 ++++++++++++++++++++++ app/controllers/answers_controller.rb | 7 +- app/views/answers/cancel_edit.js.erb | 39 ++++++++++ app/views/answers/update_answer_box.coffee | 3 - config/routes.rb | 6 +- 7 files changed, 136 insertions(+), 82 deletions(-) delete mode 100644 app/assets/javascripts/answers.coffee create mode 100644 app/assets/javascripts/answers.coffee.erb create mode 100644 app/views/answers/cancel_edit.js.erb delete mode 100644 app/views/answers/update_answer_box.coffee diff --git a/app/abilities/answer_ability.rb b/app/abilities/answer_ability.rb index f4b41b3c1..a88cc96ee 100644 --- a/app/abilities/answer_ability.rb +++ b/app/abilities/answer_ability.rb @@ -4,10 +4,8 @@ class AnswerAbility def initialize(user) clear_aliased_actions - can [:new, :create, :update, :destroy], Answer do |answer| + can [:new, :create, :update, :destroy, :cancel_edit], Answer do |answer| answer.question.present? && user.can_edit?(answer.question) end - - can :update_answer_box, Answer end end diff --git a/app/assets/javascripts/answers.coffee b/app/assets/javascripts/answers.coffee deleted file mode 100644 index c7ea9d8c4..000000000 --- a/app/assets/javascripts/answers.coffee +++ /dev/null @@ -1,69 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://coffeescript.org/ - -# change button 'Bearbeiten' to 'verwerfen' after answer body is revealed - -$(document).on 'turbolinks:load', -> - - $(document).on 'shown.bs.collapse', '[id^="collapse-answer-"]', -> - $target = $('#targets-answer-' + $(this).data('id')) - $target.empty().append($target.data('discard')) - .removeClass('btn-primary').addClass('btn-secondary') - return - - # submit form to database after answer body is hidden and restore - # buttons after after answer body is hidden - - $(document).on 'hidden.bs.collapse', '[id^="collapse-answer-"]', -> - answerId = $(this).data('id') - text = $('#tex-area-answer-' + answerId).val() - value = $('#answer-true-' + answerId).is(':checked') - explanation = $('#tex-area-explanation-' + answerId).val() - $target = $('#targets-answer-' + answerId) - $target.empty() - .append($target.data('edit')) - .removeClass('btn-secondary').addClass 'btn-primary' - $.ajax Routes.answer_path(answerId), - type: 'PATCH' - dataType: 'script' - data: { - answer: { - text: text - value: value - explanation: explanation - } - } - return - - # change correctness box for answer if radio button is clicked - - $(document).on 'change', '[id^="answer-value-"]', -> - $.ajax Routes.update_answer_box_path(), - type: 'GET' - dataType: 'script' - data: { - answer_id: $(this).data('id') - value: $('#answer-true-' + $(this).data('id')).is(':checked') - } - error: (jqXHR, textStatus, errorThrown) -> - console.log("AJAX Error: #{textStatus}") - return - - # remove card for new answer if creation of new answer is cancelled - - $(document).on 'click', '#new-answer-cancel', -> - $('#new-answer').show() - $('#new-answer-field').empty() - return - - return - -# clean up everything before turbolinks caches -$(document).on 'turbolinks:before-cache', -> - $(document).off 'shown.bs.collapse', '[id^="collapse-answer-"]' - $(document).off 'hidden.bs.collapse', '[id^="collapse-answer-"]' - $(document).off 'change', '[id^="answer-value-"]' - $(document).off 'click', '#new-answer-cancel' - return - diff --git a/app/assets/javascripts/answers.coffee.erb b/app/assets/javascripts/answers.coffee.erb new file mode 100644 index 000000000..90e037a20 --- /dev/null +++ b/app/assets/javascripts/answers.coffee.erb @@ -0,0 +1,90 @@ +<% environment.context_class.instance_eval { include ApplicationHelper } %> + +# The "target button" is either the "discard" button or the "edit" button +# what its purpose is is stored in this object with a mapping: +# answerId -> boolean +targetButtonIsDiscardButton = {} + +# Set of answer ids that have a discard listener registered +# This is to avoid registering the same listener multiple times. +window.registeredDiscardListeners = new Set(); + +$(document).on 'turbolinks:load', -> + + $(document).on 'shown.bs.collapse', '[id^="collapse-answer-"]', -> + # Answer is now shown to the user and can be edited + answerId = $(this).data('id'); + registerDiscardListeners(); + targetButtonIsDiscardButton[answerId] = true; + $target = $('#targets-answer-' + answerId) + $target.empty().append($target.data('discard')) + .removeClass('btn-primary').addClass('btn-secondary') + + $(document).on 'hidden.bs.collapse', '[id^="collapse-answer-"]', -> + # Answer is now hidden from the user + answerId = $(this).data('id') + targetButtonIsDiscardButton[answerId] = false; + $target = $('#targets-answer-' + answerId) + $target.empty().append($target.data('edit')) + .removeClass('btn-secondary').addClass('btn-primary') + + # Appearance of box + $(document).on 'change', '[id^="answer-value-"]', -> + id = $(this).data('id') + isCorrectAnswer = $('#answer-true-' + id).is(':checked') + + # Set background color + if isCorrectAnswer + newClass = "<%= bgcolor(true) %>"; + else + newClass = "<%= bgcolor(false) %>"; + $('#answer-header-' + id) + .removeClass('bg-correct') + .removeClass('bg-incorrect') + .addClass(newClass) + + # Set ballot box + answerBox = $('#answer-box-' + id) + answerBox.empty() + if isCorrectAnswer + answerBox.append '<%= ballot_box(true) %>' + else + answerBox.append '<%= ballot_box(false) %>' + + # Cancel new answer creation + $(document).on 'click', '#new-answer-cancel', -> + $('#new-answer').show() + $('#new-answer-field').empty() + +# clean up everything before turbolinks caches +$(document).on 'turbolinks:before-cache', -> + $(document).off 'shown.bs.collapse', '[id^="collapse-answer-"]' + $(document).off 'hidden.bs.collapse', '[id^="collapse-answer-"]' + $(document).off 'change', '[id^="answer-value-"]' + $(document).off 'click', '#new-answer-cancel' + + +registerDiscardListeners = () -> + buttons = $('[id^=targets-answer-]'); + $.each(buttons, (i,btn) -> + btn = $(btn); + answerId = btn.attr('id').split('-')[2]; + + # Don't register listeners multiple times + if answerId in window.registeredDiscardListeners + return; + + window.registeredDiscardListeners.add(answerId); + $(this).on('click', (evt) => + isDiscardButton = targetButtonIsDiscardButton[answerId]; + if not isDiscardButton + return; + + # On discard + $.ajax Routes.cancel_edit_answer_path(answerId), + type: 'GET' + dataType: 'script' + error: (jqXHR, textStatus, errorThrown) -> + console.log("AJAX Error: #{textStatus}") + ); + ); diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index 937273189..88d24404c 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -1,6 +1,6 @@ # AnswersController class AnswersController < ApplicationController - before_action :set_answer, except: [:new, :create, :update_answer_box] + before_action :set_answer, except: [:new, :create] authorize_resource except: [:new, :create] def current_ability @@ -34,9 +34,8 @@ def destroy @success = true end - def update_answer_box - @answer_id = params[:answer_id].to_i - @value = params[:value] == "true" + def cancel_edit + I18n.locale = @answer.question&.locale_with_inheritance end private diff --git a/app/views/answers/cancel_edit.js.erb b/app/views/answers/cancel_edit.js.erb new file mode 100644 index 000000000..7fafd4631 --- /dev/null +++ b/app/views/answers/cancel_edit.js.erb @@ -0,0 +1,39 @@ +var answerId = <%= @answer.id %>; +var answerCard = $(`#answers-accordion > #answer-card-${answerId}`); +window.registeredDiscardListeners.delete(answerId); + +// eslint-disable-next-line @stylistic/quotes +var newAnswerCardElements = $(`<%= j render partial: 'answers/card', locals: { answer: @answer } %>`).children(); + +// re-render possible MathJax content +// eslint-disable-next-line no-undef +renderMathInElement(newAnswerCardElements.get(0), { + delimiters: [ + { + left: "$$", + right: "$$", + display: true, + }, + { + left: "$", + right: "$", + display: false, + }, + { + left: "\\(", + right: "\\)", + display: false, + }, + { + left: "\\[", + right: "\\]", + display: true, + }, + ], + throwOnError: false, +}, +); + +setTimeout(() => { + answerCard.empty().append(newAnswerCardElements); +}, 100); diff --git a/app/views/answers/update_answer_box.coffee b/app/views/answers/update_answer_box.coffee deleted file mode 100644 index 4d1a0971f..000000000 --- a/app/views/answers/update_answer_box.coffee +++ /dev/null @@ -1,3 +0,0 @@ -$('#answer-box-<%= @answer_id %>').empty().append '<%= ballot_box(@value) %>' -$('#answer-header-<%= @answer_id %>').removeClass('bg-correct') - .removeClass('bg-incorrect').addClass '<%= bgcolor(@value) %>' diff --git a/config/routes.rb b/config/routes.rb index a53c7a36c..470168970 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,9 +51,9 @@ resources :announcements, only: [:index, :new, :create] # answers routes - - get "answers/update_answer_box", - as: "update_answer_box" + get "answers/:id/cancel_edit", + to: "answers#cancel_edit", + as: "cancel_edit_answer" resources :answers, except: [:index, :show, :edit] From 2988fab0920e0f94953cf15e03121f1983f7cd71 Mon Sep 17 00:00:00 2001 From: Splines <37160523+Splines@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:33:45 +0100 Subject: [PATCH 2/3] Redesign comments page (#602) * Fix unnecessary "xxxl" gridpoints * Redesign comments page * Add slight box shadow to comments --- app/assets/javascripts/lectures.coffee | 4 +-- app/assets/stylesheets/application.scss | 17 ++++++---- app/assets/stylesheets/comments.scss | 17 ++++++++++ app/controllers/media_controller.rb | 2 +- app/views/administration/index.html.erb | 4 +-- app/views/commontator/comments/_form.html.erb | 4 +-- app/views/commontator/comments/_list.html.erb | 3 +- app/views/commontator/threads/_show.html.erb | 3 +- app/views/commontator/threads/show.js.erb | 2 +- ...cation_no_sidebar_with_background.html.erb | 33 +++++++++++++++++++ app/views/lectures/edit/_form.html.erb | 6 ++-- app/views/main/start.html.erb | 6 ++-- app/views/main/start/_talks.html.erb | 2 +- app/views/media/comments/_comments.html.erb | 3 +- app/views/media/show_comments.html.erb | 2 +- app/views/notifications/index.html.erb | 2 +- 16 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 app/views/layouts/application_no_sidebar_with_background.html.erb diff --git a/app/assets/javascripts/lectures.coffee b/app/assets/javascripts/lectures.coffee index 5e47d4fea..20b6cc98c 100644 --- a/app/assets/javascripts/lectures.coffee +++ b/app/assets/javascripts/lectures.coffee @@ -103,13 +103,13 @@ $(document).on 'turbolinks:load', -> # hide the media tab if hide media button is clicked $('#hide-media-button').on 'click', -> $('#lecture-media-card').hide() - $('#lecture-content-card').removeClass('col-xxxl-9') + $('#lecture-content-card').removeClass('col-xxl-9') $('#show-media-button').show() return # display the media tab if show media button is clicked $('#show-media-button').on 'click', -> - $('#lecture-content-card').addClass('col-xxxl-9') + $('#lecture-content-card').addClass('col-xxl-9') $('#lecture-media-card').show() $('#show-media-button').hide() return diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 4fed1ddea..66e6312e3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -27,9 +27,6 @@ $grid-breakpoints: ( lg: 992px, xl: 1200px, xxl: 1440px, - xxxl: 1600px, - xxxxl: 1920px, - xxxxxl: 2160px ); $container-max-widths: ( @@ -41,9 +38,6 @@ $container-max-widths: ( lg: 992px, xl: 1200px, xxl: 1440px, - xxxl: 1600px, - xxxxl: 1920px, - xxxxxl: 2160px ); @@ -306,4 +300,15 @@ a { .toast { background-color: white; +} + +.small-width { + max-width: 900px; +} + +.subtle-background { + flex: 1; + background: radial-gradient(circle at top right, transparent 10%, #fafdff 10%, #fafdff 20%, transparent 21%), radial-gradient(circle at left bottom, transparent 10%, #fafdff 10%, #fafdff 20%, transparent 21%), radial-gradient(circle at top left, transparent 10%, #fafdff 10%, #fafdff 20%, transparent 21%), radial-gradient(circle at right bottom, transparent 10%, #fafdff 10%, #fafdff 20%, transparent 21%), radial-gradient(circle at center, #fafdff 30%, transparent 31%); + background-size: 6em 6em; + background-color: #ffffff; } \ No newline at end of file diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss index ee5fabfe1..1788da423 100644 --- a/app/assets/stylesheets/comments.scss +++ b/app/assets/stylesheets/comments.scss @@ -3,4 +3,21 @@ #toggleCommentPreviewWrapper { padding-left: $form-check-padding-start + $form-check-input-width; +} + +.form-control.commentForm { + border-color: #4173b4; + border-width: 1.5px; +} + +.comment-field { + backdrop-filter: blur(8px); + background-color: rgba(255, 255, 255, 0.44); + padding: 6px !important; +} + +.comment { + border: solid 1.5px #d2d2d2 !important; + border-radius: 4px; + box-shadow: rgba(0,0,0,0.025) 0px 2px 5px; } \ No newline at end of file diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index a8efdbd2c..ffefdc701 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -441,7 +441,7 @@ def statistics def show_comments commontator_thread_show(@medium) - render layout: "application_no_sidebar" + render layout: "application_no_sidebar_with_background" end def cancel_publication diff --git a/app/views/administration/index.html.erb b/app/views/administration/index.html.erb index 57306b6f3..ec2af45c1 100644 --- a/app/views/administration/index.html.erb +++ b/app/views/administration/index.html.erb @@ -1,10 +1,10 @@
diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index e9b91e522..617528541 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -28,7 +28,7 @@ data-nonotifications="<%= t('notifications.no_notifications') %>"> <% if @notifications.present? %> <% @notifications.each do |n| %> -
<%= render partial: 'notifications/notification',
locals: { notification: n } %>
From 4e734a4ad1cef5f8238c551fdedebc4a7b6579eb Mon Sep 17 00:00:00 2001
From: Splines <37160523+Splines@users.noreply.github.com>
Date: Sat, 23 Mar 2024 11:46:32 +0100
Subject: [PATCH 3/3] Replace search icon in admin navbar (#603)
The binocular icon is replaced by a magnifier icon in the admin navbar.
---
app/views/administration/_navbar.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/administration/_navbar.html.erb b/app/views/administration/_navbar.html.erb
index cf4959437..f6d01c6d6 100644
--- a/app/views/administration/_navbar.html.erb
+++ b/app/views/administration/_navbar.html.erb
@@ -37,7 +37,7 @@
<%= link_to '', administration_search_path,
- class: 'nav-link bi bi-binoculars-fill ' + get_class_for_path(administration_search_path()),
+ class: 'nav-link bi bi-search ' + get_class_for_path(administration_search_path()),
data: { 'bs-toggle': 'tooltip' },
title: t('navbar.search') %>