mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
chore: review save strategy
All is now orchestrated from a single method, instead of chaining calls.
This commit is contained in:
parent
73c83cfa86
commit
0fdb70ce66
3 changed files with 17 additions and 21 deletions
|
@ -1026,7 +1026,7 @@ export class DataLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (this.isDeleted) return this.saveDelete()
|
if (this.isDeleted) return await this.saveDelete()
|
||||||
if (!this.isLoaded()) {
|
if (!this.isLoaded()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1091,7 +1091,6 @@ export class DataLayer {
|
||||||
await this.map.server.post(this.getDeleteUrl())
|
await this.map.server.post(this.getDeleteUrl())
|
||||||
}
|
}
|
||||||
this.isDirty = false
|
this.isDirty = false
|
||||||
this.map.continueSaving()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMap() {
|
getMap() {
|
||||||
|
|
|
@ -182,7 +182,7 @@ export class MapPermissions {
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (!this.isDirty) return this.map.continueSaving()
|
if (!this.isDirty) return
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
if (!this.isAnonymousMap() && this.options.editors) {
|
if (!this.isAnonymousMap() && this.options.editors) {
|
||||||
const editors = this.options.editors.map((u) => u.id)
|
const editors = this.options.editors.map((u) => u.id)
|
||||||
|
@ -205,7 +205,6 @@ export class MapPermissions {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
this.commit()
|
this.commit()
|
||||||
this.isDirty = false
|
this.isDirty = false
|
||||||
this.map.continueSaving()
|
|
||||||
this.map.fire('postsync')
|
this.map.fire('postsync')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,8 +287,9 @@ export class DataLayerPermissions {
|
||||||
pk: this.datalayer.umap_id,
|
pk: this.datalayer.umap_id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
if (!this.isDirty) return this.datalayer.map.continueSaving()
|
if (!this.isDirty) return
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('edit_status', this.options.edit_status)
|
formData.append('edit_status', this.options.edit_status)
|
||||||
const [data, response, error] = await this.datalayer.map.server.post(
|
const [data, response, error] = await this.datalayer.map.server.post(
|
||||||
|
@ -300,7 +300,6 @@ export class DataLayerPermissions {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
this.commit()
|
this.commit()
|
||||||
this.isDirty = false
|
this.isDirty = false
|
||||||
this.datalayer.map.continueSaving()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1025,11 +1025,6 @@ U.Map = L.Map.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
continueSaving: function () {
|
|
||||||
if (this.dirty_datalayers.length) this.dirty_datalayers[0].save()
|
|
||||||
else this.fire('saved')
|
|
||||||
},
|
|
||||||
|
|
||||||
exportOptions: function () {
|
exportOptions: function () {
|
||||||
const properties = {}
|
const properties = {}
|
||||||
for (const option of Object.keys(U.SCHEMA)) {
|
for (const option of Object.keys(U.SCHEMA)) {
|
||||||
|
@ -1059,7 +1054,7 @@ U.Map = L.Map.extend({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (data.login_required) {
|
if (data.login_required) {
|
||||||
window.onLogin = () => this.saveSelf()
|
window.onLogin = () => this.save()
|
||||||
window.open(data.login_required)
|
window.open(data.login_required)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1069,7 +1064,7 @@ U.Map = L.Map.extend({
|
||||||
this.options.umap_id = data.id
|
this.options.umap_id = data.id
|
||||||
this.permissions.setOptions(data.permissions)
|
this.permissions.setOptions(data.permissions)
|
||||||
this.permissions.commit()
|
this.permissions.commit()
|
||||||
if (data?.permissions?.anonymous_edit_url) {
|
if (data.permissions?.anonymous_edit_url) {
|
||||||
this.once('saved', () => {
|
this.once('saved', () => {
|
||||||
U.AlertCreation.info(
|
U.AlertCreation.info(
|
||||||
L._('Your map has been created with an anonymous account!'),
|
L._('Your map has been created with an anonymous account!'),
|
||||||
|
@ -1102,22 +1097,25 @@ U.Map = L.Map.extend({
|
||||||
} else {
|
} else {
|
||||||
window.location = data.url
|
window.location = data.url
|
||||||
}
|
}
|
||||||
this.permissions.save()
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
save: function () {
|
save: async function () {
|
||||||
if (!this.isDirty) return
|
if (!this.isDirty) return
|
||||||
if (this._default_extent) this._setCenterAndZoom()
|
if (this._default_extent) this._setCenterAndZoom()
|
||||||
this.backup()
|
this.backup()
|
||||||
this.once('saved', () => {
|
|
||||||
this.isDirty = false
|
|
||||||
})
|
|
||||||
if (this.options.editMode === 'advanced') {
|
if (this.options.editMode === 'advanced') {
|
||||||
// Only save the map if the user has the rights to do so.
|
// Only save the map if the user has the rights to do so.
|
||||||
this.saveSelf()
|
const ok = await this.saveSelf()
|
||||||
} else {
|
if (!ok) return
|
||||||
this.permissions.save()
|
|
||||||
}
|
}
|
||||||
|
await this.permissions.save()
|
||||||
|
for (const datalayer of this.dirty_datalayers) {
|
||||||
|
await datalayer.save()
|
||||||
|
}
|
||||||
|
this.isDirty = false
|
||||||
|
this.renderEditToolbar()
|
||||||
|
this.fire('saved')
|
||||||
},
|
},
|
||||||
|
|
||||||
star: async function () {
|
star: async function () {
|
||||||
|
|
Loading…
Reference in a new issue