From 4368d24d74d11273009174e089e9ac34d251e01f Mon Sep 17 00:00:00 2001 From: texpert Date: Sun, 12 Nov 2023 22:20:06 +0200 Subject: [PATCH 1/3] Fix JS after conversion from CoffeeScript --- .../camaleon_cms/admin/_posttype.js | 13 ++--- .../camaleon_cms/admin/nav_menu.js | 49 ++++++++----------- spec/features/admin/menus_spec.rb | 42 +++++++++++++++- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/camaleon_cms/admin/_posttype.js b/app/assets/javascripts/camaleon_cms/admin/_posttype.js index 155762f5..bed4175b 100644 --- a/app/assets/javascripts/camaleon_cms/admin/_posttype.js +++ b/app/assets/javascripts/camaleon_cms/admin/_posttype.js @@ -9,18 +9,18 @@ window.cama_init_posttype_form = function() { item.parent().siblings().find('input').prop('disabled', $(this).is(':checked')) if ($(this).is(':checked')) - return item.prop('checked', true).prop('disabled', false) + item.prop('checked', true).prop('disabled', false) else - return item.prop('disabled', true) + item.prop('disabled', true) }).trigger('change') form.find('[name="meta[has_picture]"]').change(function() { const items = form.find('.picture_settings input') if ($(this).is(':checked')) - return items.prop('disabled', false) + items.prop('disabled', false) else - return items.prop('disabled', true) + items.prop('disabled', true) }).trigger('change') // toggle single and multiple categories checkbox @@ -28,9 +28,10 @@ window.cama_init_posttype_form = function() { 'input:checkbox[name="meta[has_category]"], input:checkbox[name="meta[has_single_category]"]' ) - return catChecks.change( + catChecks.change( function() { - if ($(this).is(':checked')) return catChecks.not(this).prop('checked', false) + if ($(this).is(':checked')) + catChecks.not(this).prop('checked', false) } ).filter(':checked').trigger('change') } diff --git a/app/assets/javascripts/camaleon_cms/admin/nav_menu.js b/app/assets/javascripts/camaleon_cms/admin/nav_menu.js index ee8b07b4..7fc5980c 100644 --- a/app/assets/javascripts/camaleon_cms/admin/nav_menu.js +++ b/app/assets/javascripts/camaleon_cms/admin/nav_menu.js @@ -1,9 +1,3 @@ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ - /* eslint-env jquery */ $(function() { const panel = $('#menu_content') @@ -21,11 +15,11 @@ $(function() { return panel.find('#menu_reoreder_loading').show() - return $.post(listPanel.attr('data-reorder_url'), data, function(res) { + $.post(listPanel.attr('data-reorder_url'), data, function(res) { lastData = data panel.find('#menu_reoreder_loading').hide() if (res) - return alert(res) + alert(res) }) }) @@ -33,13 +27,10 @@ $(function() { const saveMenu = function(data) { showLoading() - return $.post( - listPanel.attr('data-url'), - data, - function(res) { - listPanel.children('.dd-list').append($(res).children()) - return hideLoading() - }) + $.post(listPanel.attr('data-url'), data, function(res) { + listPanel.children('.dd-list').append($(res).children()) + hideLoading() + }) } // add menu items (non-external) @@ -48,7 +39,7 @@ $(function() { let flag = false $(this).closest('.panel').find('input:checkbox:checked').each(function() { flag = true - return data.items.push({ id: $(this).val(), kind: $(this).closest('.class_type').attr('data-type') }) + data.items.push({ id: $(this).val(), kind: $(this).closest('.class_type').attr('data-type') }) }).prop('checked', false) if (!flag) @@ -64,7 +55,7 @@ $(function() { let flag = false $(this).closest('.panel').find('input:checkbox:checked').each(function() { flag = true - return data.custom_items.push({ url: $(this).val(), kind: $(this).attr('data-kind'), label: $(this).attr('data-label') }) + data.custom_items.push({ url: $(this).val(), kind: $(this).attr('data-kind'), label: $(this).attr('data-label') }) }).prop('checked', false) if (!flag) @@ -93,10 +84,10 @@ $(function() { title: link.attr('data-original-title') || link.attr('title'), url: link.attr('href'), mode: 'ajax', - callback(modal) { + callback: (modal) => { const form = modal.find('form') init_form_validations(form) - return form.submit(function() { + form.submit(function() { if (!form.valid()) return false @@ -104,7 +95,7 @@ $(function() { $.post(form.attr('action'), form.serialize(), function(res) { link.closest('li').replaceWith($(res).html()) modal.modal('hide') - return hideLoading() + hideLoading() }) return false }) @@ -122,39 +113,39 @@ $(function() { showLoading() $.get(link.attr('href'), function() { link.closest('.dd-item').remove() - return hideLoading() + hideLoading() }) return false }) // new menu panel.find('.new_menu_link, .edit_menu_link').ajax_modal({ - callback(modal) { + callback: (modal) => { const form = modal.find('form') - return setTimeout(() => init_form_validations(form), 1000) + setTimeout(() => init_form_validations(form), 1000) } }) // menus list - change dropdown - panel.find('#menu_items #switch_nav_menuForm select').change(function() { + panel.find('#menu_items #switch_nav_menu_form select').change(function() { if (!$(this).val()) return - return $(this).closest('form').submit() + $(this).closest('form').submit() }) // custom fields - return listPanel.on('click', '.custom_settings_link', function() { + listPanel.on('click', '.custom_settings_link', function() { const link = $(this) open_modal({ title: link.attr('data-original-title') || link.attr('title'), url: link.attr('href'), mode: 'ajax', - callback(modal) { + callback: (modal) => { const form = modal.find('form') init_form_validations(form) - return form.submit(function() { + form.submit(function() { if (!form.valid()) return false @@ -164,7 +155,7 @@ $(function() { alert(res) modal.modal('hide') - return hideLoading() + hideLoading() }) return false }) diff --git a/spec/features/admin/menus_spec.rb b/spec/features/admin/menus_spec.rb index f1bcce84..54c18810 100644 --- a/spec/features/admin/menus_spec.rb +++ b/spec/features/admin/menus_spec.rb @@ -38,7 +38,47 @@ end end - it 'Menus Create and Delete' do + it 'creates and selects menus' do + admin_sign_in + visit "#{cama_root_relative_path}/admin/appearances/nav_menus" + + page.execute_script('jQuery("#switch_nav_menu_form .new_menu_link").click()') + + within '#ow_inline_modal' do + fill_in 'nav_menu_name', with: 'Second menu' + fill_in 'nav_menu_slug', with: 'second-menu' + click_button 'Create Menu' + wait_for_ajax + end + + within '#menu_items' do + select('Second menu', from: 'menu') + + check('Sample Post') + page.execute_script('$("#acc-post input").prop("checked", true)') + page.execute_script('$("#acc-post").prev().find("input").prop("checked", true)') + page.execute_script('$("#acc-post .add_links_to_menu").click()') + wait_for_ajax + + select('Main Menu', from: 'menu') + wait_for_ajax + end + + within '#menus_list' do + find('.dd-item', text: 'Welcome') + end + + within '#menu_items' do + select('Second menu', from: 'menu') + wait_for_ajax + end + + within '#menus_list' do + find('.dd-item', text: 'Uncategorized') + end + end + + it 'deletes menus' do admin_sign_in visit "#{cama_root_relative_path}/admin/appearances/nav_menus" page.execute_script('jQuery("#switch_nav_menu_form .btn-danger").click()') From 5021b1339df96252c1b41172cf73cb03fe042f9d Mon Sep 17 00:00:00 2001 From: texpert Date: Sun, 12 Nov 2023 22:41:13 +0200 Subject: [PATCH 2/3] Fix Rubocop issues --- app/decorators/camaleon_cms/category_decorator.rb | 3 ++- app/decorators/camaleon_cms/post_type_decorator.rb | 3 ++- app/decorators/camaleon_cms/site_decorator.rb | 3 ++- app/validators/camaleon_cms/post_uniq_validator.rb | 7 ++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/decorators/camaleon_cms/category_decorator.rb b/app/decorators/camaleon_cms/category_decorator.rb index fb8e219f..2c44dce6 100644 --- a/app/decorators/camaleon_cms/category_decorator.rb +++ b/app/decorators/camaleon_cms/category_decorator.rb @@ -29,7 +29,8 @@ def the_categories # return a child category from this category with id (integer) or by slug (string) def the_category(slug_or_id) return object.categories.where(id: slug_or_id).first if slug_or_id.is_a?(Integer) - return object.categories.find_by_slug(slug_or_id) if slug_or_id.is_a?(String) + + object.categories.find_by_slug(slug_or_id) if slug_or_id.is_a?(String) end # --------------------- diff --git a/app/decorators/camaleon_cms/post_type_decorator.rb b/app/decorators/camaleon_cms/post_type_decorator.rb index 2419d0bf..77922907 100644 --- a/app/decorators/camaleon_cms/post_type_decorator.rb +++ b/app/decorators/camaleon_cms/post_type_decorator.rb @@ -70,7 +70,8 @@ def the_full_categories # return a category from this post_type with id (integer) or by slug (string) def the_category(slug_or_id) return the_categories.where(id: slug_or_id).first if slug_or_id.is_a?(Integer) - return the_categories.find_by_slug(slug_or_id) if slug_or_id.is_a?(String) + + the_categories.find_by_slug(slug_or_id) if slug_or_id.is_a?(String) end # return all post_tags for the post_type (active_record) filtered by permissions + hidden posts + roles + etc... diff --git a/app/decorators/camaleon_cms/site_decorator.rb b/app/decorators/camaleon_cms/site_decorator.rb index 029963e3..b2ab4639 100644 --- a/app/decorators/camaleon_cms/site_decorator.rb +++ b/app/decorators/camaleon_cms/site_decorator.rb @@ -80,7 +80,8 @@ def the_post(slug_or_id) # slug_or_id: string => return all main categories of the post_type with slug = slug_or_id def the_categories(slug_or_id = nil) return the_post_type(slug_or_id).the_categories if slug_or_id.present? - return object.categories unless slug_or_id.present? + + object.categories unless slug_or_id.present? end # return the category object with id or slug = slug_or_id from this site diff --git a/app/validators/camaleon_cms/post_uniq_validator.rb b/app/validators/camaleon_cms/post_uniq_validator.rb index 9d8857ed..74a284ca 100644 --- a/app/validators/camaleon_cms/post_uniq_validator.rb +++ b/app/validators/camaleon_cms/post_uniq_validator.rb @@ -8,9 +8,10 @@ def validate(record) return unless ptype.present? # only for posts that belongs to a post type model posts = ptype.site.posts - .where("(#{slug_array.map do |s| - "#{CamaleonCms::Post.table_name}.slug LIKE '%-->#{s}#{s}