From 402efb2e90633ee15fc97a58443f441a6273e205 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 3 Dec 2021 22:53:47 +0000 Subject: [PATCH] add merge button --- app/controllers/models_controller.rb | 9 +++++++++ app/views/models/show.html.erb | 1 + config/routes.rb | 3 +++ 3 files changed, 13 insertions(+) diff --git a/app/controllers/models_controller.rb b/app/controllers/models_controller.rb index 86196cdd6..cbf5233cc 100644 --- a/app/controllers/models_controller.rb +++ b/app/controllers/models_controller.rb @@ -16,6 +16,15 @@ def update redirect_to [@library, @model] end + def merge + if (@parent = @model.parent) + @model.merge_into_parent! + redirect_to [@library, @parent] + else + render status: :bad_request + end + end + def bulk_edit @creators = Creator.all @models = @library.models diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb index 981b67469..1261881a0 100644 --- a/app/views/models/show.html.erb +++ b/app/views/models/show.html.erb @@ -33,6 +33,7 @@ <%= card :secondary, "Actions" do %> <%= link_to "Edit Details", edit_library_model_path(@library, @model), class: "btn btn-primary" %> + <%= link_to "Merge Into Parent", merge_library_model_path(@library, @model), class: "btn btn-danger", method: :post if @model.parent %> <% end %> <%= render 'tags_card', tags: @model.tags, selected: nil %> diff --git a/config/routes.rb b/config/routes.rb index e3e27abf2..e4ad42c6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,9 @@ post "/", controller: :search, action: :index resources :libraries do resources :models, except: [:index, :destroy] do + member do + post "merge" + end collection do get "edit", action: "bulk_edit" patch "update", action: "bulk_update"