From bcd88af53b1a920d728ec98b45daa9ac2e2c0917 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 12 Feb 2021 19:04:53 +0200 Subject: Moved from DevHive --- src/app/components/comment/comment.component.ts | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/app/components/comment/comment.component.ts (limited to 'src/app/components/comment/comment.component.ts') diff --git a/src/app/components/comment/comment.component.ts b/src/app/components/comment/comment.component.ts new file mode 100644 index 0000000..5076769 --- /dev/null +++ b/src/app/components/comment/comment.component.ts @@ -0,0 +1,54 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { Guid } from 'guid-typescript'; +import { CommentService } from 'src/app/services/comment.service'; +import { UserService } from 'src/app/services/user.service'; +import { Comment } from 'src/models/comment'; +import { User } from 'src/models/identity/user'; + +@Component({ + selector: 'app-comment', + templateUrl: './comment.component.html', + styleUrls: ['./comment.component.css'] +}) +export class CommentComponent implements OnInit { + public loaded = false; + public user: User; + public comment: Comment; + public timeCreated: string; + @Input() paramId: string; + + constructor(private _router: Router, private _commentService: CommentService, private _userService: UserService) + { } + + ngOnInit(): void { + this.comment = this._commentService.getDefaultComment(); + this.user = this._userService.getDefaultUser(); + + this._commentService.getCommentRequest(Guid.parse(this.paramId)).subscribe( + (result: object) => { + Object.assign(this.comment, result); + + this.timeCreated = new Date(this.comment.timeCreated).toLocaleString('en-GB'); + this.loadUser(); + } + ); + } + + private loadUser(): void { + this._userService.getUserByUsernameRequest(this.comment.issuerUsername).subscribe( + (result: object) => { + Object.assign(this.user, result); + this.loaded = true; + } + ); + } + + goToAuthorProfile(): void { + this._router.navigate(['/profile/' + this.comment.issuerUsername]); + } + + goToCommentPage(): void { + this._router.navigate(['/comment/' + this.comment.commentId]); + } +} -- cgit v1.2.3