This commit is contained in:
James Cole 2021-04-13 19:01:43 +02:00
parent 2f9724e7ca
commit 99f08da4df
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 25 additions and 9 deletions

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use Carbon\Carbon;
use Eloquent;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder;
@ -33,13 +32,13 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\Preference
*
* @property int $id
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $user_id
* @property string $name
* @property int|string|array|null $data
* @property-read User $user
* @property int $user_id
* @property string $name
* @property int|string|array|null $data
* @property-read User $user
* @method static Builder|Preference newModelQuery()
* @method static Builder|Preference newQuery()
* @method static Builder|Preference query()
@ -73,19 +72,29 @@ class Preference extends Model
*
* @param string $value
*
* @throws NotFoundHttpException
* @return Preference
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Preference
{
if (auth()->check()) {
/** @var User $user */
$user = auth()->user();
/** @var Preference $preference */
/** @var Preference|null $preference */
$preference = $user->preferences()->where('name', $value)->first();
if (null !== $preference) {
return $preference;
}
$default = config('firefly.default_preferences');
if (array_key_exists($value, $default)) {
$preference = new Preference;
$preference->name = $value;
$preference->data = $default[$value];
$preference->user_id = $user->id;
$preference->save();
return $preference;
}
}
throw new NotFoundHttpException;
}

View File

@ -850,4 +850,11 @@ return [
'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
'default_preferences' => [
'frontPageAccounts' => [],
'listPageSize' => 50,
'currencyPreference' => 'EUR',
'language' => 'en_US',
'locale' => 'equal',
],
];

View File

@ -123,7 +123,7 @@ export default {
initialiseList: function () {
this.loading = true;
this.accounts = [];
axios.get('./api/v1/preferences/frontpageAccounts')
axios.get('./api/v1/preferences/frontPageAccounts')
.then(response => {
this.loadAccounts(response);
}