chore(sync): Move the sync flag in the options

The goal being for it to be hidden for now.

- Add a `is_owner` method on the map and use it in the view
- Remove duplicated line in `global.js`
- Rename `Datalayer` to `DataLayer` everywhere
- Move the sync flag in the map options (next to slideshow)
This commit is contained in:
Alexis Métaireau 2024-05-07 12:17:38 +02:00
parent 33108a9ae0
commit 346391b311
No known key found for this signature in database
GPG key ID: 1C21B876828E5FF2
6 changed files with 19 additions and 10 deletions

View file

@ -251,6 +251,11 @@ class Map(NamedModel):
path = reverse("map_anonymous_edit_url", kwargs={"signature": signature}) path = reverse("map_anonymous_edit_url", kwargs={"signature": signature})
return settings.SITE_URL + path return settings.SITE_URL + path
def is_owner(self, user=None, request=None):
if user and self.owner == user:
return True
return self.is_anonymous_owner(request)
def is_anonymous_owner(self, request): def is_anonymous_owner(self, request):
if not request or self.owner: if not request or self.owner:
# edit cookies are only valid while the map doesn't have owner # edit cookies are only valid while the map doesn't have owner

View file

@ -22,7 +22,6 @@ window.U = {
NOKError, NOKError,
Orderable, Orderable,
Panel, Panel,
Panel,
Request, Request,
RequestError, RequestError,
SCHEMA, SCHEMA,

View file

@ -4,7 +4,7 @@ import {
MarkerUpdater, MarkerUpdater,
PolygonUpdater, PolygonUpdater,
PolylineUpdater, PolylineUpdater,
DatalayerUpdater, DataLayerUpdater,
} from './updaters.js' } from './updaters.js'
export class SyncEngine { export class SyncEngine {
@ -43,7 +43,7 @@ export class MessagesDispatcher {
marker: new MarkerUpdater(this.map), marker: new MarkerUpdater(this.map),
polyline: new PolylineUpdater(this.map), polyline: new PolylineUpdater(this.map),
polygon: new PolygonUpdater(this.map), polygon: new PolygonUpdater(this.map),
datalayer: new DatalayerUpdater(this.map), datalayer: new DataLayerUpdater(this.map),
} }
} }

View file

@ -45,7 +45,7 @@ export class MapUpdater extends BaseUpdater {
} }
} }
export class DatalayerUpdater extends BaseUpdater { export class DataLayerUpdater extends BaseUpdater {
update({ key, metadata, value }) { update({ key, metadata, value }) {
const datalayer = this.getLayerFromID(metadata.id) const datalayer = this.getLayerFromID(metadata.id)
console.log('datalayer', datalayer, key, value) console.log('datalayer', datalayer, key, value)

View file

@ -246,7 +246,7 @@ U.Map = L.Map.extend({
this.on('click contextmenu.show', this.closeInplaceToolbar) this.on('click contextmenu.show', this.closeInplaceToolbar)
this.sync = new U.SyncEngine(this) this.sync = new U.SyncEngine(this)
Promise.resolve(this.initSyncEngine()) this.initSyncEngine()
}, },
initSyncEngine: async function () { initSyncEngine: async function () {
@ -1498,6 +1498,12 @@ U.Map = L.Map.extend({
slideshow.appendChild(slideshowBuilder.build()) slideshow.appendChild(slideshowBuilder.build())
}, },
_editSync: function (container) {
const sync = L.DomUtil.createFieldset(container, L._('Real-time collaboration'))
const builder = new U.FormBuilder(this, ['options.syncEnabled'])
sync.appendChild(builder.build())
},
_advancedActions: function (container) { _advancedActions: function (container) {
const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions) const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
@ -1546,10 +1552,6 @@ U.Map = L.Map.extend({
const container = L.DomUtil.create('div', 'umap-edit-container') const container = L.DomUtil.create('div', 'umap-edit-container')
const metadataFields = ['options.name', 'options.description'] const metadataFields = ['options.name', 'options.description']
if (this.options.websocketEnabled) {
metadataFields.push('options.syncEnabled')
}
const title = L.DomUtil.create('h3', '', container) const title = L.DomUtil.create('h3', '', container)
title.textContent = L._('Edit map details') title.textContent = L._('Edit map details')
const builder = new U.FormBuilder(this, metadataFields, { const builder = new U.FormBuilder(this, metadataFields, {
@ -1584,6 +1586,9 @@ U.Map = L.Map.extend({
this._editOverlay(container) this._editOverlay(container)
this._editBounds(container) this._editBounds(container)
this._editSlideshow(container) this._editSlideshow(container)
if (this.options.websocketEnabled) {
this._editSync(container)
}
this._advancedActions(container) this._advancedActions(container)
this.editPanel.open({ content: container, className: 'dark' }) this.editPanel.open({ content: container, className: 'dark' })

View file

@ -794,7 +794,7 @@ def get_websocket_auth_token(request, map_id, map_inst):
if map_object.can_edit(request.user, request): if map_object.can_edit(request.user, request):
permissions = ["edit"] permissions = ["edit"]
if map_object.can_delete(request.user, request): if map_object.is_owner(request.user, request):
permissions.append("owner") permissions.append("owner")
if request.user.is_authenticated: if request.user.is_authenticated: