-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix missing frontend dependencies for leaflet. #3128
Conversation
<script src="/static/lib/navbar/Leaflet.NavBar.js"></script> | ||
|
||
<link rel="stylesheet" href="/static/lib/measure/leaflet.measure.css" /> | ||
<script src="/static/lib/measure/leaflet.measure.js"></script> |
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.
Deleted these so it can be included from {% leaflet_js %} tags
.gitignore
Outdated
geonode/static/lib/css/bootstrap-tokenfield.css | ||
geonode/static/lib/js/assets.min.js | ||
geonode/static/lib/js/leaflet-plugins.min.js |
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.
Included to follow .gitignore pattern that minified js and css should not automatically be committed, because it will change for every grunt production
@@ -166,6 +151,7 @@ | |||
onAdd: function(map) { | |||
var img = L.DomUtil.create('img'); | |||
|
|||
// I'm not sure what is this logo supposed to be? | |||
img.src = '../static/img/logo.png'; |
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.
Maybe this is for geonode logo?
If that is the case, we can point to geonode logo's static url.
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.
As a gut check, I would have thought that it should be /static/geonode/img/logo.png
from ./geonode/static/geonode/img/logo.png
. I would personally play with the value and test to verify this, if I had time
if(L.Control.hasOwnProperty('opacitySlider')) { | ||
//adjust opacity | ||
var opacitySlider = new L.Control.opacitySlider(); | ||
map.addControl(opacitySlider); |
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.
Follow fullscreen plugin pattern. Only add when the plugin is resolved.
L.control.navbar().addTo(map); | ||
if(L.control.hasOwnProperty('navbar')){ | ||
//adjust info | ||
L.control.navbar().addTo(map); |
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.
Follow fullscreen plugin pattern. Only add when the plugin is resolved.
'css': 'lib/css/leaflet-measure.css', | ||
'js': 'lib/js/leaflet-measure.js', | ||
'auto-include': True, | ||
}, |
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.
Add these 3 plugins with each css and js when DEBUG_STATIC = True
'leaflet-plugins': { | ||
'js': 'lib/js/leaflet-plugins.min.js', | ||
'css': 'lib/css/leaflet-plugins.min.css', | ||
'auto-include': True, |
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.
Use minified plugins, when not in DEBUG_STATIC
@@ -27,6 +27,9 @@ | |||
"angular-leaflet-directive": "0.7.9", | |||
"zeroclipboard": "2.1.5", | |||
"leaflet-fullscreen": "https://github.com/Leaflet/Leaflet.fullscreen.git", | |||
"leaflet-opacity": "https://github.com/lizardtechblog/Leaflet.OpacityControls.git#master", | |||
"leaflet-navbar": "1.0.1", | |||
"leaflet-measure": "2.1.7", |
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.
Added leaflet plugins reference in bower.
This will install the plugin to .components when doing bower install
@@ -83,8 +83,9 @@ module.exports = function(grunt) { | |||
'jquery-tree-multiselect/dist/jquery.tree-multiselect.min.css', | |||
'bootstrap/dist/css/bootstrap.min.css', | |||
'leaflet-fullscreen/dist/leaflet.fullscreen.css', | |||
'leaflet-fullscreen/dist/[email protected]', | |||
'leaflet-fullscreen/dist/fullscreen.png', |
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.
Move fullscreen*.png to lib/img
@@ -100,8 +101,15 @@ module.exports = function(grunt) { | |||
dest: 'lib/img', | |||
src: [ | |||
'bootstrap/img/*.png', | |||
'select2*.png', 'select2-spinner.gif', | |||
'select2/select2*.png', | |||
'select2/select2*.gif', |
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.
Use proper select2 namespace/folder.
Coverage increased (+0.006%) to 46.098% when pulling 114d689a6c977c7fa6aaad80238dee2a67d0df38 on lucernae:fix_leaflet_view-upstream into d0f5d72 on GeoNode:master. |
'jquery-ui/ui/minified/jquery-ui.custom.min.js', | ||
'raty/lib/jquery.raty.js', | ||
'jquery-waypoints/waypoints.js', | ||
'jquery-ui/ui/jquery-ui.custom.js', |
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 need to change these, because it is what being referenced in base.html
when DEBUG_STATIC = True.
The developers probably need the unminified version for debugging.
}, { | ||
from: /(png|gif|jpg)+(\)|'\)|"\))/g, | ||
to: '$1\')' | ||
}] |
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 changed the pattern in the hope that it will be more readable and understandable.
I also had some issues with the previous pattern didn't replace the text properly for Leaflet.NavBar.css
'lib/css/leaflet.fullscreen.css', | ||
'lib/css/Leaflet.NavBar.css', | ||
'lib/css/leaflet-measure.css', | ||
'lib/css/Control.Opacity.css' |
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.
minified all used leaflet-plugins.
'lib/js/Leaflet.NavBar.js', | ||
'lib/js/leaflet-measure.js', | ||
'lib/js/Control.Opacity.js' | ||
] |
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.
minified all used leaflet-plugins.
@@ -278,6 +355,6 @@ module.exports = function(grunt) { | |||
grunt.registerTask('default', ['jshint', 'less:development', 'concat:bootstrap', 'copy', 'replace']); | |||
|
|||
// build production | |||
grunt.registerTask('production', ['jshint', 'less:production', 'concat:bootstrap', 'copy', 'cssmin', 'uglify' ]); | |||
grunt.registerTask('production', ['jshint', 'less:production', 'concat:bootstrap', 'copy', 'replace', 'cssmin', 'uglify' ]); |
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.
Include replace
task for production
task
Thanks @lucernae this is a good description. Usually we try to avoid the js third party source files like this opacity and measure js files as they can come using bower install. Though is good to ship them minified in the leaflet.plugins.min.js. |
In that case, I can exclude these 3rd party source files from commit and only include the minified version, is that ok? I also think that's a good idea, it was included in bower.json afterall. For the missing logo, if that's ok, I can set it to geonode url (@harts-boundless suggestion). |
+1! |
**Included to bower.json** * Leaflet opacity control plugin * Leaflet measure plugin * Leaflet navbar plugin **Modify gruntfile tasks** * Modify css url images regex pattern for replace task * Create another minified file for leaflet plugins * Refactor some js filename to match in what used in the template when DEBUG_STATIC is true * Add task replace for task production **Related changes** * Included images from library from grunt copy:development task * New minified js for assets.min.js and leaflet-plugins.min.js from production task * New minified css for assets.min.css and leaflet-plugins.min.css * Moved some pngs from lib/css folder to lib/img from the new replace task * Include Geonode Logo
114d689
to
473b7e7
Compare
It seems good to me. |
**Included to bower.json** * Leaflet opacity control plugin * Leaflet measure plugin * Leaflet navbar plugin **Modify gruntfile tasks** * Modify css url images regex pattern for replace task * Create another minified file for leaflet plugins * Refactor some js filename to match in what used in the template when DEBUG_STATIC is true * Add task replace for task production **Related changes** * Included images from library from grunt copy:development task * New minified js for assets.min.js and leaflet-plugins.min.js from production task * New minified css for assets.min.css and leaflet-plugins.min.css * Moved some pngs from lib/css folder to lib/img from the new replace task * Include Geonode Logo
Related with issue #3116.
@simod can you please review this, because I'm not too familiar with bower and gruntfile.
I tried to follow the existing pattern and code practice in Geonode's staticfiles, but you can comment on it if you see something is not right.
@afabiani you might want to review this too, because I saw you made latest changes in layer_leaflet_map.html, so you are probably more familiar in this.
Changelist
Included to bower.json
Modify gruntfile tasks
DEBUG_STATIC is true
Related changes
production task
Testing Environment
Django settings
Using DEBUG_STATIC = True
Using DEBUG_STATIC = False (default production environment)
Tested views
Listed here are the views that I check (manually) to see that css and js files were resolved correctly
Screenshots
Notes
There is also a missing logo at the bottom right. I'm not sure what logo is this. Maybe geonode logo?