From a5d3e18d0f17fa26aae67b45a7111ff5ebacfc4e Mon Sep 17 00:00:00 2001 From: "VENUGOPALAN Uma (DIGIT-EXT)" Date: Mon, 26 Sep 2022 16:43:33 +0200 Subject: [PATCH 1/3] Initiate local forge service and set the value --- src/app/app.component.ts | 6 +++++- src/app/core/core.module.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4a0c047..e279c52 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,7 @@ import { Store } from '@ngrx/store'; import { getUserState, UserState } from '@eui/core'; import { Observable, Subscription } from 'rxjs'; import { I18nService } from '@eui/core'; +import { StorageService, UxAppShellService,LocalForageService } from '@eui/core'; @Component({ selector: 'app-root', @@ -25,12 +26,15 @@ export class AppComponent implements OnDestroy { { label: 'Title label 4', subLabel: 'Subtitle label' }, ]; - constructor(private store: Store,protected i18nService: I18nService,) { + constructor(private store: Store,protected i18nService: I18nService, private localForage : LocalForageService, + ) { this.userState = this.store.select(getUserState); this.subs.push(this.userState.subscribe((user: UserState) => { this.userInfos = { ...user }; })); this.i18nService.init(); + this.localForage.set('name', 'John'); + } ngOnDestroy() { diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index c56465d..109c8d8 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -15,6 +15,13 @@ import { import { appConfig } from '../../config'; import { environment } from '../../environments/environment'; import { REDUCER_TOKEN, getReducers, metaReducers } from './reducers'; +import * as localForage from 'localforage'; +import { CoreModule as UxCoreModule, StorageService, SessionStorageService,LocalStorageService, + AsyncStorageService, + LocalForageService, + LOCAL_FORAGE_SERVICE_CONFIG_TOKEN, + +} from '@eui/core'; @NgModule({ imports: [ @@ -40,7 +47,8 @@ import { REDUCER_TOKEN, getReducers, metaReducers } from './reducers'; }, { provide: APP_BASE_HREF, useValue: '/' - } + }, + { provide: AsyncStorageService, useExisting: LocalForageService }, ] }) export class CoreModule { From ff6bdb719595cd64cb15ae3a4f68ff8059324b3d Mon Sep 17 00:00:00 2001 From: "VENUGOPALAN Uma (DIGIT-EXT)" Date: Thu, 29 Sep 2022 12:29:16 +0200 Subject: [PATCH 2/3] combined sync and async storage service --- src/app/app.component.ts | 15 ++++++++++++--- src/app/core/core.module.ts | 9 +++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e279c52..311ec83 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,9 +1,9 @@ -import { Component, OnDestroy } from '@angular/core'; +import { Component, OnDestroy, Inject} from '@angular/core'; import { Store } from '@ngrx/store'; import { getUserState, UserState } from '@eui/core'; import { Observable, Subscription } from 'rxjs'; import { I18nService } from '@eui/core'; -import { StorageService, UxAppShellService,LocalForageService } from '@eui/core'; +import { StorageService,LocalForageService } from '@eui/core'; @Component({ selector: 'app-root', @@ -27,16 +27,25 @@ export class AppComponent implements OnDestroy { ]; constructor(private store: Store,protected i18nService: I18nService, private localForage : LocalForageService, + private sessionStorageService: StorageService, + @Inject('LocalStorageService') private localStorageService: StorageService, + ) { this.userState = this.store.select(getUserState); this.subs.push(this.userState.subscribe((user: UserState) => { this.userInfos = { ...user }; })); this.i18nService.init(); - this.localForage.set('name', 'John'); } + ngOnInit() { + this.sessionStorageService.set('SESSION\_STORAGE', "testSession"); + this.localStorageService.set('STORAGE', "local"); + this.localForage.set('name', 'uma'); + } + + ngOnDestroy() { this.subs.forEach((s: Subscription) => s.unsubscribe()); } diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 109c8d8..f6adde7 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -16,9 +16,9 @@ import { appConfig } from '../../config'; import { environment } from '../../environments/environment'; import { REDUCER_TOKEN, getReducers, metaReducers } from './reducers'; import * as localForage from 'localforage'; -import { CoreModule as UxCoreModule, StorageService, SessionStorageService,LocalStorageService, +import { StorageService, SessionStorageService,LocalStorageService, AsyncStorageService, - LocalForageService, + LocalForageService, LOCAL_FORAGE_SERVICE_CONFIG_TOKEN, } from '@eui/core'; @@ -48,7 +48,12 @@ import { CoreModule as UxCoreModule, StorageService, SessionStorageService,Local { provide: APP_BASE_HREF, useValue: '/' }, + SessionStorageService, + LocalStorageService, + { provide: StorageService, useExisting: LocalStorageService }, + LocalForageService, { provide: AsyncStorageService, useExisting: LocalForageService }, + ] }) export class CoreModule { From 1354920eb6cda25e29bea709d914c686c35390a7 Mon Sep 17 00:00:00 2001 From: "VENUGOPALAN Uma (DIGIT-EXT)" Date: Tue, 11 Oct 2022 08:30:46 +0200 Subject: [PATCH 3/3] updated localstorage in app module --- src/app/app.module.ts | 77 +++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 4847486..00b8a6b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,32 +1,61 @@ -import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; -import { FormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { APP_INITIALIZER, NgModule } from '@angular/core'; import { AppComponent } from './app.component'; -import { HelloComponent } from './hello.component'; - -import { EuiIconModule } from '@eui/components/atoms/eui-icon'; -import { EuiButtonModule } from '@eui/components/eui-button'; -import { EuiCardModule } from '@eui/components/eui-card'; -import { EuiLabelModule } from '@eui/components/atoms/eui-label'; -import { CommonModule } from '@angular/common'; import { CoreModule } from './core/core.module'; -import { EuiAppModule, EuiNotificationsModule } from '@eui/components/layout'; +import { CoreModule as UxCoreModule, + StorageService, + SessionStorageService, + LocalStorageService, + AsyncStorageService, + LocalForageService, LOCAL_FORAGE_SERVICE_CONFIG_TOKEN} from '@eui/core'; + import * as localForage from 'localforage'; + + + import { FormsModule } from '@angular/forms'; + + import { HelloComponent } from './hello.component'; + + import { EuiIconModule } from '@eui/components/atoms/eui-icon'; + import { EuiButtonModule } from '@eui/components/eui-button'; + import { EuiCardModule } from '@eui/components/eui-card'; + import { EuiLabelModule } from '@eui/components/atoms/eui-label'; + import { CommonModule } from '@angular/common'; + import { EuiAppModule, EuiNotificationsModule } from '@eui/components/layout'; + import { CachePreventionInterceptor } from '@eui/core'; + import { CorsSecurityInterceptor } from '@eui/core'; + import { AddLangParamInterceptor } from '@eui/core'; + import { HTTP_INTERCEPTORS } from '@angular/common/http'; + + @NgModule({ - imports: [ - CoreModule, - CommonModule, - BrowserModule, - FormsModule, - EuiButtonModule, - EuiIconModule, - EuiCardModule, - EuiLabelModule, - EuiAppModule, - EuiNotificationsModule, - ], - declarations: [AppComponent, HelloComponent], - bootstrap: [AppComponent], + declarations: [ + AppComponent, + ], + imports: [ + BrowserModule, + BrowserAnimationsModule, + CoreModule, + BrowserModule, + FormsModule, + EuiButtonModule, + EuiIconModule, + EuiCardModule, + EuiLabelModule, + EuiAppModule, + EuiNotificationsModule, + + + ], + providers: [ + { provide: 'LocalStorageService', useExisting: LocalStorageService }, + { provide: StorageService, useExisting: SessionStorageService }, + + ], + bootstrap: [ + AppComponent, + ], }) export class AppModule {}