Replies: 4 comments 5 replies
-
@tompipe, thanks for raising this. Thinking through the various options, that immediately come to mind... 1. Why not make a custom data-source? (e.g. devil's advocate 👿) You know exactly what you need. It'll save on the overhead - saves making a HTTP request, saves parsing JSON. Could it be coded directly with a custom data-source? and if the code is only available in a controller, (for whatever reasons), it is possible to extract or refactor the logic? 2. Amend JSON data-source configuration. Which I think is what you're suggesting? Adding a field to explicitly state whether it's a HTTP request or local filesystem. Also I need to consider backwards-compatibility. I already feel there are too many configuration options for this data-source, (same with CSV and XML ones). I'm least keen on this idea. 3. Amend JSON data-source code/logic. I could make an assumption about intent of the URL input. e.g. if the URL starts with 4. Placeholder tokens? Getting a bit more leftfield. I could check the URL string for tokens such as Hmmm, ideas, ideas. 🤔 My preferred option is the first, as it reduced on the extra HTTP request, and that I don't need to make any code changes. 😆 Totally open to any other suggestions. |
Beta Was this translation helpful? Give feedback.
-
I'll admit that, like @tompipe, my immediate thought was to create a local webapi to return the JSON... Primarily because I have done such a thing many times, and knew exactly how to get it up and running in minutes. Also, I was able to create a simple little model to return the right format of data, and figured it would be easy to create other JSON datasources using the same little model, and a similar api function format. My code, in case you are curious:
However, considering @leekelleher 's very valid point about unnecessary http requests... I figured I'd try his suggestion of just making the custom DataSource directly. Using the simple TimeZones example provided, I was able to quickly get it mocked up and the Contentment DataListItem model is basically the same as the one I had created for my webapi. The only issue I came across immediately is that UmbracoApiControllers have I freely admit that I am still VERY fuzzy on the Dependency Injection pattern for Umbraco 8, but I wonder if there is any way that those assets could be "pre-injected" or whatever for the I was able to fix it via the anti-pattern: Honestly, I think this is the right way to go... Look at this sexiness: Here is my "converted" code:
|
Beta Was this translation helpful? Give feedback.
-
Thanks, @leekelleher! Updated code here: https://gist.github.com/hfloyd/a6f3772420b7c1386175ae0797812300 |
Beta Was this translation helpful? Give feedback.
-
@leekelleher I was thinking if the json-file should be pickable with the filesystem picker used in the blockeditor. |
Beta Was this translation helpful? Give feedback.
-
As far as I can tell, the JsonDataListSource currently assumes any urls prefixed with http are to be downloaded with the WebClient,
umbraco-contentment/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs
Line 192 in 7a104c1
and all others are to be fetched from a file on the local file system.
umbraco-contentment/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs
Lines 206 to 209 in 7a104c1
In the event the json is to be sourced from an api controller running on the same umbraco instance, then the url entered into the contentment editor needs to be an absolute url starting with http, which works perfectly of course.
However, in cases where the codebase is synced between different environments and the url changes, then this setting must be manually updated with the new environments url. Whilst not a showstopper of course, it's just something which is easily overlooked.
Perhaps a toggle option could be added, giving the choice of whether a relative path is to be fetched via http or from the file system?
Thought I'd log the suggestion and get your thoughts before I make a PR when I next have a free moment.
Beta Was this translation helpful? Give feedback.
All reactions