Skip to content

Commit

Permalink
Added feedback messages on save/save as
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Jan 10, 2018
1 parent 7196f16 commit b408315
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 2 deletions.
1 change: 1 addition & 0 deletions docma-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

"web/client/utils/index.jsdoc",
"web/client/utils/CoordinatesUtils.js",
"web/client/utils/LocaleUtils.js",
"web/client/utils/PluginsUtils.js",
"web/client/utils/PrintUtils.js",
"web/client/utils/ogc/Filter/FilterBuilder.js",
Expand Down
27 changes: 25 additions & 2 deletions web/client/actions/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const {updateCurrentMapPermissions, updateCurrentMapGroups} = require('./current
const ConfigUtils = require('../utils/ConfigUtils');
const assign = require('object-assign');
const {get, findIndex} = require('lodash');
const {error: notificationError, success: notificationSuccess} = require('./notifications');
const {getErrorMessage} = require('../utils/LocaleUtils');

const MAPS_LIST_LOADED = 'MAPS_LIST_LOADED';
const MAPS_LIST_LOADING = 'MAPS_LIST_LOADING';
Expand Down Expand Up @@ -407,15 +409,25 @@ function loadAvailableGroups(user) {
* @param {number} resourceId the id of the map to update
* @param {object} content the new content
* @param {object} [options] options for the request
* @return {thunk} dispatches mapUpdating or loadError
* @return {thunk} dispatches notificationSuccess or loadError and notificationError
*/
function updateMap(resourceId, content, options) {
return (dispatch) => {
dispatch(mapUpdating(resourceId, content));
GeoStoreApi.putResource(resourceId, content, options).then(() => {
// dispatch(mapUpdated(resourceId, content, "success")); // TODO wrong usage, use another action
dispatch(notificationSuccess({
title: 'map.savedMapTitle',
message: 'map.savedMapMessage',
autoDismiss: 6,
position: 'tc'
}));
}).catch((e) => {
dispatch(loadError(e));
dispatch(notificationError({
...getErrorMessage(e, 'geostore', 'mapsError'),
autoDismiss: 6,
position: 'tc'
}));
});
};
}
Expand Down Expand Up @@ -626,8 +638,19 @@ function createMap(metadata, content, thumbnail, options) {
}
dispatch(mapCreated(response.data, assign({id: response.data, canDelete: true, canEdit: true, canCopy: true}, metadata), content));
dispatch(onDisplayMetadataEdit(false));
dispatch(notificationSuccess({
title: 'map.savedMapTitle',
message: 'map.savedMapMessage',
autoDismiss: 6,
position: 'tc'
}));
}).catch((e) => {
dispatch(mapError(e));
dispatch(notificationError({
...getErrorMessage(e, 'geostore', 'mapsError'),
autoDismiss: 6,
position: 'tc'
}));
});
};
}
Expand Down
6 changes: 6 additions & 0 deletions web/client/translations/data.de-DE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"enable": "Aktiviere",
"layers": "Ebenen",
"warning": "Warnung",
"errorTitleDefault": "Fehler",
"errorDefault": "Ein Fehler ist aufgetreten",
"version": {
"label": "Version"
},
Expand Down Expand Up @@ -209,16 +211,20 @@
"errorFormat": "Unterstützte Formate: png/jpg",
"errorSize": "Maximal zulässige Größe: 500kb",
"error": "Das bereitgestellte Bild ist ungültig",
"savedMapTitle": "Gespeicherte Karte",
"savedMapMessage": "Karte wurde korrekt gespeichert",
"thumbnailError": {
"error403": "Du hast keine Berechtigung um Thumbnails hochzuladen",
"error404": "Es gab einen Fehler während der Erstellung des Thumbnails",
"error409": "Ein Thumbnail mit diesem Namen existiert bereits",
"errorDefault": "Netzwerk Fehler"
},
"mapError": {
"errorTitle": "Aktuelle Karte kann nicht gespeichert werden",
"error403": "Du hast keine Berechtigung die Karte zu aktualisieren",
"error404": "Es gab einen Fehler während der Erstellung der Karte",
"error409": "Eine Karte mit diesem Namen existiert bereits",
"error500": "Interner Serverfehler. Überprüfen Sie, ob die Größe der Kartenkonfigurationsdatei den festgelegten Grenzwert überschreitet",
"errorDefault": "Netzwerk Fehler"
},
"permissions": {
Expand Down
6 changes: 6 additions & 0 deletions web/client/translations/data.en-US
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"enable": "Enable",
"layers": "Layers",
"warning": "Warning",
"errorTitleDefault": "Error",
"errorDefault": "An error occurred",
"version": {
"label": "Version"
},
Expand Down Expand Up @@ -209,16 +211,20 @@
"errorFormat": "Supported formats: png/jpg",
"errorSize": "Max allowed size: 500kb",
"error": "The provided image is invalid",
"savedMapTitle": "Saved Map",
"savedMapMessage": "Map has been saved correctly",
"thumbnailError": {
"error403": "You are not allowed to update the thumbnail",
"error404": "An error occurred while creating the thumbnail",
"error409": "A thumbnail with this name already exists",
"errorDefault": "Network error"
},
"mapError": {
"errorTitle": "Cannot save current map",
"error403": "You are not allowed to update the map",
"error404": "An error occurred while creating the map",
"error409": "A map with this name already exists",
"error500": "Internal Server Error. Verify if map configuration file size exceeds fixed limit",
"errorDefault": "Network error"
},
"permissions": {
Expand Down
6 changes: 6 additions & 0 deletions web/client/translations/data.es-ES
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"enable": "Activar",
"layers": "Capas",
"warning": "Atención",
"errorTitleDefault": "Error",
"errorDefault": "Ocurrió un error",
"version": {
"label": "Versión"
},
Expand Down Expand Up @@ -209,16 +211,20 @@
"errorFormat": "Formatos soportados: png/jpg",
"errorSize": "Tamaño máximo admitido: 500kb",
"error": "La imagen proporcionada es inválida",
"savedMapTitle": "Mapa Guardado",
"savedMapMessage": "El mapa se ha guardado correctamente",
"thumbnailError": {
"error403": "Error al modificar la viñeta",
"error404": "Error al crear la viñeta",
"error409": "Nombre de viñeta repetido",
"errorDefault": "Error de red"
},
"mapError": {
"errorTitle": "No se puede guardar el mapa actual",
"error403": "Error al modificar el mapa",
"error404": "Error al crear el mapa",
"error409": "Nombre del mapa repetido",
"error500": "Error de servidor interno. Verificar si el tamaño del archivo de configuración del mapa excede el límite fijado",
"errorDefault": "Error de red"
},
"permissions": {
Expand Down
6 changes: 6 additions & 0 deletions web/client/translations/data.fr-FR
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"enable": "Activer",
"layers": "Couches",
"warning": "Attention",
"errorTitleDefault": "Erreur",
"errorDefault": "Une erreur est survenue",
"version": {
"label": "Version"
},
Expand Down Expand Up @@ -210,16 +212,20 @@
"errorFormat": "Formats supportés: png/jpg",
"errorSize": "taille maximum autorisée: 500kb",
"error": "L'image fournie est pas valide",
"savedMapTitle": "Carte Sauvegardée",
"savedMapMessage": "La carte a été enregistrée correctement",
"thumbnailError": {
"error403": "Une erreur est survenue lors de la suppression de la vignette",
"error404": "Une erreur est survenue lors de la création de la vignette",
"error409": "Nom de la vignette déjà choisie",
"errorDefault": "Une erreur est survenue sur le serveur"
},
"mapError": {
"errorTitle": "Impossible d'enregistrer la carte actuelle",
"error403": "Une erreur est survenue lors de la suppression de la carte",
"error404": "Une erreur est survenue lors de la création de la carte",
"error409": "Nom de la carte déjà choisie",
"error500": "Erreur Interne du Serveur. Vérifier si la taille du fichier de configuration de la carte dépasse la limite fixée",
"errorDefault": "Une erreur est survenue sur le serveur"
},
"permissions": {
Expand Down
6 changes: 6 additions & 0 deletions web/client/translations/data.it-IT
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"enable": "Abilita",
"layers": "Livelli",
"warning": "Attenzione",
"errorTitleDefault": "Errore",
"errorDefault": "Si è verificato un errore",
"version": {
"label": "Versione"
},
Expand Down Expand Up @@ -209,16 +211,20 @@
"errorFormat": "Formati supportati: png/jpg",
"errorSize": "Dimensione massima consentita: 500kb",
"error": "L'immagine fornita non è valida",
"savedMapTitle": "Mappa Salvata",
"savedMapMessage": "La mappa è stata salvata correttamente",
"thumbnailError": {
"error403": "Non disponi dei permessi per aggiornare la thumbnail",
"error404": "Non è stato possibile creare la thumbnail sul server",
"error409": "Una thumbnail con questo nome esiste già",
"errorDefault": "Errore di rete"
},
"mapError": {
"errorTitle": "Non è stato possibile salvare la mappa",
"error403": "Non disponi dei permessi per aggiornare la mappa",
"error404": "Non è stato possibile creare la mappa sul server",
"error409": "Una mappa con questo nome esiste già",
"error500": "Errore interno del server. Verificare se la dimensione della configurazione di mappa supera il limite fissato",
"errorDefault": "Errore di rete"
},
"permissions": {
Expand Down
34 changes: 34 additions & 0 deletions web/client/utils/LocaleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ const DATE_FORMATS = {
"it-IT": "dd/MM/yyyy",
"nl-NL": "dd/MM/yyyy"
};

const errorParser = {
geostore: {
mapsError: e => {
if (e.status === 403 || e.status === 404 || e.status === 409 || e.status === 500) {
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.error' + e.status
};
}
return {
title: 'map.mapError.errorTitle',
message: 'map.mapError.errorDefault'
};
}
}
};
/**
* Utilities for locales.
* @memberof utils
*/
const LocaleUtils = {
ensureIntl(callback) {
require.ensure(['intl', 'intl/locale-data/jsonp/en.js', 'intl/locale-data/jsonp/it.js', 'intl/locale-data/jsonp/fr.js', 'intl/locale-data/jsonp/de.js', 'intl/locale-data/jsonp/es.js', 'intl/locale-data/jsonp/nl.js'], (require) => {
Expand Down Expand Up @@ -107,6 +128,19 @@ const LocaleUtils = {
message = message ? message[part] : null;
});
return message;
},
/**
* Return localized id of error messages
* @param e {object} error
* @param service {string} service that thrown the error
* @param section {string} section where the error happens
* @return {object} {title, message}
*/
getErrorMessage: (e, service, section) => {
return service && section && errorParser[service] && errorParser[service][section] && errorParser[service][section](e) || {
title: 'errorTitleDefault',
message: 'errorDefault'
};
}
};

Expand Down
15 changes: 15 additions & 0 deletions web/client/utils/__tests__/LocaleUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@ describe('LocaleUtils', () => {
it('getSupportedLocales', () => {
expect(LocaleUtils.getSupportedLocales()).toExist();
});

it('getErrorMessage', () => {
expect(LocaleUtils.getErrorMessage({status: 409}, 'geostore', 'mapsError')).toEqual({
title: 'map.mapError.errorTitle',
message: 'map.mapError.error409'
});
expect(LocaleUtils.getErrorMessage({status: 0}, 'geostore', 'mapsError')).toEqual({
title: 'map.mapError.errorTitle',
message: 'map.mapError.errorDefault'
});
expect(LocaleUtils.getErrorMessage()).toEqual({
title: 'errorTitleDefault',
message: 'errorDefault'
});
});
});

0 comments on commit b408315

Please sign in to comment.