Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure anonymous is owner at create #2189

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions umap/static/umap/js/modules/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export const SingleMixin = (Base) =>
DomEvent.on(close, 'click', () => {
this.selectedContainer.innerHTML = ''
this.input.style.display = 'block'
this.options.on_unselect(result)
this.options.on_unselect?.(result)
})
this.hide()
}
Expand Down Expand Up @@ -342,7 +342,7 @@ export const MultipleMixin = (Base) =>
})
DomEvent.on(close, 'click', () => {
this.selectedContainer.removeChild(result_el)
this.options.on_unselect(result)
this.options.on_unselect?.(result)
})
this.hide()
}
Expand Down
7 changes: 6 additions & 1 deletion umap/static/umap/js/modules/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export default class Caption {
open() {
const container = DomUtil.create('div', 'umap-caption')
const hgroup = DomUtil.element({ tagName: 'hgroup', parent: container })
DomUtil.createTitle(hgroup, this.map.options.name, 'icon-caption icon-block')
DomUtil.createTitle(
hgroup,
this.map.getDisplayName(),
'icon-caption icon-block',
'map-name'
)
this.map.addAuthorLink('h4', hgroup)
if (this.map.options.description) {
const description = DomUtil.element({
Expand Down
17 changes: 8 additions & 9 deletions umap/static/umap/js/modules/data/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export class DataLayer {
set isDirty(status) {
this._isDirty = status
if (status) {
this.map.addDirtyDatalayer(this)
this.map.isDirty = true
// A layer can be made dirty by indirect action (like dragging layers)
// we need to have it loaded before saving it.
if (!this.isLoaded()) this.fetchData()
} else {
this.map.removeDirtyDatalayer(this)
this.map.checkDirty()
this.isDeleted = false
}
}
Expand Down Expand Up @@ -339,11 +339,11 @@ export class DataLayer {
const id = stamp(this)
if (!this.map.datalayers[id]) {
this.map.datalayers[id] = this
if (!this.map.datalayers_index.includes(this)) {
this.map.datalayers_index.push(this)
}
this.map.onDataLayersChanged()
}
if (!this.map.datalayers_index.includes(this)) {
this.map.datalayers_index.push(this)
}
this.map.onDataLayersChanged()
}

_dataUrl() {
Expand Down Expand Up @@ -559,7 +559,6 @@ export class DataLayer {

erase() {
this.hide()
delete this.map.datalayers[stamp(this)]
this.map.datalayers_index.splice(this.getRank(), 1)
this.parentPane.removeChild(this.pane)
this.map.onDataLayersChanged()
Expand Down Expand Up @@ -1026,7 +1025,7 @@ export class DataLayer {
}

async save() {
if (this.isDeleted) return this.saveDelete()
if (this.isDeleted) return await this.saveDelete()
if (!this.isLoaded()) {
return
}
Expand Down Expand Up @@ -1090,8 +1089,8 @@ export class DataLayer {
if (this.umap_id) {
await this.map.server.post(this.getDeleteUrl())
}
delete this.map.datalayers[stamp(this)]
this.isDirty = false
this.map.continueSaving()
}

getMap() {
Expand Down
29 changes: 13 additions & 16 deletions umap/static/umap/js/modules/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export class MapPermissions {
return !this.map.options.permissions.owner
}

getMap() {
return this.map
}

_editAnonymous(container) {
const fields = []
if (this.isOwner()) {
Expand Down Expand Up @@ -182,7 +178,7 @@ export class MapPermissions {
}

async save() {
if (!this.isDirty) return this.map.continueSaving()
if (!this.isDirty) return
const formData = new FormData()
if (!this.isAnonymousMap() && this.options.editors) {
const editors = this.options.editors.map((u) => u.id)
Expand All @@ -205,7 +201,6 @@ export class MapPermissions {
if (!error) {
this.commit()
this.isDirty = false
this.map.continueSaving()
this.map.fire('postsync')
}
}
Expand All @@ -230,9 +225,11 @@ export class MapPermissions {
}

getShareStatusDisplay() {
return Object.fromEntries(this.map.options.share_statuses)[
this.options.share_status
]
if (this.map.options.share_statuses) {
return Object.fromEntries(this.map.options.share_statuses)[
this.options.share_status
]
}
}
}

Expand All @@ -258,7 +255,7 @@ export class DataLayerPermissions {
return this._isDirty
}

getMap() {
get map() {
return this.datalayer.map
}

Expand All @@ -271,7 +268,7 @@ export class DataLayerPermissions {
label: translate('Who can edit "{layer}"', {
layer: this.datalayer.getName(),
}),
selectOptions: this.datalayer.map.options.datalayer_edit_statuses,
selectOptions: this.map.options.datalayer_edit_statuses,
},
],
]
Expand All @@ -283,24 +280,24 @@ export class DataLayerPermissions {
}

getUrl() {
return Utils.template(this.datalayer.map.options.urls.datalayer_permissions, {
map_id: this.datalayer.map.options.umap_id,
return this.map.urls.get('datalayer_permissions', {
map_id: this.map.options.umap_id,
pk: this.datalayer.umap_id,
})
}

async save() {
if (!this.isDirty) return this.datalayer.map.continueSaving()
if (!this.isDirty) return
const formData = new FormData()
formData.append('edit_status', this.options.edit_status)
const [data, response, error] = await this.datalayer.map.server.post(
const [data, response, error] = await this.map.server.post(
this.getUrl(),
{},
formData
)
if (!error) {
this.commit()
this.isDirty = false
this.datalayer.map.continueSaving()
}
}

Expand Down
27 changes: 9 additions & 18 deletions umap/static/umap/js/umap.controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,15 @@ const ControlsMixin = {
],

renderEditToolbar: function () {
const container = L.DomUtil.create(
'div',
'umap-main-edit-toolbox with-transition dark',
this._controlContainer
)
const className = 'umap-main-edit-toolbox'
const container =
document.querySelector(`.${className}`) ||
L.DomUtil.create(
'div',
`${className} with-transition dark`,
this._controlContainer
)
container.innerHTML = ''
const leftContainer = L.DomUtil.create('div', 'umap-left-edit-toolbox', container)
const rightContainer = L.DomUtil.create('div', 'umap-right-edit-toolbox', container)
const logo = L.DomUtil.create('div', 'logo', leftContainer)
Expand Down Expand Up @@ -623,23 +627,10 @@ const ControlsMixin = {
},
this
)
const update = () => {
const status = this.permissions.getShareStatusDisplay()
nameButton.textContent = this.getDisplayName()
// status is not set until map is saved once
if (status) {
shareStatusButton.textContent = L._('Visibility: {status}', {
status: status,
})
}
}
update()
this.once('saved', L.bind(update, this))
if (this.options.editMode === 'advanced') {
L.DomEvent.on(nameButton, 'click', this.editCaption, this)
L.DomEvent.on(shareStatusButton, 'click', this.permissions.edit, this.permissions)
}
this.on('postsync', L.bind(update, this))
if (this.options.user?.id) {
L.DomUtil.createLink(
'umap-user',
Expand Down
6 changes: 3 additions & 3 deletions umap/static/umap/js/umap.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ L.DomUtil.createButtonIcon = (parent, className, title, callback, size = 16) =>
return el
}

L.DomUtil.createTitle = (parent, text, className, tag = 'h3') => {
L.DomUtil.createTitle = (parent, text, iconClassName, className = '', tag = 'h3') => {
const title = L.DomUtil.create(tag, '', parent)
if (className) L.DomUtil.createIcon(title, className)
L.DomUtil.add('span', '', title, text)
if (className) L.DomUtil.createIcon(title, iconClassName)
L.DomUtil.add('span', className, title, text)
return title
}

Expand Down
Loading