diff --git a/app/assets/stylesheets/terminals.css b/app/assets/stylesheets/terminals.css index cd310c2c1..69a66da23 100644 --- a/app/assets/stylesheets/terminals.css +++ b/app/assets/stylesheets/terminals.css @@ -49,7 +49,6 @@ .terminal__menu { display: none; list-style: none; - transition: display 1000ms allow-discrete; .terminal--open & { display: flex; diff --git a/app/controllers/commands/undos_controller.rb b/app/controllers/commands/undos_controller.rb new file mode 100644 index 000000000..4e1ce5e40 --- /dev/null +++ b/app/controllers/commands/undos_controller.rb @@ -0,0 +1,14 @@ +class Commands::UndosController < ApplicationController + before_action :set_command + + def create + @command.undo + @command.destroy + redirect_back_or_to root_path + end + + private + def set_command + @command = Current.user.commands.find(params[:command_id]) + end +end diff --git a/app/javascript/controllers/toggle_class_controller.js b/app/javascript/controllers/toggle_class_controller.js index ca29ad771..e582fa8a9 100644 --- a/app/javascript/controllers/toggle_class_controller.js +++ b/app/javascript/controllers/toggle_class_controller.js @@ -12,6 +12,7 @@ export default class extends Controller { } remove() { + console.debug("CALLED!"); this.element.classList.remove(this.toggleClass) } } diff --git a/app/models/command.rb b/app/models/command.rb index 34d88ac27..c7d228540 100644 --- a/app/models/command.rb +++ b/app/models/command.rb @@ -13,7 +13,7 @@ class Command < ApplicationRecord def undo end - def can_undo? + def undoable? false end diff --git a/app/models/command/assign.rb b/app/models/command/assign.rb index 6620bef72..6934ba396 100644 --- a/app/models/command/assign.rb +++ b/app/models/command/assign.rb @@ -1,22 +1,8 @@ class Command::Assign < Command - store_accessor :data, :card_ids, :assignee_ids + store_accessor :data, :card_ids, :assignee_ids, :toggled_assignees_by_card validates_presence_of :card_ids, :assignee_ids - def execute - transaction do - cards.each do |card| - assignees.each do |assignee| - card.toggle_assignment(assignee) unless card.assigned_to?(assignee) - end - end - end - end - - def undo - raise "pending" - end - def title card_description = if cards.one? "card '#{cards.first.title}'" @@ -29,6 +15,41 @@ class Command::Assign < Command "Assign #{assignee_description} to #{card_description}" end + def execute + toggled_assignees_by_card = {} + + transaction do + cards.each do |card| + toggled_assignees_by_card[card.id] = [] + assignees.each do |assignee| + unless card.assigned_to?(assignee) + toggled_assignees_by_card[card.id] << assignee.id + card.toggle_assignment(assignee) + end + end + end + + update! toggled_assignees_by_card: toggled_assignees_by_card + end + end + + def undo + toggled_assignees_by_card.each do |card_id, assignee_ids| + card = user.accessible_cards.find_by_id(card_id) + assignees = User.where(id: assignee_ids) + + if card && assignees.any? + assignees.each do |assignee| + card.toggle_assignment(assignee) if card.assigned_to?(assignee) + end + end + end + end + + def undoable? + true + end + private def assignees User.where(id: assignee_ids) diff --git a/app/models/command/go_to_card.rb b/app/models/command/go_to_card.rb index ff13b9ce6..608a6049b 100644 --- a/app/models/command/go_to_card.rb +++ b/app/models/command/go_to_card.rb @@ -1,14 +1,14 @@ class Command::GoToCard < Command store_accessor :data, :card_id - def execute - redirect_to card - end - def title "Visit card '#{card.title}'" end + def execute + redirect_to card + end + private def card user.accessible_cards.find(card_id) diff --git a/app/models/command/go_to_user.rb b/app/models/command/go_to_user.rb index 559845215..763a3f351 100644 --- a/app/models/command/go_to_user.rb +++ b/app/models/command/go_to_user.rb @@ -3,14 +3,14 @@ class Command::GoToUser < Command validates_presence_of :user_id - def execute - redirect_to user - end - def title "View profile of '#{user.name}'" end + def execute + redirect_to user + end + private def user User.find(user_id) diff --git a/app/models/command/search.rb b/app/models/command/search.rb index 84a7a0a0c..4de60b3e1 100644 --- a/app/models/command/search.rb +++ b/app/models/command/search.rb @@ -1,11 +1,11 @@ class Command::Search < Command store_accessor :data, :query - def execute - redirect_to cards_path("terms[]": query.presence) - end - def title "Search '#{query}'" end + + def execute + redirect_to cards_path("terms[]": query.presence) + end end diff --git a/app/views/commands/_command.html.erb b/app/views/commands/_command.html.erb index 667e248a5..2444ff423 100644 --- a/app/views/commands/_command.html.erb +++ b/app/views/commands/_command.html.erb @@ -1,3 +1,7 @@ -
  • +
  • <%= command.title %> + + <% if command.undoable? %> + <%= button_to "Undo", command_undo_path(command), class: "btn btn--remove", data: { confirm: "Are you sure you want to undo '#{command.title}'?", turbo_frame: "_top" } %> + <% end %>
  • diff --git a/app/views/commands/_terminal.html.erb b/app/views/commands/_terminal.html.erb index 3a78a4d8b..eefdf6bc3 100644 --- a/app/views/commands/_terminal.html.erb +++ b/app/views/commands/_terminal.html.erb @@ -1,7 +1,7 @@ <%= tag.div class: "terminal full-width flex flex-column gap justify-end", data: { controller: "toggle-class commands", toggle_class_toggle_class: "terminal--open" } do %> - <%= turbo_frame_tag :recent_commands, src: commands_path %> + <%= turbo_frame_tag :recent_commands, src: commands_path, refresh: "morph" %> <%= form_tag commands_path, class: "flex align-center gap-half", diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index f3bde31a2..995eea4dc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -47,7 +47,7 @@ <%= yield :footer %> <% if Current.user && !@hide_footer_frames %> -