Replace variable names.

This commit is contained in:
James Cole
2024-04-01 20:26:02 +02:00
parent f6e28dc88f
commit 6189d24b98
13 changed files with 52 additions and 49 deletions

View File

@@ -83,17 +83,17 @@ class AccountController extends Controller
// user's preferences // user's preferences
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); $defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
/** @var Preference $frontPage */ /** @var Preference $frontpage */
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
$default = app('amount')->getDefaultCurrency(); $default = app('amount')->getDefaultCurrency();
if (!(is_array($frontPage->data) && count($frontPage->data) > 0)) { if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
$frontPage->data = $defaultSet; $frontpage->data = $defaultSet;
$frontPage->save(); $frontpage->save();
} }
// get accounts: // get accounts:
$accounts = $this->repository->getAccountsById($frontPage->data); $accounts = $this->repository->getAccountsById($frontpage->data);
$chartData = []; $chartData = [];
/** @var Account $account */ /** @var Account $account */

View File

@@ -98,14 +98,14 @@ class AccountController extends Controller
// user's preferences // user's preferences
if (0 === $accounts->count()) { if (0 === $accounts->count()) {
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray(); $defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
if (!(is_array($frontPage->data) && count($frontPage->data) > 0)) { if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
$frontPage->data = $defaultSet; $frontpage->data = $defaultSet;
$frontPage->save(); $frontpage->save();
} }
$accounts = $this->repository->getAccountsById($frontPage->data); $accounts = $this->repository->getAccountsById($frontpage->data);
} }
// both options are overruled by "preselected" // both options are overruled by "preselected"

View File

@@ -50,7 +50,7 @@ class FixFrontpageAccounts extends Command
/** @var User $user */ /** @var User $user */
foreach ($users as $user) { foreach ($users as $user) {
$preference = app('preferences')->getForUser($user, 'frontPageAccounts'); $preference = app('preferences')->getForUser($user, 'frontpageAccounts');
if (null !== $preference) { if (null !== $preference) {
$this->fixPreference($preference); $this->fixPreference($preference);
} }
@@ -83,6 +83,6 @@ class FixFrontpageAccounts extends Command
} }
} }
} }
app('preferences')->setForUser($preference->user, 'frontPageAccounts', $fixed); app('preferences')->setForUser($preference->user, 'frontpageAccounts', $fixed);
} }
} }

View File

@@ -145,13 +145,13 @@ class CreateController extends Controller
Log::channel('audit')->info('Stored new account.', $data); Log::channel('audit')->info('Stored new account.', $data);
// update preferences if necessary: // update preferences if necessary:
$frontPage = app('preferences')->get('frontPageAccounts', [])->data; $frontpage = app('preferences')->get('frontpageAccounts', [])->data;
if (!is_array($frontPage)) { if (!is_array($frontpage)) {
$frontPage = []; $frontpage = [];
} }
if (AccountType::ASSET === $account->accountType->type) { if (AccountType::ASSET === $account->accountType->type) {
$frontPage[] = $account->id; $frontpage[] = $account->id;
app('preferences')->set('frontPageAccounts', $frontPage); app('preferences')->set('frontpageAccounts', $frontpage);
} }
// store attachment(s): // store attachment(s):

View File

@@ -301,14 +301,14 @@ class AccountController extends Controller
$end = clone session('end', today(config('app.timezone'))->endOfMonth()); $end = clone session('end', today(config('app.timezone'))->endOfMonth());
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray(); $defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
app('log')->debug('Default set is ', $defaultSet); app('log')->debug('Default set is ', $defaultSet);
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
$frontPageArray = !is_array($frontPage->data) ? [] : $frontPage->data; $frontpageArray = !is_array($frontpage->data) ? [] : $frontpage->data;
app('log')->debug('Frontpage preference set is ', $frontPageArray); app('log')->debug('Frontpage preference set is ', $frontpageArray);
if (0 === count($frontPageArray)) { if (0 === count($frontpageArray)) {
app('preferences')->set('frontPageAccounts', $defaultSet); app('preferences')->set('frontpageAccounts', $defaultSet);
app('log')->debug('frontpage set is empty!'); app('log')->debug('frontpage set is empty!');
} }
$accounts = $repository->getAccountsById($frontPageArray); $accounts = $repository->getAccountsById($frontpageArray);
return response()->json($this->accountBalanceChart($accounts, $start, $end)); return response()->json($this->accountBalanceChart($accounts, $start, $end));
} }

