diff --git a/app/assets/javascripts/admin/plugins/treeview.js b/app/assets/javascripts/admin/plugins/treeview.js index f0be31424445e933c5970b0c2cdc015c942acd78..708e7f3e74a217bdb9793bb83f2ed0ec52968571 100644 --- a/app/assets/javascripts/admin/plugins/treeview.js +++ b/app/assets/javascripts/admin/plugins/treeview.js @@ -21,7 +21,8 @@ window.osuny.treeView = { fallbackOnBody: true, swapThreshold: 0.65, onEnd: function (evt) { - var from = evt.from, + var item = evt.item, + from = evt.from, to = evt.to, ids = [], parentId, @@ -47,8 +48,10 @@ window.osuny.treeView = { // call to application $.post(url, { + oldParentId: from.dataset.id, parentId: parentId, - ids: ids + ids: ids, + itemId: item.dataset.id }); } }); diff --git a/app/controllers/admin/communication/websites/categories_controller.rb b/app/controllers/admin/communication/websites/categories_controller.rb index 175cf6cfffdf9a5ea2fb367eb19206e002863122..aa82e97e7e7300ab2bbdf0800dd6de0e15db758c 100644 --- a/app/controllers/admin/communication/websites/categories_controller.rb +++ b/app/controllers/admin/communication/websites/categories_controller.rb @@ -12,22 +12,20 @@ class Admin::Communication::Websites::CategoriesController < Admin::Communicatio def reorder parent_id = params[:parentId].blank? ? nil : params[:parentId] + old_parent_id = params[:oldParentId].blank? ? nil : params[:oldParentId] ids = params[:ids] || [] - first_category = nil ids.each.with_index do |id, index| category = @website.categories.find(id) - first_category = category if index == 0 category.update( parent_id: parent_id, position: index + 1 ) end - if parent_id - parent = @website.categories.find(parent_id) - parent.sync_with_git - else - first_category&.sync_with_git # Will sync siblings + if old_parent_id + old_parent = @website.categories.find(old_parent_id) + old_parent.sync_with_git end + @website.categories.find(params[:itemId]).sync_with_git # Will sync siblings end def children diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index 887f3e1ae8ab2d6219bc6d1e0998bca1923a023b..aa248025be383f943e9bd4ab5120636a48c9cb9c 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -13,6 +13,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We def reorder parent_page = @website.pages.find(params[:parentId]) + old_parent_page = @website.pages.find(params[:oldParentId]) ids = params[:ids] || [] ids.each.with_index do |id, index| page = @website.pages.find(id) @@ -21,6 +22,7 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We position: index + 1 ) end + old_parent_page.sync_with_git parent_page.sync_with_git end diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index 9a24a588efd2597671eb6af488eba4ee0642c8b8..77f2f23b71fba57f818b635ea7e878889aa963af 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -23,23 +23,24 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro def reorder parent_id = params[:parentId].blank? ? nil : params[:parentId] + old_parent_id = params[:oldParentId].blank? ? nil : params[:oldParentId] ids = params[:ids] || [] ids.each.with_index do |id, index| - @program = current_university.education_programs.find(id) - @program.update( + program = current_university.education_programs.find(id) + program.update( parent_id: parent_id, position: index + 1, skip_websites_categories_callback: true ) end - if parent_id - parent = current_university.education_programs.find(parent_id) - parent.set_websites_categories - parent.sync_with_git - else - @program&.set_websites_categories - @program&.sync_with_git + if old_parent_id + old_parent = current_university.education_programs.find(old_parent_id) + old_parent.set_websites_categories + old_parent.sync_with_git end + program = current_university.education_programs.find(params[:itemId]) + program.set_websites_categories + program.sync_with_git end def children diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 2658bb7db55f7c209366e7cb7c5edfe23c41abb3..2291e765315a9f16191e108bd8cf3a6939722bb6 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -96,7 +96,7 @@ class Communication::Website::Category < ApplicationRecord end def git_dependencies(website) - [self] + siblings + descendants + active_storage_blobs + posts + website.menus + [self] + parent + siblings + descendants + active_storage_blobs + posts + website.menus end def git_destroy_dependencies(website) diff --git a/db/schema.rb b/db/schema.rb index 2d9fa7c66d988518c61ea961863f4bb96ea96ab0..bd7fe33c83ab8752965d9d8e71f67a0fdc583ea6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -811,12 +811,12 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_13_083544) do t.string "zipcode" t.string "city" t.string "country" - t.string "hal_person_identifier" - t.string "hal_doc_identifier" - t.string "hal_form_identifier" t.string "mastodon" t.uuid "language_id", null: false t.uuid "original_id" + t.string "hal_person_identifier" + t.string "hal_doc_identifier" + t.string "hal_form_identifier" t.index ["language_id"], name: "index_university_people_on_language_id" t.index ["original_id"], name: "index_university_people_on_original_id" t.index ["university_id"], name: "index_university_people_on_university_id"