wip: control plugins from settings

This commit is contained in:
Yohan Boniface 2024-05-30 19:41:51 +02:00
parent a7a214d7fe
commit 93a189497b
5 changed files with 39 additions and 14 deletions

View file

@ -259,6 +259,16 @@ 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 = {
# "geodatamine": {},
# "communesfr": {},
# "presets": {
# "choices": [
# {"label": "Régions", "url": "https://france-geojson.gregoiredavid.fr/repo/regions.geojson", "format": "geojson"},
# {"label": "Départements", "url": "https://france-geojson.gregoiredavid.fr/repo/departements.geojson", "format": "geojson"},
# ]
# }
}
UMAP_READONLY = env("UMAP_READONLY", default=False) UMAP_READONLY = env("UMAP_READONLY", default=False)
UMAP_GZIP = True UMAP_GZIP = True

View file

@ -2,9 +2,8 @@ import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from './i18n.js' 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'
import { Importer as GeoDataMine } from './importers/geodatamine.js'
import { Importer as Communes } from './importers/communes.js' const AVAILABLE_PLUGINS = ['geodatamine', 'communesfr', 'presets']
import { Importer as Presets } from './importers/presets.js'
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>
@ -41,10 +40,21 @@ 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 = [new GeoDataMine(map), new Communes(map), new Presets(map)] this.PLUGINS = []
this.loadPlugins()
this.dialog = new Dialog(this.map._controlContainer) this.dialog = new Dialog(this.map._controlContainer)
} }
loadPlugins() {
for (const key of AVAILABLE_PLUGINS) {
if (key in this.map.options.plugins) {
import(`./importers/${key}.js`).then((mod) => {
this.PLUGINS.push(new mod.Importer(this.map, this.map.options.plugins[key]))
})
}
}
}
qs(query) { qs(query) {
return this.container.querySelector(query) return this.container.querySelector(query)
} }
@ -85,6 +95,7 @@ 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) {
for (const plugin of this.PLUGINS) { for (const plugin of this.PLUGINS) {
L.DomUtil.createButton( L.DomUtil.createButton(
'flat', 'flat',
@ -93,6 +104,9 @@ export default class Importer {
() => plugin.open(this) () => plugin.open(this)
) )
} }
} else {
this.qs('.plugins').style.display = 'none'
}
for (const type of this.TYPES) { for (const type of this.TYPES) {
DomUtil.element({ DomUtil.element({
tagName: 'option', tagName: 'option',

View file

@ -2,9 +2,9 @@ import { DomUtil } from '../../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from '../i18n.js' import { translate } from '../i18n.js'
export class Importer { export class Importer {
constructor(map) { constructor(map, options) {
this.name = 'Presets' this.name = 'Presets'
this.presets = map.options.importPresets this.choices = options?.choices
} }
async open(importer) { async open(importer) {
@ -16,7 +16,7 @@ export class Importer {
value: '', value: '',
textContent: translate('Choose a preset'), textContent: translate('Choose a preset'),
}) })
for (const preset of this.presets) { for (const preset of this.choices) {
const option = DomUtil.create('option', '', select) const option = DomUtil.create('option', '', select)
option.value = preset.url option.value = preset.url
option.textContent = preset.label option.textContent = preset.label

View file

@ -505,6 +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,
} }
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):