View File

@@ -116,8 +116,8 @@ class CategoryController extends Controller
return response()->json($cache->get()); return response()->json($cache->get());
} }
$frontPageGenerator = new FrontpageChartGenerator($start, $end); $frontpageGenerator = new FrontpageChartGenerator($start, $end);
$chartData = $frontPageGenerator->generate(); $chartData = $frontpageGenerator->generate();
$data = $this->generator->multiSet($chartData); $data = $this->generator->multiSet($chartData);
$cache->store($data); $cache->store($data);

View File

@@ -129,10 +129,10 @@ class HomeController extends Controller
} }
$subTitle = (string)trans('firefly.welcome_back'); $subTitle = (string)trans('firefly.welcome_back');
$transactions = []; $transactions = [];
$frontPage = app('preferences')->getFresh('frontPageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray()); $frontpage = app('preferences')->getFresh('frontpageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray());
$frontPageArray = $frontPage->data; $frontpageArray = $frontpage->data;
if (!is_array($frontPageArray)) { if (!is_array($frontpageArray)) {
$frontPageArray = []; $frontpageArray = [];
} }
/** @var Carbon $start */ /** @var Carbon $start */
@@ -140,13 +140,13 @@ class HomeController extends Controller
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth()); $end = session('end', today(config('app.timezone'))->endOfMonth());
$accounts = $repository->getAccountsById($frontPageArray); $accounts = $repository->getAccountsById($frontpageArray);
$today = today(config('app.timezone')); $today = today(config('app.timezone'));
// sort frontpage accounts by order // sort frontpage accounts by order
$accounts = $accounts->sortBy('order'); $accounts = $accounts->sortBy('order');
app('log')->debug('Frontpage accounts are ', $frontPageArray); app('log')->debug('Frontpage accounts are ', $frontpageArray);
/** @var BillRepositoryInterface $billRepository */ /** @var BillRepositoryInterface $billRepository */
$billRepository = app(BillRepositoryInterface::class); $billRepository = app(BillRepositoryInterface::class);

View File

@@ -115,7 +115,7 @@ class NewUserController extends Controller
// store frontpage preferences: // store frontpage preferences:
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); $accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
app('preferences')->set('frontPageAccounts', $accounts); app('preferences')->set('frontpageAccounts', $accounts);
// mark. // mark.
app('preferences')->mark(); app('preferences')->mark();

View File

