mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 14:01:50 +02:00
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:
parent
f10ebb24a2
commit
9e41ad1d81
5 changed files with 19 additions and 9 deletions
|
@ -251,6 +251,11 @@ class Map(NamedModel):
|
|||
path = reverse("map_anonymous_edit_url", kwargs={"signature": signature})
|
||||
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):
|
||||
if not request or self.owner:
|
||||
# edit cookies are only valid while the map doesn't have owner
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
MarkerUpdater,
|
||||
PolygonUpdater,
|
||||
PolylineUpdater,
|
||||
DatalayerUpdater,
|
||||
DataLayerUpdater,
|
||||
} from './updaters.js'
|
||||
|
||||
export class SyncEngine {
|
||||
|
@ -43,7 +43,7 @@ export class MessagesDispatcher {
|
|||
marker: new MarkerUpdater(this.map),
|
||||
polyline: new PolylineUpdater(this.map),
|
||||
polygon: new PolygonUpdater(this.map),
|
||||
datalayer: new DatalayerUpdater(this.map),
|
||||
datalayer: new DataLayerUpdater(this.map),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ export class MapUpdater extends BaseUpdater {
|
|||
}
|
||||
}
|
||||
|
||||
export class DatalayerUpdater extends BaseUpdater {
|
||||
export class DataLayerUpdater extends BaseUpdater {
|
||||
update({ key, metadata, value }) {
|
||||
const datalayer = this.getLayerFromID(metadata.id)
|
||||
console.log('datalayer', datalayer, key, value)
|
||||
|
|
|
@ -250,7 +250,7 @@ U.Map = L.Map.extend({
|
|||
this.on('click contextmenu.show', this.closeInplaceToolbar)
|
||||
this.sync = new U.SyncEngine(this)
|
||||
|
||||
Promise.resolve(this.initSyncEngine())
|
||||
this.initSyncEngine()
|
||||
},
|
||||
|
||||
initSyncEngine: async function () {
|
||||
|
@ -1501,6 +1501,12 @@ U.Map = L.Map.extend({
|
|||
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) {
|
||||
const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
|
||||
const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
|
||||
|
@ -1549,10 +1555,6 @@ U.Map = L.Map.extend({
|
|||
const container = L.DomUtil.create('div', 'umap-edit-container')
|
||||
const metadataFields = ['options.name', 'options.description']
|
||||
|
||||
if (this.options.websocketEnabled) {
|
||||
metadataFields.push('options.syncEnabled')
|
||||
}
|
||||
|
||||
const title = L.DomUtil.create('h3', '', container)
|
||||
title.textContent = L._('Edit map details')
|
||||
const builder = new U.FormBuilder(this, metadataFields, {
|
||||
|
@ -1587,6 +1589,9 @@ U.Map = L.Map.extend({
|
|||
this._editOverlay(container)
|
||||
this._editBounds(container)
|
||||
this._editSlideshow(container)
|
||||
if (this.options.websocketEnabled) {
|
||||
this._editSync(container)
|
||||
}
|
||||
this._advancedActions(container)
|
||||
|
||||
this.editPanel.open({ content: container, className: 'dark' })
|
||||
|
|
|
@ -794,7 +794,7 @@ def get_websocket_auth_token(request, map_id, map_inst):
|
|||
|
||||
if map_object.can_edit(request.user, request):
|
||||
permissions = ["edit"]
|
||||
if map_object.can_delete(request.user, request):
|
||||
if map_object.is_owner(request.user, request):
|
||||
permissions.append("owner")
|
||||
|
||||
if request.user.is_authenticated:
|
||||
|
|
Loading…
Reference in a new issue