Skip to content

Commit

Permalink
Continuous Release 1.10.1
Browse files Browse the repository at this point in the history
Merge pull request #604 from MaMpf-HD/dev
  • Loading branch information
Splines authored Mar 23, 2024
2 parents ee2bc9a + 4e734a4 commit a0e26f8
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 110 deletions.
4 changes: 1 addition & 3 deletions app/abilities/answer_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 0 additions & 69 deletions app/assets/javascripts/answers.coffee

This file was deleted.

90 changes: 90 additions & 0 deletions app/assets/javascripts/answers.coffee.erb
Original file line number Diff line number Diff line change
@@ -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}")
);
);
4 changes: 2 additions & 2 deletions app/assets/javascripts/lectures.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ $grid-breakpoints: (
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px,
xxxxl: 1920px,
xxxxxl: 2160px
);

$container-max-widths: (
Expand All @@ -41,9 +38,6 @@ $container-max-widths: (
lg: 992px,
xl: 1200px,
xxl: 1440px,
xxxl: 1600px,
xxxxl: 1920px,
xxxxxl: 2160px
);


Expand Down Expand Up @@ -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;
}
17 changes: 17 additions & 0 deletions app/assets/stylesheets/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 3 additions & 4 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/administration/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<li class="nav-item" id="adminSearch">
<%= 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') %>
</li>
Expand Down
4 changes: 2 additions & 2 deletions app/views/administration/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="row mt-3 pr-2">
<div class="col-12 col-md-8">
<div class="row">
<div class="col-12 col-xxxl-8 mb-2">
<div class="col-12 col-xxl-8 mb-2">
<%= render partial: 'administration/index/my_lectures' %>
</div>
<div class="col-12 col-xxxl-4 mb-2">
<div class="col-12 col-xxl-4 mb-2">
<%= render partial: 'administration/index/my_courses' %>
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions app/views/answers/cancel_edit.js.erb
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 0 additions & 3 deletions app/views/answers/update_answer_box.coffee

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/commontator/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<div class="field">
<%=
form.text_area :body, rows: '7', class: 'form-control commentForm', id: new_record ?
form.text_area :body, rows: '7', class: 'form-control commentForm comment-field', id: new_record ?
comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment-body" :
"commontator-comment-#{comment.parent.id}-reply" :
"commontator-comment-#{comment.id}-edit-body"
Expand Down Expand Up @@ -78,7 +78,7 @@
comment.parent.nil? ? "commontator-thread-#{@commontator_thread.id}-new-comment-body-preview" :
"commontator-comment-#{comment.parent.id}-reply-preview" :
"commontator-comment-#{comment.id}-edit-body-preview" %>'
class="border p-2"
class="border p-2 comment-field"
style="display: none; min-height: 3em;">
<%= commontator_simple_format comment.body %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/commontator/comments/_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<%= stylesheet_link_tag 'comments' %>
<%#
Controllers that use this partial must supply the following variables:
user
nested_comments
%>

<% nested_comments.each do |comment, nested_children| %>
<div id="commontator-comment-<%= comment.id %>" class="comment">
<div id="commontator-comment-<%= comment.id %>" class="comment comment-field">
<%=
render partial: 'commontator/comments/show', formats: [ :html ], locals: {
user: user, comment: comment, nested_children: nested_children
Expand Down
3 changes: 2 additions & 1 deletion app/views/commontator/threads/_show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= stylesheet_link_tag 'comments' %>
<%
# Views that use this partial must supply the following variables:
# user
Expand Down Expand Up @@ -69,7 +70,7 @@

<%= render partial: 'commontator/threads/reply', locals: { thread: thread, user: user } %>

<div id="commontator-thread-<%= thread.id %>-comment-list" class="comment-list">
<div id="commontator-thread-<%= thread.id %>-comment-field">
<%=
render partial: 'commontator/comments/list', locals: {
user: user, nested_comments: nested_comments
Expand Down
2 changes: 1 addition & 1 deletion app/views/commontator/threads/show.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
}
%>

$("#commontator-thread-<%= @commontator_thread.id %>-comment-list").hide().fadeIn();
$("#commontator-thread-<%= @commontator_thread.id %>-comment-field").hide().fadeIn();

<%= javascript_proc %>
Loading

0 comments on commit a0e26f8

Please sign in to comment.