@@ -89,10 +89,10 @@ class PreferencesController extends Controller
/** @var array<int, int> $accountIds */ /** @var array<int, int> $accountIds */
$accountIds = $accounts->pluck('id')->toArray(); $accountIds = $accounts->pluck('id')->toArray();
$viewRange = app('navigation')->getViewRange(false); $viewRange = app('navigation')->getViewRange(false);
$frontPageAccountsPref = app('preferences')->get('frontPageAccounts', $accountIds); $frontpageAccountsPref = app('preferences')->get('frontpageAccounts', $accountIds);
$frontPageAccounts = $frontPageAccountsPref->data; $frontpageAccounts = $frontpageAccountsPref->data;
if (!is_array($frontPageAccounts)) { if (!is_array($frontpageAccounts)) {
$frontPageAccounts = $accountIds; $frontpageAccounts = $accountIds;
} }
$language = app('steam')->getLanguage(); $language = app('steam')->getLanguage();
$languages = config('firefly.languages'); $languages = config('firefly.languages');
@@ -128,8 +128,8 @@ class PreferencesController extends Controller
$locales = ['equal' => (string)trans('firefly.equal_to_language')] + $locales; $locales = ['equal' => (string)trans('firefly.equal_to_language')] + $locales;
// an important fallback is that the frontPageAccount array gets refilled automatically // an important fallback is that the frontPageAccount array gets refilled automatically
// when it turns up empty. // when it turns up empty.
if (0 === count($frontPageAccounts)) { if (0 === count($frontpageAccounts)) {
$frontPageAccounts = $accountIds; $frontpageAccounts = $accountIds;
} }
// for the demo user, the slackUrl is automatically emptied. // for the demo user, the slackUrl is automatically emptied.
@@ -139,7 +139,7 @@ class PreferencesController extends Controller
$slackUrl = ''; $slackUrl = '';
} }
return view('preferences.index', compact('language', 'groupedAccounts', 'isDocker', 'frontPageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart')); return view('preferences.index', compact('language', 'groupedAccounts', 'isDocker', 'frontpageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart'));
} }
/** /**
@@ -155,12 +155,12 @@ class PreferencesController extends Controller
public function postIndex(Request $request) public function postIndex(Request $request)
{ {
// front page accounts // front page accounts
$frontPageAccounts = []; $frontpageAccounts = [];
if (is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) { if (is_array($request->get('frontpageAccounts')) && count($request->get('frontpageAccounts')) > 0) {
foreach ($request->get('frontPageAccounts') as $id) { foreach ($request->get('frontpageAccounts') as $id) {
$frontPageAccounts[] = (int)$id; $frontpageAccounts[] = (int)$id;
} }
app('preferences')->set('frontPageAccounts', $frontPageAccounts); app('preferences')->set('frontpageAccounts', $frontpageAccounts);
} }
// extract notifications: // extract notifications:

View File

@@ -216,13 +216,13 @@ return [
], ],
// administration specific preferences // administration specific preferences
'admin_specific_prefs' => ['frontPageAccounts', 'lastActivity'], 'admin_specific_prefs' => ['frontpageAccounts', 'lastActivity'],
// default user-related values // default user-related values
'darkMode' => 'browser', 'darkMode' => 'browser',
'list_length' => 10, // to be removed if v1 is cancelled. 'list_length' => 10, // to be removed if v1 is cancelled.
'default_preferences' => [ 'default_preferences' => [
'frontPageAccounts' => [], 'frontpageAccounts' => [],
'listPageSize' => 50, 'listPageSize' => 50,
'currencyPreference' => 'EUR', 'currencyPreference' => 'EUR',
'language' => 'en_US', 'language' => 'en_US',

View File

@@ -35,6 +35,7 @@ export default () => ({
getFreshData() { getFreshData() {
const start = new Date(window.store.get('start')); const start = new Date(window.store.get('start'));
const end = new Date(window.store.get('end')); const end = new Date(window.store.get('end'));
// needs user data.
const cacheKey = getCacheKey(PIGGY_CACHE_KEY, start, end); const cacheKey = getCacheKey(PIGGY_CACHE_KEY, start, end);
const cacheValid = window.store.get('cacheValid'); const cacheValid = window.store.get('cacheValid');

View File

@@ -19,9 +19,11 @@
*/ */
import {format} from "date-fns"; import {format} from "date-fns";
import store from "store";
function getCacheKey(string, start, end) { function getCacheKey(string, start, end) {
const cacheKey = format(start, 'y-MM-dd') + '_' + format(end, 'y-MM-dd') + '_' + string; const localValue = store.get('lastActivity');
const cacheKey = format(start, 'y-MM-dd') + '_' + format(end, 'y-MM-dd') + '_' + string + localValue;
console.log('getCacheKey: ' + cacheKey); console.log('getCacheKey: ' + cacheKey);
return String(cacheKey); return String(cacheKey);
} }

View File

@@ -17,7 +17,7 @@
<div class="row mb-3"> <div class="row mb-3">
<template x-for="(group, index) in userGroups" :key="index"> <template x-for="(group, index) in userGroups" :key="index">
<div class="col-xl-4 col-lg-4 col-sm-6 col-xs-12 mb-3"> <div class="col-xl-4 col-lg-4 col-sm-6 col-xs-12 mb-3">
<div class="card"> <div :class="{'card': true, 'card-primary': group.in_use}">
<div class="card-header"> <div class="card-header">
<h3 class="card-title"> <h3 class="card-title">
<template x-if="group.in_use"> <template x-if="group.in_use">