-
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.
Merge pull request #75 from ducktordanny/feat/changelog-view
Feat: Changelog view
- Loading branch information
Showing
23 changed files
with
231 additions
and
35 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
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import {Module} from '@nestjs/common'; | ||
|
||
import {AssignmentProblemModule} from './controllers/assignment-problem/assignment-problem.module'; | ||
import {ChangelogModule} from './controllers/changelog/changelog.module'; | ||
import {TransportProblemModule} from './controllers/transport-problem/transport-problem.module'; | ||
import {TspModule} from './controllers/tsp/tsp.module'; | ||
import {AppController} from './app.controller'; | ||
|
||
@Module({ | ||
imports: [TransportProblemModule, AssignmentProblemModule, TspModule], | ||
imports: [ChangelogModule, TransportProblemModule, AssignmentProblemModule, TspModule], | ||
controllers: [AppController], | ||
}) | ||
export class AppModule {} |
15 changes: 15 additions & 0 deletions
15
apps/backend/src/app/controllers/changelog/changelog.controller.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Controller, Get, Res} from '@nestjs/common'; | ||
|
||
import {Response} from 'express'; | ||
|
||
@Controller('changelog') | ||
export class ChangelogController { | ||
@Get() | ||
public getChangelogContentInMD(@Res() res: Response) { | ||
res.sendFile(__dirname + '/assets/CHANGELOG.md', { | ||
headers: { | ||
'Content-Type': 'text/markdown', | ||
}, | ||
}); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
apps/backend/src/app/controllers/changelog/changelog.module.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {Module} from '@nestjs/common'; | ||
|
||
import {ChangelogController} from './changelog.controller'; | ||
|
||
@Module({ | ||
controllers: [ChangelogController], | ||
}) | ||
export class ChangelogModule {} |
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
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
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,24 @@ | ||
import {CommonModule} from '@angular/common'; | ||
import {HttpClientModule} from '@angular/common/http'; | ||
import {NgModule} from '@angular/core'; | ||
import {MatSnackBarModule} from '@angular/material/snack-bar'; | ||
|
||
import {MdPreviewModule} from '../../pipes/md-preview/md-preview.module'; | ||
|
||
import {ChangelogPageComponent} from './changelog.page'; | ||
import {ChangelogRouteModule} from './changelog.routing'; | ||
import {ChangelogService} from './changelog.service'; | ||
|
||
@NgModule({ | ||
declarations: [ChangelogPageComponent], | ||
providers: [ChangelogService], | ||
imports: [ | ||
ChangelogRouteModule, | ||
CommonModule, | ||
HttpClientModule, | ||
MatSnackBarModule, | ||
MdPreviewModule, | ||
], | ||
exports: [], | ||
}) | ||
export class ChangelogPageModule {} |
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,47 @@ | ||
import {AfterViewInit, ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {MatSnackBar} from '@angular/material/snack-bar'; | ||
|
||
import {UntilDestroy, untilDestroyed} from '@ngneat/until-destroy'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {Observable} from 'rxjs'; | ||
|
||
import {ChangelogService} from './changelog.service'; | ||
|
||
@UntilDestroy() | ||
@Component({ | ||
templateUrl: './changelog.template.html', | ||
styles: [ | ||
` | ||
section { | ||
padding: 16px; | ||
} | ||
`, | ||
], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ChangelogPageComponent implements AfterViewInit { | ||
public changelogContent: Observable<string>; | ||
|
||
constructor( | ||
private changelogService: ChangelogService, | ||
private snackBar: MatSnackBar, | ||
private translateService: TranslateService, | ||
) { | ||
this.changelogContent = this.changelogService.getChangelogContent(); | ||
} | ||
|
||
public ngAfterViewInit(): void { | ||
this.showLanguageInfo(); | ||
this.translateService.onLangChange | ||
.pipe(untilDestroyed(this)) | ||
.subscribe(() => this.showLanguageInfo()); | ||
} | ||
|
||
public showLanguageInfo(): void { | ||
const snackBarContent = this.translateService.instant('CHANGELOG.INFO'); | ||
const actionContent = this.translateService.instant('CLOSE'); | ||
this.snackBar.open(snackBarContent, actionContent, { | ||
duration: 5_000, | ||
}); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
apps/frontend/src/app/pages/changelog/changelog.routing.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {RouterModule, Routes} from '@angular/router'; | ||
|
||
import {ChangelogPageComponent} from './changelog.page'; | ||
|
||
const routes: Routes = [{path: '', component: ChangelogPageComponent}]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule], | ||
}) | ||
export class ChangelogRouteModule {} |
26 changes: 26 additions & 0 deletions
26
apps/frontend/src/app/pages/changelog/changelog.service.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {HttpClient, HttpHeaders} from '@angular/common/http'; | ||
import {Injectable} from '@angular/core'; | ||
|
||
import {Observable} from 'rxjs'; | ||
import {map} from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class ChangelogService { | ||
constructor(private http: HttpClient) {} | ||
|
||
public getChangelogContent(): Observable<string> { | ||
const headers = new HttpHeaders(); | ||
headers.append('Access', 'text/markdown'); | ||
headers.append('Content-Type', 'text/markdown'); | ||
|
||
const request = this.http.get<ArrayBuffer>('/api/changelog', { | ||
headers, | ||
responseType: 'arraybuffer' as 'json', | ||
}); | ||
|
||
return request.pipe(map(this.getContentFromArrayBuffer)); | ||
} | ||
|
||
private getContentFromArrayBuffer = (arrbuffer: ArrayBuffer): string => | ||
new TextDecoder().decode(arrbuffer); | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/frontend/src/app/pages/changelog/changelog.template.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<section> | ||
<p [innerHTML]="changelogContent | async | mdPreview"></p> | ||
<a | ||
href="https://github.com/ducktordanny/opres.help/blob/master/apps/backend/src/assets/CHANGELOG.md" | ||
>See on GitHub.</a | ||
> | ||
</section> |
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,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {MdPreviewPipe} from './md-preview.pipe'; | ||
|
||
@NgModule({ | ||
declarations: [MdPreviewPipe], | ||
exports: [MdPreviewPipe], | ||
}) | ||
export class MdPreviewModule {} |
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,23 @@ | ||
import {Pipe, SecurityContext} from '@angular/core'; | ||
import {DomSanitizer} from '@angular/platform-browser'; | ||
import {PipeTransform} from '@nestjs/common'; | ||
|
||
import {marked} from 'marked'; | ||
|
||
@Pipe({ | ||
name: 'mdPreview', | ||
}) | ||
export class MdPreviewPipe implements PipeTransform { | ||
constructor(private sanitizer: DomSanitizer) {} | ||
|
||
public transform(value: string | null): string { | ||
if (value === null) { | ||
console.error('mdPreview input value is null'); | ||
return ''; | ||
} | ||
const rawPreview = marked.parse(value); | ||
const preview = this.sanitizer.sanitize(SecurityContext.HTML, rawPreview); | ||
if (preview === null) console.error('Cannot display HTML content because of security reasons.'); | ||
return preview ?? ''; | ||
} | ||
} |
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,18 +1,19 @@ | ||
import {Injectable} from '@angular/core'; | ||
import {MatSnackBar} from '@angular/material/snack-bar'; | ||
|
||
import {TranslateService} from '@ngx-translate/core'; | ||
import {EMPTY, Observable} from 'rxjs'; | ||
|
||
import {APIError} from '../types/api.type'; | ||
|
||
@Injectable() | ||
export class ErrorHandlerService { | ||
constructor(private snackbar: MatSnackBar) {} | ||
constructor(private snackbar: MatSnackBar, private translateService: TranslateService) {} | ||
|
||
public showError = (value: {error: APIError}): Observable<never> => { | ||
const message = | ||
value?.error?.message || value?.error?.error || 'Something went wrong'; | ||
this.snackbar.open(message, 'Close'); | ||
const message = value?.error?.message || value?.error?.error || 'Something went wrong'; | ||
const action = this.translateService.instant('CLOSE'); | ||
this.snackbar.open(message, action); | ||
return EMPTY; | ||
}; | ||
} |
Oops, something went wrong.