chore: direct import of the Alert class in modules

This commit is contained in:
David Larlet 2024-06-12 18:30:40 -04:00
parent cea2aee88f
commit 8400b55b9d
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
2 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,6 @@
import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js' import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from './i18n.js' import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js'
export default class Importer { export default class Importer {
constructor(map) { constructor(map) {
@ -163,12 +164,14 @@ export default class Importer {
this.map.processFileToImport(file, layer, type) this.map.processFileToImport(file, layer, type)
} }
} else { } else {
if (!type) return U.Alert.error(L._('Please choose a format')) if (!type) {
return Alert.error(L._('Please choose a format'))
}
if (this.rawInput.value && type === 'umap') { if (this.rawInput.value && type === 'umap') {
try { try {
this.map.importRaw(this.rawInput.value, type) this.map.importRaw(this.rawInput.value, type)
} catch (e) { } catch (e) {
U.Alert.error(L._('Invalid umap data')) Alert.error(L._('Invalid umap data'))
console.error(e) console.error(e)
} }
} else { } else {

View file

@ -1,4 +1,5 @@
import { translate } from './i18n.js' import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js'
export class RequestError extends Error {} export class RequestError extends Error {}
@ -79,7 +80,7 @@ export class Request extends BaseRequest {
} }
_onError(error) { _onError(error) {
U.Alert.error(translate('Problem in the response')) Alert.error(translate('Problem in the response'))
} }
_onNOK(error) { _onNOK(error) {
@ -125,9 +126,9 @@ export class ServerRequest extends Request {
try { try {
const data = await response.json() const data = await response.json()
if (data.info) { if (data.info) {
U.Alert.info(data.info) Alert.info(data.info)
} else if (data.error) { } else if (data.error) {
U.Alert.error(data.error) Alert.error(data.error)
return this._onError(new Error(data.error)) return this._onError(new Error(data.error))
} }
return [data, response, null] return [data, response, null]
@ -142,7 +143,7 @@ export class ServerRequest extends Request {
_onNOK(error) { _onNOK(error) {
if (error.status === 403) { if (error.status === 403) {
U.Alert.error(error.message || translate('Action not allowed :(')) Alert.error(error.message || translate('Action not allowed :('))
} }
return [{}, error.response, error] return [{}, error.response, error]
} }