Skip to content

Commit

Permalink
FEATURE: backlink to site (#220)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lis2 committed Feb 14, 2024
1 parent b726b74 commit c9becc5
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions 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;
}
}
10 changes: 10 additions & 0 deletions client-app/app/controllers/index.js
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions client-app/app/styles/app.css
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions client-app/app/templates/components/back-to-site-link.hbs
@@ -0,0 +1,8 @@
{{#if this.shouldDisplay}}
<div id="back-to-site-panel">
<a href={{@path}} rel="noopener noreferrer">
<FaIcon @icon="arrow-left" />
{{@text}}
</a>
</div>
{{/if}}
4 changes: 4 additions & 0 deletions client-app/app/templates/index.hbs
@@ -1,4 +1,8 @@
<div id="top-panel">
<BackToSiteLink
@path={{this.backToSiteLinkPath}}
@text={{this.backToSiteLinkText}}
/>
<div id="log-table">
{{#if this.model.moreBefore}}
<div {{on "click" this.showMoreBefore}} class="show-more">
Expand Down
1 change: 1 addition & 0 deletions client-app/config/icons.js
@@ -1,6 +1,7 @@
module.exports = function () {
return {
"free-solid-svg-icons": [
"arrow-left",
"check-square",
"trash-alt",
"ellipsis-h",
Expand Down
20 changes: 20 additions & 0 deletions 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`<BackToSiteLink @path="/admin" @text="back to site"/>`);
assert.dom("#back-to-site-panel a").exists("It shows back to site link");
});

test("Without required paremeters", async function (assert) {
await render(hbs`<BackToSiteLink />`);
assert
.dom("#back-to-site-panel a")
.doesNotExist("It does not show back link to site");
});
});
2 changes: 2 additions & 0 deletions lib/logster/configuration.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/logster/middleware/viewer.rb
Expand Up @@ -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

Expand Down

0 comments on commit c9becc5

Please sign in to comment.