andreasgerstmayr / fava-dashboards

Custom Dashboards for Beancount in Fava
MIT License
143 stars 17 forks source link

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

Closed ileodo closed 7 months ago

ileodo commented 8 months ago

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

Thanks

andreasgerstmayr commented 8 months ago

hi @ileodo, yes that's possible, take a look at the example dashboard: https://github.com/andreasgerstmayr/fava-dashboards/blob/4d6340babb69ce77722cdcafbb17262d25a08fea/example/dashboards.yaml#L592

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

ileodo commented 7 months ago

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 commented 7 months ago

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

mattmattmatt commented 3 months ago

@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 commented 3 months ago

@mattmattmatt thanks for the snippet!

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