1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02: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:
Tony Vincent 2024-07-05 13:36:18 +02:00 committed by GitHub
parent 48092cb704
commit cc6bf6e961
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 33 additions and 0 deletions

View file

@ -69,6 +69,22 @@ class AccountsController < ApplicationController
redirect_to account_path(@account), notice: t(".success") redirect_to account_path(@account), notice: t(".success")
end 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 private
def set_account def set_account

View file

@ -17,5 +17,7 @@
<%= lucide_icon("plus", class: "w-5 h-5") %> <%= lucide_icon("plus", class: "w-5 h-5") %>
<p class="text-sm font-medium"><%= t(".new") %></p> <p class="text-sm font-medium"><%= t(".new") %></p>
<% end %> <% end %>
<%= render "sync_all_button" %>
</div> </div>
</header> </header>

View 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 %>

View file

@ -24,6 +24,8 @@
<%= lucide_icon("plus", class: "w-5 h-5") %> <%= lucide_icon("plus", class: "w-5 h-5") %>
<p class="text-sm font-medium"><%= t(".new_account") %></p> <p class="text-sm font-medium"><%= t(".new_account") %></p>
<% end %> <% end %>
<%= render "sync_all_button" %>
</div> </div>
</div> </div>
</header> </header>

View file

@ -65,5 +65,8 @@ en:
new: New account new: New account
sync: sync:
success: Account sync started success: Account sync started
sync_all:
no_accounts_to_sync: No accounts were eligible for syncing.
success: Successfully queued %{count} accounts for syncing.
update: update:
success: Account updated success: Account updated

View file

@ -63,6 +63,7 @@ Rails.application.routes.draw do
collection do collection do
get :summary get :summary
get :list get :list
post :sync_all
end end
member do member do

View file

@ -30,6 +30,12 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to account_url(@account) assert_redirected_to account_url(@account)
end end
test "can sync all accounts" do
post sync_all_accounts_path
assert_redirected_to accounts_url
assert_equal "Successfully queued #{ @user.family.accounts.size } accounts for syncing.", flash[:notice]
end
test "should update account" do test "should update account" do
patch account_url(@account), params: { patch account_url(@account), params: {
account: { account: {