@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
103 lines • 4.35 kB
TypeScript
import { InventoryService, IUser, UserService } from '@c8y/client';
import { Observable, Subject } from 'rxjs';
import { AppStateService } from '../ui-state.service';
import { UserPreference } from './user-preference.model';
import { AlertService } from '../../alert/alert.service';
import * as i0 from "@angular/core";
export declare class UserPreferencesService {
private user;
private inventory;
private appState;
private alert;
currentUser: Observable<IUser>;
preferenceChanges$: Subject<UserPreference>;
private storage;
constructor(user: UserService, inventory: InventoryService, appState: AppStateService, alert: AlertService);
/**
* Returns an observable of a user preference with given key.
* Emits its initial value first and then updated values when set by user.
* @param key The storage key for searched value.
* @returns An Observable of a user preference.
*/
observe<T>(key: string): Observable<T>;
/**
* Get an Observable value for searched key for current user.
* @param key The storage key for searched value.
* @returns An Observable with the value of preference.
*/
get(key: string): Observable<any>;
/**
* Sets a value in storage for current user.
* @param key The storage key for the value to be set.
* @param value The storage value to be set.
* @returns A promise with saved value.
*/
set(key: string, value: any): Promise<any>;
/**
* Get an Observable value of searched key for a specific user.
* @param key The storage key for searched value.
* @param user The user for whom the search is done.
* @returns An Observable with the value of preference.
*
* @deprecated Uses depracted inventory approach. Use get instead.
*/
getForUser(key: string, user: IUser): Observable<any>;
/**
* Sets a value in storage for a specific user.
* @param key The storage key for the value to be set.
* @param value The storage value to be set.
* @returns A promise with saved value.
*
* @deprecated Uses deprecated inventory approach. Use set instead.
*/
setForUser(key: string, value: any, user: IUser): Promise<any>;
/**
* Get value of searched key for current user.
* If preference is not found in user's customProperties, it will try to get it from inventory or local storage and
* update user's customProperties with the value and return that value.
* @param key The preference key for searched value.
* @param user The user for whom the search is done.
* @returns A Promise with the value of preference.
*/
private getForCurrentUser;
/**
* Sets a value for current user.
* @param key The preference key for the value to be set.
* @param value The preference value to be set.
*/
private setForCurrentUser;
/**
* Get a string of key concatenated with username.
* Used by deprecated invetory storage approach and for leftovers in local storage.
* It was used to store preferences for specific users and it as replacing "." with "__"
* because of MongoDB restrictions.
* @param key The storage key for searched value.
* @param user The user for whom the search is done.
* @returns A string of key concatenated with username.
*/
private getTransformedRawKey;
/**
* Get a string of key concatenated with username.
* Used by local storage.
* @param key The storage key for searched value.
* @param user The user for whom the search is done.
* @returns A string of key concatenated with username.
*/
private getRawKey;
/**
* Get a key for user preferences. Used current user customProperties.
* @param key The storage key for searched value.
* @returns A key for user preferences.
*/
private getCustomPropertiesKey;
/**
* Gets a proper storage depending on the user roles.
* @param user The user for whom the role check is done.
* @returns A proper storage.
*/
private getStorage;
private getCurrentUserStorage;
static ɵfac: i0.ɵɵFactoryDeclaration<UserPreferencesService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<UserPreferencesService>;
}
//# sourceMappingURL=user-preferences.service.d.ts.map