x

Ideal practice for storing external settings in snippet/dashboard based apps?

With elements, it's trivial to store layout settings and communicate external settings back to an element. But how would one do so for a snippet.tpl or dashboard card app?

Things that come to mind are loading the app settings from an external server as a lightweight data format, or attempting to embed the settings in something persistent such as a dashboard card (if possible), but I was curious if there was an intended practice that I am missing.

As example, imagine an app that puts a social media link on every page that could be customized with position or text colors or so. Where does the app, ideally, store and retrieve the styling information?

1,911 Views
Message 1 of 7
Report
1 Best Answer

Best Answer

Great question @jacob_b!

Dashboard Card Apps are expected to be accompanied by a Webhook app in order to update UI component data associated with the respective card. The Webhook app subscribes to `dashboard.card.update` events. Valid events should trigger:

  • GET /v1/user/sites/{SITE_ID}/cards/{CARD_ID} --> Retrieve current state data for the dashboard card
  • Perform internal system requests to determine if the current state data for the dashboard card is out of date
  • If the data for the dashboard card does require an update, PATCH /v1/user/sites/{SITE_ID}/cards/{CARD_ID}

Once data for a dashboard card has been updated via the API, per the above instructions, Weebly caches that data and will not fire another `dashboard.card.update` webhook event until the user has logged out/logged back in, or once they have closed the takeover displayed when a user clicks the "header" of the dashboard card to engage the optional management UI your app provides.

Dashboard Card Apps optionally can include a link property to a URL (must be employ `https` scheme) for content to display in a takeover when the user clicks the header of the card. This URL property can include a JWT token that, once decoded and verified, can be used to lookup contextual information for the respective user/site.

Snippet apps would need to be "managed" from within the "My Apps" section of the respective site, and the code contained within the snippet would need to be dynamic to handle updating based upon the settings defined/configured by the user. This would mean any backend/service code that supports your snippet app would need to accept cross-origin AJAX requests in order to retrieve the respective settings/configs.

Does this help answer your question?

View Best Answer >

1,879 Views
Message 2 of 7
Report
6 REPLIES 6

Best Answer

Great question @jacob_b!

Dashboard Card Apps are expected to be accompanied by a Webhook app in order to update UI component data associated with the respective card. The Webhook app subscribes to `dashboard.card.update` events. Valid events should trigger:

  • GET /v1/user/sites/{SITE_ID}/cards/{CARD_ID} --> Retrieve current state data for the dashboard card
  • Perform internal system requests to determine if the current state data for the dashboard card is out of date
  • If the data for the dashboard card does require an update, PATCH /v1/user/sites/{SITE_ID}/cards/{CARD_ID}

Once data for a dashboard card has been updated via the API, per the above instructions, Weebly caches that data and will not fire another `dashboard.card.update` webhook event until the user has logged out/logged back in, or once they have closed the takeover displayed when a user clicks the "header" of the dashboard card to engage the optional management UI your app provides.

Dashboard Card Apps optionally can include a link property to a URL (must be employ `https` scheme) for content to display in a takeover when the user clicks the header of the card. This URL property can include a JWT token that, once decoded and verified, can be used to lookup contextual information for the respective user/site.

Snippet apps would need to be "managed" from within the "My Apps" section of the respective site, and the code contained within the snippet would need to be dynamic to handle updating based upon the settings defined/configured by the user. This would mean any backend/service code that supports your snippet app would need to accept cross-origin AJAX requests in order to retrieve the respective settings/configs.

Does this help answer your question?

1,880 Views
Message 2 of 7
Report

It does, yes, thank you so much! And lastly for the last part ("code contained within the snippet would need to be dynamic to handle updating based upon the settings defined/configured by the user"), to my understanding it is not possible to dynamically reference the `site_id` during runtime, is there?

Example: User loads coolsite.com which has a snippet.tpl which runs a <script> tag. Though the <script> tag knows the host etc, it does not have any contextual reference for the Weebly site_id or user_id of the owner of the website.

1,867 Views
Message 3 of 7
Report

Hey @jacob_b

I don't think there is a native way to achieve this, but since site administrators must "install" the app (containing the snippet), you can use this to your advantage.

During installation, you are provided the `user_id`, `site_id` and know which app, and you could have a worker which looks up the site domain in the background.

Since you can include JavaScript in snippets as part of <script> tags, you could have that JS make a request to your service that contains the `location` (from the Web API), where you could perform the lookup against the domain.

And since <script> tags are blocking, you could perform the above action in one <script> tag, and then have a subsequent <script> tag that consumes that information to dynamically render any output or perform any contextualized actions.

Does this make sense? If not, perhaps I could write up some sample code and share.

1,862 Views
Message 4 of 7
Report

Funny, I actually had originally done exactly that! A lookup against the domain : ) I just wanted to be sure I wasn't adding in an external depency and layer without reason, good to know I wasn't doing something dumb, then.

Thank you so much for this level of detailed support and offer to draft some code, I really appreciate it.

1,855 Views
Message 5 of 7
Report

My pleasure @jacob_b

Please do keep me posted and let me know how things proceed, or if you have any other developer questions!

Smiley Very Happy

1,832 Views
Message 6 of 7
Report



I own a Note 8, the app was working fine with my phone running Android Nougat. However as I updated to latest Android Oreo (8.0) today whenever I am opening the app it only loads a blank white screen on the start up and crashes after a while automatically. How do I fix it??

https://tutuhelperx.com https://tutuappapk.vip https://emus4u.co

1,618 Views
Message 7 of 7
Report