Fix account list and remove sanctum

This commit is contained in:
James Cole
2025-05-08 20:22:01 +02:00
parent ee96dd3ab6
commit 07ff2305fd
9 changed files with 73 additions and 44 deletions

View File

@@ -296,13 +296,6 @@ STATIC_CRON_TOKEN=
# However if you know what you're doing you can significantly speed up container start times. # However if you know what you're doing you can significantly speed up container start times.
# Set each value to true to enable, or false to disable. # Set each value to true to enable, or false to disable.
# Set this to true to build all locales supported by Firefly III.
# This may take quite some time (several minutes) and is generally not recommended.
# If you wish to change or alter the list of locales, start your Docker container with
# `docker run -v locale.gen:/etc/locale.gen -e DKR_BUILD_LOCALE=true`
# and make sure your preferred locales are in your own locale.gen.
DKR_BUILD_LOCALE=false
# Check if the SQLite database exists. Can be skipped if you're not using SQLite. # Check if the SQLite database exists. Can be skipped if you're not using SQLite.
# Won't significantly speed up things. # Won't significantly speed up things.
DKR_CHECK_SQLITE=true DKR_CHECK_SQLITE=true

View File

@@ -177,7 +177,7 @@ class Kernel extends HttpKernel
// full API authentication // full API authentication
'api' => [ 'api' => [
AcceptHeaders::class, AcceptHeaders::class,
EnsureFrontendRequestsAreStateful::class, // EnsureFrontendRequestsAreStateful::class,
'auth:api,sanctum', 'auth:api,sanctum',
'bindings', 'bindings',
], ],

View File

