mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-08 23:24:07 -06:00
Option to re-enable intro boxes.
This commit is contained in:
parent
456dd39ec4
commit
f16a186faf
@ -30,6 +30,8 @@ class Help implements HelpInterface
|
||||
/** @var string */
|
||||
protected $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36';
|
||||
|
||||
const CACHEKEY = 'help_%s_%s';
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
@ -38,7 +40,7 @@ class Help implements HelpInterface
|
||||
*/
|
||||
public function getFromCache(string $route, string $language): string
|
||||
{
|
||||
$line = sprintf('help.%s.%s', $route, $language);
|
||||
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||
|
||||
return Cache::get($line);
|
||||
}
|
||||
@ -64,12 +66,12 @@ class Help implements HelpInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
Log::debug(sprintf('Status code is %d', $result->status_code));
|
||||
|
||||
if ($result->status_code === 200) {
|
||||
$content = trim($result->body);
|
||||
}
|
||||
|
||||
if (strlen($content) > 0) {
|
||||
Log::debug('Content is longer than zero. Expect something.');
|
||||
$converter = new CommonMarkConverter();
|
||||
@ -98,7 +100,7 @@ class Help implements HelpInterface
|
||||
*/
|
||||
public function inCache(string $route, string $language): bool
|
||||
{
|
||||
$line = sprintf('help.%s.%s', $route, $language);
|
||||
$line = sprintf(self::CACHEKEY, $route, $language);
|
||||
$result = Cache::has($line);
|
||||
if ($result) {
|
||||
Log::debug(sprintf('Cache has this entry: %s', 'help.' . $route . '.' . $language));
|
||||
@ -120,7 +122,7 @@ class Help implements HelpInterface
|
||||
*/
|
||||
public function putInCache(string $route, string $language, string $content)
|
||||
{
|
||||
$key = sprintf('help.%s.%s', $route, $language);
|
||||
$key = sprintf(self::CACHEKEY, $route, $language);
|
||||
if (strlen($content) > 0) {
|
||||
Log::debug(sprintf('Will store entry in cache: %s', $key));
|
||||
Cache::put($key, $content, 10080); // a week.
|
||||
|
@ -25,62 +25,95 @@ use Response;
|
||||
*/
|
||||
class HelpController extends Controller
|
||||
{
|
||||
|
||||
/** @var HelpInterface */
|
||||
private $help;
|
||||
|
||||
/**
|
||||
* HelpController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->help = app(HelpInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HelpInterface $help
|
||||
* @param $route
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(HelpInterface $help, string $route)
|
||||
public function show(string $route)
|
||||
{
|
||||
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
$html = $this->getHelpText($route, $language);
|
||||
|
||||
if (!$help->hasRoute($route)) {
|
||||
return Response::json(['html' => $html]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getHelpText(string $route, string $language): string
|
||||
{
|
||||
// get language and default variables.
|
||||
|
||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
|
||||
// if no such route, log error and return default text.
|
||||
if (!$this->help->hasRoute($route)) {
|
||||
Log::error('No such route: ' . $route);
|
||||
|
||||
return Response::json($content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
if ($help->inCache($route, $language)) {
|
||||
$content = $help->getFromCache($route, $language);
|
||||
// help content may be cached:
|
||||
if ($this->help->inCache($route, $language)) {
|
||||
$content = $this->help->getFromCache($route, $language);
|
||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||
|
||||
return Response::json($content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
$content = $help->getFromGithub($route, $language);
|
||||
$notYourLanguage = '<p><em>' . strval(trans('firefly.help_may_not_be_your_language')) . '</em></p>';
|
||||
// get help content from Github:
|
||||
$content = $this->help->getFromGithub($route, $language);
|
||||
|
||||
// get backup language content (try English):
|
||||
// content will have 0 length when Github failed. Try en_US when it does:
|
||||
if (strlen($content) === 0) {
|
||||
$language = 'en_US';
|
||||
if ($help->inCache($route, $language)) {
|
||||
|
||||
// also check cache first:
|
||||
if ($this->help->inCache($route, $language)) {
|
||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||
$content = $notYourLanguage . $help->getFromCache($route, $language);
|
||||
}
|
||||
if (!$help->inCache($route, $language)) {
|
||||
$content = trim($notYourLanguage . $help->getFromGithub($route, $language));
|
||||
$content = $this->help->getFromCache($route, $language);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
$content = $this->help->getFromGithub($route, $language);
|
||||
|
||||
}
|
||||
|
||||
if ($content === $notYourLanguage) {
|
||||
$content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
// help still empty?
|
||||
if (strlen($content) !== 0) {
|
||||
$this->help->putInCache($route, $language, $content);
|
||||
|
||||
return $content;
|
||||
|
||||
}
|
||||
|
||||
$help->putInCache($route, $language, $content);
|
||||
|
||||
return Response::json($content);
|
||||
|
||||
return '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,6 +69,23 @@ class IntroController
|
||||
|
||||
return in_array('outro', $keys);
|
||||
}
|
||||
/**
|
||||
* @param string $route
|
||||
* @param string $specialPage
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function postEnable(string $route, string $specialPage = '')
|
||||
{
|
||||
$key = 'shown_demo_' . $route;
|
||||
if ($specialPage !== '') {
|
||||
$key .= '_' . $specialPage;
|
||||
}
|
||||
Log::debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
Preferences::set($key, false);
|
||||
|
||||
return Response::json(['message' => trans('firefly.intro_boxes_after_refresh')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
@ -82,8 +99,8 @@ class IntroController
|
||||
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);
|
||||
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
Preferences::set($key, true);
|
||||
|
||||
return Response::json(['result' => sprintf('Reported demo watched for route "%s".', $route)]);
|
||||
}
|
||||
|
@ -11,27 +11,40 @@
|
||||
$(function () {
|
||||
"use strict";
|
||||
$('#help').click(showHelp);
|
||||
$(function () {
|
||||
|
||||
//$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
});
|
||||
|
||||
function showHelp(e) {
|
||||
"use strict";
|
||||
var target = $(e.target);
|
||||
var route = target.data('route');
|
||||
//
|
||||
var specialPage = target.data('extra');
|
||||
|
||||
if (typeof specialPage === 'undefined') {
|
||||
specialPage = '';
|
||||
}
|
||||
$('#helpBody').html('<i class="fa fa-refresh fa-spin"></i>');
|
||||
$('#helpTitle').html('Please hold...');
|
||||
|
||||
$('#helpModal').modal('show');
|
||||
$('#helpTitle').html('Help for this page');
|
||||
$.getJSON('help/' + encodeURI(route)).done(function (data) {
|
||||
$('#helpBody').html(data);
|
||||
$('#helpBody').html(data.html);
|
||||
}).fail(function () {
|
||||
$('#helpBody').html('<p class="text-danger">No help text could be found.</p>');
|
||||
$('#helpTitle').html('Apologies');
|
||||
});
|
||||
$('#reenableGuidance').unbind('click').click(function () {
|
||||
enableGuidance(route, specialPage);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function enableGuidance(route, specialPage) {
|
||||
$.post('json/intro/enable/' + route + '/' + specialPage).done(function (data) {
|
||||
alert(data.message);
|
||||
}).fail(function () {
|
||||
alert('Could not re-enable introduction.');
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,8 @@ return [
|
||||
'user_id_is' => 'Your user id is <strong>:user</strong>',
|
||||
'field_supports_markdown' => 'This field supports <a href="https://en.support.wordpress.com/markdown-quick-reference/">Markdown</a>.',
|
||||
'need_more_help' => 'If you need more help using Firefly III, please <a href="https://github.com/firefly-iii/firefly-iii/issues">open a ticket on Github</a>.',
|
||||
'reenable_intro_text' => 'You can also reenable <a href="#" id="reenableGuidance">the introduction guidance</a>.',
|
||||
'intro_boxes_after_refresh' => 'The introduction boxes will reappear when you refresh the page.',
|
||||
'nothing_to_display' => 'There are no transactions to show you',
|
||||
'show_all_no_filter' => 'Show all transactions without grouping them by date.',
|
||||
'expenses_by_category' => 'Expenses by category',
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
<header class="main-header">
|
||||
|
||||
<!-- Logo -->
|
||||
{# Logo #}
|
||||
<a href="{{ route('index') }}" class="logo">
|
||||
<!-- mini logo for sidebar mini 50x50 pixels -->
|
||||
<span class="logo-mini">FF</span>
|
||||
@ -65,7 +65,7 @@
|
||||
<ul class="nav navbar-nav">
|
||||
|
||||
<li class="hidden-sm hidden-xs">
|
||||
<a href="#" id="help" data-route="{{ original_route_name }}">
|
||||
<a href="#" id="help" data-route="{{ original_route_name }}" data-extra="{{ what|default("") }}">
|
||||
<i class="fa fa-question-circle" data-route="{{ original_route_name }}"></i>
|
||||
</a>
|
||||
</li>
|
||||
@ -168,6 +168,9 @@
|
||||
<div class="modal-footer">
|
||||
<small class="pull-left">
|
||||
{{ 'need_more_help'|_ }}
|
||||
</small><br />
|
||||
<small class="pull-left">
|
||||
{{ trans('firefly.reenable_intro_text')|raw }}
|
||||
</small>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button>
|
||||
</div>
|
||||
|
@ -452,6 +452,7 @@ Route::group(
|
||||
// intro things:
|
||||
Route::get('intro/{route}/{specificPage?}', ['uses' => 'Json\IntroController@getIntroSteps', 'as' => 'intro']);
|
||||
Route::post('intro/finished/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postFinished', 'as' => 'intro.finished']);
|
||||
Route::post('intro/enable/{route}/{specificPage?}', ['uses' => 'Json\IntroController@postEnable', 'as' => 'intro.enable']);
|
||||
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user