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
33108a9ae0
commit
346391b311
6 changed files with 19 additions and 10 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
|
||||
|
|
|
@ -22,7 +22,6 @@ window.U = {
|
|||
NOKError,
|
||||
Orderable,
|
||||
Panel,
|
||||
Panel,
|
||||
Request,
|
||||
RequestError,
|
||||
SCHEMA,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -246,7 +246,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 () {
|
||||
|
@ -1498,6 +1498,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)
|
||||
|
@ -1546,10 +1552,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, {
|
||||
|
@ -1584,6 +1586,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