mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-03-15 19:22:27 +00:00
feat: separate prettier from eslint
This commit is contained in:
committed by
Thea Schöbl
parent
939fb6ef0f
commit
a88d000ccd
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -15,12 +15,7 @@
|
||||
import {Component, Input} from '@angular/core';
|
||||
import {AlertController} from '@ionic/angular';
|
||||
import {LangChangeEvent, TranslateService} from '@ngx-translate/core';
|
||||
import {
|
||||
SCLanguageCode,
|
||||
SCSetting,
|
||||
SCSettingValue,
|
||||
SCSettingValues,
|
||||
} from '@openstapps/core';
|
||||
import {SCLanguageCode, SCSetting, SCSettingValue, SCSettingValues} from '@openstapps/core';
|
||||
import {SettingsProvider} from '../settings.provider';
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,17 +25,11 @@
|
||||
>
|
||||
<ion-card-subtitle>
|
||||
{{ vals.name }}
|
||||
<ion-icon
|
||||
*ngIf="compactView"
|
||||
name="info"
|
||||
(click)="presentAlert(vals.name, vals.desc)"
|
||||
></ion-icon>
|
||||
<ion-icon *ngIf="compactView" name="info" (click)="presentAlert(vals.name, vals.desc)"></ion-icon>
|
||||
</ion-card-subtitle>
|
||||
</ion-card-header>
|
||||
<ion-card-content>
|
||||
<ion-note *ngIf="!compactView">{{
|
||||
'description' | thingTranslate: setting | titlecase
|
||||
}}</ion-note>
|
||||
<ion-note *ngIf="!compactView">{{ 'description' | thingTranslate: setting | titlecase }}</ion-note>
|
||||
|
||||
<div [ngSwitch]="setting.inputType" *ngIf="isVisible">
|
||||
<ion-item *ngSwitchCase="'number'">
|
||||
@@ -83,10 +77,7 @@
|
||||
[(ngModel)]="setting.value"
|
||||
(ionChange)="settingChanged()"
|
||||
>
|
||||
<ion-select-option
|
||||
*ngFor="let val of setting.values; index as i"
|
||||
[value]="val"
|
||||
>
|
||||
<ion-select-option *ngFor="let val of setting.values; index as i" [value]="val">
|
||||
<div *ngIf="typeOf(val) !== 'number'">
|
||||
{{ ('values' | thingTranslate: setting)[i] | titlecase }}
|
||||
</div>
|
||||
@@ -97,15 +88,8 @@
|
||||
|
||||
<ion-item *ngSwitchCase="'multiple choice'">
|
||||
<ion-label></ion-label>
|
||||
<ion-select
|
||||
[(ngModel)]="setting.value"
|
||||
multiple="true"
|
||||
(ionChange)="settingChanged()"
|
||||
>
|
||||
<ion-select-option
|
||||
*ngFor="let val of setting.values; index as i"
|
||||
[value]="val"
|
||||
>
|
||||
<ion-select [(ngModel)]="setting.value" multiple="true" (ionChange)="settingChanged()">
|
||||
<ion-select-option *ngFor="let val of setting.values; index as i" [value]="val">
|
||||
<div *ngIf="typeOf(val) !== 'number'">
|
||||
{{ ('values' | thingTranslate: setting)[i] | titlecase }}
|
||||
</div>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {StorageProvider} from '../../storage/storage.provider';
|
||||
@@ -18,9 +18,7 @@ import {StorageProvider} from '../../storage/storage.provider';
|
||||
export const CALENDAR_SYNC_SETTINGS_KEY = 'calendarSettings';
|
||||
export const CALENDAR_SYNC_ENABLED_KEY = 'sync';
|
||||
export const CALENDAR_NOTIFICATIONS_ENABLED_KEY = 'notifications';
|
||||
export type CALENDAR_SYNC_KEYS =
|
||||
| typeof CALENDAR_SYNC_ENABLED_KEY
|
||||
| typeof CALENDAR_NOTIFICATIONS_ENABLED_KEY;
|
||||
export type CALENDAR_SYNC_KEYS = typeof CALENDAR_SYNC_ENABLED_KEY | typeof CALENDAR_NOTIFICATIONS_ENABLED_KEY;
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
@@ -63,18 +63,11 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
||||
this.isWeb = it.platform === 'web';
|
||||
});
|
||||
|
||||
this.getSetting(CALENDAR_SYNC_ENABLED_KEY).then(
|
||||
it => (this.syncEnabled = it),
|
||||
);
|
||||
this.getSetting(CALENDAR_NOTIFICATIONS_ENABLED_KEY).then(
|
||||
it => (this.notificationsEnabled = it),
|
||||
);
|
||||
this.getSetting(CALENDAR_SYNC_ENABLED_KEY).then(it => (this.syncEnabled = it));
|
||||
this.getSetting(CALENDAR_NOTIFICATIONS_ENABLED_KEY).then(it => (this.notificationsEnabled = it));
|
||||
}
|
||||
|
||||
async getSetting(
|
||||
key: CALENDAR_SYNC_KEYS,
|
||||
defaultValue = false,
|
||||
): Promise<boolean> {
|
||||
async getSetting(key: CALENDAR_SYNC_KEYS, defaultValue = false): Promise<boolean> {
|
||||
return getCalendarSetting(this.storageProvider, key, defaultValue);
|
||||
}
|
||||
|
||||
@@ -82,11 +75,8 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
||||
this.syncEnabled = sync;
|
||||
|
||||
if (sync) {
|
||||
const uuids = this.scheduleProvider.partialEvents$.value.map(
|
||||
it => it.uid,
|
||||
);
|
||||
const dateSeries = (await this.scheduleProvider.getDateSeries(uuids))
|
||||
.dates;
|
||||
const uuids = this.scheduleProvider.partialEvents$.value.map(it => it.uid);
|
||||
const dateSeries = (await this.scheduleProvider.getDateSeries(uuids)).dates;
|
||||
|
||||
await this.calendarService.syncEvents(
|
||||
getNativeCalendarExport(dateSeries, this.thingTranslator.translator),
|
||||
@@ -132,31 +122,19 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
||||
const uuids = JSON.parse(await file.text()) as SCUuid[] | unknown;
|
||||
if (!Array.isArray(uuids) || uuids.some(it => typeof it !== 'string')) {
|
||||
return Dialog.alert({
|
||||
title: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.rejectFile.title',
|
||||
),
|
||||
message: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.rejectFile.message',
|
||||
),
|
||||
title: this.translator.instant('settings.calendar.export.dialogs.restore.rejectFile.title'),
|
||||
message: this.translator.instant('settings.calendar.export.dialogs.restore.rejectFile.message'),
|
||||
});
|
||||
}
|
||||
const dateSeries = await this.scheduleProvider.restore(uuids);
|
||||
return dateSeries
|
||||
? Dialog.confirm({
|
||||
title: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.success.title',
|
||||
),
|
||||
message: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.success.message',
|
||||
),
|
||||
title: this.translator.instant('settings.calendar.export.dialogs.restore.success.title'),
|
||||
message: this.translator.instant('settings.calendar.export.dialogs.restore.success.message'),
|
||||
})
|
||||
: Dialog.alert({
|
||||
title: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.error.title',
|
||||
),
|
||||
message: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.restore.error.message',
|
||||
),
|
||||
title: this.translator.instant('settings.calendar.export.dialogs.restore.error.title'),
|
||||
message: this.translator.instant('settings.calendar.export.dialogs.restore.error.message'),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,13 +144,9 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
||||
}
|
||||
|
||||
async backup() {
|
||||
const uuids = JSON.stringify(
|
||||
this.scheduleProvider.partialEvents$.value.map(it => it.uid),
|
||||
);
|
||||
const uuids = JSON.stringify(this.scheduleProvider.partialEvents$.value.map(it => it.uid));
|
||||
|
||||
const fileName = `${this.translator.instant(
|
||||
'settings.calendar.export.fileName',
|
||||
)}.json`;
|
||||
const fileName = `${this.translator.instant('settings.calendar.export.fileName')}.json`;
|
||||
const info = await Device.getInfo();
|
||||
if (info.platform === 'web') {
|
||||
const blob = new Blob([uuids], {type: 'application/json'});
|
||||
@@ -191,16 +165,10 @@ export class CalendarSyncSettingsComponent implements OnInit {
|
||||
});
|
||||
|
||||
await Share.share({
|
||||
title: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.backup.save.title',
|
||||
),
|
||||
text: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.backup.save.message',
|
||||
),
|
||||
title: this.translator.instant('settings.calendar.export.dialogs.backup.save.title'),
|
||||
text: this.translator.instant('settings.calendar.export.dialogs.backup.save.message'),
|
||||
url: result.uri,
|
||||
dialogTitle: this.translator.instant(
|
||||
'settings.calendar.export.dialogs.backup.save.title',
|
||||
),
|
||||
dialogTitle: this.translator.instant('settings.calendar.export.dialogs.backup.save.title'),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,28 @@
|
||||
<!--
|
||||
~ Copyright (C) 2022 StApps
|
||||
~ This program is free software: you can redistribute it and/or modify it
|
||||
~ under the terms of the GNU General Public License as published by the Free
|
||||
~ Software Foundation, version 3.
|
||||
~ Copyright (C) 2023 StApps
|
||||
~ This program is free software: you can redistribute it and/or modify it
|
||||
~ under the terms of the GNU General Public License as published by the Free
|
||||
~ Software Foundation, version 3.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along with
|
||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
~ You should have received a copy of the GNU General Public License along with
|
||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ion-card>
|
||||
<ion-card-header>
|
||||
<ion-card-subtitle>{{
|
||||
'settings.calendar.title' | translate
|
||||
}}</ion-card-subtitle>
|
||||
<ion-card-subtitle>{{ 'settings.calendar.title' | translate }}</ion-card-subtitle>
|
||||
</ion-card-header>
|
||||
|
||||
<ion-card-content>
|
||||
<ion-list lines="none">
|
||||
<ion-item-group>
|
||||
<ion-item-divider>
|
||||
<ion-label>{{
|
||||
'settings.calendar.sync.title' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.sync.title' | translate }}</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item>
|
||||
<ion-toggle
|
||||
@@ -40,9 +36,7 @@
|
||||
"
|
||||
>
|
||||
</ion-toggle>
|
||||
<ion-label>{{
|
||||
'settings.calendar.sync.syncWithCalendar' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.sync.syncWithCalendar' | translate }}</ion-label>
|
||||
</ion-item>
|
||||
<!--
|
||||
~ TODO:
|
||||
@@ -67,49 +61,35 @@
|
||||
</ion-item>
|
||||
-->
|
||||
<ion-item *ngIf="!isWeb">
|
||||
<ion-button
|
||||
[disabled]="isWeb || !syncEnabled"
|
||||
fill="clear"
|
||||
(click)="syncCalendar(true)"
|
||||
>
|
||||
<ion-button [disabled]="isWeb || !syncEnabled" fill="clear" (click)="syncCalendar(true)">
|
||||
<ion-label>Sync Now</ion-label>
|
||||
<ion-icon slot="end" name="sync"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-item>
|
||||
<ion-item *ngIf="isWeb">
|
||||
<ion-label color="medium" class="ion-text-wrap"
|
||||
><b>{{
|
||||
'settings.calendar.sync.unavailableWeb' | translate
|
||||
}}</b></ion-label
|
||||
><b>{{ 'settings.calendar.sync.unavailableWeb' | translate }}</b></ion-label
|
||||
>
|
||||
</ion-item>
|
||||
</ion-item-group>
|
||||
|
||||
<ion-item-group>
|
||||
<ion-item-divider>
|
||||
<ion-label>{{
|
||||
'settings.calendar.export.title' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.export.title' | translate }}</ion-label>
|
||||
</ion-item-divider>
|
||||
<ion-item>
|
||||
<ion-button fill="clear" (click)="export()">
|
||||
<ion-label>{{
|
||||
'settings.calendar.export.exportEvents' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.export.exportEvents' | translate }}</ion-label>
|
||||
<ion-icon slot="end" name="download"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-button fill="clear" (click)="backup()">
|
||||
<ion-label>{{
|
||||
'settings.calendar.export.backup' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.export.backup' | translate }}</ion-label>
|
||||
<ion-icon slot="end" name="save"></ion-icon>
|
||||
</ion-button>
|
||||
<ion-button fill="clear" (click)="restoreInput.click()">
|
||||
<ion-label>{{
|
||||
'settings.calendar.export.restore' | translate
|
||||
}}</ion-label>
|
||||
<ion-label>{{ 'settings.calendar.export.restore' | translate }}</ion-label>
|
||||
<ion-icon slot="end" name="settings_backup_restore"></ion-icon>
|
||||
</ion-button>
|
||||
<!--suppress CheckEmptyScriptTag -->
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019, 2020 StApps
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -98,18 +98,10 @@ export class SettingsPageComponent implements OnInit {
|
||||
* Presents an alert to the user to reset settings to default values
|
||||
*/
|
||||
async presentResetAlert() {
|
||||
const cancelText = await this.translateService
|
||||
.get('settings.resetAlert.buttonCancel')
|
||||
.toPromise();
|
||||
const yesText = await this.translateService
|
||||
.get('settings.resetAlert.buttonYes')
|
||||
.toPromise();
|
||||
const title = await this.translateService
|
||||
.get('settings.resetAlert.title')
|
||||
.toPromise();
|
||||
const message = await this.translateService
|
||||
.get('settings.resetAlert.message')
|
||||
.toPromise();
|
||||
const cancelText = await this.translateService.get('settings.resetAlert.buttonCancel').toPromise();
|
||||
const yesText = await this.translateService.get('settings.resetAlert.buttonYes').toPromise();
|
||||
const title = await this.translateService.get('settings.resetAlert.title').toPromise();
|
||||
const message = await this.translateService.get('settings.resetAlert.message').toPromise();
|
||||
|
||||
const alert = await this.alertController.create({
|
||||
buttons: [
|
||||
@@ -147,9 +139,7 @@ export class SettingsPageComponent implements OnInit {
|
||||
buttons: [
|
||||
{
|
||||
role: 'cancel',
|
||||
text: this.translateService.instant(
|
||||
'settings.resetAlert.buttonCancel',
|
||||
),
|
||||
text: this.translateService.instant('settings.resetAlert.buttonCancel'),
|
||||
},
|
||||
{
|
||||
handler: async () => {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<!--
|
||||
~ Copyright (C) 2022 StApps
|
||||
~ This program is free software: you can redistribute it and/or modify it
|
||||
~ under the terms of the GNU General Public License as published by the Free
|
||||
~ Software Foundation, version 3.
|
||||
~ This program is free software: you can redistribute it and/or modify it
|
||||
~ under the terms of the GNU General Public License as published by the Free
|
||||
~ Software Foundation, version 3.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~ This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along with
|
||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
~ You should have received a copy of the GNU General Public License along with
|
||||
~ this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ion-header>
|
||||
@@ -31,18 +31,14 @@
|
||||
'categories[0]'
|
||||
| thingTranslate
|
||||
: $any(
|
||||
settingsCache[categoryKey]?.settings[
|
||||
objectKeys(settingsCache[categoryKey]?.settings)[0]
|
||||
]
|
||||
settingsCache[categoryKey]?.settings[objectKeys(settingsCache[categoryKey]?.settings)[0]]
|
||||
)
|
||||
| titlecase
|
||||
}}
|
||||
</h5>
|
||||
</ion-item-divider>
|
||||
<stapps-settings-item
|
||||
*ngFor="
|
||||
let settingKeys of objectKeys(settingsCache[categoryKey].settings)
|
||||
"
|
||||
*ngFor="let settingKeys of objectKeys(settingsCache[categoryKey].settings)"
|
||||
[setting]="settingsCache[categoryKey].settings[settingKeys]"
|
||||
></stapps-settings-item>
|
||||
</div>
|
||||
@@ -50,12 +46,7 @@
|
||||
|
||||
<calendar-sync-settings></calendar-sync-settings>
|
||||
|
||||
<ion-button
|
||||
color="medium"
|
||||
expand="block"
|
||||
fill="outline"
|
||||
(click)="presentResetAlert()"
|
||||
>
|
||||
<ion-button color="medium" expand="block" fill="outline" (click)="presentResetAlert()">
|
||||
{{ 'settings.resetSettings' | translate }}
|
||||
<ion-icon slot="start" name="device_reset"></ion-icon>
|
||||
</ion-button>
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
import {SCSetting} from '@openstapps/core';
|
||||
@@ -17,19 +32,11 @@ export class SettingTranslatePipe implements PipeTransform {
|
||||
) {}
|
||||
|
||||
transform(setting: SCSetting) {
|
||||
const thingTranslatePipe = new ThingTranslatePipe(
|
||||
this.translate,
|
||||
this.thingTranslate,
|
||||
);
|
||||
const translatedSettingValues = thingTranslatePipe.transform(
|
||||
'values',
|
||||
setting,
|
||||
);
|
||||
const thingTranslatePipe = new ThingTranslatePipe(this.translate, this.thingTranslate);
|
||||
const translatedSettingValues = thingTranslatePipe.transform('values', setting);
|
||||
|
||||
return translatedSettingValues
|
||||
? translatedSettingValues[
|
||||
setting.values?.indexOf(setting.value as string) as number
|
||||
]
|
||||
? translatedSettingValues[setting.values?.indexOf(setting.value as string) as number]
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
@@ -35,9 +35,7 @@ import {BackgroundModule} from '../background/background.module';
|
||||
import {UtilModule} from '../../util/util.module';
|
||||
import {IonIconModule} from '../../util/ion-icon/ion-icon.module';
|
||||
|
||||
const settingsRoutes: Routes = [
|
||||
{path: 'settings', component: SettingsPageComponent},
|
||||
];
|
||||
const settingsRoutes: Routes = [{path: 'settings', component: SettingsPageComponent}];
|
||||
|
||||
/**
|
||||
* Settings Module
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -14,19 +14,10 @@
|
||||
*/
|
||||
/* eslint-disable unicorn/no-useless-undefined, @typescript-eslint/no-non-null-assertion */
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {
|
||||
SCSetting,
|
||||
SCThingOriginType,
|
||||
SCThingType,
|
||||
SCSettingInputType,
|
||||
} from '@openstapps/core';
|
||||
import {SCSetting, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
|
||||
import {ConfigProvider} from '../config/config.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';
|
||||
import {ScheduleSyncService} from '../background/schedule/schedule-sync.service';
|
||||
|
||||
describe('SettingsProvider', () => {
|
||||
@@ -36,12 +27,7 @@ describe('SettingsProvider', () => {
|
||||
let scheduleSyncServiceSpy: jasmine.SpyObj<ScheduleSyncService>;
|
||||
|
||||
beforeEach(async () => {
|
||||
storageProviderSpy = jasmine.createSpyObj('StorageProvider', [
|
||||
'init',
|
||||
'get',
|
||||
'has',
|
||||
'put',
|
||||
]);
|
||||
storageProviderSpy = jasmine.createSpyObj('StorageProvider', ['init', 'get', 'has', 'put']);
|
||||
configProviderSpy = jasmine.createSpyObj('ConfigProvider', ['getValue']);
|
||||
scheduleSyncServiceSpy = jasmine.createSpyObj('ScheduleSyncService', [
|
||||
'getDifferences',
|
||||
@@ -73,9 +59,7 @@ describe('SettingsProvider', () => {
|
||||
});
|
||||
|
||||
it('should provide and get setting', async () => {
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])));
|
||||
const setting: SCSetting = await settingsProvider.getSetting(
|
||||
CONFIG_SETTINGS_MOCK[0].categories[0],
|
||||
CONFIG_SETTINGS_MOCK[0].name,
|
||||
@@ -84,9 +68,7 @@ describe('SettingsProvider', () => {
|
||||
});
|
||||
|
||||
it('should provide and get settings value', async () => {
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])));
|
||||
const value = await settingsProvider.getValue(
|
||||
CONFIG_SETTINGS_MOCK[0].categories[0],
|
||||
CONFIG_SETTINGS_MOCK[0].name,
|
||||
@@ -97,9 +79,7 @@ describe('SettingsProvider', () => {
|
||||
it('should get persisted setting value', async () => {
|
||||
// set return values of storage
|
||||
storageProviderSpy.has.and.returnValue(Promise.resolve(true));
|
||||
storageProviderSpy.get.and.returnValue(
|
||||
Promise.resolve(SETTING_VALUES_MOCK),
|
||||
);
|
||||
storageProviderSpy.get.and.returnValue(Promise.resolve(SETTING_VALUES_MOCK));
|
||||
|
||||
const value = await settingsProvider.getValue(
|
||||
CONFIG_SETTINGS_MOCK[3].categories[0],
|
||||
@@ -123,20 +103,13 @@ describe('SettingsProvider', () => {
|
||||
const settings = [CONFIG_SETTINGS_MOCK[4], CONFIG_SETTINGS_MOCK[5]];
|
||||
configProviderSpy.getValue.and.returnValue(settings);
|
||||
storageProviderSpy.has.and.returnValue(Promise.resolve(true));
|
||||
storageProviderSpy.get.and.returnValue(
|
||||
Promise.resolve(SETTING_VALUES_MOCK),
|
||||
);
|
||||
storageProviderSpy.get.and.returnValue(Promise.resolve(SETTING_VALUES_MOCK));
|
||||
await settingsProvider.init();
|
||||
expect(storageProviderSpy.put).toHaveBeenCalledWith(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
SETTING_VALUES_MOCK,
|
||||
);
|
||||
expect(storageProviderSpy.put).toHaveBeenCalledWith(STORAGE_KEY_SETTING_VALUES, SETTING_VALUES_MOCK);
|
||||
});
|
||||
|
||||
it('should set value of a provided setting', async () => {
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[1])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[1])));
|
||||
await settingsProvider.setSettingValue(
|
||||
CONFIG_SETTINGS_MOCK[1].categories[0],
|
||||
CONFIG_SETTINGS_MOCK[1].name,
|
||||
@@ -152,21 +125,15 @@ describe('SettingsProvider', () => {
|
||||
it('should return copy of settingsCache', async () => {
|
||||
const category = CONFIG_SETTINGS_MOCK[0].categories[0];
|
||||
const name = CONFIG_SETTINGS_MOCK[0].name;
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])));
|
||||
const settings = await settingsProvider.getCache();
|
||||
settings[category].settings[name].value = 'testValue';
|
||||
// cached setting value should still be defaultValue
|
||||
expect(await settingsProvider.getValue(category, name)).toEqual(
|
||||
CONFIG_SETTINGS_MOCK[0].defaultValue,
|
||||
);
|
||||
expect(await settingsProvider.getValue(category, name)).toEqual(CONFIG_SETTINGS_MOCK[0].defaultValue);
|
||||
});
|
||||
|
||||
it('should call storage put on setSettingValue', async () => {
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])));
|
||||
await settingsProvider.setSettingValue(
|
||||
CONFIG_SETTINGS_MOCK[0].categories[0],
|
||||
CONFIG_SETTINGS_MOCK[0].name,
|
||||
@@ -177,18 +144,13 @@ describe('SettingsProvider', () => {
|
||||
|
||||
it('should clear settings', async () => {
|
||||
await settingsProvider.reset();
|
||||
expect(storageProviderSpy.put).toHaveBeenCalledWith(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
{},
|
||||
);
|
||||
expect(storageProviderSpy.put).toHaveBeenCalledWith(STORAGE_KEY_SETTING_VALUES, {});
|
||||
});
|
||||
|
||||
it('should reset settings', async () => {
|
||||
const category = CONFIG_SETTINGS_MOCK[0].categories[0];
|
||||
const name = CONFIG_SETTINGS_MOCK[0].name;
|
||||
await settingsProvider.provideSetting(
|
||||
JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])),
|
||||
);
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(CONFIG_SETTINGS_MOCK[0])));
|
||||
await settingsProvider.setSettingValue(category, name, 'guest');
|
||||
await settingsProvider.resetDefault();
|
||||
const value = await settingsProvider.getValue(
|
||||
@@ -243,11 +205,7 @@ describe('SettingsProvider', () => {
|
||||
let error: Error | undefined = undefined;
|
||||
await settingsProvider.provideSetting(JSON.parse(JSON.stringify(setting)));
|
||||
try {
|
||||
await settingsProvider.setSettingValue(
|
||||
setting.categories[0],
|
||||
setting.name,
|
||||
value as never,
|
||||
);
|
||||
await settingsProvider.setSettingValue(setting.categories[0], setting.name, value as never);
|
||||
} catch (error_) {
|
||||
error = error_ as Error;
|
||||
}
|
||||
|
||||
@@ -151,9 +151,7 @@ export class SettingsProvider {
|
||||
}
|
||||
|
||||
return (
|
||||
possibleValues !== undefined &&
|
||||
Array.isArray(possibleValues) &&
|
||||
possibleValues.includes(enteredValue)
|
||||
possibleValues !== undefined && Array.isArray(possibleValues) && possibleValues.includes(enteredValue)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -163,10 +161,7 @@ export class SettingsProvider {
|
||||
* @param setting setting to check value against
|
||||
* @param value value to validate
|
||||
*/
|
||||
public static validateValue(
|
||||
setting: SCSetting,
|
||||
value: SCSettingValue | SCSettingValues,
|
||||
): boolean {
|
||||
public static validateValue(setting: SCSetting, value: SCSettingValue | SCSettingValues): boolean {
|
||||
let isValueValid = false;
|
||||
switch (setting.inputType) {
|
||||
case 'number':
|
||||
@@ -201,10 +196,7 @@ export class SettingsProvider {
|
||||
* @param storage TODO
|
||||
* @param configProvider TODO
|
||||
*/
|
||||
constructor(
|
||||
private readonly storage: StorageProvider,
|
||||
private readonly configProvider: ConfigProvider,
|
||||
) {
|
||||
constructor(private readonly storage: StorageProvider, private readonly configProvider: ConfigProvider) {
|
||||
this.categoriesOrder = [];
|
||||
this.settingsCache = {};
|
||||
}
|
||||
@@ -222,8 +214,7 @@ export class SettingsProvider {
|
||||
if (setting.value === undefined) {
|
||||
setting.value = setting.defaultValue;
|
||||
}
|
||||
this.settingsCache[setting.categories[0]].settings[setting.name] =
|
||||
setting;
|
||||
this.settingsCache[setting.categories[0]].settings[setting.name] = setting;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,9 +226,7 @@ export class SettingsProvider {
|
||||
// iterate through keys of categories
|
||||
for (const categoryKey of Object.keys(this.settingsCache)) {
|
||||
// iterate through keys of settingValueContainer
|
||||
for (const settingKey of Object.keys(
|
||||
this.settingsCache[categoryKey].settings,
|
||||
)) {
|
||||
for (const settingKey of Object.keys(this.settingsCache[categoryKey].settings)) {
|
||||
if (typeof settingValuesContainer[categoryKey] === 'undefined') {
|
||||
settingValuesContainer[categoryKey] = {};
|
||||
}
|
||||
@@ -302,9 +291,7 @@ export class SettingsProvider {
|
||||
await this.init();
|
||||
if (this.settingExists(category, name)) {
|
||||
// return a copy of the settings
|
||||
return JSON.parse(
|
||||
JSON.stringify(this.settingsCache[category].settings[name]),
|
||||
);
|
||||
return JSON.parse(JSON.stringify(this.settingsCache[category].settings[name]));
|
||||
}
|
||||
throw new Error(`Setting "${name}" not provided`);
|
||||
}
|
||||
@@ -316,16 +303,11 @@ export class SettingsProvider {
|
||||
* @param name the name of requested setting
|
||||
* @throws Exception if setting is not provided
|
||||
*/
|
||||
public async getValue(
|
||||
category: string,
|
||||
name: string,
|
||||
): Promise<SCSettingValue | SCSettingValues> {
|
||||
public async getValue(category: string, name: string): Promise<SCSettingValue | SCSettingValues> {
|
||||
await this.init();
|
||||
if (this.settingExists(category, name)) {
|
||||
// return a copy of the settings value
|
||||
return JSON.parse(
|
||||
JSON.stringify(this.settingsCache[category].settings[name].value),
|
||||
);
|
||||
return JSON.parse(JSON.stringify(this.settingsCache[category].settings[name].value));
|
||||
}
|
||||
throw new Error(`Setting "${name}" not provided`);
|
||||
}
|
||||
@@ -338,9 +320,7 @@ export class SettingsProvider {
|
||||
this.needsInit = false;
|
||||
|
||||
try {
|
||||
const settings: SCSetting[] = this.configProvider.getValue(
|
||||
'settings',
|
||||
) as SCSetting[];
|
||||
const settings: SCSetting[] = this.configProvider.getValue('settings') as SCSetting[];
|
||||
for (const setting of settings) this.addSetting(setting);
|
||||
|
||||
for (const category of Object.keys(this.settingsCache)) {
|
||||
@@ -354,16 +334,13 @@ export class SettingsProvider {
|
||||
|
||||
if (await this.storage.has(STORAGE_KEY_SETTING_VALUES)) {
|
||||
// get setting values from StorageProvider into settingsCache
|
||||
const valuesContainer: SettingValuesContainer =
|
||||
await this.storage.get<SettingValuesContainer>(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
);
|
||||
const valuesContainer: SettingValuesContainer = await this.storage.get<SettingValuesContainer>(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
);
|
||||
// iterate through keys of categories
|
||||
for (const categoryKey of Object.keys(this.settingsCache)) {
|
||||
// iterate through setting keys of category
|
||||
for (const settingKey of Object.keys(
|
||||
this.settingsCache[categoryKey].settings,
|
||||
)) {
|
||||
for (const settingKey of Object.keys(this.settingsCache[categoryKey].settings)) {
|
||||
// if saved setting value exists set it, otherwise set to default value
|
||||
if (
|
||||
typeof valuesContainer[categoryKey] !== 'undefined' &&
|
||||
@@ -404,9 +381,7 @@ export class SettingsProvider {
|
||||
*/
|
||||
async resetDefault(): Promise<void> {
|
||||
for (const catKey of Object.keys(this.settingsCache)) {
|
||||
for (const settingKey of Object.keys(
|
||||
this.settingsCache[catKey].settings,
|
||||
)) {
|
||||
for (const settingKey of Object.keys(this.settingsCache[catKey].settings)) {
|
||||
const settingInput = this.settingsCache[catKey].settings[settingKey];
|
||||
settingInput.value = settingInput.defaultValue;
|
||||
}
|
||||
@@ -419,19 +394,12 @@ export class SettingsProvider {
|
||||
*/
|
||||
public async saveSettingValues(): Promise<void> {
|
||||
if (await this.storage.has(STORAGE_KEY_SETTING_VALUES)) {
|
||||
const savedSettingsValues: SettingValuesContainer =
|
||||
await this.storage.get<SettingValuesContainer>(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
);
|
||||
const cacheSettingsValues = this.getSettingValuesFromCache();
|
||||
const mergedSettingValues = deepMerge(
|
||||
savedSettingsValues,
|
||||
cacheSettingsValues,
|
||||
);
|
||||
await this.storage.put<SettingValuesContainer>(
|
||||
const savedSettingsValues: SettingValuesContainer = await this.storage.get<SettingValuesContainer>(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
mergedSettingValues,
|
||||
);
|
||||
const cacheSettingsValues = this.getSettingValuesFromCache();
|
||||
const mergedSettingValues = deepMerge(savedSettingsValues, cacheSettingsValues);
|
||||
await this.storage.put<SettingValuesContainer>(STORAGE_KEY_SETTING_VALUES, mergedSettingValues);
|
||||
} else {
|
||||
await this.storage.put<SettingValuesContainer>(
|
||||
STORAGE_KEY_SETTING_VALUES,
|
||||
@@ -492,9 +460,6 @@ export class SettingsProvider {
|
||||
* @param setting Setting key name
|
||||
*/
|
||||
public settingExists(category: string, setting: string): boolean {
|
||||
return (
|
||||
this.categoryExists(category) &&
|
||||
this.settingsCache[category].settings[setting] !== undefined
|
||||
);
|
||||
return this.categoryExists(category) && this.settingsCache[category].settings[setting] !== undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
/*!
|
||||
* Copyright (C) 2022 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
page-settings {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user