@@ -50,7 +50,7 @@ class AccountEnrichment implements EnrichmentInterface
private array $accountIds; private array $accountIds;
private array $accountTypeIds; private array $accountTypeIds;
private array $accountTypes; private array $accountTypes;
private Collection $collection; private Collection $collection;
private array $currencies; private array $currencies;
private array $locations; private array $locations;
private array $meta; private array $meta;
@@ -59,6 +59,7 @@ class AccountEnrichment implements EnrichmentInterface
private array $openingBalances; private array $openingBalances;
private User $user; private User $user;
private UserGroup $userGroup; private UserGroup $userGroup;
private array $lastActivities;
public function __construct() public function __construct()
{ {
@@ -69,6 +70,7 @@ class AccountEnrichment implements EnrichmentInterface
$this->accountTypes = []; $this->accountTypes = [];
$this->meta = []; $this->meta = [];
$this->notes = []; $this->notes = [];
$this->lastActivities = [];
$this->locations = []; $this->locations = [];
// $this->repository = app(AccountRepositoryInterface::class); // $this->repository = app(AccountRepositoryInterface::class);
// $this->currencyRepository = app(CurrencyRepositoryInterface::class); // $this->currencyRepository = app(CurrencyRepositoryInterface::class);
@@ -77,7 +79,7 @@ class AccountEnrichment implements EnrichmentInterface
} }
#[\Override] #[\Override]
public function enrichSingle(array|Model $model): Account|array public function enrichSingle(array | Model $model): Account | array
{ {
Log::debug(__METHOD__); Log::debug(__METHOD__);
$collection = new Collection([$model]); $collection = new Collection([$model]);
@@ -100,6 +102,7 @@ class AccountEnrichment implements EnrichmentInterface
$this->getAccountTypes(); $this->getAccountTypes();
$this->collectMetaData(); $this->collectMetaData();
$this->collectNotes(); $this->collectNotes();
$this->collectLastActivities();
$this->collectLocations(); $this->collectLocations();
$this->collectOpeningBalances(); $this->collectOpeningBalances();
$this->appendCollectedData(); $this->appendCollectedData();
@@ -130,10 +133,9 @@ class AccountEnrichment implements EnrichmentInterface
private function collectMetaData(): void private function collectMetaData(): void
{ {
$set = AccountMeta::whereIn('name', ['is_multi_currency', 'include_net_worth', 'currency_id', 'account_role', 'account_number', 'BIC', 'liability_direction', 'interest', 'interest_period', 'current_debt']) $set = AccountMeta::whereIn('name', ['is_multi_currency', 'include_net_worth', 'currency_id', 'account_role', 'account_number', 'BIC', 'liability_direction', 'interest', 'interest_period', 'current_debt'])
->whereIn('account_id', $this->accountIds) ->whereIn('account_id', $this->accountIds)
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray() ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray();
;
/** @var array $entry */ /** @var array $entry */
foreach ($set as $entry) { foreach ($set as $entry) {
@@ -142,7 +144,7 @@ class AccountEnrichment implements EnrichmentInterface
$this->currencies[(int) $entry['data']] = true; $this->currencies[(int) $entry['data']] = true;
} }
} }
$currencies = TransactionCurrency::whereIn('id', array_keys($this->currencies))->get(); $currencies = TransactionCurrency::whereIn('id', array_keys($this->currencies))->get();
foreach ($currencies as $currency) { foreach ($currencies as $currency) {
$this->currencies[(int) $currency->id] = $currency; $this->currencies[(int) $currency->id] = $currency;
} }
@@ -157,10 +159,9 @@ class AccountEnrichment implements EnrichmentInterface
private function collectNotes(): void private function collectNotes(): void
{ {
$notes = Note::query()->whereIn('noteable_id', $this->accountIds) $notes = Note::query()->whereIn('noteable_id', $this->accountIds)
->whereNotNull('notes.text') ->whereNotNull('notes.text')
->where('notes.text', '!=', '') ->where('notes.text', '!=', '')
->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray() ->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray();
;
foreach ($notes as $note) { foreach ($notes as $note) {
$this->notes[(int) $note['noteable_id']] = (string) $note['text']; $this->notes[(int) $note['noteable_id']] = (string) $note['text'];
} }
@@ -170,15 +171,14 @@ class AccountEnrichment implements EnrichmentInterface
private function collectLocations(): void private function collectLocations(): void
{ {
$locations = Location::query()->whereIn('locatable_id', $this->accountIds) $locations = Location::query()->whereIn('locatable_id', $this->accountIds)
->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray() ->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray();
;
foreach ($locations as $location) { foreach ($locations as $location) {
$this->locations[(int) $location['locatable_id']] $this->locations[(int) $location['locatable_id']]
= [ = [
'latitude' => (float) $location['latitude'], 'latitude' => (float) $location['latitude'],
'longitude' => (float) $location['longitude'], 'longitude' => (float) $location['longitude'],
'zoom_level' => (int) $location['zoom_level'], 'zoom_level' => (int) $location['zoom_level'],
]; ];
} }
Log::debug(sprintf('Enrich with %d locations(s)', count($this->locations))); Log::debug(sprintf('Enrich with %d locations(s)', count($this->locations)));
} }
@@ -193,20 +193,19 @@ class AccountEnrichment implements EnrichmentInterface
->setUserGroup($this->userGroup) ->setUserGroup($this->userGroup)
->setAccounts($this->collection) ->setAccounts($this->collection)
->withAccountInformation() ->withAccountInformation()
->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]) ->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]);
; $journals = $collector->getExtractedJournals();
$journals = $collector->getExtractedJournals();
foreach ($journals as $journal) { foreach ($journals as $journal) {
$this->openingBalances[(int) $journal['source_account_id']] $this->openingBalances[(int) $journal['source_account_id']]
= [ = [
'amount' => Steam::negative($journal['amount']), 'amount' => Steam::negative($journal['amount']),
'date' => $journal['date'], 'date' => $journal['date'],
]; ];
$this->openingBalances[(int) $journal['destination_account_id']] $this->openingBalances[(int) $journal['destination_account_id']]
= [ = [
'amount' => Steam::positive($journal['amount']), 'amount' => Steam::positive($journal['amount']),
'date' => $journal['date'], 'date' => $journal['date'],
]; ];
} }
} }
@@ -229,7 +228,8 @@ class AccountEnrichment implements EnrichmentInterface
$notes = $this->notes; $notes = $this->notes;
$openingBalances = $this->openingBalances; $openingBalances = $this->openingBalances;
$locations = $this->locations; $locations = $this->locations;
$this->collection = $this->collection->map(function (Account $item) use ($accountTypes, $meta, $currencies, $notes, $openingBalances, $locations) { $lastActivities = $this->lastActivities;
$this->collection = $this->collection->map(function (Account $item) use ($accountTypes, $meta, $currencies, $notes, $openingBalances, $locations, $lastActivities) {
$item->full_account_type = $accountTypes[(int) $item->account_type_id] ?? null; $item->full_account_type = $accountTypes[(int) $item->account_type_id] ?? null;
$accountMeta = [ $accountMeta = [
'currency' => null, 'currency' => null,
@@ -264,7 +264,10 @@ class AccountEnrichment implements EnrichmentInterface
if (array_key_exists($item->id, $locations)) { if (array_key_exists($item->id, $locations)) {
$accountMeta['location'] = $locations[$item->id]; $accountMeta['location'] = $locations[$item->id];
} }
$item->meta = $accountMeta; if (array_key_exists($item->id, $lastActivities)) {
$accountMeta['last_activity'] = $lastActivities[$item->id];
}
$item->meta = $accountMeta;
return $item; return $item;
}); });
@@ -274,4 +277,9 @@ class AccountEnrichment implements EnrichmentInterface
{ {
$this->native = $native; $this->native = $native;
} }
private function collectLastActivities(): void
{
$this->lastActivities = Steam::getLastActivities($this->accountIds);
}
} }

View File

