mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
wip: permissions does not inherit from ServerStored anymore
This commit is contained in:
parent
0389e9a185
commit
6b2038e83e
2 changed files with 2 additions and 59 deletions
|
@ -7,12 +7,10 @@ import * as Utils from './utils.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 +194,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 +252,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 +301,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) {}
|
||||
}
|
Loading…
Reference in a new issue