mirror of
https://github.com/umap-project/umap.git
synced 2025-05-05 14:01:50 +02:00
wip: permissions does not inherit from ServerStored anymore
This commit is contained in:
parent
12e456d24e
commit
e9f2ff9a6c
3 changed files with 2 additions and 61 deletions
|
@ -1,18 +1,15 @@
|
|||
import { DomUtil } from '../../vendors/leaflet/leaflet-src.esm.js'
|
||||
import { translate } from './i18n.js'
|
||||
import { uMapAlert as Alert } from '../components/alerts/alert.js'
|
||||
import { ServerStored } from './saving.js'
|
||||
import * as Utils from './utils.js'
|
||||
import { MutatingForm } from './form/builder.js'
|
||||
|
||||
// Dedicated object so we can deal with a separate dirty status, and thus
|
||||
// call the endpoint only when needed, saving one call at each save.
|
||||
export class MapPermissions extends ServerStored {
|
||||
export class MapPermissions {
|
||||
constructor(umap) {
|
||||
super()
|
||||
this.setProperties(umap.properties.permissions)
|
||||
this._umap = umap
|
||||
this._isDirty = false
|
||||
this.sync = umap.syncEngine.proxy(this)
|
||||
}
|
||||
|
||||
|
@ -196,7 +193,6 @@ export class MapPermissions extends ServerStored {
|
|||
}
|
||||
|
||||
async save() {
|
||||
if (!this.isDirty) return
|
||||
const formData = new FormData()
|
||||
if (!this.isAnonymousMap() && this.properties.editors) {
|
||||
const editors = this.properties.editors.map((u) => u.id)
|
||||
|
@ -255,9 +251,8 @@ export class MapPermissions extends ServerStored {
|
|||
}
|
||||
}
|
||||
|
||||
export class DataLayerPermissions extends ServerStored {
|
||||
export class DataLayerPermissions {
|
||||
constructor(umap, datalayer) {
|
||||
super()
|
||||
this._umap = umap
|
||||
this.properties = Object.assign(
|
||||
{
|
||||
|
@ -305,7 +300,6 @@ export class DataLayerPermissions extends ServerStored {
|
|||
}
|
||||
|
||||
async save() {
|
||||
if (!this.isDirty) return
|
||||
const formData = new FormData()
|
||||
formData.append('edit_status', this.properties.edit_status)
|
||||
const [data, response, error] = await this._umap.server.post(
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
const _queue = new Set()
|
||||
|
||||
export let isDirty = false
|
||||
|
||||
export async function save() {
|
||||
for (const obj of _queue) {
|
||||
const ok = await obj.save()
|
||||
if (!ok) break
|
||||
remove(obj)
|
||||
}
|
||||
}
|
||||
|
||||
export function clear() {
|
||||
_queue.clear()
|
||||
onUpdate()
|
||||
}
|
||||
|
||||
function add(obj) {
|
||||
_queue.add(obj)
|
||||
onUpdate()
|
||||
}
|
||||
|
||||
function remove(obj) {
|
||||
_queue.delete(obj)
|
||||
onUpdate()
|
||||
}
|
||||
|
||||
function has(obj) {
|
||||
return _queue.has(obj)
|
||||
}
|
||||
|
||||
function onUpdate() {
|
||||
isDirty = Boolean(_queue.size)
|
||||
// document.body.classList.toggle('umap-is-dirty', isDirty)
|
||||
}
|
||||
|
||||
export class ServerStored {
|
||||
set isDirty(status) {
|
||||
if (status) {
|
||||
add(this)
|
||||
} else {
|
||||
remove(this)
|
||||
}
|
||||
this.onDirty(status)
|
||||
}
|
||||
|
||||
get isDirty() {
|
||||
return has(this)
|
||||
}
|
||||
|
||||
onDirty(status) {}
|
||||
}
|
|
@ -9,7 +9,6 @@ import {
|
|||
} from './updaters.js'
|
||||
import { WebSocketTransport } from './websocket.js'
|
||||
import { UndoManager } from './undo.js'
|
||||
import * as SaveManager from '../saving.js'
|
||||
|
||||
// Start reconnecting after 2 seconds, then double the delay each time
|
||||
// maxing out at 32 seconds.
|
||||
|
|
Loading…
Reference in a new issue