diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index d6ffcfaee2..ed1835d9c9 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -23,6 +23,7 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; +use Log; use Route; use Session; use URL; @@ -49,40 +50,48 @@ class Controller extends BaseController */ public function __construct() { + // for transaction lists: View::share('hideBudgets', false); View::share('hideCategories', false); View::share('hideBills', false); View::share('hideTags', false); + + // is site a demo site? $isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data; View::share('IS_DEMO_SITE', $isDemoSite); View::share('DEMO_USERNAME', env('DEMO_USERNAME', '')); View::share('DEMO_PASSWORD', env('DEMO_PASSWORD', '')); - // translations: + $this->middleware( function ($request, $next) { + // translations for specific strings: $this->monthFormat = (string)trans('config.month'); $this->monthAndDayFormat = (string)trans('config.month_and_day'); $this->dateTimeFormat = (string)trans('config.date_time'); // get shown-intro-preference: if (auth()->check()) { - $route = Route::currentRouteName(); - $originalRoute = $route; + // some routes have a "what" parameter, which indicates a special page: + $specificPage = is_null(Route::current()->parameter('what')) ? '' : '_' . Route::current()->parameter('what'); + $page = str_replace('.', '_', Route::currentRouteName()); - // TODO get parameters from route? + // indicator if user has seen the help for this page ( + special page): + $key = 'shown_demo_' . $page . $specificPage; + // is there an intro for this route? + $intro = config('intro.' . $page); + $specialIntro = config('intro.' . $page . $specificPage); + $shownDemo = true; - $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; + // either must be array and either must be > 0 + if ((is_array($intro) || is_array($specialIntro)) && (count($intro) > 0 || count($specialIntro) > 0)) { + $shownDemo = Preferences::get($key, false)->data; + Log::debug(sprintf('Check if user has already seen intro with key "%s". Result is %d', $key, $shownDemo)); } + View::share('shownDemo', $shownDemo); - View::share('current_route_name', $route); - View::share('original_route_name', $originalRoute); + View::share('current_route_name', $page); + View::share('original_route_name', Route::currentRouteName()); } return $next($request); diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php index 7e92e24798..7361e8d535 100644 --- a/app/Http/Controllers/Json/IntroController.php +++ b/app/Http/Controllers/Json/IntroController.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Json; +use FireflyIII\Support\Facades\Preferences; +use Log; use Response; /** @@ -60,20 +62,27 @@ class IntroController { $routeKey = str_replace('.', '_', $route); $elements = config(sprintf('intro.%s', $routeKey)); - $keys = array_keys($elements); + if (!is_array($elements)) { + return false; + } + $keys = array_keys($elements); return in_array('outro', $keys); } /** * @param string $route + * @param string $specialPage * * @return \Illuminate\Http\JsonResponse */ - public function postFinished(string $route) + public function postFinished(string $route, string $specialPage = '') { $key = 'shown_demo_' . $route; - + if ($specialPage !== '') { + $key .= '_' . $specialPage; + } + Log::debug(sprintf('Going to mark the following route as doen: %s with special "%s" (%s)', $route, $specialPage, $key)); //Preferences::set($key, true); return Response::json(['result' => sprintf('Reported demo watched for route "%s".', $route)]); @@ -121,8 +130,7 @@ class IntroController $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']; + $currentStep = $options; // get the text: $currentStep['intro'] = trans('intro.' . $route . '_' . $specificPage . '_' . $key); diff --git a/config/intro.php b/config/intro.php index ded26a665a..b93343dfc8 100644 --- a/config/intro.php +++ b/config/intro.php @@ -15,7 +15,7 @@ declare(strict_types=1); return [ // index - 'index' => [ + 'index' => [ 'intro' => [], 'accounts-chart' => ['element' => '#accounts-chart'], 'box_out_holder' => ['element' => '#box_out_holder'], @@ -24,19 +24,19 @@ return [ 'outro' => [], ], // accounts: create - 'accounts_create' => [ + 'accounts_create' => [ 'intro' => [], 'iban' => ['element' => '#ffInput_iban'], ], // extra text for asset account creation. - 'accounts_create_asset' => [ + 'accounts_create_asset' => [ 'opening_balance' => ['element' => '#ffInput_openingBalance'], 'currency' => ['element' => '#ffInput_currency_id'], 'virtual' => ['element' => '#ffInput_virtualBalance'], ], // budgets: index - 'budgets_index' => [ + 'budgets_index' => [ 'intro' => [], 'set_budget' => ['element' => '#availableBar',], 'see_expenses_bar' => ['element' => '#spentBar'], @@ -47,54 +47,80 @@ return [ ], // tags: wait for upgrade // reports: index, default report, audit, budget, cat, tag - 'reports_index' => [ + 'reports_index' => [ + 'intro' => [], + 'inputReportType' => ['element' => '#inputReportType'], + 'inputAccountsSelect' => ['element' => '#inputAccountsSelect'], + 'inputDateRange' => ['element' => '#inputDateRange'], + 'extra-options-box' => ['element' => '#extra-options-box'], + ], + 'reports_report_default' => [ 'intro' => [], ], - 'reports_report_default' => [ - 'intro' => [], + 'reports_report_audit' => [ + 'intro' => [], + 'optionsBox' => ['element' => '#optionsBox'], ], - 'reports_report_audit' => [ - 'intro' => [], + 'reports_report_category' => [ + 'intro' => [], + 'pieCharts' => ['element' => '#pieCharts'], + 'incomeAndExpensesChart' => ['element' => '#incomeAndExpensesChart', 'position' => 'top'], + ], - 'reports_report_category' => [ - 'intro' => [], + 'reports_report_tag' => [ + 'intro' => [], + 'pieCharts' => ['element' => '#pieCharts'], + 'incomeAndExpensesChart' => ['element' => '#incomeAndExpensesChart', 'position' => 'top'], ], - 'reports_report_report' => [ - 'intro' => [], - ], - 'reports_report_budget' => [ - 'intro' => [], + 'reports_report_budget' => [ + 'intro' => [], + 'pieCharts' => ['element' => '#pieCharts'], + 'incomeAndExpensesChart' => ['element' => '#incomeAndExpensesChart', 'position' => 'top'], ], - // transactions: create - 'transactions_create' => [ + // transactions: create (also per type!) + 'transactions_create' => [ 'intro' => [], 'switch_box' => ['element' => '#switch-box'], 'ffInput_category' => ['element' => '#ffInput_category'], ], + 'transactions_create_withdrawal' => [ + 'ffInput_budget' => ['element' => '#ffInput_budget_id'], + 'currency_dropdown_amount' => ['element' => '#currency_dropdown_amount'], + ], + 'transactions_create_deposit' => [ + 'currency_dropdown_amount' => ['element' => '#currency_dropdown_amount'], + ], + 'transactions_create_transfer' => [ + 'ffInput_piggy_bank_id' => ['element' => '#ffInput_piggy_bank_id'], + ], + // piggies: index, create, show - 'piggy-banks_index' => [ + 'piggy-banks_index' => [ + 'intro' => [], + 'saved' => ['element' => '.piggySaved'], + 'button' => ['element' => '.piggyBar',], + 'accountStatus' => ['element' => '#accountStatus', 'position' => 'top'], + ], + 'piggy-banks_create' => [ 'intro' => [], ], - 'piggy-banks_create' => [ - 'intro' => [], - ], - 'piggy-banks_show' => [ + 'piggy-banks_show' => [ 'intro' => [], ], // bills: index, create, show - 'bills_index' => [ + 'bills_index' => [ 'intro' => [], ], - 'bills_create' => [ + 'bills_create' => [ 'intro' => [], ], - 'bills_show' => [ + 'bills_show' => [ 'intro' => [], ], // rules: index, create-rule, edit-rule - 'rules_index' => [ + 'rules_index' => [ 'intro' => [], 'new_rule_group' => ['element' => '#new_rule_group'], 'new_rule' => ['element' => '.new_rule'], @@ -103,36 +129,36 @@ return [ 'rule-triggers' => ['element' => '.rule-triggers'], 'outro' => [], ], - 'rules_create' => [ + 'rules_create' => [ 'intro' => [], ], - 'rules_edit' => [ + 'rules_edit' => [ 'intro' => [], ], // import: index, config-steps - 'import_index' => [ + 'import_index' => [ 'intro' => [], ], - 'import_configure' => [ + 'import_configure' => [ 'intro' => [], ], // export: index - 'export_index' => [ + 'export_index' => [ 'intro' => [], ], // preferences: index - 'preferences_index' => [ + 'preferences_index' => [ 'intro' => [], ], // currencies: index, create - 'currencies_index' => [ + 'currencies_index' => [ 'intro' => [], ], - 'currencies_create' => [ + 'currencies_create' => [ 'intro' => [], ], // admin: index - 'admin_index' => [ + 'admin_index' => [ 'intro' => [], ], diff --git a/public/js/ff/intro/intro.js b/public/js/ff/intro/intro.js index cc63d45370..e5949556ce 100644 --- a/public/js/ff/intro/intro.js +++ b/public/js/ff/intro/intro.js @@ -10,8 +10,9 @@ $(function () { "use strict"; - //alert('show user intro for ' + route_for_tour); - $.getJSON(routeStepsUri).done(setupIntro) + if(!forceDemoOff) { + $.getJSON(routeStepsUri).done(setupIntro) + } }); function setupIntro(steps) { diff --git a/resources/views/layout/default.twig b/resources/views/layout/default.twig index 9ac89dad44..887a4a9442 100644 --- a/resources/views/layout/default.twig +++ b/resources/views/layout/default.twig @@ -33,6 +33,9 @@ + {# favicons #} {% include('partials.favicons') %} @@ -185,7 +188,7 @@ diff --git a/resources/views/list/piggy-banks.twig b/resources/views/list/piggy-banks.twig index cee5a80dd1..bcd7d26ac7 100644 --- a/resources/views/list/piggy-banks.twig +++ b/resources/views/list/piggy-banks.twig @@ -34,7 +34,7 @@