From a94d0ceec66e90818b3d8aa713c85d693ba5d7c3 Mon Sep 17 00:00:00 2001 From: karol Date: Wed, 26 Feb 2025 00:01:54 +0100 Subject: [PATCH 1/3] Add functionality to deselect radio buttons for usage_by_lms --- app/assets/javascripts/tasks_form.coffee | 20 ++++++++++++++++++++ app/models/task_file.rb | 2 ++ app/views/tasks/_file_config.html.slim | 1 + 3 files changed, 23 insertions(+) diff --git a/app/assets/javascripts/tasks_form.coffee b/app/assets/javascripts/tasks_form.coffee index 8713dcac9..a41bfd3ef 100644 --- a/app/assets/javascripts/tasks_form.coffee +++ b/app/assets/javascripts/tasks_form.coffee @@ -1,6 +1,7 @@ ready = -> initializeFileTypeSelection() initializeVisibilityWarning() + initializeRadioButtonDeselection() initializeLoadSelect2 = -> $('#task_programming_language_id').select2 @@ -32,6 +33,25 @@ initializeVisibilityWarning = -> $('#task_access_level_public').on 'change', -> warning_message.addClass('d-none') +initializeRadioButtonDeselection = -> + radios = $('.radio-switch input[type="radio"][name*="[usage_by_lms]"]') + hidden_field = $('input[name="file[usage_by_lms]"][type="hidden"]') + + radios.each -> + $radio = $(this) + $radio.data('was-checked', $radio.prop('checked')) + + radios.on 'click', -> + $radio = $(this) + + if $radio.prop('checked') and $radio.data('was-checked') + $radio.prop('checked', false).data('was-checked', false) + hidden_field.val(null) # Reset the value to `nil` + else + radios.data('was-checked', false) # Reset all other radios + $radio.data('was-checked', true) + hidden_field.val('') # Clear hidden field since something is selected + destroy_select2 = -> $('#task_programming_language_id').select2('destroy'); $('.my-group').select2('destroy'); diff --git a/app/models/task_file.rb b/app/models/task_file.rb index 1c0b87d85..98c74213c 100644 --- a/app/models/task_file.rb +++ b/app/models/task_file.rb @@ -17,6 +17,8 @@ class TaskFile < ApplicationRecord validate :parent_validation_check attr_accessor :use_attached_file, :file_marked_for_deletion, :parent_blob_id + normalizes :usage_by_lms, with: ->(usage_by_lms) { usage_by_lms.presence } + before_validation :attach_parent_blob, if: -> { attachment.blank? && task&.contribution? && parent.present? && parent_blob_id.present? } before_save :remove_attachment diff --git a/app/views/tasks/_file_config.html.slim b/app/views/tasks/_file_config.html.slim index 867d2e6cb..4828ad3bc 100644 --- a/app/views/tasks/_file_config.html.slim +++ b/app/views/tasks/_file_config.html.slim @@ -31,6 +31,7 @@ .form-control.placeholder = file.label :usage_by_lms, TaskFile.human_attribute_name('usage_by_lms'), class: 'form-label w-auto me-2' .radio-switch + = file.hidden_field :usage_by_lms, value: nil, class: 'fallback' = file.radio_button :usage_by_lms, 'edit', value: 'edit' = file.label :usage_by_lms_edit, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.edit'), class: 'radio-left small-radio radio-third' do span.fa-stack From 850288fab500605fd05a8c6b496545c48e7031b5 Mon Sep 17 00:00:00 2001 From: karol Date: Tue, 8 Jul 2025 22:33:08 +0200 Subject: [PATCH 2/3] Add additional radio buttons for usage_by_lms: none --- app/assets/javascripts/tasks_form.coffee | 20 ------------------- .../stylesheets/buttons-and-controls.css.scss | 4 ++++ app/views/tasks/_file_config.html.slim | 5 ++++- config/locales/de/views/tasks.yml | 2 ++ config/locales/en/views/tasks.yml | 2 ++ 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/tasks_form.coffee b/app/assets/javascripts/tasks_form.coffee index a41bfd3ef..8713dcac9 100644 --- a/app/assets/javascripts/tasks_form.coffee +++ b/app/assets/javascripts/tasks_form.coffee @@ -1,7 +1,6 @@ ready = -> initializeFileTypeSelection() initializeVisibilityWarning() - initializeRadioButtonDeselection() initializeLoadSelect2 = -> $('#task_programming_language_id').select2 @@ -33,25 +32,6 @@ initializeVisibilityWarning = -> $('#task_access_level_public').on 'change', -> warning_message.addClass('d-none') -initializeRadioButtonDeselection = -> - radios = $('.radio-switch input[type="radio"][name*="[usage_by_lms]"]') - hidden_field = $('input[name="file[usage_by_lms]"][type="hidden"]') - - radios.each -> - $radio = $(this) - $radio.data('was-checked', $radio.prop('checked')) - - radios.on 'click', -> - $radio = $(this) - - if $radio.prop('checked') and $radio.data('was-checked') - $radio.prop('checked', false).data('was-checked', false) - hidden_field.val(null) # Reset the value to `nil` - else - radios.data('was-checked', false) # Reset all other radios - $radio.data('was-checked', true) - hidden_field.val('') # Clear hidden field since something is selected - destroy_select2 = -> $('#task_programming_language_id').select2('destroy'); $('.my-group').select2('destroy'); diff --git a/app/assets/stylesheets/buttons-and-controls.css.scss b/app/assets/stylesheets/buttons-and-controls.css.scss index 9cc4eb906..31d1f36ad 100644 --- a/app/assets/stylesheets/buttons-and-controls.css.scss +++ b/app/assets/stylesheets/buttons-and-controls.css.scss @@ -14,6 +14,10 @@ width: 33%; } +.radio-quarter { + width: 25%; +} + .radio-base { border: #cccccc 1px solid; padding: 5px; diff --git a/app/views/tasks/_file_config.html.slim b/app/views/tasks/_file_config.html.slim index 4828ad3bc..2a48fbf7e 100644 --- a/app/views/tasks/_file_config.html.slim +++ b/app/views/tasks/_file_config.html.slim @@ -31,7 +31,6 @@ .form-control.placeholder = file.label :usage_by_lms, TaskFile.human_attribute_name('usage_by_lms'), class: 'form-label w-auto me-2' .radio-switch - = file.hidden_field :usage_by_lms, value: nil, class: 'fallback' = file.radio_button :usage_by_lms, 'edit', value: 'edit' = file.label :usage_by_lms_edit, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.edit'), class: 'radio-left small-radio radio-third' do span.fa-stack @@ -44,3 +43,7 @@ = file.label :usage_by_lms_download, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.download'), class: 'radio-right small-radio radio-third' do span.fa-stack i.fa-solid.fa-download.fa-stack-1x.fa-2x + = file.radio_button :usage_by_lms, '' + = file.label :usage_by_lms_, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.no_value'), class: 'radio-right small-radio radio-quarter' do + span.fa-stack + i.fa-solid.fa-ban.fa-stack-1x.fa-2x diff --git a/config/locales/de/views/tasks.yml b/config/locales/de/views/tasks.yml index cb886c0e3..eb8132aea 100644 --- a/config/locales/de/views/tasks.yml +++ b/config/locales/de/views/tasks.yml @@ -25,6 +25,8 @@ de: delayed: Verzögert display: Anzeigen download: Herunterladen + edit: Bearbeiten + no_value: Kein Wert form: button: add_model_solution: Musterlösung hinzufügen diff --git a/config/locales/en/views/tasks.yml b/config/locales/en/views/tasks.yml index db6e57367..c77743642 100644 --- a/config/locales/en/views/tasks.yml +++ b/config/locales/en/views/tasks.yml @@ -25,6 +25,8 @@ en: delayed: delayed display: display download: download + edit: edit + no_value: no value form: button: add_model_solution: Add Model Solution From 996ccb33ad88d7c02c9be1c870b4d46ad7b9b463 Mon Sep 17 00:00:00 2001 From: karol Date: Tue, 8 Jul 2025 22:33:28 +0200 Subject: [PATCH 3/3] fix tooltips --- app/assets/javascripts/tasks_form.coffee | 5 +++++ app/views/account_links/_form.html.slim | 8 ++++---- app/views/tasks/_file_config.html.slim | 18 +++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/tasks_form.coffee b/app/assets/javascripts/tasks_form.coffee index 8713dcac9..b702a7230 100644 --- a/app/assets/javascripts/tasks_form.coffee +++ b/app/assets/javascripts/tasks_form.coffee @@ -1,6 +1,7 @@ ready = -> initializeFileTypeSelection() initializeVisibilityWarning() + initializeNewFileTooltips() initializeLoadSelect2 = -> $('#task_programming_language_id').select2 @@ -32,6 +33,10 @@ initializeVisibilityWarning = -> $('#task_access_level_public').on 'change', -> warning_message.addClass('d-none') +initializeNewFileTooltips = -> + $(document).on "fields_added.nested_form_fields", (event, param) -> + $('[data-bs-toggle="tooltip"]').tooltip(); + destroy_select2 = -> $('#task_programming_language_id').select2('destroy'); $('.my-group').select2('destroy'); diff --git a/app/views/account_links/_form.html.slim b/app/views/account_links/_form.html.slim index 6658f60c6..58fe9c7e5 100644 --- a/app/views/account_links/_form.html.slim +++ b/app/views/account_links/_form.html.slim @@ -3,17 +3,17 @@ = render('shared/form_errors', object: @account_link) .field-element.form-group = f.label :name, AccountLink.human_attribute_name('name'), class: 'form-label' - = f.text_field :name, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.info.name'), class: 'form-control' + = f.text_field :name, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.info.name'), class: 'form-control' .field-element.form-group = f.label :push_url, AccountLink.human_attribute_name('push_url'), class: 'form-label' - = f.text_field :push_url, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.info.push_url'), class: 'form-control' + = f.text_field :push_url, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.info.push_url'), class: 'form-control' .field-element.form-group = f.label :check_uuid_url, AccountLink.human_attribute_name('check_uuid_url'), class: 'form-label' - = f.text_field :check_uuid_url, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.info.check_uuid_url'), class: 'form-control' + = f.text_field :check_uuid_url, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.info.check_uuid_url'), class: 'form-control' .field-element.form-group = f.label :api_key, AccountLink.human_attribute_name('api_key'), class: 'form-label' .input-group - = f.text_field :api_key, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.info.token'), class: 'form-control' + = f.text_field :api_key, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.info.token'), class: 'form-control' = button_tag t('.button.generate'), type: 'button', class: 'generate-api-key-token btn btn-light' .field-element.form-group = f.label :proforma_version, AccountLink.human_attribute_name('proforma_version'), class: 'form-label' diff --git a/app/views/tasks/_file_config.html.slim b/app/views/tasks/_file_config.html.slim index 2a48fbf7e..4499852eb 100644 --- a/app/views/tasks/_file_config.html.slim +++ b/app/views/tasks/_file_config.html.slim @@ -4,11 +4,11 @@ = file.label :used_by_grader, TaskFile.human_attribute_name('used_by_grader'), class: 'form-label w-auto me-2' .radio-switch = file.radio_button :used_by_grader, true, value: true, checked: true - = file.label :used_by_grader_true, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.yes'), class: 'radio-left small-radio radio-half' do + = file.label :used_by_grader_true, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('common.button.yes'), class: 'radio-left small-radio radio-half' do span.fa-stack i.fa-solid.fa-check.fa-stack-1x.fa-2x = file.radio_button :used_by_grader, false, value: false - = file.label :used_by_grader_false, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.no'), class: 'radio-right small-radio radio-half' do + = file.label :used_by_grader_false, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('common.button.no'), class: 'radio-right small-radio radio-half' do span.fa-stack i.fa-solid.fa-xmark.fa-stack-1x.fa-2x @@ -16,15 +16,15 @@ = file.label :used_by_grader, TaskFile.human_attribute_name('visible'), class: 'form-label w-auto me-2' .radio-switch = file.radio_button :visible, 'yes', value: 'yes', checked: true - = file.label :visible_yes, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.yes'), class: 'radio-left small-radio radio-third' do + = file.label :visible_yes, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('common.button.yes'), class: 'radio-left small-radio radio-third' do span.fa-stack i.fa-regular.fa-eye.fa-stack-1x.fa-2x = file.radio_button :visible, 'no', value: 'no' - = file.label :visible_no, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.no'), class: 'radio-right radio-left small-radio radio-third' do + = file.label :visible_no, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('common.button.no'), class: 'radio-right radio-left small-radio radio-third' do span.fa-stack i.fa-regular.fa-eye-slash.fa-stack-1x.fa-2x = file.radio_button :visible, 'delayed', value: 'delayed' - = file.label :visible_delayed, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.delayed'), class: 'radio-right small-radio radio-third' do + = file.label :visible_delayed, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.delayed'), class: 'radio-right small-radio radio-third' do span.fa-stack i.fa-regular.fa-clock.fa-stack-1x.fa-2x @@ -32,18 +32,18 @@ = file.label :usage_by_lms, TaskFile.human_attribute_name('usage_by_lms'), class: 'form-label w-auto me-2' .radio-switch = file.radio_button :usage_by_lms, 'edit', value: 'edit' - = file.label :usage_by_lms_edit, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('common.button.edit'), class: 'radio-left small-radio radio-third' do + = file.label :usage_by_lms_edit, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.edit'), class: 'radio-left small-radio radio-quarter' do span.fa-stack i.fa-solid.fa-pencil.fa-stack-1x.fa-2x = file.radio_button :usage_by_lms, 'display', value: 'display' - = file.label :usage_by_lms_display, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.display'), class: 'radio-right radio-left small-radio radio-third' do + = file.label :usage_by_lms_display, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.display'), class: 'radio-right radio-left small-radio radio-quarter' do span.fa-stack i.fa-regular.fa-eye.fa-stack-1x.fa-2x = file.radio_button :usage_by_lms, 'download', value: 'download' - = file.label :usage_by_lms_download, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.download'), class: 'radio-right small-radio radio-third' do + = file.label :usage_by_lms_download, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.download'), class: 'radio-right radio-left small-radio radio-quarter' do span.fa-stack i.fa-solid.fa-download.fa-stack-1x.fa-2x = file.radio_button :usage_by_lms, '' - = file.label :usage_by_lms_, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.no_value'), class: 'radio-right small-radio radio-quarter' do + = file.label :usage_by_lms_, data: {'bs-toggle': 'tooltip', placement: 'bottom'}, title: t('.no_value'), class: 'radio-right small-radio radio-quarter' do span.fa-stack i.fa-solid.fa-ban.fa-stack-1x.fa-2x