Skip to content

Commit

Permalink
Create new board columns with Turbo Streams
Browse files Browse the repository at this point in the history
  • Loading branch information
maikhel committed Jul 18, 2024
1 parent cc3fede commit 0ab2840
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/board_columns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def create
respond_to do |format|
if @board_column.save
format.html { redirect_to board_url(@board), notice: "BoardColumn was successfully created." }
format.turbo_stream
else
format.html { render :new, status: :unprocessable_entity }
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/board_columns/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<% end %>

<div class="form-group">
<%= form.label :name %>
<%= form.text_field :name, class: 'form-control' %>
<%= form.text_field :name, placeholder: 'Column name', class: 'form-control' %>
</div>

<div class="actions mt-2 text-center">
Expand Down
9 changes: 9 additions & 0 deletions app/views/board_columns/create.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= turbo_stream.remove dom_id(BoardColumn.new) %>

<%= turbo_stream.append dom_id(@board, 'columns') do %>
<%= render 'board_columns/board_column', board_column: @board_column %>
<% end %>

<%= turbo_stream.append dom_id(@board, 'columns') do %>
<%= turbo_frame_tag dom_id(BoardColumn.new) %>
<% end %>
10 changes: 7 additions & 3 deletions app/views/board_columns/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<h1 class="text-primary-dark-500">New Board Column</h1>

<div class="row w-100 justify-content-center mt-3">
<div class="col-6">
<%= render 'form' %>
</div>
<%= turbo_frame_tag dom_id(@board_column) do %>
<div class = 'board-column'>
<div class="border border-primary-grey-200 bg-light p-2">
<%= render 'form' %>
</div>
</div>
<% end %>
</div>
5 changes: 3 additions & 2 deletions app/views/boards/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
<%= @board.name %>
</h1>
<div>
<%= link_to 'New Column', new_board_board_column_path(@board), class: 'btn btn-outline-primary' %>
<%= link_to 'New Column', new_board_board_column_path(@board), data: { turbo_frame: dom_id(BoardColumn.new) }, class: 'btn btn-outline-primary' %>
</div>
</div>
</div>
</div>

<div class="board-container">
<div class="board-scroll p-3" data-controller="sortable" data-sortable-group-value="<%= @board.id %>" data-sortable-url-value="<%= card_path(":id") %>">
<div id= <%= dom_id(@board, 'columns') %> 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 %>
<%= turbo_frame_tag dom_id(BoardColumn.new) %>
</div>
</div>

0 comments on commit 0ab2840

Please sign in to comment.