Allow setting of notifications.

This commit is contained in:
James Cole
2022-09-18 16:49:15 +02:00
parent c25b63d87b
commit d2c52b47f1
4 changed files with 121 additions and 50 deletions

View File

@@ -106,6 +106,13 @@ class PreferencesController extends Controller
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
// notification preferences (single value for each):
$notifications = [];
foreach (config('firefly.available_notifications') as $notification) {
$notifications[$notification] = app('preferences')->get(sprintf('notification_%s', $notification), true)->data;
}
ksort($languages);
// list of locales also has "equal" which makes it equal to whatever the language is.
@@ -131,6 +138,7 @@ class PreferencesController extends Controller
'isDocker',
'frontPageAccounts',
'languages',
'notifications',
'locales',
'locale',
'tjOptionalFields',
@@ -163,6 +171,18 @@ class PreferencesController extends Controller
app('preferences')->set('frontPageAccounts', $frontPageAccounts);
}
// extract notifications:
$all = $request->all();
foreach(config('firefly.available_notifications') as $option) {
$key = sprintf('notification_%s', $option);
if(array_key_exists($key, $all)) {
app('preferences')->set($key, true);
}
if(!array_key_exists($key, $all)) {
app('preferences')->set($key, false);
}
}
// view range:
app('preferences')->set('viewRange', $request->get('viewRange'));
// forget session values:

View File

@@ -144,6 +144,9 @@ return [
'update_endpoint' => 'https://version.firefly-iii.org/index.json',
'update_minimum_age' => 7,
// notifications
'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'],
// enabled languages
'languages' => [
// currently enabled languages

View File

@@ -1014,6 +1014,7 @@ return [
'preferences_frontpage' => 'Home screen',
'preferences_security' => 'Security',
'preferences_layout' => 'Layout',
'preferences_notifications' => 'Notifications',
'pref_home_show_deposits' => 'Show deposits on the home screen',
'pref_home_show_deposits_info' => 'The home screen already shows your expense accounts. Should it also show your revenue accounts?',
'pref_home_do_show_deposits' => 'Yes, show them',
@@ -1044,7 +1045,12 @@ return [
'optional_field_attachments' => 'Attachments',
'optional_field_meta_data' => 'Optional meta data',
'external_url' => 'External URL',
'pref_notification_bill_reminder' => 'Reminder about expiring bills',
'pref_notification_new_access_token' => 'Alert when a new API access token is created',
'pref_notification_transaction_creation' => 'Alert when a transaction is created automatically',
'pref_notification_user_login' => 'Alert when you login from a new location',
'pref_notifications' => 'Notifications',
'pref_notifications_help' => 'Indicate if these are notifications you would like to get. Some notifications may contain sensitive financial information.',
// profile:
'delete_stuff_header' => 'Delete data',
'permanent_delete_stuff' => 'Be careful with these buttons. Deleting stuff is permanent.',

View File

@@ -5,7 +5,8 @@
{% endblock %}
{% block content %}
<form method="POST" action="{{ route('preferences.update') }}" accept-charset="UTF-8" class="form-horizontal" id="preferences">
<form method="POST" action="{{ route('preferences.update') }}" accept-charset="UTF-8" class="form-horizontal"
id="preferences">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
<div class="row">
@@ -13,9 +14,14 @@
{# start of preferences tabs #}
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active"><a href="#general" data-toggle="tab" aria-expanded="true">{{ 'preferences_general'|_ }}</a></li>
<li class=""><a href="#frontpage" data-toggle="tab" aria-expanded="false">{{ 'preferences_frontpage'|_ }}</a></li>
<li class=""><a href="#layout" data-toggle="tab" aria-expanded="false">{{ 'preferences_layout'|_ }}</a></li>
<li class="active"><a href="#general" data-toggle="tab"
aria-expanded="true">{{ 'preferences_general'|_ }}</a></li>
<li class=""><a href="#frontpage" data-toggle="tab"
aria-expanded="false">{{ 'preferences_frontpage'|_ }}</a></li>
<li class=""><a href="#layout" data-toggle="tab"
aria-expanded="false">{{ 'preferences_layout'|_ }}</a></li>
<li class=""><a href="#notifications" data-toggle="tab"
aria-expanded="false">{{ 'preferences_notifications'|_ }}</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="general">
@@ -33,13 +39,16 @@
{% for key, lang in languages %}
<option {% if language == key %}
selected
{% endif %} value="{{ key }}">{{ lang.name_locale }} ({{ lang.name_english }})</option>
{% endif %} value="{{ key }}">{{ lang.name_locale }}
({{ lang.name_english }})
</option>
{% endfor %}
</select>
</div></div>
</div>
</div>
<p class="text-info">
@@ -68,10 +77,12 @@
{% endfor %}
</select>
</div></div>
</div>
</div>
<ul class="text-warning">
{% if IS_DEMO_SITE %}<li class="text-danger">{{ 'pref_locale_no_demo'|_ }}</li>{% endif %}
{% if IS_DEMO_SITE %}
<li class="text-danger">{{ 'pref_locale_no_demo'|_ }}</li>{% endif %}
</ul>
</div>
{% else %}
@@ -136,7 +147,8 @@
<div class="checkbox">
<label>
{% if id in frontPageAccounts.data or frontPageAccounts.data|length == 0 %}
<input type="checkbox" name="frontPageAccounts[]" value="{{ id }}"
<input type="checkbox" name="frontPageAccounts[]"
value="{{ id }}"
checked> {{ name }}
{% else %}
<input type="checkbox" name="frontPageAccounts[]"
@@ -224,6 +236,32 @@
</div>
</div>
</div>
<div class="tab-pane" id="notifications">
{# layout settings here #}
<div class="row">
{# layout settings column A #}
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
{# view range #}
<div class="preferences-box">
<h3>{{ 'pref_notifications'|_ }}</h3>
<p class="text-info">{{ 'pref_notifications_help'|_ }}</p>
{% for id, enabled in notifications %}
<div class="form-group">
<div class="col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox" name="notification_{{ id }}" {{ enabled == true ? 'checked' : '' }} value="1">
{{ trans('firefly.pref_notification_' ~ id) }}
</label>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -240,12 +278,16 @@
</form>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}"
nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/ff/preferences/index.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/ff/preferences/index.js?v={{ FF_VERSION }}"
nonce="{{ JS_NONCE }}"></script>
{% endblock %}
{% block styles %}
<link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all" nonce="{{ JS_NONCE }}">
<link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all" nonce="{{ JS_NONCE }}">
<link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet"
media="all" nonce="{{ JS_NONCE }}">
<link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet"
media="all" nonce="{{ JS_NONCE }}">
{% endblock %}