From fc6cf6169868e60c189e4b243330c3717ff159f3 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 26 May 2022 13:58:07 +0200 Subject: ... --- .../spm/frontend/src/app/app-routing.module.ts | 17 ++++++ overlays/spm/frontend/src/app/app.component.html | 7 +++ overlays/spm/frontend/src/app/app.component.sass | 0 overlays/spm/frontend/src/app/app.component.ts | 21 ++++++++ overlays/spm/frontend/src/app/app.module.ts | 32 +++++++++++ .../spm/frontend/src/app/color-scheme.service.ts | 62 ++++++++++++++++++++++ .../page-not-found/page-not-found.component.html | 5 ++ .../page-not-found/page-not-found.component.sass | 0 .../app/page-not-found/page-not-found.component.ts | 15 ++++++ .../spm/frontend/src/app/spm/spm.component.html | 3 ++ .../spm/frontend/src/app/spm/spm.component.sass | 0 overlays/spm/frontend/src/app/spm/spm.component.ts | 24 +++++++++ 12 files changed, 186 insertions(+) create mode 100644 overlays/spm/frontend/src/app/app-routing.module.ts create mode 100644 overlays/spm/frontend/src/app/app.component.html create mode 100644 overlays/spm/frontend/src/app/app.component.sass create mode 100644 overlays/spm/frontend/src/app/app.component.ts create mode 100644 overlays/spm/frontend/src/app/app.module.ts create mode 100644 overlays/spm/frontend/src/app/color-scheme.service.ts create mode 100644 overlays/spm/frontend/src/app/page-not-found/page-not-found.component.html create mode 100644 overlays/spm/frontend/src/app/page-not-found/page-not-found.component.sass create mode 100644 overlays/spm/frontend/src/app/page-not-found/page-not-found.component.ts create mode 100644 overlays/spm/frontend/src/app/spm/spm.component.html create mode 100644 overlays/spm/frontend/src/app/spm/spm.component.sass create mode 100644 overlays/spm/frontend/src/app/spm/spm.component.ts (limited to 'overlays/spm/frontend/src/app') diff --git a/overlays/spm/frontend/src/app/app-routing.module.ts b/overlays/spm/frontend/src/app/app-routing.module.ts new file mode 100644 index 00000000..2da97cea --- /dev/null +++ b/overlays/spm/frontend/src/app/app-routing.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +import { SpmComponent } from './spm/spm.component'; +import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; + +const routes: Routes = [ + { path: 'spm', component: SpmComponent }, + { path: '', redirectTo: '/spm', pathMatch: 'full' }, + { path: '**', component: PageNotFoundComponent } +]; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) +export class AppRoutingModule { } diff --git a/overlays/spm/frontend/src/app/app.component.html b/overlays/spm/frontend/src/app/app.component.html new file mode 100644 index 00000000..f9b5b8fc --- /dev/null +++ b/overlays/spm/frontend/src/app/app.component.html @@ -0,0 +1,7 @@ + +
+ spm +
+
+ + diff --git a/overlays/spm/frontend/src/app/app.component.sass b/overlays/spm/frontend/src/app/app.component.sass new file mode 100644 index 00000000..e69de29b diff --git a/overlays/spm/frontend/src/app/app.component.ts b/overlays/spm/frontend/src/app/app.component.ts new file mode 100644 index 00000000..7c231203 --- /dev/null +++ b/overlays/spm/frontend/src/app/app.component.ts @@ -0,0 +1,21 @@ +import { Component, OnInit, OnDestroy } from '@angular/core'; + +import { ColorSchemeService } from './color-scheme.service'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.sass'] +}) +export class AppComponent implements OnInit, OnDestroy { + title = 'spm-frontend'; + + constructor(private colorSchemeService: ColorSchemeService) {} + + ngOnInit() { + this.colorSchemeService.init(); + } + ngOnDestroy() { + this.colorSchemeService.destroy(); + } +} diff --git a/overlays/spm/frontend/src/app/app.module.ts b/overlays/spm/frontend/src/app/app.module.ts new file mode 100644 index 00000000..914f73a2 --- /dev/null +++ b/overlays/spm/frontend/src/app/app.module.ts @@ -0,0 +1,32 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; +import { SpmComponent } from './spm/spm.component'; +import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MatIconModule } from '@angular/material/icon'; +import { HttpClientModule } from "@angular/common/http"; +import { MatToolbarModule } from '@angular/material/toolbar'; +import { MatButtonModule } from '@angular/material/button'; + +@NgModule({ + declarations: [ + AppComponent, + SpmComponent, + PageNotFoundComponent + ], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatIconModule, + HttpClientModule, + MatToolbarModule, + MatButtonModule + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/overlays/spm/frontend/src/app/color-scheme.service.ts b/overlays/spm/frontend/src/app/color-scheme.service.ts new file mode 100644 index 00000000..c56e9c23 --- /dev/null +++ b/overlays/spm/frontend/src/app/color-scheme.service.ts @@ -0,0 +1,62 @@ +import { Injectable, Renderer2, RendererFactory2 } from '@angular/core'; +import { MediaMatcher } from '@angular/cdk/layout'; +import { LocalStorage } from 'ngx-webstorage'; + +type ColorScheme = "dark" | "light"; + +@Injectable({ + providedIn: 'root' +}) +export class ColorSchemeService { + private renderer: Renderer2; + matcher!: MediaQueryList; + + @LocalStorage('prefers-color-scheme') + public colorSchemeOverride: ColorScheme; + + public activeColorScheme: BehaviorSubject = new BehaviorSubject("light"); + + constructor(rendererFactory: RendererFactory2, + mediaMatcher: MediaMatcher + ) { + // Create new renderer from renderFactory, to make it possible to use renderer2 in a service + this.renderer = rendererFactory.createRenderer(null, null); + this.matcher = mediaMatcher.matchMedia('(prefers-color-scheme: dark)'); + + this._listener = this._listener.bind(this); + } + + init() { + this.matcher.addEventListener('change', this._listener); + this.load(); + } + + _listener(event: { matches: any; }) { + this.activeColorScheme.next(event.matches ? 'dark' : 'light'); + } + + destroy() { + this.matcher.removeEventListener('change', this._listener); + } + + _getColorScheme() { + if (this.colorSchemeOverride) { + this.colorSchemeOverride + } else { + this.matcher.matches ? 'dark' : 'light' + } + } + + load() { + this.activeColorScheme.next(this._getColorScheme()); + } + + update(scheme: ColorScheme) { + this.colorSchemeOverride = scheme; + this.activeColorScheme.next(scheme); + } + + currentActive() { + return this.colorScheme; + } +} diff --git a/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.html b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.html new file mode 100644 index 00000000..26a283ed --- /dev/null +++ b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.html @@ -0,0 +1,5 @@ +
+

