chore: rename alert choice to conflict + CSS vars

This commit is contained in:
David Larlet 2024-06-12 18:15:28 -04:00
parent 6edad8a385
commit cea2aee88f
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
7 changed files with 26 additions and 23 deletions

View file

@ -300,7 +300,7 @@ ul.umap-autocomplete {
} }
.messages .error { .messages .error {
background-color: #c60f13; background-color: var(--color-red);
} }

View file

@ -20,7 +20,7 @@
min-width: 80%; min-width: 80%;
} }
[role="dialog"][data-level="error"] { [role="dialog"][data-level="error"] {
background-color: #c60f13; background-color: var(--color-red);
} }
[role="dialog"] a { [role="dialog"] a {
text-decoration: underline; text-decoration: underline;
@ -93,23 +93,25 @@
#link-wrapper { #link-wrapper {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
#choice-wrapper form { #conflict-wrapper form {
display: flex; display: flex;
justify-content: space-around; justify-content: space-around;
} }
#choice-wrapper form [type="submit"] { #conflict-wrapper form [type="submit"] {
width: initial; width: initial;
background: inherit; background: inherit;
color: var(--color-light); color: var(--color-light);
border: 1px solid var(--color-red);
font-weight: bold;
} }
#choice-wrapper form [type="submit"]:hover { #conflict-wrapper form [type="submit"]:hover {
width: initial; width: initial;
background: darkred; background: darkred;
color: var(--color-light); color: var(--color-light);
border: 1px solid var(--color-light); border: 1px solid var(--color-light);
} }
@media only screen and (max-width:770px) { @media only screen and (max-width:770px) {
#choice-wrapper form { #conflict-wrapper form {
flex-direction: column; flex-direction: column;
text-align: center; text-align: center;
} }

View file

@ -53,11 +53,11 @@
<umap-alert-creation></umap-alert-creation> <umap-alert-creation></umap-alert-creation>
<template id="umap-alert-choice-template"> <template id="umap-alert-conflict-template">
<div role="dialog" class="dark window"> <div role="dialog" class="dark window">
<div> <div>
<p role="alert"></p> <p role="alert"></p>
<div id="choice-wrapper"> <div id="conflict-wrapper">
<form> <form>
<a href="#" onclick="document.url" target="_blank">{% translate "See their edits in another tab" %}</a> <a href="#" onclick="document.url" target="_blank">{% translate "See their edits in another tab" %}</a>
<input id="your-changes" type="submit" value="{% translate "Keep your changes and loose theirs" %}"> <input id="your-changes" type="submit" value="{% translate "Keep your changes and loose theirs" %}">
@ -73,16 +73,16 @@
</div> </div>
</template> </template>
<umap-alert-choice></umap-alert-choice> <umap-alert-conflict></umap-alert-conflict>
<script type="module"> <script type="module">
import { register } from '{% static 'umap/js/components/base.js' %}' import { register } from '{% static 'umap/js/components/base.js' %}'
import { import {
uMapAlert, uMapAlert,
uMapAlertCreation, uMapAlertCreation,
uMapAlertChoice uMapAlertConflict
} from '{% static 'umap/js/components/alerts/alert.js' %}' } from '{% static 'umap/js/components/alerts/alert.js' %}'
register(uMapAlert, 'umap-alert') register(uMapAlert, 'umap-alert')
register(uMapAlertCreation, 'umap-alert-creation') register(uMapAlertCreation, 'umap-alert-creation')
register(uMapAlertChoice, 'umap-alert-choice') register(uMapAlertConflict, 'umap-alert-conflict')
</script> </script>

View file

