mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2025-12-13 17:56:20 +00:00
@@ -235,37 +235,6 @@ export const sampleIndexResponse: SCIndexResponse = {
|
||||
uid: 'dc9d6dec-6576-45ef-9e35-3598c0d6a662',
|
||||
values: ['de', 'en'],
|
||||
},
|
||||
{
|
||||
categories: ['privacy'],
|
||||
defaultValue: false,
|
||||
description: 'Allow the App to use the device location to provide additional information\'s based ' +
|
||||
'on your actual location.',
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'geoLocation',
|
||||
order: 0,
|
||||
origin: {
|
||||
indexed: '2018-09-11T12:30:00Z',
|
||||
name: 'Dummy',
|
||||
type: SCThingOriginType.Remote,
|
||||
},
|
||||
translations: {
|
||||
de: {
|
||||
description: `Berechtigung für die Verwendung des Ortungsdienstes, für die Anzeige der aktuellen Position '
|
||||
auf der Karte und zur Berechnung der Entfernung zu Gebäuden und Orten des Campus.`,
|
||||
name: 'Position',
|
||||
values: ['ja', 'nein'],
|
||||
},
|
||||
en: {
|
||||
description: 'Allow the App to use the device location to provide additional information\'s based ' +
|
||||
'on your actual location.',
|
||||
name: 'Position',
|
||||
values: ['yes', 'no'],
|
||||
},
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
uid: '0dbff2de-23b4-442b-9aa7-7bd2c707c199',
|
||||
values: [true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
backend: {
|
||||
|
||||
@@ -62,30 +62,6 @@ export class SettingsItemComponent {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for user permission to use location,
|
||||
* if no permission is granted, setting is set to false and an alert is presented to the user
|
||||
*/
|
||||
private async checkGeoLocationPermission() {
|
||||
const permissionGranted = await this.settingsProvider.checkGeoLocationPermission();
|
||||
if (!permissionGranted) {
|
||||
// revert setting value
|
||||
this.setting.value = false;
|
||||
await this.presentGeoLocationAlert();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows alert with error message on denied user permission or disabled location services
|
||||
*/
|
||||
private async presentGeoLocationAlert() {
|
||||
const title = await this.translateService.get('settings.geoLocation.permission_denied_title')
|
||||
.toPromise();
|
||||
const message = await this.translateService.get('settings.geoLocation.permission_denied_message')
|
||||
.toPromise();
|
||||
await this.presentAlert(title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows alert with given title and message and a 'ok' button
|
||||
*
|
||||
@@ -112,11 +88,6 @@ export class SettingsItemComponent {
|
||||
case 'language':
|
||||
this.translateService.use(this.setting.value as SCLanguageCode);
|
||||
break;
|
||||
case 'geoLocation':
|
||||
if (!!this.setting.value) {
|
||||
await this.checkGeoLocationPermission();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
await this.settingsProvider
|
||||
|
||||
@@ -16,7 +16,6 @@ import {CommonModule} from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {IonicModule} from '@ionic/angular';
|
||||
import {TranslateModule} from '@ngx-translate/core';
|
||||
|
||||
@@ -51,7 +50,6 @@ const settingsRoutes: Routes = [
|
||||
],
|
||||
providers: [
|
||||
ConfigProvider,
|
||||
Geolocation,
|
||||
SettingsProvider,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {SCSetting, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {SettingsProvider, SettingValuesContainer, STORAGE_KEY_SETTING_VALUES} from './settings.provider';
|
||||
@@ -38,7 +37,6 @@ describe('SettingsProvider', () => {
|
||||
{
|
||||
provide: ConfigProvider, useValue: configProviderMethodSpy,
|
||||
},
|
||||
Geolocation,
|
||||
],
|
||||
});
|
||||
configProviderSpy = TestBed.get(ConfigProvider);
|
||||
@@ -317,7 +315,7 @@ describe('SettingsProvider', () => {
|
||||
description: '',
|
||||
defaultValue: false,
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'geoLocation',
|
||||
name: 'foo',
|
||||
order: 0,
|
||||
origin: {
|
||||
indexed: '2018-09-11T12:30:00Z',
|
||||
@@ -326,14 +324,12 @@ describe('SettingsProvider', () => {
|
||||
},
|
||||
translations: {
|
||||
de: {
|
||||
description: 'Berechtigung für die Verwendung des Ortungsdienstes, für die Anzeige der aktuellen ' +
|
||||
'Position \'\n auf der Karte und zur Berechnung der Entfernung zu Gebäuden und Orten des Campus',
|
||||
name: 'Position',
|
||||
description: 'Foo Beschreibung',
|
||||
name: 'Foo',
|
||||
},
|
||||
en: {
|
||||
description: 'Allow the App to use the device location to provide additional informationsbased ' +
|
||||
'on your actual location',
|
||||
name: 'Position',
|
||||
description: 'Foo Description',
|
||||
name: 'Foo',
|
||||
},
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
@@ -374,7 +370,7 @@ const SETTING_VALUES_MOCK: SettingValuesContainer = {
|
||||
bar: 'foo-bar',
|
||||
},
|
||||
privacy: {
|
||||
geoLocation: 'true',
|
||||
foo: true,
|
||||
},
|
||||
profile: {
|
||||
group: 'employee',
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {
|
||||
SCSetting,
|
||||
SCSettingValue,
|
||||
@@ -196,11 +195,9 @@ export class SettingsProvider {
|
||||
*
|
||||
* @param storage TODO
|
||||
* @param configProvider TODO
|
||||
* @param geoLocation TODO
|
||||
*/
|
||||
constructor(private readonly storage: StorageProvider,
|
||||
private readonly configProvider: ConfigProvider,
|
||||
private readonly geoLocation: Geolocation) {
|
||||
private readonly configProvider: ConfigProvider) {
|
||||
this.categoriesOrder = [];
|
||||
this.settingsCache = {};
|
||||
}
|
||||
@@ -265,32 +262,6 @@ export class SettingsProvider {
|
||||
return this.settingsCache[category] !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for user permission to use location
|
||||
*/
|
||||
public async checkGeoLocationPermission(): Promise<boolean> {
|
||||
// request geoLocation to test the user permission
|
||||
try {
|
||||
// set enableHighAccuracy, otherwise android platform does not respond
|
||||
const options = {
|
||||
enableHighAccuracy: true,
|
||||
};
|
||||
await this.geoLocation.getCurrentPosition(options);
|
||||
} catch (error) {
|
||||
// if error code is 1 the user denied permission,
|
||||
// other errors like 'timeout' or 'no location' will be ignored here
|
||||
if (error.code === 1) {
|
||||
// ios has special error message for disabled location services, for the setting we ignore it
|
||||
if (error.message.toLowerCase() !== 'location services are disabled.') {
|
||||
// revert setting value
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns copy of cached settings
|
||||
*/
|
||||
|
||||
@@ -78,10 +78,6 @@
|
||||
"resetAlert.buttonCancel": "Abbrechen",
|
||||
"resetToast.message": "Einstellungen wurden zurückgesetzt",
|
||||
"title": "Einstellungen",
|
||||
"geoLocation": {
|
||||
"permission_denied_title": "Erlaubnis für Ortungsdienst nicht gegeben",
|
||||
"permission_denied_message": "Erlaube der App die Nutzung des Ortungsdienstes, um diese Funktion zu aktivieren."
|
||||
},
|
||||
"resetSettings": "Einstellungen zurücksetzen"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,10 +78,6 @@
|
||||
"resetAlert.buttonCancel": "cancel",
|
||||
"resetToast.message": "Settings reset",
|
||||
"title": "Settings",
|
||||
"geoLocation": {
|
||||
"permission_denied_title": "Location permission not granted",
|
||||
"permission_denied_message": "Allow this app to use location services to activate this feature."
|
||||
},
|
||||
"resetSettings": "Reset Settings"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user