mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 21:51:50 +02:00
fixup! Introduce a _future_uuid property to track not-yet-synced datalayers
This commit is contained in:
parent
9759f780ad
commit
d68a34e591
4 changed files with 39 additions and 24 deletions
|
@ -36,7 +36,7 @@ const LAYER_MAP = LAYER_TYPES.reduce((acc, klass) => {
|
||||||
}, {})
|
}, {})
|
||||||
|
|
||||||
export class DataLayer {
|
export class DataLayer {
|
||||||
constructor(map, data, sync) {
|
constructor(map, data, sync, future_uuid) {
|
||||||
this.map = map
|
this.map = map
|
||||||
this.sync = map.sync_engine.proxy(this)
|
this.sync = map.sync_engine.proxy(this)
|
||||||
this._index = Array()
|
this._index = Array()
|
||||||
|
@ -61,6 +61,13 @@ export class DataLayer {
|
||||||
this._isDirty = false
|
this._isDirty = false
|
||||||
this._isDeleted = false
|
this._isDeleted = false
|
||||||
this.setUmapId(data.id)
|
this.setUmapId(data.id)
|
||||||
|
|
||||||
|
if (!this.umap_id) {
|
||||||
|
// Generate a random uuid if none is provided
|
||||||
|
this._future_uuid = future_uuid !== undefined ? future_uuid : crypto.randomUUID()
|
||||||
|
console.log('Future UUID for datalayer', this._future_uuid)
|
||||||
|
}
|
||||||
|
|
||||||
this.setOptions(data)
|
this.setOptions(data)
|
||||||
|
|
||||||
if (!Utils.isObject(this.options.remoteData)) {
|
if (!Utils.isObject(this.options.remoteData)) {
|
||||||
|
@ -79,8 +86,9 @@ export class DataLayer {
|
||||||
this.connectToMap()
|
this.connectToMap()
|
||||||
this.permissions = new DataLayerPermissions(this)
|
this.permissions = new DataLayerPermissions(this)
|
||||||
|
|
||||||
if (!this.createdOnServer) {
|
console.debug("createdOnServer", this.createdOnServer)
|
||||||
// When importing data, show the layer immediately if applicable
|
if (!this.umap_id) {
|
||||||
|
console.debug("showAtLoad", this.showAtLoad())
|
||||||
if (this.showAtLoad()) this.show()
|
if (this.showAtLoad()) this.show()
|
||||||
this.isDirty = true
|
this.isDirty = true
|
||||||
}
|
}
|
||||||
|
@ -92,8 +100,7 @@ export class DataLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
get createdOnServer(){
|
get createdOnServer(){
|
||||||
console.log("reference version", this._reference_version)
|
return this.umap_id !== undefined
|
||||||
return this._reference_version !== undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set isDirty(status) {
|
set isDirty(status) {
|
||||||
|
@ -127,6 +134,7 @@ export class DataLayer {
|
||||||
subject: 'datalayer',
|
subject: 'datalayer',
|
||||||
metadata: {
|
metadata: {
|
||||||
id: this.umap_id,
|
id: this.umap_id,
|
||||||
|
future_uuid: this._future_uuid,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,13 +227,14 @@ export class DataLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchData() {
|
async fetchData() {
|
||||||
if (!this.createdOnServer) return
|
console.trace("fetchData", this.umap_id)
|
||||||
|
if (!this.umap_id) return
|
||||||
if (this._loading) return
|
if (this._loading) return
|
||||||
this._loading = true
|
this._loading = true
|
||||||
const [geojson, response, error] = await this.map.server.get(this._dataUrl())
|
const [geojson, response, error] = await this.map.server.get(this._dataUrl())
|
||||||
if (!error) {
|
if (!error) {
|
||||||
this._reference_version = response.headers.get('X-Datalayer-Version')
|
this._reference_version = response.headers.get('X-Datalayer-Version')
|
||||||
// FIXME: for now this property is set dynamically from backend
|
// FIXME: for now the _umap_options property is set dynamically from backend
|
||||||
// And thus it's not in the geojson file in the server
|
// And thus it's not in the geojson file in the server
|
||||||
// So do not let all options to be reset
|
// So do not let all options to be reset
|
||||||
// Fix is a proper migration so all datalayers settings are
|
// Fix is a proper migration so all datalayers settings are
|
||||||
|
@ -311,7 +320,7 @@ export class DataLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoaded() {
|
isLoaded() {
|
||||||
return !this.createdOnServer || this._loaded
|
return !this.umap_id || this._loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
hasDataLoaded() {
|
hasDataLoaded() {
|
||||||
|
@ -321,11 +330,6 @@ export class DataLayer {
|
||||||
setUmapId(id) {
|
setUmapId(id) {
|
||||||
// Datalayer ID is null when listening creation form
|
// Datalayer ID is null when listening creation form
|
||||||
if (!this.umap_id && id) this.umap_id = id
|
if (!this.umap_id && id) this.umap_id = id
|
||||||
else {
|
|
||||||
// Generate a random uuid if none is provided
|
|
||||||
this.umap_id = crypto.randomUUID()
|
|
||||||
console.log('Generating random UUID for datalayer', this.umap_id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backupOptions() {
|
backupOptions() {
|
||||||
|
@ -909,6 +913,7 @@ export class DataLayer {
|
||||||
|
|
||||||
async show() {
|
async show() {
|
||||||
this.map.addLayer(this.layer)
|
this.map.addLayer(this.layer)
|
||||||
|
|
||||||
if (!this.isLoaded()) await this.fetchData()
|
if (!this.isLoaded()) await this.fetchData()
|
||||||
this.propagateShow()
|
this.propagateShow()
|
||||||
}
|
}
|
||||||
|
@ -1054,7 +1059,7 @@ export class DataLayer {
|
||||||
formData.append('geojson', blob)
|
formData.append('geojson', blob)
|
||||||
const saveURL = this.map.urls.get('datalayer_save', {
|
const saveURL = this.map.urls.get('datalayer_save', {
|
||||||
map_id: this.map.options.umap_id,
|
map_id: this.map.options.umap_id,
|
||||||
pk: this.umap_id,
|
pk: this.umap_id || this._future_uuid,
|
||||||
created: this.createdOnServer,
|
created: this.createdOnServer,
|
||||||
})
|
})
|
||||||
console.log("saveUrl", saveURL)
|
console.log("saveUrl", saveURL)
|
||||||
|
|
|
@ -563,4 +563,9 @@ export const SCHEMA = {
|
||||||
type: Object,
|
type: Object,
|
||||||
impacts: ['data'],
|
impacts: ['data'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_reference_version: {
|
||||||
|
type: Number,
|
||||||
|
impacts: ['data'],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ class BaseUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getDataLayerFromID(layerId) {
|
getDataLayerFromID(layerId, future_uuid) {
|
||||||
if (layerId) return this.map.getDataLayerByUmapId(layerId)
|
if (layerId) return this.map.getDataLayerByUmapId(layerId, future_uuid)
|
||||||
return this.map.defaultEditDataLayer()
|
return this.map.defaultEditDataLayer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,14 +53,15 @@ export class MapUpdater extends BaseUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataLayerUpdater extends BaseUpdater {
|
export class DataLayerUpdater extends BaseUpdater {
|
||||||
upsert({ value }) {
|
upsert({ value, metadata }) {
|
||||||
// Inserts does not happen (we use multiple updates instead).
|
console.log('upsert', value, metadata)
|
||||||
this.map.createDataLayer(value, false)
|
// Upsert only happens when a new datalayer is created.
|
||||||
|
this.map.createDataLayer(value, false, metadata.future_uuid)
|
||||||
this.map.render([])
|
this.map.render([])
|
||||||
}
|
}
|
||||||
|
|
||||||
update({ key, metadata, value }) {
|
update({ key, metadata, value }) {
|
||||||
const datalayer = this.getDataLayerFromID(metadata.id)
|
const datalayer = this.getDataLayerFromID(metadata.id, metadata.future_uuid)
|
||||||
if (fieldInSchema(key)) {
|
if (fieldInSchema(key)) {
|
||||||
this.updateObjectValue(datalayer, key, value)
|
this.updateObjectValue(datalayer, key, value)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -817,9 +817,10 @@ U.Map = L.Map.extend({
|
||||||
return L.Map.prototype.setMaxBounds.call(this, bounds)
|
return L.Map.prototype.setMaxBounds.call(this, bounds)
|
||||||
},
|
},
|
||||||
|
|
||||||
createDataLayer: function (options = {}, sync = true) {
|
createDataLayer: function (options = {}, sync = true, future_uuid = undefined) {
|
||||||
|
console.log("Create Datalayer", options)
|
||||||
options.name = options.name || `${L._('Layer')} ${this.datalayers_index.length + 1}`
|
options.name = options.name || `${L._('Layer')} ${this.datalayers_index.length + 1}`
|
||||||
const datalayer = new U.DataLayer(this, options, sync)
|
const datalayer = new U.DataLayer(this, options, sync, future_uuid)
|
||||||
|
|
||||||
if (sync !== false) {
|
if (sync !== false) {
|
||||||
datalayer.sync.upsert(datalayer.options)
|
datalayer.sync.upsert(datalayer.options)
|
||||||
|
@ -828,7 +829,7 @@ U.Map = L.Map.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
newDataLayer: function () {
|
newDataLayer: function () {
|
||||||
const datalayer = this.createDataLayer({})
|
const datalayer = this.createDataLayer({}, sync=true)
|
||||||
datalayer.edit()
|
datalayer.edit()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1192,7 +1193,10 @@ U.Map = L.Map.extend({
|
||||||
return this.createDataLayer()
|
return this.createDataLayer()
|
||||||
},
|
},
|
||||||
|
|
||||||
getDataLayerByUmapId: function (umap_id) {
|
getDataLayerByUmapId: function (umap_id, future_uuid) {
|
||||||
|
if (future_uuid !== undefined) {
|
||||||
|
return this.findDataLayer((d) => d._future_uuid === future_uuid)
|
||||||
|
}
|
||||||
return this.findDataLayer((d) => d.umap_id === umap_id)
|
return this.findDataLayer((d) => d.umap_id === umap_id)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue