Skip to content
Snippets Groups Projects
Commit 14cc75bd authored by Philipp Sautner's avatar Philipp Sautner
Browse files

Merge branch 'Shared-Local-Storage-frag-jetzt-antworte-jetzt' into 'staging'

Adds basic service to respond with localStorage info

See merge request arsnova/frag.jetzt!706
parents 6467f9bb 64d1de9e
Branches
Tags
No related merge requests found
This diff is collapsed.
...@@ -2,10 +2,12 @@ import { Injectable } from '@angular/core'; ...@@ -2,10 +2,12 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment'; import { environment } from '../environments/environment';
import { IAppConfig } from './models/app-config.model'; import { IAppConfig } from './models/app-config.model';
@Injectable() @Injectable()
export class AppConfig { export class AppConfig {
static settings: IAppConfig; static settings: IAppConfig;
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {
}
load() { load() {
const jsonFile = `assets/config/config.${environment.name}.json`; const jsonFile = `assets/config/config.${environment.name}.json`;
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
......
import { NgModule } from '@angular/core'; import { NgModule, APP_INITIALIZER } from '@angular/core';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { RegisterComponent } from './components/home/_dialogs/register/register.component'; import { RegisterComponent } from './components/home/_dialogs/register/register.component';
import { PasswordResetComponent } from './components/home/_dialogs/password-reset/password-reset.component'; import { PasswordResetComponent } from './components/home/_dialogs/password-reset/password-reset.component';
...@@ -62,6 +62,7 @@ import { SpacyService } from './services/http/spacy.service'; ...@@ -62,6 +62,7 @@ import { SpacyService } from './services/http/spacy.service';
import { QuizNowComponent } from './components/shared/quiz-now/quiz-now.component'; import { QuizNowComponent } from './components/shared/quiz-now/quiz-now.component';
import { JoyrideModule } from 'ngx-joyride'; import { JoyrideModule } from 'ngx-joyride';
import { QuillModule } from 'ngx-quill'; import { QuillModule } from 'ngx-quill';
import { LocalStorageShareService } from './services/http/local-storage-share.service';
import 'prismjs'; import 'prismjs';
import 'prismjs/plugins/line-numbers/prism-line-numbers.js'; import 'prismjs/plugins/line-numbers/prism-line-numbers.js';
...@@ -149,11 +150,11 @@ export function initializeApp(appConfig: AppConfig) { ...@@ -149,11 +150,11 @@ export function initializeApp(appConfig: AppConfig) {
QuillModule.forRoot() QuillModule.forRoot()
], ],
providers: [ providers: [
/*AppConfig, AppConfig,
{ provide: APP_INITIALIZER, { provide: APP_INITIALIZER,
useFactory: initializeApp, useFactory: initializeApp,
deps: [AppConfig], multi: true deps: [AppConfig, LocalStorageShareService], multi: true
},*/ },
{ {
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,
useClass: AuthenticationInterceptor, useClass: AuthenticationInterceptor,
......
/*import { TestBed } from '@angular/core/testing';
import { LocalStorageShareService } from './local-storage-share.service';
describe('LocalStorageShareService', () => {
let service: LocalStorageShareService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LocalStorageShareService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});*/
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class LocalStorageShareService {
constructor() {
window.addEventListener('message', this.messageHandler, false);
}
messageHandler(event) {
const { action, key, value} = event.data;
if (action === 'save') {
window.localStorage.setItem(key, JSON.stringify(value));
} else if (action === 'get') {
const obj = JSON.parse(window.localStorage.getItem(key));
if(obj !== null) {
event.source.postMessage({
action: 'returnData',
key,
obj
}, '*');
}
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment