Skip to content

Firefly III: a personal finances manager

Allow setting of notifications.

James Coled2c52b47f152
diff --git a/app/Http/Controllers/PreferencesController.php b/app/Http/Controllers/PreferencesController.php
index 737ad506bc..b99dd19535 100644
--- a/app/Http/Controllers/PreferencesController.php
+++ b/app/Http/Controllers/PreferencesController.php
@@ -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:
diff --git a/config/firefly.php b/config/firefly.php
index 273b65db53..736a469bec 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -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
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 28c8d5ef4c..2f4a2f6c87 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -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.',
diff --git a/resources/views/preferences/index.twig b/resources/views/preferences/index.twig
index ee8130ae8b..e8d3c73c48 100644
--- a/resources/views/preferences/index.twig
+++ b/resources/views/preferences/index.twig
@@ -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">
@@ -31,15 +37,18 @@
<div class="col-sm-12">
<select class="form-control" id="lang_holder" name="language">
{% for key, lang in languages %}
- <option {% if language == key %}
- selected
- {% endif %} value="{{ key }}">{{ lang.name_locale }} ({{ lang.name_english }})</option>
+ <option {% if language == key %}
+ selected
+ {% endif %} value="{{ key }}">{{ lang.name_locale }}
+ ({{ lang.name_english }})
+ </option>
{% endfor %}
</select>
- </div></div>
+ </div>
+ </div>
<p class="text-info">
@@ -50,32 +59,34 @@
{# locale #}
{% if not isDocker %}
- <div class="preferences-box">
- <h3>{{ 'pref_locale'|_ }}</h3>
- <p class="text-info">{{ 'pref_locale_help'|_ }}</p>
- <div class="form-group">
- <div class="col-sm-12">
- <select class="form-control" id="locale_holder" name="locale">
- {% for key, loc in locales %}
- <option {% if locale == key %}
- selected
- {% endif %} value="{{ key }}">
- {% if key == 'equal' %}
- {{ 'equal_to_language'|_ }}
- {% else %}
- {{ loc }}
- {% endif %}</option>
+ <div class="preferences-box">
+ <h3>{{ 'pref_locale'|_ }}</h3>
+ <p class="text-info">{{ 'pref_locale_help'|_ }}</p>
+ <div class="form-group">
+ <div class="col-sm-12">
+ <select class="form-control" id="locale_holder" name="locale">
+ {% for key, loc in locales %}
+ <option {% if locale == key %}
+ selected
+ {% endif %} value="{{ key }}">
+ {% if key == 'equal' %}
+ {{ 'equal_to_language'|_ }}
+ {% else %}
+ {{ loc }}
+ {% endif %}</option>
- {% endfor %}
- </select>
- </div></div>
- <ul class="text-warning">
+ {% endfor %}
+ </select>
+ </div>
+ </div>
+ <ul class="text-warning">
- {% if IS_DEMO_SITE %}<li class="text-danger">{{ 'pref_locale_no_demo'|_ }}</li>{% endif %}
- </ul>
- </div>
+ {% if IS_DEMO_SITE %}
+ <li class="text-danger">{{ 'pref_locale_no_demo'|_ }}</li>{% endif %}
+ </ul>
+ </div>
{% else %}
- <input type="hidden" name="locale" value="equal" />
+ <input type="hidden" name="locale" value="equal"/>
{% endif %}
{# fiscal year #}
@@ -131,22 +142,23 @@
{% for type, accounts in groupedAccounts %}
<strong>{{ type }}</strong>
{% for id, name in accounts %}
- <div class="form-group">
- <div class="col-sm-10">
- <div class="checkbox">
- <label>
- {% if id in frontPageAccounts.data or frontPageAccounts.data|length == 0 %}
- <input type="checkbox" name="frontPageAccounts[]" value="{{ id }}"
- checked> {{ name }}
- {% else %}
- <input type="checkbox" name="frontPageAccounts[]"
- value="{{ id }}"> {{ name }}
- {% endif %}
- </label>
+ <div class="form-group">
+ <div class="col-sm-10">
+ <div class="checkbox">
+ <label>
+ {% if id in frontPageAccounts.data or frontPageAccounts.data|length == 0 %}
+ <input type="checkbox" name="frontPageAccounts[]"
+ value="{{ id }}"
+ checked> {{ name }}
+ {% else %}
+ <input type="checkbox" name="frontPageAccounts[]"
+ value="{{ id }}"> {{ name }}
+ {% endif %}
+ </label>
+ </div>
</div>
</div>
- </div>
- {% endfor %}
+ {% endfor %}
{% endfor %}
</div>
</div>
@@ -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 %}