-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditional navigation for legal documents; open URLs directly fr…
…om overview or display markdown content in detail view (#113) * feat: add conditional navigation for legal documents --------- Co-authored-by: Kunz Robert <robert_kunz@sluz.ch>
- Loading branch information
1 parent
d77bca4
commit 952649d
Showing
15 changed files
with
183 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { buildCollection } from 'firecms'; | ||
|
||
type Legal = { | ||
title: string; | ||
description: string; | ||
markdown?: string; | ||
url?: string; | ||
displayType: 'markdown' | 'url'; | ||
}; | ||
|
||
export const legalCollection = buildCollection<Legal>({ | ||
name: 'Legal', | ||
singularName: 'Legal', | ||
path: 'legal', | ||
icon: 'Gavel', | ||
defaultSize: 's', | ||
permissions: () => ({ | ||
read: true, | ||
edit: true, | ||
create: true, | ||
delete: true, | ||
}), | ||
properties: { | ||
title: { | ||
name: 'Title', | ||
validation: { required: true, min: 3, max: 100 }, | ||
dataType: 'string', | ||
}, | ||
description: { | ||
name: 'Description', | ||
validation: { required: true, min: 3, max: 500 }, | ||
dataType: 'string', | ||
}, | ||
markdown: { | ||
name: 'Markdown', | ||
validation: { | ||
required: (values: Legal) => values.displayType === 'markdown', | ||
min: 3, | ||
max: 100000, | ||
}, | ||
dataType: 'string', | ||
markdown: true, | ||
}, | ||
url: { | ||
name: 'URL', | ||
validation: { | ||
required: (values: Legal) => values.displayType === 'url', | ||
url: true, | ||
}, | ||
dataType: 'string', | ||
}, | ||
displayType: { | ||
name: 'Display Type', | ||
validation: { required: true }, | ||
dataType: 'string', | ||
enumValues: { | ||
markdown: 'Markdown', | ||
url: 'URL', | ||
}, | ||
}, | ||
}, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import { inject, Injectable } from '@angular/core'; | ||
import { Legal, LegalDocument } from '../../types/legal.type'; | ||
import * as legalData from '../../../assets/legal/legal.json'; | ||
import { ToastService } from '../feedback/toast.service'; | ||
import { ToastType } from '../../types/feedback/toast.types'; | ||
import { Injectable } from '@angular/core'; | ||
import { LegalDocument } from '../../types/legal.type'; | ||
import { AngularFirestore } from '@angular/fire/compat/firestore'; | ||
import { map } from 'rxjs/operators'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class LegalService { | ||
public legals: LegalDocument[] = (legalData as Legal).files; | ||
constructor(private firestore: AngularFirestore) {} | ||
|
||
getLegalDocumentByFileId(file: string): LegalDocument | undefined { | ||
return this.legals.find((legal) => { | ||
if (legal) { | ||
return legal.file === file; | ||
} else { | ||
inject(ToastService).showToast( | ||
'Could not find the legal document, try again.', | ||
ToastType.Error, | ||
); | ||
} | ||
return undefined; | ||
}); | ||
getLegalDocuments(): Observable<LegalDocument[]> { | ||
return this.firestore | ||
.collection<LegalDocument>('legal') | ||
.valueChanges({ idField: 'id' }); | ||
} | ||
|
||
getLegalDocumentById(id: string): Observable<LegalDocument | undefined> { | ||
return this.firestore | ||
.collection<LegalDocument>('legal') | ||
.doc<LegalDocument>(id) | ||
.valueChanges() | ||
.pipe(map((document) => document ?? undefined)); | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
apps/course/src/app/features/legal/legal-detail/legal-detail.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
<article class="flex justify-center c-min-h-80"> | ||
<div class="mx-2 my-3 sm:mx-5 sm:my-9 w-full max-w-6xl"> | ||
<div class="mx-3 sm:mx-5 my-3 sm:my-9"> | ||
<app-legal-info [legal]="legal" /> | ||
<app-legal-info [legal]="safeLegalDocument"></app-legal-info> | ||
<div class="divider"></div> | ||
<app-legal-markdown-renderer [legal]="legal" /> | ||
@if (safeLegalDocument?.displayType === 'markdown') { | ||
<app-legal-markdown-renderer | ||
[legal]="safeLegalDocument" | ||
></app-legal-markdown-renderer> | ||
} | ||
</div> | ||
</div> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/course/src/app/features/legal/legal-detail/legal-info/legal-info.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<h1 class="text-4xl font-semibold subpixel-antialiased dark:text-gray-100"> | ||
{{ legal?.name }} | ||
{{ legal?.title }} | ||
</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 2 additions & 7 deletions
9
...eatures/legal/legal-detail/legal-markdown-renderer/legal-markdown-renderer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
@if (isLoading) { | ||
<app-loading-bars /> | ||
} @else { | ||
<markdown | ||
[src]="'assets/legal/content/' + legal?.file + '.md'" | ||
class="markdown-content" | ||
/> | ||
@if (legal) { | ||
<markdown [data]="legal.markdown" class="markdown-content"></markdown> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 33 additions & 12 deletions
45
apps/course/src/app/features/legal/legal-overview/legal-overview.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.material-symbols-outlined { | ||
font-variation-settings: 'FILL' 0, | ||
'wght' 400, | ||
'GRAD' 0, | ||
'opsz' 24; | ||
} |
32 changes: 14 additions & 18 deletions
32
apps/course/src/app/features/legal/legal-overview/legal-overview.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { LegalService } from '../../../core/data/legal.service'; | ||
import { LegalDocument } from '../../../types/legal.type'; | ||
import { Title } from '@angular/platform-browser'; | ||
import { RouterLink } from '@angular/router'; | ||
import { environment } from '../../../../environments/environment'; | ||
import { AppComponent } from '../../../app.component'; | ||
import { LoadingBarsComponent } from '../../../shared/feedback/loading-bars/loading-bars.component'; | ||
import { Observable } from 'rxjs'; | ||
import { AsyncPipe } from '@angular/common'; | ||
|
||
@Component({ | ||
selector: 'app-legal-overview', | ||
standalone: true, | ||
imports: [RouterLink, LoadingBarsComponent], | ||
imports: [RouterLink, LoadingBarsComponent, AsyncPipe], | ||
templateUrl: './legal-overview.component.html', | ||
styleUrl: './legal-overview.component.scss', | ||
}) | ||
export class LegalOverviewComponent implements OnInit { | ||
legalDocuments: LegalDocument[] = []; | ||
public isLoading = true; | ||
legalDocuments$: Observable<LegalDocument[]>; | ||
isLoading = true; | ||
|
||
constructor( | ||
private legalService: LegalService, | ||
private titleService: Title, | ||
) { | ||
this.titleService.setTitle( | ||
'Legal - ' + | ||
environment.metaConfig.title + | ||
' - ' + | ||
AppComponent.chorizo.title, | ||
); | ||
constructor(private legalService: LegalService) { | ||
this.legalDocuments$ = this.legalService.getLegalDocuments(); | ||
} | ||
|
||
ngOnInit() { | ||
this.legalDocuments = this.legalService.legals; | ||
ngOnInit(): void { | ||
this.isLoading = false; | ||
} | ||
|
||
openUrl(url: string | undefined): void { | ||
if (url) { | ||
window.open(url, '_blank'); | ||
} | ||
} | ||
} |
Oops, something went wrong.