JGirault has uploaded a new change for review. https://gerrit.wikimedia.org/r/320538
Change subject: Gracefully handle broken ExternalData groups, by not crashing and displaying a user-friendly warning ...................................................................... Gracefully handle broken ExternalData groups, by not crashing and displaying a user-friendly warning Bug: T148883 Change-Id: I681561e148d3c4a0cdaa9897e8891f4652cb5477 --- M extension.json M i18n/en.json M i18n/qqq.json M modules/box/Map.js M styles/images/COPYING A styles/images/alert.png A styles/images/alert.svg M styles/kartographer.less 8 files changed, 115 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer refs/changes/38/320538/1 diff --git a/extension.json b/extension.json index 6b2729d..7687ff8 100644 --- a/extension.json +++ b/extension.json @@ -188,7 +188,8 @@ "modules/box/index.js" ], "messages": [ - "kartographer-attribution" + "kartographer-attribution", + "kartographer-error-loadgroups" ], "targets": [ "mobile", diff --git a/i18n/en.json b/i18n/en.json index 193add7..eaef032 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -23,6 +23,7 @@ "kartographer-error-context": "<$1>: $2", "kartographer-error-context-multi": "<$1> problems:\n$2", "kartographer-error-json": "Couldn't parse JSON: $1", + "kartographer-error-loadgroups": "An issue happened while loading map data.", "kartographer-error-missing-attr": "Attribute \"$1\" is missing", "kartographer-error-bad_attr": "Attribute \"$1\" has an invalid value", "kartographer-error-bad_data": "The JSON content is not valid GeoJSON+simplestyle", diff --git a/i18n/qqq.json b/i18n/qqq.json index 06a721f..9a3e6de 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -27,6 +27,7 @@ "kartographer-error-context": "{{Optional}}\nGeneral message shown before a single specific error\n\nParameters:\n* $1 - tag name, 'mapframe' or 'maplink'\n* $2 - error message", "kartographer-error-context-multi": "General message shown before multiple errors\n\nParameters:\n* $1 - tag name, 'mapframe', 'maplink' or 'mapdata'\n* $2 - list of errors combined into a bullet list", "kartographer-error-json": "Error message preceding JSON errors\nParameters: $1 - underlying message from JSON parser", + "kartographer-error-loadgroups": "Error message to warn the user that some map data is missing, because an error happened when loading map data.", "kartographer-error-missing-attr": "Error shown instead of a map when required parameter(s) is missing.\n\nParameters:\n* $1 - non-localized attribute name, such as 'height', 'latitude', etc", "kartographer-error-bad_attr": "Error shown instead of a map in case of a problem with parameters.\n\nParameters:\n* $1 - non-localized attribute name, such as 'height', 'latitude', etc", "kartographer-error-bad_data": "This error is shown if the content of the tag is syntactically valid JSON however it does not adhere to GeoJSON and simplestyle specifications", diff --git a/modules/box/Map.js b/modules/box/Map.js index 1fa5c9b..537179b 100644 --- a/modules/box/Map.js +++ b/modules/box/Map.js @@ -304,9 +304,19 @@ } else { ready(); } - } ).then( undefined, function ( err ) { - // console will catch this - throw err; + } ).then( undefined, function () { + // Handle failed groups gracefully. + var $errors = $( '<div class="mw-kartographer-errors">' ), + $error = $( '<p class="warning">' ) + .append( '<span class="mw-kartographer-warning-icon">' ) + .append( $( '<span class="mw-kartographer-warning-text">' ).text( mw.msg( 'kartographer-error-loadgroups' ) ) ); + + map.$container + .append( $errors.append( $error ) ) + .one( 'click', function () { + $errors.remove(); + } ); + ready(); } ); }, @@ -378,11 +388,15 @@ } DataManager.loadGroups( dataGroups ).then( function ( dataGroups ) { - + var containsErrors = !dataGroups.length; $.each( dataGroups, function ( key, group ) { var layerOptions = { attribution: group.attribution }; + if ( group.failed ) { + containsErrors = true; + return; + } if ( group.isExternal ) { layerOptions.name = group.attribution; } @@ -392,7 +406,11 @@ mw.log.warn( 'Layer not found or contains no data: "' + group.id + '"' ); } } ); - deferred.resolve(); + if ( containsErrors ) { + deferred.reject(); + } else { + deferred.resolve(); + } } ).then( undefined, function ( err ) { deferred.reject( err ); } ); @@ -413,11 +431,16 @@ options = options || {}; DataManager.load( groupData ).then( function ( dataGroups ) { + var containsErrors = false; $.each( dataGroups, function ( key, group ) { var groupId = inlineDataLayerKey + inlineDataLayerId++, layerOptions = { attribution: group.attribution || options.attribution }; + if ( group.failed ) { + containsErrors = true; + return; + } if ( group.isExternal ) { layerOptions.name = group.attribution; } @@ -427,7 +450,11 @@ mw.log.warn( 'Layer not found or contains no data: "' + groupId + '"' ); } } ); - deferred.resolve(); + if ( containsErrors ) { + deferred.reject(); + } else { + deferred.resolve(); + } } ).then( undefined, function ( err ) { deferred.reject( err ); } ); diff --git a/styles/images/COPYING b/styles/images/COPYING index beb4377..d1695d8 100644 --- a/styles/images/COPYING +++ b/styles/images/COPYING @@ -6,3 +6,10 @@ === mapPin-progressive.png === Same as above, copied from OOjs UI repository after the build process generated the progressive icons. + +=== alert.svg === +This icon file was copied from OOjs UI repository. +The master version is: https://github.com/wikimedia/oojs-ui/blob/master/src/themes/mediawiki/images/icons/alert.svg + +=== alert.png === +Same as above, copied from OOjs UI repository after the build process generated the icons. diff --git a/styles/images/alert.png b/styles/images/alert.png new file mode 100644 index 0000000..7355084 --- /dev/null +++ b/styles/images/alert.png Binary files differ diff --git a/styles/images/alert.svg b/styles/images/alert.svg new file mode 100644 index 0000000..8b601d5 --- /dev/null +++ b/styles/images/alert.svg @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> + <g id="alert"> + <path id="point" d="M11 16h2v2h-2z"/> + <path id="stroke" d="M13.516 10h-3L11 15h2z"/> + <path id="triangle" d="M12.017 5.974L19.537 19H4.497l7.52-13.026m0-2.474c-.545 0-1.09.357-1.5 1.07L2.53 18.403C1.705 19.833 2.38 21 4.03 21H20c1.65 0 2.325-1.17 1.5-2.6L13.517 4.575c-.413-.715-.956-1.072-1.5-1.072z"/> + </g> +</svg> diff --git a/styles/kartographer.less b/styles/kartographer.less index 2ff1141..f2ad1d6 100644 --- a/styles/kartographer.less +++ b/styles/kartographer.less @@ -34,6 +34,7 @@ * .mw-kartographer-link then, if displaying static snapshot. * .mw-kartographer-interactive then, if directly interactive. */ +@import 'mediawiki.mixins'; .mw-kartographer-mapDialog-map { position: absolute; @@ -130,3 +131,65 @@ clear: left; margin: 0.3em 0.5em 0.5em 0; } + +.leaflet-container { + .mw-kartographer-errors { + position: absolute; + top: 2em; + left: 0; + right: 0; + z-index: 4; + text-align: center; + + p { + border-radius: 2px; + + display: inline-block; + + max-width: 60%; + margin-left: auto; + margin-right: auto; + padding: 0.5em 0.5em; + box-shadow: 0 1px 2px 0 rgba( 0, 0, 0, 0.2 ); + + font-size: 14px; + font-weight: bold; + line-height: normal; + text-align: left; + + .mw-kartographer-warning-text { + display: table-cell; + padding-left: 0.5em; + padding-right: 0.5em; + } + .mw-kartographer-warning-icon { + /** + * These two files were copied from OOjs UI repository after the build process + * generated the icons. + * + * See ./images/COPYING + * + * The master version of the icon is at: + * https://github.com/wikimedia/oojs-ui/blob/master/src/themes/mediawiki/images/icons/alert.svg + */ + .background-image-svg('./images/alert.svg', './images/alert.png'); + background-position: center center; + background-repeat: no-repeat; + + display: table-cell; + + width: 18px; + padding-left: 0.5em; + padding-right: 0.5em; + + line-height: normal; + vertical-align: middle; + + } + &.warning { + background-color: rgba( 254, 246, 231, 0.8 ); // #fef6e7, 80% + color: #ac6600; + } + } + } +} -- To view, visit https://gerrit.wikimedia.org/r/320538 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I681561e148d3c4a0cdaa9897e8891f4652cb5477 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Kartographer Gerrit-Branch: master Gerrit-Owner: JGirault <julien.inbox.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits