Skip to content

Firefly III: a personal finances manager

Improve code for intro texts.

James Colef2d388f742c5
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index 81170bb392..d6ffcfaee2 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -67,12 +67,15 @@ class Controller extends BaseController
// get shown-intro-preference:
if (auth()->check()) {
- $route = Route::currentRouteName();
+ $route = Route::currentRouteName();
$originalRoute = $route;
- $route = str_replace('.', '_', $route);
- $key = 'shown_demo_' . $route;
- $config = config('intro.' . $route);
- $shownDemo = Preferences::get($key, false)->data;
+
+ // TODO get parameters from route?
+
+ $route = str_replace('.', '_', $route);
+ $key = 'shown_demo_' . $route;
+ $config = config('intro.' . $route);
+ $shownDemo = Preferences::get($key, false)->data;
if (is_null($config) || (is_array($config) && count($config) === 0)) {
// no demo when no data for demo.
$shownDemo = true;
diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php
index 0a68bb82b0..7e92e24798 100644
--- a/app/Http/Controllers/Json/IntroController.php
+++ b/app/Http/Controllers/Json/IntroController.php
@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
-use Preferences;
use Response;
/**
@@ -24,23 +23,76 @@ class IntroController
/**
* @param string $route
+ * @param string $specificPage
*
* @return \Illuminate\Http\JsonResponse
*/
- public function getIntroSteps(string $route)
+ public function getIntroSteps(string $route, string $specificPage = '')
{
- $route = str_replace('.', '_', $route);
- $elements = config(sprintf('intro.%s', $route));
+ $steps = $this->getBasicSteps($route);
+ $specificSteps = $this->getSpecificSteps($route, $specificPage);
+ if (count($specificSteps) === 0) {
+ return Response::json($steps);
+ }
+ if ($this->hasOutroStep($route)) {
+ // save last step:
+ $lastStep = $steps[count($steps) - 1];
+ // remove last step:
+ array_pop($steps);
+ // merge arrays and add last step again
+ $steps = array_merge($steps, $specificSteps);
+ $steps[] = $lastStep;
+
+ }
+ if (!$this->hasOutroStep($route)) {
+ $steps = array_merge($steps, $specificSteps);
+ }
+
+ return Response::json($steps);
+ }
+
+ /**
+ * @param string $route
+ *
+ * @return bool
+ */
+ public function hasOutroStep(string $route): bool
+ {
+ $routeKey = str_replace('.', '_', $route);
+ $elements = config(sprintf('intro.%s', $routeKey));
+ $keys = array_keys($elements);
+
+ return in_array('outro', $keys);
+ }
+
+ /**
+ * @param string $route
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function postFinished(string $route)
+ {
+ $key = 'shown_demo_' . $route;
+
+ //Preferences::set($key, true);
+
+ return Response::json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
+ }
+
+ /**
+ * @param string $route
+ *
+ * @return array
+ */
+ private function getBasicSteps(string $route): array
+ {
+ $routeKey = str_replace('.', '_', $route);
+ $elements = config(sprintf('intro.%s', $routeKey));
$steps = [];
if (is_array($elements) && count($elements) > 0) {
foreach ($elements as $key => $options) {
$currentStep = $options;
- // point to HTML element when not an intro or outro:
- if (!in_array($key, ['intro', 'outro'])) {
- $currentStep['element'] = $options['selector'];
- }
-
// get the text:
$currentStep['intro'] = trans('intro.' . $route . '_' . $key);
@@ -50,20 +102,38 @@ class IntroController
}
}
- return Response::json($steps);
+ return $steps;
}
/**
* @param string $route
+ * @param string $specificPage
*
- * @return \Illuminate\Http\JsonResponse
+ * @return array
*/
- public function postFinished(string $route)
+ private function getSpecificSteps(string $route, string $specificPage): array
{
- $key = 'shown_demo_' . $route;
- Preferences::set($key, true);
+ $steps = [];
- return Response::json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
+ // user is on page with specific instructions:
+ if (strlen($specificPage) > 0) {
+ $routeKey = str_replace('.', '_', $route);
+ $elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
+ if (is_array($elements) && count($elements) > 0) {
+ foreach ($elements as $key => $options) {
+ $currentStep = $options;
+ $currentStep['element'] = $options['selector'];
+
+ // get the text:
+ $currentStep['intro'] = trans('intro.' . $route . '_' . $specificPage . '_' . $key);
+
+ // save in array:
+ $steps[] = $currentStep;
+ }
+ }
+ }
+
+ return $steps;
}
}
\ No newline at end of file
diff --git a/config/intro.php b/config/intro.php
index 90c6a517b0..ded26a665a 100644
--- a/config/intro.php
+++ b/config/intro.php
@@ -14,22 +14,126 @@ declare(strict_types=1);
*/
return [
- 'index' => [
+ // index
+ 'index' => [
'intro' => [],
- 'accounts-chart' => ['selector' => '#accounts-chart'],
- 'box_out_holder' => ['selector' => '#box_out_holder'],
- 'help' => ['selector' => '#help', 'position' => 'bottom'],
- 'sidebar-toggle' => ['selector' => '#sidebar-toggle', 'position' => 'bottom'],
+ 'accounts-chart' => ['element' => '#accounts-chart'],
+ 'box_out_holder' => ['element' => '#box_out_holder'],
+ 'help' => ['element' => '#help', 'position' => 'bottom'],
+ 'sidebar-toggle' => ['element' => '#sidebar-toggle', 'position' => 'bottom'],
'outro' => [],
],
- 'rules_index' => [
+ // accounts: create
+ 'accounts_create' => [
+ 'intro' => [],
+ 'iban' => ['element' => '#ffInput_iban'],
+ ],
+ // extra text for asset account creation.
+ 'accounts_create_asset' => [
+ 'opening_balance' => ['element' => '#ffInput_openingBalance'],
+ 'currency' => ['element' => '#ffInput_currency_id'],
+ 'virtual' => ['element' => '#ffInput_virtualBalance'],
+ ],
+
+ // budgets: index
+ 'budgets_index' => [
+ 'intro' => [],
+ 'set_budget' => ['element' => '#availableBar',],
+ 'see_expenses_bar' => ['element' => '#spentBar'],
+ 'navigate_periods' => ['element' => '#periodNavigator'],
+ 'new_budget' => ['element' => '#createBudgetBox'],
+ 'list_of_budgets' => ['element' => '#budgetList'],
+
+ ],
+ // tags: wait for upgrade
+ // reports: index, default report, audit, budget, cat, tag
+ 'reports_index' => [
+ 'intro' => [],
+ ],
+ 'reports_report_default' => [
+ 'intro' => [],
+ ],
+ 'reports_report_audit' => [
+ 'intro' => [],
+ ],
+ 'reports_report_category' => [
+ 'intro' => [],
+ ],
+ 'reports_report_report' => [
+ 'intro' => [],
+ ],
+ 'reports_report_budget' => [
+ 'intro' => [],
+ ],
+
+ // transactions: create
+ 'transactions_create' => [
+ 'intro' => [],
+ 'switch_box' => ['element' => '#switch-box'],
+ 'ffInput_category' => ['element' => '#ffInput_category'],
+ ],
+ // piggies: index, create, show
+ 'piggy-banks_index' => [
+ 'intro' => [],
+ ],
+ 'piggy-banks_create' => [
+ 'intro' => [],
+ ],
+ 'piggy-banks_show' => [
+ 'intro' => [],
+ ],
+
+ // bills: index, create, show
+ 'bills_index' => [
+ 'intro' => [],
+ ],
+ 'bills_create' => [
+ 'intro' => [],
+ ],
+ 'bills_show' => [
+ 'intro' => [],
+ ],
+ // rules: index, create-rule, edit-rule
+ 'rules_index' => [
'intro' => [],
- 'new_rule_group' => ['selector' => '#new_rule_group'],
- 'new_rule' => ['selector' => '.new_rule'],
- 'prio_buttons' => ['selector' => '.prio_buttons'],
- 'test_buttons' => ['selector' => '.test_buttons'],
- 'rule-triggers' => ['selector' => '.rule-triggers'],
+ 'new_rule_group' => ['element' => '#new_rule_group'],
+ 'new_rule' => ['element' => '.new_rule'],
+ 'prio_buttons' => ['element' => '.prio_buttons'],
+ 'test_buttons' => ['element' => '.test_buttons'],
+ 'rule-triggers' => ['element' => '.rule-triggers'],
'outro' => [],
-
],
+ 'rules_create' => [
+ 'intro' => [],
+ ],
+ 'rules_edit' => [
+ 'intro' => [],
+ ],
+ // import: index, config-steps
+ 'import_index' => [
+ 'intro' => [],
+ ],
+ 'import_configure' => [
+ 'intro' => [],
+ ],
+ // export: index
+ 'export_index' => [
+ 'intro' => [],
+ ],
+ // preferences: index
+ 'preferences_index' => [
+ 'intro' => [],
+ ],
+ // currencies: index, create
+ 'currencies_index' => [
+ 'intro' => [],
+ ],
+ 'currencies_create' => [
+ 'intro' => [],
+ ],
+ // admin: index
+ 'admin_index' => [
+ 'intro' => [],
+ ],
+
];
\ No newline at end of file
diff --git a/public/js/ff/intro/intro.js b/public/js/ff/intro/intro.js
index e8dad19903..cc63d45370 100644
--- a/public/js/ff/intro/intro.js
+++ b/public/js/ff/intro/intro.js
@@ -21,7 +21,7 @@ function setupIntro(steps) {
steps: steps,
exitOnEsc: true,
exitOnOverlayClick: true,
- keyboardNavigation: true,
+ keyboardNavigation: true
});
intro.oncomplete(reportIntroFinished);
intro.onexit(reportIntroFinished);
diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twig
index 1753737b57..d09f2af40c 100644
--- a/resources/views/budgets/index.twig
+++ b/resources/views/budgets/index.twig
@@ -17,7 +17,7 @@
<small>{{ 'budgeted'|_ }}: <span id="budgetedAmount" class="text-success">{{ budgeted|formatAmountPlain }}</span></small>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" style="text-align:right;">
- <small>{{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}:
+ <small id="availableBar">{{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}:
<a href="#" class="updateIncome"><span id="available"
data-value="{{ available }}">{{ available|formatAmountPlain }}</span></a>
</small>
@@ -36,7 +36,7 @@
</div>
</div>
</div>
- <div class="row">
+ <div class="row" id="spentBar">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<small>{{ trans('firefly.spent_between', {start: periodStart, end: periodEnd}) }}: {{ spent|formatAmount }}</small>
</div>
@@ -71,7 +71,7 @@
</div>
</div>
{% if budgets.count > 0 and inactive.count > 0 %}
- <div class="box">
+ <div class="box" id="createBudgetBox">
<div class="box-header with-border">
<h3 class="box-title">{{ 'createBudget'|_ }}</h3>
</div>
@@ -84,6 +84,8 @@
</div>
{% if budgets.count == 0 and inactive.count == 0 %}
{% include 'partials.empty' with {what: 'default', type: 'budgets',route: route('budgets.create')} %}
+ {# make FF ignore demo for now. #}
+ {% set shownDemo = true %}
{% endif %}
{# date thing #}
@@ -91,10 +93,10 @@
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="box">
<div class="box-header with-border">
- <h3 class="box-title">Period thing</h3>
+ <h3 class="box-title">{{ 'budget_period_navigator'|_ }}</h3>
</div>
<div class="box-body">
- <div class="row">
+ <div class="row" id="periodNavigator">
<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12">
<select class="form-control selectPeriod" name="previous">
<option label="{{ 'select_date'|_ }}" value="x">{{ 'select_date'|_ }}</option>
@@ -128,10 +130,10 @@
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="box">
<div class="box-header with-border">
- <h3 class="box-title">Budget stuff</h3>
+ <h3 class="box-title">{{ 'budgets'|_ }}</h3>
</div>
<div class="box-body no-padding">
- <table class="table table-bordered table-striped sortable">
+ <table class="table table-bordered table-striped sortable" id="budgetList">
<thead>
<tr>
<th data-defaultsort="disabled" class="hidden-sm hidden-xs" style="width:10%;">&nbsp;</th>
diff --git a/resources/views/layout/default.twig b/resources/views/layout/default.twig
index 2c22f78db5..9ac89dad44 100644
--- a/resources/views/layout/default.twig
+++ b/resources/views/layout/default.twig
@@ -184,7 +184,7 @@
{% if not shownDemo %}
<script type="text/javascript">
var routeForTour = "{{ current_route_name }}";
- var routeStepsUri = "{{ route('json.intro', [current_route_name]) }}";
+ var routeStepsUri = "{{ route('json.intro', [current_route_name, what|default("")]) }}";
var routeForFinishedTour = "{{ route('json.intro.finished', [current_route_name]) }}";
</script>
<script type="text/javascript" src="lib/intro/intro.min.js"></script>
diff --git a/resources/views/transactions/single/create.twig b/resources/views/transactions/single/create.twig
index 43d74ab252..a55254bf04 100644
--- a/resources/views/transactions/single/create.twig
+++ b/resources/views/transactions/single/create.twig
@@ -19,7 +19,7 @@
<div class="form-group">
<label class="col-sm-4 control-label">Quickswitch</label>
- <div class="col-sm-8">
+ <div class="col-sm-8" id="switch-box">
<div class="btn-group btn-group-justified">
<a href="#" data-what="withdrawal" class="switch btn btn-default"> {{ 'withdrawal'|_ }}</a>
<a href="#" data-what="deposit" class="switch btn btn-default"> {{ 'deposit'|_ }}</a>
diff --git a/routes/web.php b/routes/web.php
index 1daa344814..5d1db91e33 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -450,8 +450,8 @@ Route::group(
Route::get('rate/{fromCurrencyCode}/{toCurrencyCode}/{date}', ['uses' => 'Json\ExchangeController@getRate', 'as' => 'rate']);
// intro things:
- Route::get('intro/{route}', ['uses' => 'Json\IntroController@getIntroSteps', 'as' => 'intro']);
- Route::post('intro/finished/{route}', ['uses' => 'Json\IntroController@postFinished', 'as' => 'intro.finished']);
+ Route::get('intro/{route}/{specificPage?}', ['uses' => 'Json\IntroController@getIntroSteps', 'as' => 'intro']);
+ Route::post('intro/finished/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postFinished', 'as' => 'intro.finished']);
}
);