-
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Use JS modules for client URL routing
- Loading branch information
Showing
10 changed files
with
114 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import URLs from "./modules/urls.mjs" | ||
|
||
window.URLs = URLs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default class URLs { | ||
constructor(serverUrls) { | ||
this.urls = serverUrls; | ||
} | ||
|
||
/** | ||
* Returns the URL to the requested resource. | ||
* | ||
* @param {String} urlName The URL name, as specified by the server. | ||
* @param {String|Object} params If a string, the map id, otherwise the parameters passed to the URL template. | ||
* @returns {String} The URL that has been built. | ||
*/ | ||
get(urlName, params) { | ||
if (typeof params != 'object') | ||
params = { map_id: params }; | ||
|
||
if (typeof this[urlName] === "function") | ||
return this[urlName](params); | ||
|
||
if (this.urls.hasOwnProperty(urlName)) { | ||
console.log("urls", this.urls, urlName, params); | ||
return L.Util.template(this.urls[urlName], params); | ||
} else { | ||
throw `Unable to find a URL for route ${urlName}`; | ||
} | ||
} | ||
|
||
// Update if map_id is passed, create otherwise. | ||
map_save({ map_id }) { | ||
if (map_id) | ||
return this.get("map_update", map_id); | ||
return this.get("map_create"); | ||
} | ||
|
||
// Update the layer if pk is passed, create otherwise. | ||
datalayer_save({ map_id, pk }) { | ||
if (pk) | ||
return this.get( | ||
"datalayer_update", | ||
{ map_id: map_id, pk: pk } | ||
); | ||
return this.get("datalayer_create", map_id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{% load umap_tags %} | ||
<div id="{{ unique_id }}" class="map_fragment"></div> | ||
<!-- djlint:off --> | ||
<script type="text/javascript"> | ||
new L.U.Map("{{ unique_id }}", {{ map_settings|notag|safe }}) | ||
<script defer type="text/javascript"> | ||
window.addEventListener('load', (event) => { | ||
new L.U.Map("{{ unique_id }}", {{ map_settings|notag|safe }}) | ||
}); | ||
</script> | ||
<!-- djlint:on --> |
Oops, something went wrong.