mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
refactor: adjust code after upgrade of ionic from v4 to v5
Note: used observables instead of events service which doesn't exist in ionic 5 anymore.
This commit is contained in:
committed by
Rainer Killinger
parent
cc357f36b6
commit
2e8d717607
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018, 2019, 2020 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.
|
||||
@@ -16,7 +16,7 @@ import {CommonModule} from '@angular/common';
|
||||
import {HttpClientModule} from '@angular/common/http';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Events, IonicModule} from '@ionic/angular';
|
||||
import {IonicModule} from '@ionic/angular';
|
||||
import {TranslateModule} from '@ngx-translate/core';
|
||||
import {MarkdownModule} from 'ngx-markdown';
|
||||
import {MomentModule} from 'ngx-moment';
|
||||
@@ -129,7 +129,6 @@ import {VideoListItem} from './types/video/video-list-item.component';
|
||||
providers: [
|
||||
DataProvider,
|
||||
DataFacetsProvider,
|
||||
Events,
|
||||
StAppsWebHttpClient,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018, 2019, 2020 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.
|
||||
@@ -13,20 +13,19 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {AlertController, Events} from '@ionic/angular';
|
||||
import {AlertController} from '@ionic/angular';
|
||||
import {
|
||||
SCFacet,
|
||||
SCSearchFilter,
|
||||
SCSearchQuery,
|
||||
SCSearchSort,
|
||||
SCSettingValue,
|
||||
SCSettingValues,
|
||||
SCThing,
|
||||
} from '@openstapps/core';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {Subject} from 'rxjs';
|
||||
import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
|
||||
import {MenuService} from '../../menu/menu.service';
|
||||
import {SettingsProvider} from '../../settings/settings.provider';
|
||||
import {DataProvider} from '../data.provider';
|
||||
|
||||
/**
|
||||
@@ -82,14 +81,13 @@ export class DataListComponent implements OnInit {
|
||||
*
|
||||
* @param alertController AlertController
|
||||
* @param dataProvider DataProvider
|
||||
* @param events Events
|
||||
* @param menuService MenuService
|
||||
*/
|
||||
constructor(
|
||||
private readonly alertController: AlertController,
|
||||
private dataProvider: DataProvider,
|
||||
private readonly events: Events,
|
||||
private readonly menuService: MenuService,
|
||||
private readonly settingsProvider: SettingsProvider,
|
||||
) {
|
||||
this.queryTextChanged
|
||||
.pipe(
|
||||
@@ -115,10 +113,12 @@ export class DataListComponent implements OnInit {
|
||||
/**
|
||||
* Subscribe to 'settings.changed' events
|
||||
*/
|
||||
this.events.subscribe('stapps.settings.changed',
|
||||
(category: string, name: string, value: SCSettingValue | SCSettingValues) => {
|
||||
Logger.log(`received event "settings.changed" with category:
|
||||
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
|
||||
this.settingsProvider.settingsActionChanged$.subscribe(({type, payload}) => {
|
||||
if (type === 'stapps.settings.changed') {
|
||||
const {category, name, value} = payload!;
|
||||
Logger.log(`received event "settings.changed" with category:
|
||||
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018, 2019 StApps
|
||||
* Copyright (C) 2018, 2019, 2020 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.
|
||||
@@ -17,7 +17,7 @@ import {NgModule} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {Events, IonicModule} from '@ionic/angular';
|
||||
import {IonicModule} from '@ionic/angular';
|
||||
import {TranslateModule} from '@ngx-translate/core';
|
||||
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
@@ -49,7 +49,6 @@ const settingsRoutes: Routes = [
|
||||
],
|
||||
providers: [
|
||||
ConfigProvider,
|
||||
Events,
|
||||
Geolocation,
|
||||
SettingsProvider,
|
||||
],
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* Copyright (C) 2019, 2020 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,13 +14,13 @@
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {Events} from '@ionic/angular';
|
||||
import {
|
||||
SCSetting,
|
||||
SCSettingValue,
|
||||
SCSettingValues,
|
||||
} from '@openstapps/core';
|
||||
import deepMerge from 'deepmerge';
|
||||
import {Subject} from 'rxjs';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
|
||||
@@ -63,11 +63,43 @@ export interface SettingValueContainer {
|
||||
[key: string]: SCSettingValue | SCSettingValue[] | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structure of the settings events
|
||||
*/
|
||||
export interface SettingsAction {
|
||||
/**
|
||||
* Data related to the action
|
||||
*/
|
||||
payload?: {
|
||||
/**
|
||||
* Setting category
|
||||
*/
|
||||
category: string;
|
||||
/**
|
||||
* Setting name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Setting value
|
||||
*/
|
||||
value: SCSettingValue | SCSettingValues;
|
||||
};
|
||||
|
||||
/**
|
||||
* Type of the settings action
|
||||
*/
|
||||
type: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider for app settings
|
||||
*/
|
||||
@Injectable()
|
||||
export class SettingsProvider {
|
||||
/**
|
||||
* Source of settings actions
|
||||
*/
|
||||
private settingsActionSource = new Subject<SettingsAction>();
|
||||
/**
|
||||
* Order of the setting categories
|
||||
*/
|
||||
@@ -76,6 +108,10 @@ export class SettingsProvider {
|
||||
* Is provider initialized
|
||||
*/
|
||||
initialized = false;
|
||||
/**
|
||||
* Settings actions observable
|
||||
*/
|
||||
settingsActionChanged$ = this.settingsActionSource.asObservable();
|
||||
/**
|
||||
* Cache for the imported settings
|
||||
*/
|
||||
@@ -165,12 +201,10 @@ export class SettingsProvider {
|
||||
* @param storage TODO
|
||||
* @param configProvider TODO
|
||||
* @param geoLocation TODO
|
||||
* @param events TODO
|
||||
*/
|
||||
constructor(private readonly storage: StorageProvider,
|
||||
private readonly configProvider: ConfigProvider,
|
||||
private readonly geoLocation: Geolocation,
|
||||
private readonly events: Events) {
|
||||
private readonly geoLocation: Geolocation) {
|
||||
this.categoriesOrder = [];
|
||||
this.settingsCache = {};
|
||||
}
|
||||
@@ -251,7 +285,7 @@ export class SettingsProvider {
|
||||
}
|
||||
this.initialized = true;
|
||||
// publish provider initialised
|
||||
this.events.publish('stapps.settings.initialised');
|
||||
this.settingsActionSource.next({type: 'stapps.settings.initialized'});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,7 +469,7 @@ export class SettingsProvider {
|
||||
this.settingsCache[category].settings[name].value = value;
|
||||
await this.saveSettingValues();
|
||||
// publish setting changes
|
||||
this.events.publish('stapps.settings.changed', category, name, value);
|
||||
this.settingsActionSource.next({type: 'stapps.settings.changed', payload: {category, name, value}});
|
||||
} else {
|
||||
throw new Error(`Value "${value}" of type
|
||||
${typeof value} is not valid for ${setting.inputType}`);
|
||||
|
||||
Reference in New Issue
Block a user