list.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # User taskbar list actions.
  3. module Taskbar::List
  4. extend ActiveSupport::Concern
  5. class_methods do
  6. def reorder_list(user, order)
  7. order_as_hash = order.each_with_object({}) do |elem, sum|
  8. sum[elem[:id]] = elem[:prio]
  9. end
  10. ActiveRecord::Base.transaction do |transaction|
  11. TaskbarPolicy::Scope
  12. .new(user, Taskbar)
  13. .resolve
  14. .where(id: order_as_hash.keys)
  15. .each do |taskbar|
  16. taskbar.skip_item_trigger = true
  17. taskbar.skip_live_user_trigger = true
  18. taskbar.update! prio: order_as_hash[taskbar.id]
  19. end
  20. transaction.after_commit do
  21. trigger_list_update(user, 'desktop')
  22. end
  23. end
  24. end
  25. def trigger_list_update(user, app)
  26. user_id = Gql::ZammadSchema.id_from_object(user)
  27. Gql::Subscriptions::User::Current::TaskbarItem::ListUpdates.trigger(nil, arguments: { user_id:, app: })
  28. end
  29. end
  30. end