From f2d388f742c58a44a53c8f94e72c3717ac7fd248 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 21 Jul 2017 06:00:10 +0200 Subject: [PATCH] Improve code for intro texts. --- app/Http/Controllers/Controller.php | 13 +- app/Http/Controllers/Json/IntroController.php | 112 ++++++++++++--- config/intro.php | 130 ++++++++++++++++-- public/js/ff/intro/intro.js | 2 +- resources/views/budgets/index.twig | 16 ++- resources/views/layout/default.twig | 2 +- .../views/transactions/single/create.twig | 2 +- routes/web.php | 4 +- 8 files changed, 230 insertions(+), 51 deletions(-) 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,35 +23,48 @@ 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 = []; - if (is_array($elements) && count($elements) > 0) { - foreach ($elements as $key => $options) { - $currentStep = $options; + $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; - // 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); - - - // save in array: - $steps[] = $currentStep; - } + } + 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 * @@ -61,9 +73,67 @@ class IntroController public function postFinished(string $route) { $key = 'shown_demo_' . $route; - Preferences::set($key, true); + + //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; + + // get the text: + $currentStep['intro'] = trans('intro.' . $route . '_' . $key); + + + // save in array: + $steps[] = $currentStep; + } + } + + return $steps; + } + + /** + * @param string $route + * @param string $specificPage + * + * @return array + */ + private function getSpecificSteps(string $route, string $specificPage): array + { + $steps = []; + + // 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' => [ - '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'], - 'outro' => [], + // 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' => ['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 @@ {{ 'budgeted'|_ }}: {{ budgeted|formatAmountPlain }}
- {{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}: + {{ trans('firefly.available_between',{start : periodStart, end: periodEnd }) }}: {{ available|formatAmountPlain }} @@ -36,7 +36,7 @@
-
+
{{ trans('firefly.spent_between', {start: periodStart, end: periodEnd}) }}: {{ spent|formatAmount }}
@@ -71,7 +71,7 @@
{% if budgets.count > 0 and inactive.count > 0 %} -
+

{{ 'createBudget'|_ }}

@@ -84,6 +84,8 @@
{% 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 @@
-

Period thing

+

{{ 'budget_period_navigator'|_ }}

-
+