|
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { HttpClient } from '@angular/common/http'; |
| 3 | +import { ReleaseNotesJSON, ReleaseNotes } from './release-notes'; |
| 4 | +import releaseNotes from '../../../assets/release-notes.json'; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + selector: 'app-release-notes', |
| 8 | + templateUrl: './release-notes.component.html', |
| 9 | + styles: [] |
| 10 | +}) |
| 11 | +export class ReleaseNotesComponent implements OnInit { |
| 12 | + |
| 13 | + constructor(private http: HttpClient) { } |
| 14 | + |
| 15 | + /** Retrieves the release notes JSON file. */ |
| 16 | + get releaseNotes(): ReleaseNotesJSON { |
| 17 | + return releaseNotes; |
| 18 | + } |
| 19 | + |
| 20 | + /** Retrieves the list of versions. */ |
| 21 | + get versions(): string[] { |
| 22 | + return Object.keys(this.releaseNotes.releases); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Retrieves the release notes for the specified `version`. |
| 27 | + * @param version The version |
| 28 | + */ |
| 29 | + getReleaseNote(version: string): ReleaseNotes { |
| 30 | + return this.releaseNotes.releases[version].releaseNotes; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Joins a list of release notes to a string. |
| 35 | + * @param notes The notes to join |
| 36 | + */ |
| 37 | + joinReleaseNotes(notes: string[]): string { |
| 38 | + return notes.join('\n'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Checks if the specified `val` parameter is an array. |
| 43 | + * @param val The value to check. |
| 44 | + */ |
| 45 | + isArray(val: any): boolean { |
| 46 | + return Array.isArray(val); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Checks whether the specified `val` parameter is a URL. |
| 51 | + * @param val The value to check. |
| 52 | + * |
| 53 | + * _See https://stackoverflow.com/a/46296668/6782707 for more info._ |
| 54 | + */ |
| 55 | + isUrl(val: string): boolean { |
| 56 | + return /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/.test(val); |
| 57 | + } |
| 58 | + ngOnInit() { |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments