Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Refer to the current fava filters (time, account, filter) in link field #24

Closed
ileodo opened this issue Oct 30, 2023 · 5 comments · Fixed by #41
Closed

Comments

@ileodo
Copy link
Contributor

ileodo commented Oct 30, 2023

as per above, is that possible to refer to the fava's current filters, including time, account and filter?

Thanks

@andreasgerstmayr
Copy link
Owner

hi @ileodo, yes that's possible, take a look at the example dashboard:

const time = new URLSearchParams(window.location.search).get("time") ?? "";

You can access the account and filter in the same way.

@ileodo
Copy link
Contributor Author

ileodo commented Nov 28, 2023

thanks @andreasgerstmayr, it would be great to just support a special variable name in the link filed which will be replaced with the time instead of manually do it in js.

@andreasgerstmayr
Copy link
Owner

I'd like to keep the extension as simple as possible, and don't plan to support this for now.

@andreasgerstmayr andreasgerstmayr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
@mattmattmatt
Copy link

@ileodo: Related to this, just wanted to share this snippet of code that makes the above request pretty easy to implement within the new utils configuration:

# dashboards.yml

utils:
  inline: |
    const linkReplacer = () => {
      const windowUrl = new URL(window.location.href);
      window.document.querySelectorAll('h2 a').forEach(function (el) {
        const linkUrl = new URL(el.href);
        linkUrl.searchParams.set('time', windowUrl.searchParams.get('time'));
        linkUrl.searchParams.set('conversion', windowUrl.searchParams.get('conversion'));
        el.href = linkUrl;
      });
    }

    linkReplacer();

This JS snippet runs after each page load, loops through all the dashboard's panel headlines, and updates their href with the current page's time and conversion parameters. It's easy to extend with other dynamic parts as well.

@andreasgerstmayr
Copy link
Owner

@mattmattmatt thanks for the snippet!

I've added a generic way to copy Fava's filter parameters to all links in #41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants