-
Notifications
You must be signed in to change notification settings - Fork 1k
Add user preferences support to iD editor via server-side rendering #6199
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
base: master
Are you sure you want to change the base?
Add user preferences support to iD editor via server-side rendering #6199
Conversation
app/assets/javascripts/id.js
Outdated
| window.OSM = window.OSM || {}; | ||
| window.OSM.userPreferences = userPreferences; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could probably better handled in method of the idContext object, instead of as a new global variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have now embedded a function in the idContext object to store and then consume user preferences
Just for clarity: this is not quite yet implemented in the current version of iD, but @Deeptanshu-sankhwar is working on it right now. This means that the code will only be needed to be merged once we're deploying the next release of iD which comes with that code (that PR than probably be replacing this one). But we thought it might be nice to put this out anyway for you to give it a look already. |
app/views/site/id.html.erb
Outdated
| data[:asset_map] = assets("iD").to_json | ||
|
|
||
| # Include user preferences for iD editor | ||
| if current_user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's probably not required to check for current_user as this page requires to be logged in to load, and the variable is already used on line 14.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tyrasd , I have removed the redundant check now
app/views/site/id.html.erb
Outdated
|
|
||
| # Include user preferences for iD editor | ||
| if current_user | ||
| user_preferences = current_user.preferences.each_with_object({}) do |pref, hash| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need all user preferences for iD? This could be a fair amount of data, such as lots of overpass turbo queries. How about only adding preferences that are relevant for iD?
It seems that all of these would come from one call of |
Add User Preferences Support to iD Editor
Summary
This PR implements server-side rendering of user preferences for the iD editor, making them accessible in the client-side JavaScript context.
Technical Changes
Server-side (
app/views/site/id.html.erb):{key => value})Client-side (
app/assets/javascripts/id.js):window.OSM.userPreferencesImplementation Details
current_user.preferences.each_with_object({})for efficient hash constructioncurrent_userexists (authenticated users)Use Case
This enables the iD editor to access user-specific preferences (such as display settings, editor configurations, etc.) that were previously only available through separate API calls, improving performance and reducing client-server round trips during editor initialization.
Testing
window.OSM.userPreferencesin browser console