From 62991a1a94ec8b949f3046bb5ae1380cccae40af Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 14 Feb 2024 11:08:26 +1100 Subject: [PATCH] FEATURE: backlink to site Introduce two configuration attributes `back_to_site_link_text` and `back_to_site_link_path`. It is used to display the backlink to the original site. --- README.md | 4 ++++ .../app/components/back-to-site-link.js | 9 +++++++++ client-app/app/controllers/index.js | 10 ++++++++++ client-app/app/styles/app.css | 5 +++++ .../components/back-to-site-link.hbs | 7 +++++++ client-app/app/templates/index.hbs | 4 ++++ .../components/back-to-site-link-test.js | 20 +++++++++++++++++++ lib/logster/configuration.rb | 2 ++ lib/logster/middleware/viewer.rb | 6 ++++++ 9 files changed, 67 insertions(+) create mode 100644 client-app/app/components/back-to-site-link.js create mode 100644 client-app/app/templates/components/back-to-site-link.hbs create mode 100644 client-app/tests/integration/components/back-to-site-link-test.js diff --git a/README.md b/README.md index 892a0447..471b84c6 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,10 @@ Logster can be configured using `Logster.config`: - `Logster.config.gems_dir` : The value of this config is `Gem.dir + "/gems/"` by default. You probably don't need to change this config, but it's available in case your app gems are installed in a different directory. An example where this config is needed is Logster [demo site](http://logster.info/logs/): [https://github.com/discourse/logster/blob/master/website/sample.rb#L77](https://github.com/discourse/logster/blob/master/website/sample.rb#L77). +- `Logster.config.back_to_site_link_path` : Path for the backlink to site. + +- `Logster.config.back_to_site_link_text` : Text for the backlink to site. + ### Tracking Error Rate Logster allows you to register a callback when the rate of errors has exceeded diff --git a/client-app/app/components/back-to-site-link.js b/client-app/app/components/back-to-site-link.js new file mode 100644 index 00000000..1eef261c --- /dev/null +++ b/client-app/app/components/back-to-site-link.js @@ -0,0 +1,9 @@ +import Component from "@ember/component"; +import { computed } from "@ember/object"; + +export default class BackToSiteLink extends Component { + @computed("attrs.text", "attrs.path") + get shouldDisplay() { + return this.text && this.path; + } +} diff --git a/client-app/app/controllers/index.js b/client-app/app/controllers/index.js index e426eeec..81edfe3a 100644 --- a/client-app/app/controllers/index.js +++ b/client-app/app/controllers/index.js @@ -29,6 +29,16 @@ export default class IndexController extends Controller { return Preload.get("patterns_enabled"); } + @computed + get backToSiteLinkText() { + return Preload.get("back_to_site_link_text"); + } + + @computed + get backToSiteLinkPath() { + return Preload.get("back_to_site_link_path"); + } + get actionsInMenu() { return ( /mobile/i.test(navigator.userAgent) && !/iPad/.test(navigator.userAgent) diff --git a/client-app/app/styles/app.css b/client-app/app/styles/app.css index 4798fe15..6d108893 100644 --- a/client-app/app/styles/app.css +++ b/client-app/app/styles/app.css @@ -278,6 +278,11 @@ tbody tr { overflow: auto; } +#back-to-site-panel { + padding: 10px; + background-color: #f1f1f1; +} + .message-info { position: absolute; border-bottom: 1px solid #ddd; diff --git a/client-app/app/templates/components/back-to-site-link.hbs b/client-app/app/templates/components/back-to-site-link.hbs new file mode 100644 index 00000000..bc514781 --- /dev/null +++ b/client-app/app/templates/components/back-to-site-link.hbs @@ -0,0 +1,7 @@ +{{#if this.shouldDisplay}} +
+ + {{@text}} + +
+{{/if}} \ No newline at end of file diff --git a/client-app/app/templates/index.hbs b/client-app/app/templates/index.hbs index 1ae24aed..10f12da6 100644 --- a/client-app/app/templates/index.hbs +++ b/client-app/app/templates/index.hbs @@ -1,4 +1,8 @@
+
{{#if this.model.moreBefore}}
diff --git a/client-app/tests/integration/components/back-to-site-link-test.js b/client-app/tests/integration/components/back-to-site-link-test.js new file mode 100644 index 00000000..6a2c90ed --- /dev/null +++ b/client-app/tests/integration/components/back-to-site-link-test.js @@ -0,0 +1,20 @@ +import { module, test } from "qunit"; +import { setupRenderingTest } from "ember-qunit"; +import { render } from "@ember/test-helpers"; +import hbs from "htmlbars-inline-precompile"; + +module("Integration | Component | back-to-site-link", function (hooks) { + setupRenderingTest(hooks); + + test("With path and text paremeter", async function (assert) { + await render(hbs``); + assert.dom("#back-to-site-panel a").exists("It shows back link to site"); + }); + + test("Without required paremeters", async function (assert) { + await render(hbs``); + assert + .dom("#back-to-site-panel a") + .doesNotExist("It shows back link to site"); + }); +}); diff --git a/lib/logster/configuration.rb b/lib/logster/configuration.rb index d790ef47..83eb8db8 100644 --- a/lib/logster/configuration.rb +++ b/lib/logster/configuration.rb @@ -20,6 +20,8 @@ class Configuration :max_env_count_per_message, :maximum_message_length, :use_full_hostname, + :back_to_site_link_text, + :back_to_site_link_path, ) attr_writer :subdirectory diff --git a/lib/logster/middleware/viewer.rb b/lib/logster/middleware/viewer.rb index 4b2deaf0..7736f823 100644 --- a/lib/logster/middleware/viewer.rb +++ b/lib/logster/middleware/viewer.rb @@ -335,6 +335,12 @@ def preloaded_data preload.merge!(gems_dir: gems_dir, backtrace_links_enabled: backtrace_links_enabled) preload.merge!(preload_backtrace_data) if backtrace_links_enabled + if Logster.config.back_to_site_link_text && Logster.config.back_to_site_link_path + preload.merge!( + back_to_site_link_text: Logster.config.back_to_site_link_text, + back_to_site_link_path: Logster.config.back_to_site_link_path, + ) + end preload end