glanceapp / glance

A self-hosted dashboard that puts all your feeds in one place
GNU Affero General Public License v3.0
8.56k stars 297 forks source link

[Feature Request] - Reusable widgets. #233

Closed moonstar-x closed 1 month ago

moonstar-x commented 1 month ago

Hi, thanks for this brilliant project, I love it!

In my own instance I'm looking to have multiple pages, and some of them share the same widgets across multiple pages.

Currently I would have to copy-paste the widgets in each page's definition but it can be a bit difficult to update them in the future since I would have to make changes everywhere I use them.

It'd be cool if I could define widgets outside the pages definition so that I could reference them instead. An example of what a configuration file would look like:

widgets:
  reusable-clock:
    type: clock
    timezones:
      - timezone: America/Los_Angeles
        label: Los Angeles
      - timezone: America/New_York
        label: New York

pages:
  - name: Page 1
    columns:
      - size: full
        widgets:
          - type: reference
            key: reusable-clock
  - name: Page 2
    columns:
      - size: full
        widgets:
          - type: reference
            key: reusable-clock

Thanks, let me know what you think, if I have some free time off work I could probably cook up a PR but my Go skills are a bit rusty. 😄

svilenmarkov commented 1 month ago

Thanks for the kind words!

You can already do this using YAML anchors, which you can read more about here and here.

Here's a slightly modified version of the example you provided that uses them:

widgets:
  - &reusable-clock
    type: clock
    timezones:
      - timezone: America/Los_Angeles
        label: Los Angeles
      - timezone: America/New_York
        label: New York

pages:
  - name: Page 1
    columns:
      - size: full
        widgets:
          - <<: *reusable-clock
  - name: Page 2
    columns:
      - size: full
        widgets:
          - <<: *reusable-clock
moonstar-x commented 1 month ago

Oh wow thank you. I remember seeing something about that in your documentation but I didn't think it could be used like that.

Thanks for your help!