diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 422f3dbae5..7a4f5ccfbe 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -67,10 +67,16 @@ class Controller extends BaseController // get shown-intro-preference: if (auth()->check()) { - $key = 'shown_demo_' . Route::currentRouteName(); + $route = Route::currentRouteName(); + $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; + } View::share('shownDemo', $shownDemo); - View::share('current_route_name', Route::currentRouteName()); + View::share('current_route_name', $route); } return $next($request); diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php new file mode 100644 index 0000000000..6b448d6f38 --- /dev/null +++ b/app/Http/Controllers/Json/IntroController.php @@ -0,0 +1,67 @@ + 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'] = '#' . $key; + } + + // get the text: + $currentStep['intro'] = trans('intro.' . $route . '_' . $key); + + // save in array: + $steps[] = $currentStep; + } + } + + return Response::json($steps); + } + + /** + * @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)]); + } + +} \ No newline at end of file diff --git a/config/intro.php b/config/intro.php new file mode 100644 index 0000000000..8bb0bc1301 --- /dev/null +++ b/config/intro.php @@ -0,0 +1,25 @@ + [ + 'intro' => [], + 'accounts-chart' => [], + 'box_out_holder' => [], + 'all_transactions' => ['position' => 'left'], + 'help' => ['position' => 'bottom'], + 'outro' => [], + ], +]; \ No newline at end of file diff --git a/public/js/ff/intro/intro.js b/public/js/ff/intro/intro.js index f6b253ec6c..e8dad19903 100644 --- a/public/js/ff/intro/intro.js +++ b/public/js/ff/intro/intro.js @@ -6,9 +6,28 @@ * See the LICENSE file for details. */ -/** global: route_for_tour */ +/** global: routeForTour, routeStepsUri, routeForFinishedTour */ $(function () { "use strict"; //alert('show user intro for ' + route_for_tour); -}); \ No newline at end of file + $.getJSON(routeStepsUri).done(setupIntro) +}); + +function setupIntro(steps) { + + var intro = introJs(); + intro.setOptions({ + steps: steps, + exitOnEsc: true, + exitOnOverlayClick: true, + keyboardNavigation: true, + }); + intro.oncomplete(reportIntroFinished); + intro.onexit(reportIntroFinished); + intro.start(); +} + +function reportIntroFinished() { + $.post(routeForFinishedTour); +} \ No newline at end of file diff --git a/resources/lang/en_US/intro.php b/resources/lang/en_US/intro.php new file mode 100644 index 0000000000..fce1d669de --- /dev/null +++ b/resources/lang/en_US/intro.php @@ -0,0 +1,18 @@ + 'Welcome to the index page of Firefly III. Please take the time to walk through this intro to get a feeling of how Firefly III works.', + 'index_accounts-chart' => 'This chart shows the current balance of your asset accounts. You can select the accounts visible here in your preferences.', + 'index_box_out_holder' => 'This little box and the boxes next to this one will give you a quick overview of your financial situation', + 'index_all_transactions' => 'These boxes will hold your most recent transactions.', + 'index_help' => 'If you ever need help with a page or a form, press this button.', + 'index_outro' => 'Most pages of Firefly III will start with a little tour like this one. Please contact me when you have questions or comments. Enjoy!', + +]; \ No newline at end of file diff --git a/resources/views/index.twig b/resources/views/index.twig index fe9f935511..7d41d22695 100644 --- a/resources/views/index.twig +++ b/resources/views/index.twig @@ -56,48 +56,50 @@ {% endif %} {# TRANSACTIONS #} - {% for data in transactions %} -
+ + {{ trans('firefly.no_transactions_account', {name: data[1].name}) }} + +
+- - {{ trans('firefly.no_transactions_account', {name: data[1].name}) }} - -
-