Skip to content

Firefly III: a personal finances manager

New help thing.

James Cole48b062062940
diff --git a/app/Helpers/Help/Help.php b/app/Helpers/Help/Help.php
index 2c7d83e219..2933b2a0ca 100644
--- a/app/Helpers/Help/Help.php
+++ b/app/Helpers/Help/Help.php
@@ -26,47 +26,39 @@ class Help implements HelpInterface
{
/**
- *
- * @param string $key
+ * @param string $route
+ * @param string $language
*
* @return string
*/
- public function getFromCache(string $key): string
+ public function getFromCache(string $route, string $language): string
{
- return Cache::get($key);
+ return Cache::get('help.' . $route . '.' . $language);
}
/**
* @param string $language
* @param string $route
*
- * @return array
+ * @return string
*/
- public function getFromGithub(string $language, string $route): array
+ public function getFromGithub(string $language, string $route): string
{
- $uri = sprintf('https://raw.githubusercontent.com/JC5/firefly-iii-help/master/%s/%s.md', $language, $route);
- $routeIndex = str_replace('.', '-', $route);
- $title = trans('help.' . $routeIndex);
- $content = [
- 'text' => '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>',
- 'title' => $title,
- ];
-
-
- $result = Requests::get($uri);
-
+ $uri = sprintf('https://raw.githubusercontent.com/firefly-iii/help/master/%s/%s.md', $language, $route);
+ $content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
+ $result = Requests::get($uri);
if ($result->status_code === 200) {
- $content['text'] = $result->body;
+ $content = $result->body;
}
- if (strlen(trim($content['text'])) == 0) {
- $content['text'] = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
+ if (strlen(trim($content)) == 0) {
+ $content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
}
- $converter = new CommonMarkConverter();
- $content['text'] = $converter->convertToHtml($content['text']);
+ $converter = new CommonMarkConverter();
+ $content = $converter->convertToHtml($content);
return $content;
@@ -84,27 +76,26 @@ class Help implements HelpInterface
}
/**
- *
* @param string $route
+ * @param string $language
*
* @return bool
*/
- public function inCache(string $route):bool
+ public function inCache(string $route, string $language):bool
{
- return Cache::has('help.' . $route . '.title') && Cache::has('help.' . $route . '.text');
+ return Cache::has('help.' . $route . '.' . $language);
}
/**
*
* @param string $route
* @param string $language
- * @param array $content
+ * @param string $content
*
* @internal param $title
*/
- public function putInCache(string $route, string $language, array $content)
+ public function putInCache(string $route, string $language, string $content)
{
- Cache::put('help.' . $route . '.text.' . $language, $content['text'], 10080); // a week.
- Cache::put('help.' . $route . '.title.' . $language, $content['title'], 10080);
+ Cache::put('help.' . $route . '.' . $language, $content, 10080); // a week.
}
}
diff --git a/app/Helpers/Help/HelpInterface.php b/app/Helpers/Help/HelpInterface.php
index 28665be118..7356ba0ba2 100644
--- a/app/Helpers/Help/HelpInterface.php
+++ b/app/Helpers/Help/HelpInterface.php
@@ -21,19 +21,20 @@ interface HelpInterface
{
/**
- * @param string $key
+ * @param string $route
+ * @param string $language
*
* @return string
*/
- public function getFromCache(string $key): string;
+ public function getFromCache(string $route, string $language): string;
/**
* @param string $language
* @param string $route
*
- * @return array
+ * @return string
*/
- public function getFromGithub(string $language, string $route):array;
+ public function getFromGithub(string $language, string $route):string;
/**
* @param string $route
@@ -44,15 +45,16 @@ interface HelpInterface
/**
* @param string $route
+ * @param string $language
*
* @return bool
*/
- public function inCache(string $route): bool;
+ public function inCache(string $route, string $language ): bool;
/**
* @param string $route
* @param string $language
- * @param array $content
+ * @param string $content
*/
- public function putInCache(string $route, string $language, array $content);
+ public function putInCache(string $route, string $language, string $content);
}
diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php
index b813a4371e..4b56c6e89e 100644
--- a/app/Http/Controllers/HelpController.php
+++ b/app/Http/Controllers/HelpController.php
@@ -41,11 +41,9 @@ class HelpController extends Controller
*/
public function show(HelpInterface $help, string $route)
{
+
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
- $content = [
- 'text' => '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>',
- 'title' => 'Help',
- ];
+ $content = '<p>' . strval(trans('firefly.route_has_no_help')) . '</p>';
if (!$help->hasRoute($route)) {
Log::error('No such route: ' . $route);
@@ -53,11 +51,9 @@ class HelpController extends Controller
return Response::json($content);
}
- if ($help->inCache($route)) {
- $content = [
- 'text' => $help->getFromCache('help.' . $route . '.text.' . $language),
- 'title' => $help->getFromCache('help.' . $route . '.title.' . $language),
- ];
+ if ($help->inCache($route, $language)) {
+ $content = $help->getFromCache($route, $language);
+ Log::debug('Help text was in cache.');
return Response::json($content);
}
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 8afd02006f..08a1153e5d 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -164,36 +164,29 @@ class HomeController extends Controller
public function routes()
{
// these routes are not relevant for the help pages:
- $ignore = [
+ $ignore = ['login', 'registe', 'logout', 'two-fac', 'lost-two', 'confirm', 'resend', 'do_confirm', 'testFla', 'json.', 'piggy-banks.add',
+ 'piggy-banks.remove', 'preferences.', 'rules.rule.up', 'rules.rule.down', 'rules.rule-group.up', 'rules.rule-group.down', 'popup.report',
+ 'admin.users.domains.block-','import.json','help.'
];
$routes = Route::getRoutes();
+
+ echo '<pre>';
+
/** @var \Illuminate\Routing\Route $route */
foreach ($routes as $route) {
-
$name = $route->getName();
$methods = $route->getMethods();
- $search = [
- '{account}', '{what}', '{rule}', '{tj}', '{category}', '{budget}', '{code}', '{date}', '{attachment}', '{bill}', '{limitrepetition}',
- '{currency}', '{jobKey}', '{piggyBank}', '{ruleGroup}', '{rule}', '{route}', '{unfinishedJournal}',
- '{reportType}', '{start_date}', '{end_date}', '{accountList}', '{tag}', '{journalList}',
-
- ];
- $replace = [1, 'asset', 1, 1, 1, 1, 'abc', '2016-01-01', 1, 1, 1, 1, 1, 1, 1, 1, 'index', 1,
- 'default', '20160101', '20160131', '1,2', 1, '1,2',
- ];
- if (count($search) != count($replace)) {
- echo 'count';
- exit;
- }
- $url = str_replace($search, $replace, $route->getUri());
- if (!is_null($name) && in_array('GET', $methods) && !$this->startsWithAny($ignore, $name)) {
- echo '<a href="/' . $url . '" title="' . $name . '">' . $name . '</a><br>' . "\n";
+ if (!is_null($name) && strlen($name) > 0 && in_array('GET', $methods) && !$this->startsWithAny($ignore, $name)) {
+ echo sprintf('touch %s.md', $name)."\n";
}
}
+ echo '</pre>';
+
+ echo '<hr />';
- return '<hr>';
+ return '&nbsp;';
}
/**
diff --git a/public/js/ff/help.js b/public/js/ff/help.js
index e5d8fc59ae..1d6e14e477 100644
--- a/public/js/ff/help.js
+++ b/public/js/ff/help.js
@@ -16,12 +16,12 @@ function showHelp(e) {
$('#helpTitle').html('Please hold...');
$('#helpModal').modal('show');
+ $('#helpTitle').html('Help for this page');
$.getJSON('help/' + encodeURI(route)).done(function (data) {
- $('#helpBody').html(data.text);
- $('#helpTitle').html(data.title);
+ $('#helpBody').html(data);
}).fail(function () {
$('#helpBody').html('<p class="text-danger">No help text could be found.</p>');
- $('#helpTitle').html('Sorry...');
+ $('#helpTitle').html('Apologies');
});
return false;
}