From afb146abb9043e5a9f6fe8ae07ccea5948bf3aa7 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Mon, 19 May 2025 21:33:33 +0800 Subject: [PATCH] fix for backend and added frontend support --- app/controllers/curations_controller.rb | 32 +++++- app/views/admin/curations/_form.html.erb | 105 ++++++++++-------- .../curations/_form_section_post.html.erb | 23 ++-- app/views/curations/show.html.erb | 3 +- modules/curation/show.html.erb | 11 ++ 5 files changed, 116 insertions(+), 58 deletions(-) diff --git a/app/controllers/curations_controller.rb b/app/controllers/curations_controller.rb index 89bea1c..f970b7b 100644 --- a/app/controllers/curations_controller.rb +++ b/app/controllers/curations_controller.rb @@ -686,6 +686,7 @@ class CurationsController < ApplicationController end announcement = CurationPost.where(:uid => uid).first if announcement.nil? return nil if announcement.nil? + return {} if (announcement.category.disable rescue false) @bulletin = announcement url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/curations/#{announcement.id.to_s}/edit" : "" @@ -701,8 +702,34 @@ class CurationsController < ApplicationController return {} end end - - return {} if (announcement.category.disable rescue false) + module_app = ModuleApp.find_by_key("universal_table") + sections = [] + sections = announcement.curation_post_sections.map do |section| + if section.section_type == "universal_table" + entries = section.get_table_entries.map do |entry| + { + "uid" => entry.uid, + "type" => section.section_type, + "url_to_show" => OrbitHelper.cal_url_to_show(module_app, entry), + "text" => entry.column_entries.first.text + } + end + { + "section" => section.title, + "entries" => entries, + "text" => "" + } + elsif section.section_type == "text" + { + "section" => section.title, + "entries" => [], + "uid" => "", + "type" => section.section_type, + "url_to_show" => "", + "text" => section.text.html_safe + } + end + end if !announcement.deadline.nil? && announcement.deadline < Time.now return { @@ -819,6 +846,7 @@ class CurationsController < ApplicationController "tags" => tags, "bulletin_files" => files, "bulletin_links" => links, + "sections" => sections, "data" => { "title" => announcement.title, "subtitle_ann" => subtitle_ann, diff --git a/app/views/admin/curations/_form.html.erb b/app/views/admin/curations/_form.html.erb index 75e02d4..ec93d65 100644 --- a/app/views/admin/curations/_form.html.erb +++ b/app/views/admin/curations/_form.html.erb @@ -758,55 +758,66 @@ } }) <% if defined? UniversalTable %> - var selectedUTable = null; - var select2Options = { - maximumSelectionSize: 10, - minimumResultsForSearch: Infinity, - multiple: true, - minimumInputLength: 2, - placeholder: "<%= t("curation.search_entries") %>", - ajax: { - type: 'get', - url: "", - allowClear: true, - dataType: 'json', - delay: 250, - data: function (term) { - var query = { - q: term - } - return query; + var selectedUTable = null; + var select2Options = { + maximumSelectionSize: 10, + minimumResultsForSearch: Infinity, + multiple: true, + minimumInputLength: 2, + placeholder: "<%= t("curation.search_entries") %>", + ajax: { + type: 'get', + url: "", + allowClear: true, + dataType: 'json', + delay: 250, + data: function (term) { + var query = { + q: term + } + return query; + }, + results: function(data, page) { + return { + results: data + }; + }, + cache: true }, - results: function(data, page) { - return { - results: data - }; - }, - cache: true - }, - formatResult: function(i) { - return '
' + i.text + '
'; - }, // Formats results in drop down - formatSelection: function(i) { - return '
' + i.text + '
'; - }, //Formats result that is selected - escapeMarkup: function(m) { - return m; - } // we do not want to escape markup since we are displaying html in results - } - $(document).on('change', '.section_type_ut select', function(){ - var parent = $(this).parents(".curation_section"); - if($(this).val()){ - selectedUTable = $(this).val(); - parent.find(".section_type_ut_entries").show(); - select2Options.ajax.url = "/admin/universal_tables/get_entries?uid=" + selectedUTable; - parent.find('.section_type_ut_entries input.select2').select2(select2Options); - }else{ - parent.find(".section_type_ut_entries").hide(); - parent.find('.section_type_ut_entries input.select2').select2('destroy'); + formatResult: function(i) { + return '
' + i.text + '
'; + }, // Formats results in drop down + formatSelection: function(i) { + return '
' + i.text + '
'; + }, //Formats result that is selected + escapeMarkup: function(m) { + return m; + } // we do not want to escape markup since we are displaying html in results } - }) - + $(document).on('change', '.section_type_ut select', function(){ + var parent = $(this).parents(".curation_section"); + if($(this).val()){ + selectedUTable = $(this).val(); + parent.find(".section_type_ut_entries").show(); + select2Options.ajax.url = "/admin/universal_tables/get_entries?uid=" + selectedUTable; + parent.find('.section_type_ut_entries input.select2').select2(select2Options); + }else{ + parent.find(".section_type_ut_entries").hide(); + parent.find('.section_type_ut_entries input.select2').select2('destroy'); + } + }) + $('.select2').each(function () { + const data = $(this).data('value'); + if (data) { + $(this).select2({ + data: data, + multiple: true, + width: '100%' + }).val(data.map(i => i.id)).trigger('change'); + } else { + $(this).select2({ multiple: true, width: '100%' }); + } + }); <% end %> $("#enable_sub_annc").click(function(){ diff --git a/app/views/admin/curations/_form_section_post.html.erb b/app/views/admin/curations/_form_section_post.html.erb index 47299f1..e2eb893 100644 --- a/app/views/admin/curations/_form_section_post.html.erb +++ b/app/views/admin/curations/_form_section_post.html.erb @@ -42,7 +42,7 @@ class: 'form-control' %> -