@ -119,29 +119,29 @@ class uMapAlertCreation extends uMapAlert {
} }
} }
class uMapAlertChoice extends uMapAlert { class uMapAlertConflict extends uMapAlert {
static error( static error(
message, message,
// biome-ignore lint/style/useNumberNamespace: Number.Infinity returns undefined by default // biome-ignore lint/style/useNumberNamespace: Number.Infinity returns undefined by default
duration = Infinity duration = Infinity
) { ) {
uMapAlertChoice.emit('alertChoice', { level: 'error', message, duration }) uMapAlertConflict.emit('alertConflict', { level: 'error', message, duration })
} }
constructor() { constructor() {
super() super()
this.choiceWrapper = this.container.querySelector('#choice-wrapper') this.conflictWrapper = this.container.querySelector('#conflict-wrapper')
} }
onAlertChoice(event) { onAlertConflict(event) {
const { level = 'info', duration = 5000, message = '' } = event.detail const { level = 'info', duration = 5000, message = '' } = event.detail
uMapAlert.prototype.onAlert.call(this, { detail: { level, duration, message } }) uMapAlert.prototype.onAlert.call(this, { detail: { level, duration, message } })
const form = this.choiceWrapper.querySelector('form') const form = this.conflictWrapper.querySelector('form')
form.addEventListener('submit', (event) => { form.addEventListener('submit', (event) => {
event.preventDefault() event.preventDefault()
switch (event.submitter.id) { switch (event.submitter.id) {
case 'your-changes': case 'your-changes':
uMapAlertChoice.emit('alertChoiceOverride') uMapAlertConflict.emit('alertConflictOverride')
break break
case 'their-changes': case 'their-changes':
window.location.reload() window.location.reload()
@ -153,8 +153,8 @@ class uMapAlertChoice extends uMapAlert {
connectedCallback() { connectedCallback() {
this._handleClose() this._handleClose()
this.listen('alertChoice') this.listen('alertConflict')
} }
} }
export { uMapAlert, uMapAlertCreation, uMapAlertChoice } export { uMapAlert, uMapAlertCreation, uMapAlertConflict }

View file

@ -16,7 +16,7 @@ import { SyncEngine } from './sync/engine.js'
import { import {
uMapAlert as Alert, uMapAlert as Alert,
uMapAlertCreation as AlertCreation, uMapAlertCreation as AlertCreation,
uMapAlertChoice as AlertChoice, uMapAlertConflict as AlertConflict,
} from '../components/alerts/alert.js' } from '../components/alerts/alert.js'
// Import modules and export them to the global scope. // Import modules and export them to the global scope.
@ -26,7 +26,7 @@ import {
window.U = { window.U = {
Alert, Alert,
AlertCreation, AlertCreation,
AlertChoice, AlertConflict,
AjaxAutocomplete, AjaxAutocomplete,
AjaxAutocompleteMultiple, AjaxAutocompleteMultiple,
Browser, Browser,

View file

@ -1707,13 +1707,13 @@ U.DataLayer = L.Evented.extend({
const [data, response, error] = await this.map.server.post(url, headers, formData) const [data, response, error] = await this.map.server.post(url, headers, formData)
if (error) { if (error) {
if (response && response.status === 412) { if (response && response.status === 412) {
U.AlertChoice.error( U.AlertConflict.error(
L._( L._(
'Whoops! Other contributor(s) changed some of the same map elements as you. ' + 'Whoops! Other contributor(s) changed some of the same map elements as you. ' +
'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.'
) )
) )
document.addEventListener('alertChoiceOverride', async (event) => { document.addEventListener('alertConflictOverride', async (event) => {
await this._trySave(url, {}, formData) await this._trySave(url, {}, formData)
}) })
} }

View file

@ -8,6 +8,7 @@
--color-limeGreen: #b9f5d2; --color-limeGreen: #b9f5d2;
--color-brightCyan: #46ece6; --color-brightCyan: #46ece6;
--color-lightCyan: #d4fbf9; --color-lightCyan: #d4fbf9;
--color-red: #c60f13;
--background-color: var(--color-light); --background-color: var(--color-light);
--color-accent: var(--color-brightCyan); --color-accent: var(--color-brightCyan);