Built a new routine for intro tours.

This commit is contained in:
James Cole
2017-07-16 07:35:08 +02:00
parent 09131e8c36
commit 58bfb35fa6
9 changed files with 185 additions and 44 deletions

View File

@@ -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);

View File

@@ -0,0 +1,67 @@
<?php
/**
* IntroController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Preferences;
use Response;
/**
* Class IntroController
*
* @package FireflyIII\Http\Controllers\Json
*/
class IntroController
{
/**
* @param string $route
*
* @return \Illuminate\Http\JsonResponse
*/
public function getIntroSteps(string $route)
{
$elements = config(sprintf('intro.%s', $route));
$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'] = '#' . $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)]);
}
}