From 6b2038e83eef8cf2b3286f6a0d680359c3b0d55e Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 26 Mar 2025 10:54:00 +0100 Subject: [PATCH] wip: permissions does not inherit from ServerStored anymore --- umap/static/umap/js/modules/permissions.js | 9 +--- umap/static/umap/js/modules/saving.js | 52 ---------------------- 2 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 umap/static/umap/js/modules/saving.js diff --git a/umap/static/umap/js/modules/permissions.js b/umap/static/umap/js/modules/permissions.js index d4eca1e0..7c07fd94 100644 --- a/umap/static/umap/js/modules/permissions.js +++ b/umap/static/umap/js/modules/permissions.js @@ -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( diff --git a/umap/static/umap/js/modules/saving.js b/umap/static/umap/js/modules/saving.js deleted file mode 100644 index d5181a37..00000000 --- a/umap/static/umap/js/modules/saving.js +++ /dev/null @@ -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) {} -}