wip(naming): replace "plugin" by "importer"

We are not ready yet to talk about plugins
This commit is contained in:
Yohan Boniface 2024-05-31 19:07:42 +02:00
parent 93a189497b
commit f5eea1fe3f
4 changed files with 17 additions and 18 deletions

View file

@ -259,7 +259,7 @@ UMAP_DEFAULT_SHARE_STATUS = None
UMAP_DEFAULT_EDIT_STATUS = None UMAP_DEFAULT_EDIT_STATUS = None
UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False UMAP_DEFAULT_FEATURES_HAVE_OWNERS = False
UMAP_HOME_FEED = "latest" UMAP_HOME_FEED = "latest"
UMAP_EXPERIMENTAL_PLUGINS = { UMAP_EXPERIMENTAL_IMPORTERS = {
# "geodatamine": {}, # "geodatamine": {},
# "communesfr": {}, # "communesfr": {},
# "presets": { # "presets": {

View file

@ -3,7 +3,7 @@ import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js' import { uMapAlert as Alert } from '../components/alerts/alert.js'
import Dialog from './ui/dialog.js' import Dialog from './ui/dialog.js'
const AVAILABLE_PLUGINS = ['geodatamine', 'communesfr', 'presets'] const AVAILABLE_IMPORTERS = ['geodatamine', 'communesfr', 'presets']
const TEMPLATE = ` const TEMPLATE = `
<h3><i class="icon icon-16 icon-upload"></i><span>${translate('Import data')}</span></h3> <h3><i class="icon icon-16 icon-upload"></i><span>${translate('Import data')}</span></h3>
@ -12,9 +12,9 @@ const TEMPLATE = `
<input type="url" placeholder="${translate('Provide an URL here')}" /> <input type="url" placeholder="${translate('Provide an URL here')}" />
<textarea placeholder="${translate('Paste your data here')}"></textarea> <textarea placeholder="${translate('Paste your data here')}"></textarea>
</div> </div>
<div class="plugins"> <div class="importers">
<h4>${translate('Import from:')}</h4> <h4>${translate('Import from:')}</h4>
<div class="button-bar by4" id="plugins"> <div class="button-bar by4" id="importers">
</div> </div>
</div> </div>
<label data-help="importFormats"> <label data-help="importFormats">
@ -40,16 +40,18 @@ export default class Importer {
constructor(map) { constructor(map) {
this.map = map this.map = map
this.TYPES = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap'] this.TYPES = ['geojson', 'csv', 'gpx', 'kml', 'osm', 'georss', 'umap']
this.PLUGINS = [] this.IMPORTERS = []
this.loadPlugins() this.loadImporterss()
this.dialog = new Dialog(this.map._controlContainer) this.dialog = new Dialog(this.map._controlContainer)
} }
loadPlugins() { loadImporterss() {
for (const key of AVAILABLE_PLUGINS) { for (const key of AVAILABLE_IMPORTERS) {
if (key in this.map.options.plugins) { if (key in this.map.options.importers) {
import(`./importers/${key}.js`).then((mod) => { import(`./importers/${key}.js`).then((mod) => {
this.PLUGINS.push(new mod.Importer(this.map, this.map.options.plugins[key])) this.IMPORTERS.push(
new mod.Importer(this.map, this.map.options.importers[key])
)
}) })
} }
} }
@ -95,17 +97,17 @@ export default class Importer {
build() { build() {
this.container = DomUtil.create('div', 'umap-upload') this.container = DomUtil.create('div', 'umap-upload')
this.container.innerHTML = TEMPLATE this.container.innerHTML = TEMPLATE
if (this.PLUGINS.length) { if (this.IMPORTERS.length) {
for (const plugin of this.PLUGINS) { for (const plugin of this.IMPORTERS) {
L.DomUtil.createButton( L.DomUtil.createButton(
'flat', 'flat',
this.container.querySelector('#plugins'), this.container.querySelector('#importers'),
plugin.name, plugin.name,
() => plugin.open(this) () => plugin.open(this)
) )
} }
} else { } else {
this.qs('.plugins').style.display = 'none' this.qs('.importers').style.display = 'none'
} }
for (const type of this.TYPES) { for (const type of this.TYPES) {
DomUtil.element({ DomUtil.element({

View file

@ -20,9 +20,6 @@ L.Map.mergeOptions({
enablePolygonDraw: true, enablePolygonDraw: true,
enablePolylineDraw: true, enablePolylineDraw: true,
limitBounds: {}, limitBounds: {},
importPresets: [
// {url: 'http://localhost:8019/en/datalayer/1502/', label: 'Simplified World Countries', format: 'geojson'}
],
slideshow: {}, slideshow: {},
clickable: true, clickable: true,
permissions: {}, permissions: {},

View file

@ -505,7 +505,7 @@ class MapDetailMixin:
"featuresHaveOwner": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS, "featuresHaveOwner": settings.UMAP_DEFAULT_FEATURES_HAVE_OWNERS,
"websocketEnabled": settings.WEBSOCKET_ENABLED, "websocketEnabled": settings.WEBSOCKET_ENABLED,
"websocketURI": settings.WEBSOCKET_FRONT_URI, "websocketURI": settings.WEBSOCKET_FRONT_URI,
"plugins": settings.UMAP_EXPERIMENTAL_PLUGINS, "importers": settings.UMAP_EXPERIMENTAL_IMPORTERS,
} }
created = bool(getattr(self, "object", None)) created = bool(getattr(self, "object", None))
if (created and self.object.owner) or (not created and not user.is_anonymous): if (created and self.object.owner) or (not created and not user.is_anonymous):