wip: DataLayer does not inherit anymore from ServerStored

This commit is contained in:
Yohan Boniface 2025-03-23 12:23:46 +01:00
parent 90ea3737f2
commit 6bea9339b6

View file

@ -18,7 +18,6 @@ import { translate } from '../i18n.js'
import { DataLayerPermissions } from '../permissions.js' import { DataLayerPermissions } from '../permissions.js'
import { Point, LineString, Polygon } from './features.js' import { Point, LineString, Polygon } from './features.js'
import TableEditor from '../tableeditor.js' import TableEditor from '../tableeditor.js'
import { ServerStored } from '../saving.js'
import * as Schema from '../schema.js' import * as Schema from '../schema.js'
import { MutatingForm } from '../form/builder.js' import { MutatingForm } from '../form/builder.js'
@ -36,9 +35,8 @@ const LAYER_MAP = LAYER_TYPES.reduce((acc, klass) => {
return acc return acc
}, {}) }, {})
export class DataLayer extends ServerStored { export class DataLayer {
constructor(umap, leafletMap, data = {}) { constructor(umap, leafletMap, data = {}) {
super()
this._umap = umap this._umap = umap
this.sync = umap.syncEngine.proxy(this) this.sync = umap.syncEngine.proxy(this)
this._index = Array() this._index = Array()
@ -114,7 +112,6 @@ export class DataLayer extends ServerStored {
set isDeleted(status) { set isDeleted(status) {
this._isDeleted = status this._isDeleted = status
if (status) this.isDirty = status
} }
get isDeleted() { get isDeleted() {
@ -530,10 +527,6 @@ export class DataLayer extends ServerStored {
return this._umap.formatter return this._umap.formatter
.parse(raw, format) .parse(raw, format)
.then((geojson) => this.addData(geojson)) .then((geojson) => this.addData(geojson))
.then((data) => {
if (data?.length) this.isDirty = true
return data
})
.catch((error) => { .catch((error) => {
console.debug(error) console.debug(error)
Alert.error(translate('Import failed: invalid data')) Alert.error(translate('Import failed: invalid data'))
@ -610,7 +603,6 @@ export class DataLayer extends ServerStored {
empty() { empty() {
if (this.isRemoteLayer()) return if (this.isRemoteLayer()) return
this.clear() this.clear()
this.isDirty = true
} }
clone() { clone() {
@ -634,25 +626,6 @@ export class DataLayer extends ServerStored {
this.clear() this.clear()
} }
reset() {
if (!this.createdOnServer) {
this.erase()
return
}
this.resetOptions()
this.parentPane.appendChild(this.pane)
if (this._leaflet_events_bk && !this._leaflet_events) {
this._leaflet_events = this._leaflet_events_bk
}
this.clear()
this.hide()
if (this.isRemoteLayer()) this.fetchRemoteData()
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk)
this.show()
this.isDirty = false
}
redraw() { redraw() {
if (!this.isVisible()) return if (!this.isVisible()) return
this.eachFeature((feature) => feature.redraw()) this.eachFeature((feature) => feature.redraw())
@ -948,7 +921,6 @@ export class DataLayer extends ServerStored {
this.empty() this.empty()
if (this.isRemoteLayer()) this.fetchRemoteData() if (this.isRemoteLayer()) this.fetchRemoteData()
else this.addData(geojson) else this.addData(geojson)
this.isDirty = true
} }
}) })
} }
@ -1129,6 +1101,10 @@ export class DataLayer extends ServerStored {
} }
async _trySave(url, headers, formData) { async _trySave(url, headers, formData) {
if (this._forceSave) {
headers = {}
this._forceSave = false
}
const [data, response, error] = await this._umap.server.post(url, headers, formData) const [data, response, error] = await this._umap.server.post(url, headers, formData)
if (error) { if (error) {
if (response && response.status === 412) { if (response && response.status === 412) {
@ -1138,15 +1114,8 @@ export class DataLayer extends ServerStored {
'This situation is tricky, you have to choose carefully which version is pertinent.' 'This situation is tricky, you have to choose carefully which version is pertinent.'
), ),
async () => { async () => {
// Save again this layer this._forceSave = true
const status = await this._trySave(url, {}, formData) await this._umap.saveAll()
if (status) {
this.isDirty = false
// Call the main save, in case something else needs to be saved
// as the conflict stopped the saving flow
await this._umap.saveAll()
}
} }
) )
} }