mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Enable syncing all accounts in one click (#948)
* Enable syncing all accounts on one click * Remove argument to sync_later method call * Add partial for sync all accounts button * Redirect back if possible when syncing all accounts
This commit is contained in:
@@ -69,6 +69,22 @@ class AccountsController < ApplicationController
|
||||
redirect_to account_path(@account), notice: t(".success")
|
||||
end
|
||||
|
||||
def sync_all
|
||||
synced_accounts_count = 0
|
||||
Current.family.accounts.each do |account|
|
||||
next unless account.can_sync?
|
||||
|
||||
account.sync_later
|
||||
synced_accounts_count += 1
|
||||
end
|
||||
|
||||
if synced_accounts_count > 0
|
||||
redirect_back_or_to accounts_path, notice: t(".success", count: synced_accounts_count)
|
||||
else
|
||||
redirect_back_or_to accounts_path, alert: t(".no_accounts_to_sync")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
|
||||
@@ -17,5 +17,7 @@
|
||||
<%= lucide_icon("plus", class: "w-5 h-5") %>
|
||||
<p class="text-sm font-medium"><%= t(".new") %></p>
|
||||
<% end %>
|
||||
|
||||
<%= render "sync_all_button" %>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
3
app/views/accounts/_sync_all_button.html.erb
Normal file
3
app/views/accounts/_sync_all_button.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= button_to sync_all_accounts_path, method: :post, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", title: "Sync All" do %>
|
||||
<%= lucide_icon "refresh-cw", class: "w-5 h-5" %>
|
||||
<% end %>
|
||||
@@ -24,6 +24,8 @@
|
||||
<%= lucide_icon("plus", class: "w-5 h-5") %>
|
||||
<p class="text-sm font-medium"><%= t(".new_account") %></p>
|
||||
<% end %>
|
||||
|
||||
<%= render "sync_all_button" %>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user