Skip to content

Commit

Permalink
Update sortable controller for better data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
piowit committed Jul 17, 2024
1 parent c1633b6 commit 5ae06e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
14 changes: 13 additions & 1 deletion app/javascript/controllers/sortable_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ export default class extends Controller {
const newColumnId = to.closest('.board-column').dataset.sortableColumnIdValue;
const url = this.urlValue.replace(":id", id);

const card = {
position: newIndex,
board_column_id: newColumnId,
};

const body = {
_method: 'patch',
authenticity_token: document.querySelector("[name='csrf-token']").content,
card: card,
commit: 'Save'
};

put(url, {
body: JSON.stringify({ position: newIndex, column_id: newColumnId }),
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector("[name='csrf-token']").content
Expand Down
2 changes: 1 addition & 1 deletion app/views/boards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>

<div class="board-container">
<div class="board-scroll p-3" data-controller="sortable" data-sortable-group-value="<%= @board.id %>" data-sortable-url-value="<%= update_card_positions_board_column_path(":id") %>">
<div class="board-scroll p-3" data-controller="sortable" data-sortable-group-value="<%= @board.id %>" data-sortable-url-value="<%= card_path(":id") %>">
<% @board_columns.each do |board_column| %>
<%= render partial: 'board_columns/board_column', locals: { board_column: board_column } %>
<% end %>
Expand Down
6 changes: 1 addition & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
root "boards#index"

resources :boards, shallow: true do
resources :board_columns, except: [ :index, :show ] do
member do
put :update_card_positions

This comment has been minimized.

Copy link
@maikhel

maikhel Jul 17, 2024

Collaborator

@piowit So you can also remove this action from controller

end
end
resources :board_columns, except: [ :index, :show ]
end

resources :cards, except: [ :index ]
Expand Down

0 comments on commit 5ae06e1

Please sign in to comment.