From 2846e6838a9abd6c14c4fbb662ba732b8c0e9eb1 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 10 Dec 2019 17:06:04 +0100 Subject: [PATCH 1/3] MOBILE-2159 geolocation: Improve error message when permission is denied --- src/addon/mod/data/fields/latlong/component/latlong.ts | 10 ++++++++++ src/addon/mod/data/lang/en.json | 1 + src/assets/lang/en.json | 1 + 3 files changed, 12 insertions(+) diff --git a/src/addon/mod/data/fields/latlong/component/latlong.ts b/src/addon/mod/data/fields/latlong/component/latlong.ts index 767487e9d..013c4586e 100644 --- a/src/addon/mod/data/fields/latlong/component/latlong.ts +++ b/src/addon/mod/data/fields/latlong/component/latlong.ts @@ -117,9 +117,19 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo this.form.controls['f_' + this.field.id + '_0'].setValue(result.coords.latitude); this.form.controls['f_' + this.field.id + '_1'].setValue(result.coords.longitude); }).catch((error) => { + if (this.isPositionError(error) && error.code === error.PERMISSION_DENIED) { + this.domUtils.showErrorModal('addon.mod_data.locationpermissiondenied', true); + + return; + } + this.domUtils.showErrorModalDefault(error, 'Error getting location'); }).finally(() => { modal.dismiss(); }); } + + protected isPositionError(error?: any): error is PositionError { + return error && 'code' in error && 'PERMISSION_DENIED' in error; + } } diff --git a/src/addon/mod/data/lang/en.json b/src/addon/mod/data/lang/en.json index 54de61215..de89c6bca 100644 --- a/src/addon/mod/data/lang/en.json +++ b/src/addon/mod/data/lang/en.json @@ -22,6 +22,7 @@ "foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)", "gettinglocation": "Getting location", "latlongboth": "Both latitude and longitude are required.", + "locationpermissiondenied": "Permission to access your location has been denied.", "menuchoose": "Choose...", "modulenameplural": "Databases", "more": "More", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 93693ba6f..e0fb0fd71 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -501,6 +501,7 @@ "addon.mod_data.foundrecords": "Found records: {{$a.num}}/{{$a.max}} (Reset filters)", "addon.mod_data.gettinglocation": "Getting location", "addon.mod_data.latlongboth": "Both latitude and longitude are required.", + "addon.mod_data.locationpermissiondenied": "Permission to access your location has been denied.", "addon.mod_data.menuchoose": "Choose...", "addon.mod_data.modulenameplural": "Databases", "addon.mod_data.more": "More", From 74362d2abab22e9799a8dd31db140c4f0728a534 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 10 Dec 2019 17:23:26 +0100 Subject: [PATCH 2/3] MOBILE-2159 geolocation: Add new message key to langindex.json --- scripts/langindex.json | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/langindex.json b/scripts/langindex.json index d5a8c1769..5200cc6d6 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -502,6 +502,7 @@ "addon.mod_data.foundrecords": "data", "addon.mod_data.gettinglocation": "local_moodlemobileapp", "addon.mod_data.latlongboth": "data", + "addon.mod_data.locationpermissiondenied": "local_moodlemobileapp", "addon.mod_data.menuchoose": "data", "addon.mod_data.modulenameplural": "data", "addon.mod_data.more": "data", From 3d67ee62dee58afdabd194fa318e57094fabc5d1 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 11 Dec 2019 10:18:21 +0100 Subject: [PATCH 3/3] MOBILE-2159 geolocation: Replace type guard with simpler code --- src/addon/mod/data/fields/latlong/component/latlong.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/addon/mod/data/fields/latlong/component/latlong.ts b/src/addon/mod/data/fields/latlong/component/latlong.ts index 013c4586e..e322abf07 100644 --- a/src/addon/mod/data/fields/latlong/component/latlong.ts +++ b/src/addon/mod/data/fields/latlong/component/latlong.ts @@ -117,7 +117,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo this.form.controls['f_' + this.field.id + '_0'].setValue(result.coords.latitude); this.form.controls['f_' + this.field.id + '_1'].setValue(result.coords.longitude); }).catch((error) => { - if (this.isPositionError(error) && error.code === error.PERMISSION_DENIED) { + if (this.isPermissionDeniedError(error)) { this.domUtils.showErrorModal('addon.mod_data.locationpermissiondenied', true); return; @@ -129,7 +129,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo }); } - protected isPositionError(error?: any): error is PositionError { - return error && 'code' in error && 'PERMISSION_DENIED' in error; + protected isPermissionDeniedError(error?: any): boolean { + return error && 'code' in error && 'PERMISSION_DENIED' in error && error.code === error.PERMISSION_DENIED; } }