summaryrefslogtreecommitdiff
path: root/overlays/spm/frontend/src/app
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-05-26 13:58:07 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2022-05-26 13:58:07 +0200
commitfc6cf6169868e60c189e4b243330c3717ff159f3 (patch)
tree3f6dea9c1420e23756257b5abea27ec9ed92d58a /overlays/spm/frontend/src/app
parent84f2affd66a0ff3947b91a30308cb8e6a8ff7594 (diff)
downloadnixos-fc6cf6169868e60c189e4b243330c3717ff159f3.tar
nixos-fc6cf6169868e60c189e4b243330c3717ff159f3.tar.gz
nixos-fc6cf6169868e60c189e4b243330c3717ff159f3.tar.bz2
nixos-fc6cf6169868e60c189e4b243330c3717ff159f3.tar.xz
nixos-fc6cf6169868e60c189e4b243330c3717ff159f3.zip
...
Diffstat (limited to 'overlays/spm/frontend/src/app')
-rw-r--r--overlays/spm/frontend/src/app/app-routing.module.ts17
-rw-r--r--overlays/spm/frontend/src/app/app.component.html7
-rw-r--r--overlays/spm/frontend/src/app/app.component.sass0
-rw-r--r--overlays/spm/frontend/src/app/app.component.ts21
-rw-r--r--overlays/spm/frontend/src/app/app.module.ts32
-rw-r--r--overlays/spm/frontend/src/app/color-scheme.service.ts62
-rw-r--r--overlays/spm/frontend/src/app/page-not-found/page-not-found.component.html5
-rw-r--r--overlays/spm/frontend/src/app/page-not-found/page-not-found.component.sass0
-rw-r--r--overlays/spm/frontend/src/app/page-not-found/page-not-found.component.ts15
-rw-r--r--overlays/spm/frontend/src/app/spm/spm.component.html3
-rw-r--r--overlays/spm/frontend/src/app/spm/spm.component.sass0
-rw-r--r--overlays/spm/frontend/src/app/spm/spm.component.ts24
12 files changed, 186 insertions, 0 deletions
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 @@
1import { NgModule } from '@angular/core';
2import { RouterModule, Routes } from '@angular/router';
3
4import { SpmComponent } from './spm/spm.component';
5import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
6
7const routes: Routes = [
8 { path: 'spm', component: SpmComponent },
9 { path: '', redirectTo: '/spm', pathMatch: 'full' },
10 { path: '**', component: PageNotFoundComponent }
11];
12
13@NgModule({
14 imports: [RouterModule.forRoot(routes)],
15 exports: [RouterModule]
16})
17export 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 @@
1<mat-toolbar color="primary">
2 <div>
3 <a mat-button routerLink="/spm" routerLinkActive="active">spm</a>
4 </div>
5</mat-toolbar>
6<!-- The routed views render in the <router-outlet> -->
7<router-outlet></router-outlet>
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
--- /dev/null
+++ b/overlays/spm/frontend/src/app/app.component.sass
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 @@
1import { Component, OnInit, OnDestroy } from '@angular/core';
2
3import { ColorSchemeService } from './color-scheme.service';
4
5@Component({
6 selector: 'app-root',
7 templateUrl: './app.component.html',
8 styleUrls: ['./app.component.sass']
9})
10export class AppComponent implements OnInit, OnDestroy {
11 title = 'spm-frontend';
12
13 constructor(private colorSchemeService: ColorSchemeService) {}
14
15 ngOnInit() {
16 this.colorSchemeService.init();
17 }
18 ngOnDestroy() {
19 this.colorSchemeService.destroy();
20 }
21}
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 @@
1import { NgModule } from '@angular/core';
2import { BrowserModule } from '@angular/platform-browser';
3
4import { AppRoutingModule } from './app-routing.module';
5import { AppComponent } from './app.component';
6import { SpmComponent } from './spm/spm.component';
7import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
8import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
9import { MatIconModule } from '@angular/material/icon';
10import { HttpClientModule } from "@angular/common/http";
11import { MatToolbarModule } from '@angular/material/toolbar';
12import { MatButtonModule } from '@angular/material/button';
13
14@NgModule({
15 declarations: [
16 AppComponent,
17 SpmComponent,
18 PageNotFoundComponent
19 ],
20 imports: [
21 BrowserModule,
22 AppRoutingModule,
23 BrowserAnimationsModule,
24 MatIconModule,
25 HttpClientModule,
26 MatToolbarModule,
27 MatButtonModule
28 ],
29 providers: [],
30 bootstrap: [AppComponent]
31})
32export 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 @@
1import { Injectable, Renderer2, RendererFactory2 } from '@angular/core';
2import { MediaMatcher } from '@angular/cdk/layout';
3import { LocalStorage } from 'ngx-webstorage';
4
5type ColorScheme = "dark" | "light";
6
7@Injectable({
8 providedIn: 'root'
9})
10export class ColorSchemeService {
11 private renderer: Renderer2;
12 matcher!: MediaQueryList;
13
14 @LocalStorage('prefers-color-scheme')
15 public colorSchemeOverride: ColorScheme;
16
17 public activeColorScheme: BehaviorSubject<ColorScheme> = new BehaviorSubject("light");
18
19 constructor(rendererFactory: RendererFactory2,
20 mediaMatcher: MediaMatcher
21 ) {
22 // Create new renderer from renderFactory, to make it possible to use renderer2 in a service
23 this.renderer = rendererFactory.createRenderer(null, null);
24 this.matcher = mediaMatcher.matchMedia('(prefers-color-scheme: dark)');
25
26 this._listener = this._listener.bind(this);
27 }
28
29 init() {
30 this.matcher.addEventListener('change', this._listener);
31 this.load();
32 }
33
34 _listener(event: { matches: any; }) {
35 this.activeColorScheme.next(event.matches ? 'dark' : 'light');
36 }
37
38 destroy() {
39 this.matcher.removeEventListener('change', this._listener);
40 }
41
42 _getColorScheme() {
43 if (this.colorSchemeOverride) {
44 this.colorSchemeOverride
45 } else {
46 this.matcher.matches ? 'dark' : 'light'
47 }
48 }
49
50 load() {
51 this.activeColorScheme.next(this._getColorScheme());
52 }
53
54 update(scheme: ColorScheme) {
55 this.colorSchemeOverride = scheme;
56 this.activeColorScheme.next(scheme);
57 }
58
59 currentActive() {
60 return this.colorScheme;
61 }
62}
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 @@
1<div style="margin: 1rem;">
2 <h1>
3 No Such Component
4 </h1>
5</div>
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
--- /dev/null
+++ b/overlays/spm/frontend/src/app/page-not-found/page-not-found.component.sass
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 @@
1import { Component, OnInit } from '@angular/core';
2
3@Component({
4 selector: 'app-page-not-found',
5 templateUrl: './page-not-found.component.html',
6 styleUrls: ['./page-not-found.component.sass']
7})
8export class PageNotFoundComponent implements OnInit {
9
10 constructor() { }
11
12 ngOnInit(): void {
13 }
14
15}
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 @@
1<p>spm works!</p>
2
3<mat-icon aria-hidden="false" aria-label="Thumbs up" svgIcon="thumb_up"></mat-icon>
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
--- /dev/null
+++ b/overlays/spm/frontend/src/app/spm/spm.component.sass
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 @@
1import { Component, OnInit } from '@angular/core';
2import { MatIconRegistry, MatIconModule } from '@angular/material/icon';
3import { DomSanitizer } from "@angular/platform-browser";
4
5@Component({
6 selector: 'app-spm',
7 templateUrl: './spm.component.html',
8 styleUrls: ['./spm.component.sass']
9})
10export class SpmComponent implements OnInit {
11
12 constructor(private matIconRegistry: MatIconRegistry,
13 private domSanitizer: DomSanitizer
14 ) {
15 this.matIconRegistry.addSvgIcon(
16 `thumb_up`,
17 this.domSanitizer.bypassSecurityTrustResourceUrl(`icons/thumb_up/baseline.svg`)
18 );
19 }
20
21 ngOnInit(): void {
22 }
23
24}