+ No Such Component +

+
diff --git a/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.sass b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.sass new file mode 100644 index 00000000..e69de29b diff --git a/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.ts b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.ts new file mode 100644 index 00000000..2d1091ce --- /dev/null +++ b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-page-not-found', + templateUrl: './page-not-found.component.html', + styleUrls: ['./page-not-found.component.sass'] +}) +export class PageNotFoundComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/overlays/spm/frontend/src/app/spm/spm.component.html b/overlays/spm/frontend/src/app/spm/spm.component.html new file mode 100644 index 00000000..d1339d95 --- /dev/null +++ b/overlays/spm/frontend/src/app/spm/spm.component.html @@ -0,0 +1,3 @@ +

spm works!

+ + diff --git a/overlays/spm/frontend/src/app/spm/spm.component.sass b/overlays/spm/frontend/src/app/spm/spm.component.sass new file mode 100644 index 00000000..e69de29b diff --git a/overlays/spm/frontend/src/app/spm/spm.component.ts b/overlays/spm/frontend/src/app/spm/spm.component.ts new file mode 100644 index 00000000..7d172052 --- /dev/null +++ b/overlays/spm/frontend/src/app/spm/spm.component.ts @@ -0,0 +1,24 @@ +import { Component, OnInit } from '@angular/core'; +import { MatIconRegistry, MatIconModule } from '@angular/material/icon'; +import { DomSanitizer } from "@angular/platform-browser"; + +@Component({ + selector: 'app-spm', + templateUrl: './spm.component.html', + styleUrls: ['./spm.component.sass'] +}) +export class SpmComponent implements OnInit { + + constructor(private matIconRegistry: MatIconRegistry, + private domSanitizer: DomSanitizer + ) { + this.matIconRegistry.addSvgIcon( + `thumb_up`, + this.domSanitizer.bypassSecurityTrustResourceUrl(`icons/thumb_up/baseline.svg`) + ); + } + + ngOnInit(): void { + } + +} -- cgit v1.2.3