mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
@@ -235,37 +235,6 @@ export const sampleIndexResponse: SCIndexResponse = {
|
|||||||
uid: 'dc9d6dec-6576-45ef-9e35-3598c0d6a662',
|
uid: 'dc9d6dec-6576-45ef-9e35-3598c0d6a662',
|
||||||
values: ['de', 'en'],
|
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: {
|
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
|
* Shows alert with given title and message and a 'ok' button
|
||||||
*
|
*
|
||||||
@@ -112,11 +88,6 @@ export class SettingsItemComponent {
|
|||||||
case 'language':
|
case 'language':
|
||||||
this.translateService.use(this.setting.value as SCLanguageCode);
|
this.translateService.use(this.setting.value as SCLanguageCode);
|
||||||
break;
|
break;
|
||||||
case 'geoLocation':
|
|
||||||
if (!!this.setting.value) {
|
|
||||||
await this.checkGeoLocationPermission();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
await this.settingsProvider
|
await this.settingsProvider
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {CommonModule} from '@angular/common';
|
|||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {FormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {RouterModule, Routes} from '@angular/router';
|
import {RouterModule, Routes} from '@angular/router';
|
||||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
|
||||||
import {IonicModule} from '@ionic/angular';
|
import {IonicModule} from '@ionic/angular';
|
||||||
import {TranslateModule} from '@ngx-translate/core';
|
import {TranslateModule} from '@ngx-translate/core';
|
||||||
|
|
||||||
@@ -51,7 +50,6 @@ const settingsRoutes: Routes = [
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
ConfigProvider,
|
ConfigProvider,
|
||||||
Geolocation,
|
|
||||||
SettingsProvider,
|
SettingsProvider,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {SCSetting, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
|
import {SCSetting, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
|
||||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
|
||||||
import {ConfigProvider} from '../config/config.provider';
|
import {ConfigProvider} from '../config/config.provider';
|
||||||
import {StorageProvider} from '../storage/storage.provider';
|
import {StorageProvider} from '../storage/storage.provider';
|
||||||
import {SettingsProvider, SettingValuesContainer, STORAGE_KEY_SETTING_VALUES} from './settings.provider';
|
import {SettingsProvider, SettingValuesContainer, STORAGE_KEY_SETTING_VALUES} from './settings.provider';
|
||||||
@@ -38,7 +37,6 @@ describe('SettingsProvider', () => {
|
|||||||
{
|
{
|
||||||
provide: ConfigProvider, useValue: configProviderMethodSpy,
|
provide: ConfigProvider, useValue: configProviderMethodSpy,
|
||||||
},
|
},
|
||||||
Geolocation,
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
configProviderSpy = TestBed.get(ConfigProvider);
|
configProviderSpy = TestBed.get(ConfigProvider);
|
||||||
@@ -317,7 +315,7 @@ describe('SettingsProvider', () => {
|
|||||||
description: '',
|
description: '',
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
inputType: SCSettingInputType.SingleChoice,
|
inputType: SCSettingInputType.SingleChoice,
|
||||||
name: 'geoLocation',
|
name: 'foo',
|
||||||
order: 0,
|
order: 0,
|
||||||
origin: {
|
origin: {
|
||||||
indexed: '2018-09-11T12:30:00Z',
|
indexed: '2018-09-11T12:30:00Z',
|
||||||
@@ -326,14 +324,12 @@ describe('SettingsProvider', () => {
|
|||||||
},
|
},
|
||||||
translations: {
|
translations: {
|
||||||
de: {
|
de: {
|
||||||
description: 'Berechtigung für die Verwendung des Ortungsdienstes, für die Anzeige der aktuellen ' +
|
description: 'Foo Beschreibung',
|
||||||
'Position \'\n auf der Karte und zur Berechnung der Entfernung zu Gebäuden und Orten des Campus',
|
name: 'Foo',
|
||||||
name: 'Position',
|
|
||||||
},
|
},
|
||||||
en: {
|
en: {
|
||||||
description: 'Allow the App to use the device location to provide additional informationsbased ' +
|
description: 'Foo Description',
|
||||||
'on your actual location',
|
name: 'Foo',
|
||||||
name: 'Position',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
type: SCThingType.Setting,
|
type: SCThingType.Setting,
|
||||||
@@ -374,7 +370,7 @@ const SETTING_VALUES_MOCK: SettingValuesContainer = {
|
|||||||
bar: 'foo-bar',
|
bar: 'foo-bar',
|
||||||
},
|
},
|
||||||
privacy: {
|
privacy: {
|
||||||
geoLocation: 'true',
|
foo: true,
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
group: 'employee',
|
group: 'employee',
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
|
||||||
import {
|
import {
|
||||||
SCSetting,
|
SCSetting,
|
||||||
SCSettingValue,
|
SCSettingValue,
|
||||||
@@ -196,11 +195,9 @@ export class SettingsProvider {
|
|||||||
*
|
*
|
||||||
* @param storage TODO
|
* @param storage TODO
|
||||||
* @param configProvider TODO
|
* @param configProvider TODO
|
||||||
* @param geoLocation TODO
|
|
||||||
*/
|
*/
|
||||||
constructor(private readonly storage: StorageProvider,
|
constructor(private readonly storage: StorageProvider,
|
||||||
private readonly configProvider: ConfigProvider,
|
private readonly configProvider: ConfigProvider) {
|
||||||
private readonly geoLocation: Geolocation) {
|
|
||||||
this.categoriesOrder = [];
|
this.categoriesOrder = [];
|
||||||
this.settingsCache = {};
|
this.settingsCache = {};
|
||||||
}
|
}
|
||||||
@@ -265,32 +262,6 @@ export class SettingsProvider {
|
|||||||
return this.settingsCache[category] !== undefined;
|
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
|
* Returns copy of cached settings
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -78,10 +78,6 @@
|
|||||||
"resetAlert.buttonCancel": "Abbrechen",
|
"resetAlert.buttonCancel": "Abbrechen",
|
||||||
"resetToast.message": "Einstellungen wurden zurückgesetzt",
|
"resetToast.message": "Einstellungen wurden zurückgesetzt",
|
||||||
"title": "Einstellungen",
|
"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"
|
"resetSettings": "Einstellungen zurücksetzen"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,10 +78,6 @@
|
|||||||
"resetAlert.buttonCancel": "cancel",
|
"resetAlert.buttonCancel": "cancel",
|
||||||
"resetToast.message": "Settings reset",
|
"resetToast.message": "Settings reset",
|
||||||
"title": "Settings",
|
"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"
|
"resetSettings": "Reset Settings"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user