@@ -152,6 +152,7 @@ class AccountTransformer extends AbstractTransformer
'longitude' => $longitude, 'longitude' => $longitude,
'latitude' => $latitude, 'latitude' => $latitude,
'zoom_level' => $zoomLevel, 'zoom_level' => $zoomLevel,
'last_activity' => array_key_exists('last_activity', $account->meta) ? $account->meta['last_activity']->toAtomString() : null,
'links' => [ 'links' => [
[ [
'rel' => 'self', 'rel' => 'self',

6
package-lock.json generated
View File

@@ -4416,9 +4416,9 @@
} }
}, },
"node_modules/caniuse-lite": { "node_modules/caniuse-lite": {
"version": "1.0.30001716", "version": "1.0.30001717",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001716.tgz", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001717.tgz",
"integrity": "sha512-49/c1+x3Kwz7ZIWt+4DvK3aMJy9oYXXG6/97JKsnjdCk/6n9vVyWL8NAwVt95Lwt9eigI10Hl782kDfZUUlRXw==", "integrity": "sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw==",
"dev": true, "dev": true,
"funding": [ "funding": [
{ {

View File

@@ -20,6 +20,7 @@
import {api} from "../../../../boot/axios"; import {api} from "../../../../boot/axios";
import format from "date-fns/format"; import format from "date-fns/format";
import {getCacheKey} from "../../../../support/get-cache-key.js";
export default class Get { export default class Get {
@@ -37,6 +38,31 @@ export default class Get {
return api.get('/api/v1/accounts/' + identifier, {params: params}); return api.get('/api/v1/accounts/' + identifier, {params: params});
} }
/**
*
* @param params
* @returns {Promise<AxiosResponse<any>>}
*/
index(params) {
// first, check API in some consistent manner.
// then, load if necessary.
const cacheKey = getCacheKey('/api/v1/accounts', params);
const cacheValid = window.store.get('cacheValid');
let cachedData = window.store.get(cacheKey);
if (cacheValid && typeof cachedData !== 'undefined') {
console.log('Cache is valid, return cache.');
return Promise.resolve(cachedData);
}
// if not, store in cache and then return res.
return api.get('/api/v1/accounts', {params: params}).then(response => {
console.log('Cache is invalid, return fresh.');
window.store.set(cacheKey, response.data);
return Promise.resolve({data: response.data.data, meta: response.data.meta});
});
}
/** /**
* *

View File

@@ -383,7 +383,8 @@ let index = function () {
// one page only.o // one page only.o
(new Get()).index(params).then(response => { (new Get()).index(params).then(response => {
console.log(response); console.log(response);
this.totalPages = response.meta.lastPage; this.totalPages = response.meta.pagination.total_pages;
console.log('a');
for (let i = 0; i < response.data.length; i++) { for (let i = 0; i < response.data.length; i++) {
if (response.data.hasOwnProperty(i)) { if (response.data.hasOwnProperty(i)) {
let current = response.data[i]; let current = response.data[i];

View File

@@ -9,7 +9,7 @@
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h3 class="card-title"> <h3 class="card-title">
<a :href="'{{ route('accounts.show', '') }}/' + account.id" <a :href="'{{ route('accounts.show', '0') }}/' + account.id"
x-text="account.name"></a> x-text="account.name"></a>
<span class="small"> <span class="small">
@@ -42,7 +42,7 @@
<template x-if="group.transactions[0].type === 'transfer'"> <template x-if="group.transactions[0].type === 'transfer'">
<span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span> <span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span>
</template> </template>
<a :href="'{{route('transactions.show', '') }}/' + group.id" x-text="group.title"></a><br/></span> <a :href="'{{route('transactions.show', '0') }}/' + group.id" x-text="group.title"></a><br/></span>
</template> </template>
<ul class="list-unstyled list-no-margin"> <ul class="list-unstyled list-no-margin">
<template x-for="transaction in group.transactions"> <template x-for="transaction in group.transactions">
@@ -61,7 +61,7 @@
<template x-if="transaction.type == 'transfer'"> <template x-if="transaction.type == 'transfer'">
<span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span> <span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span>
</template> </template>
<a :href="'{{route('transactions.show', '') }}/' + group.id" x-text="transaction.description"></a> <a :href="'{{route('transactions.show', '0') }}/' + group.id" x-text="transaction.description"></a>
</span> </span>
</template> </template>
</li> </li>

View File

@@ -30,7 +30,7 @@
<template x-for="bill in group.bills"> <template x-for="bill in group.bills">
<tr> <tr>
<td> <td>
<a :href="'{{ route('subscriptions.show',['']) }}/' + bill.id" :title="bill.name"> <a :href="'{{ route('subscriptions.show',['0']) }}/' + bill.id" :title="bill.name">
<span x-text="bill.name"></span> <span x-text="bill.name"></span>
</a> </a>
<template x-if="bill.paid"> <template x-if="bill.paid">