mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Improve code for intro texts.
This commit is contained in:
parent
d79008495a
commit
f2d388f742
@ -69,6 +69,9 @@ class Controller extends BaseController
|
||||
if (auth()->check()) {
|
||||
$route = Route::currentRouteName();
|
||||
$originalRoute = $route;
|
||||
|
||||
// TODO get parameters from route?
|
||||
|
||||
$route = str_replace('.', '_', $route);
|
||||
$key = 'shown_demo_' . $route;
|
||||
$config = config('intro.' . $route);
|
||||
|
@ -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;
|
||||
|
||||
// point to HTML element when not an intro or outro:
|
||||
if (!in_array($key, ['intro', 'outro'])) {
|
||||
$currentStep['element'] = $options['selector'];
|
||||
$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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
126
config/intro.php
126
config/intro.php
@ -14,22 +14,126 @@ declare(strict_types=1);
|
||||
*/
|
||||
|
||||
return [
|
||||
// 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' => [],
|
||||
'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' => [],
|
||||
'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' => [],
|
||||
],
|
||||
|
||||
];
|
@ -21,7 +21,7 @@ function setupIntro(steps) {
|
||||
steps: steps,
|
||||
exitOnEsc: true,
|
||||
exitOnOverlayClick: true,
|
||||
keyboardNavigation: true,
|
||||
keyboardNavigation: true
|
||||
});
|
||||
intro.oncomplete(reportIntroFinished);
|
||||
intro.onexit(reportIntroFinished);
|
||||
|
@ -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%;"> </th>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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']);
|
||||
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user