Skip to content
Snippets Groups Projects
Commit bca64f2d authored by Tom Käsler's avatar Tom Käsler Committed by Tom Käsler
Browse files

use new service for comments

parent 1261e94d
No related merge requests found
{ {
"/api/comment": {
"target": "http://localhost:8088",
"secure": false,
"pathRewrite": {
"^/api": ""
},
"logLevel": "debug"
},
"/api": { "/api": {
"target": "http://localhost:8080", "target": "http://localhost:8080",
"secure": false, "secure": false,
......
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { FormControl, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { Comment } from '../../../models/comment';
import { CommentService } from '../../../services/http/comment.service';
import { NotificationService } from '../../../services/util/notification.service';
import { AuthenticationService } from '../../../services/http/authentication.service';
import { User } from '../../../models/user';
import { CommentListComponent } from '../../shared/comment-list/comment-list.component';
import { RxStompService } from '@stomp/ng2-stompjs';
import { CreateComment } from '../../../models/messages/create-comment';
@Component({
selector: 'app-comment-create-page',
templateUrl: './comment-create-page.component.html',
styleUrls: ['./comment-create-page.component.scss']
})
export class CommentCreatePageComponent implements OnInit {
@ViewChild(CommentListComponent) child: CommentListComponent;
roomId: string;
roomShortId: string;
user: User;
private date = new Date(Date.now());
subjectForm = new FormControl('', [Validators.required]);
bodyForm = new FormControl('', [Validators.required]);
constructor(
protected authenticationService: AuthenticationService,
private route: ActivatedRoute,
private notification: NotificationService,
private translationService: TranslateService,
private rxStompService: RxStompService) { }
ngOnInit(): void {
this.user = this.authenticationService.getUser();
this.roomShortId = this.route.snapshot.paramMap.get('roomId');
this.roomId = localStorage.getItem(`roomId`);
}
send(subject: string, body: string): void {
subject = subject.trim();
body = body.trim();
if (!subject && !body) {
this.translationService.get('comment-page.error-both-fields').subscribe(translatedMessage => {
this.notification.show(translatedMessage);
});
return;
}
if (!subject) {
this.translationService.get('comment-page.error-title').subscribe(translatedMessage => {
this.notification.show(translatedMessage);
});
return;
}
if (!body) {
this.translationService.get('comment-page.error-comment').subscribe(translatedMessage => {
this.notification.show(translatedMessage);
});
return;
}
const message = new CreateComment(this.roomId, this.user.id, subject, body);
this.rxStompService.publish({
destination: `/queue/comment.command`,
body: JSON.stringify(message),
headers: {
'content-type': 'application/json'
}
});
/*this.commentService.addComment({
id: '',
roomId: this.roomId,
userId: this.user.id,
subject: subject,
body: body,
creationTimestamp: this.date.getTime(),
read: false,
revision: ''
} as Comment).subscribe(() => {
this.child.getComments();
this.notification.show(`Comment '${subject}' successfully created.`);
this.goBack();
});*/
}
}
import { Component, Inject, OnInit } from '@angular/core'; import { Component, Inject, OnInit } from '@angular/core';
import { Comment } from '../../../../models/comment'; import { Comment } from '../../../../models/comment';
import { ActivatedRoute } from '@angular/router';
import { NotificationService } from '../../../../services/util/notification.service'; import { NotificationService } from '../../../../services/util/notification.service';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material'; import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { CommentPageComponent } from '../../comment-page/comment-page.component'; import { CommentPageComponent } from '../../comment-page/comment-page.component';
import { AuthenticationService } from '../../../../services/http/authentication.service';
import { FormControl, Validators } from '@angular/forms'; import { FormControl, Validators } from '@angular/forms';
import { User } from '../../../../models/user'; import { User } from '../../../../models/user';
...@@ -20,16 +18,16 @@ export class SubmitCommentComponent implements OnInit { ...@@ -20,16 +18,16 @@ export class SubmitCommentComponent implements OnInit {
comment: Comment; comment: Comment;
user: User; user: User;
roomId: string;
subjectForm = new FormControl('', [Validators.required]); subjectForm = new FormControl('', [Validators.required]);
bodyForm = new FormControl('', [Validators.required]); bodyForm = new FormControl('', [Validators.required]);
private date = new Date(Date.now()); private date = new Date(Date.now());
constructor(private route: ActivatedRoute, constructor(
private notification: NotificationService, private notification: NotificationService,
public dialogRef: MatDialogRef<CommentPageComponent>, public dialogRef: MatDialogRef<CommentPageComponent>,
private translateService: TranslateService, private translateService: TranslateService,
protected authenticationService: AuthenticationService,
public dialog: MatDialog, public dialog: MatDialog,
private translationService: TranslateService, private translationService: TranslateService,
@Inject(MAT_DIALOG_DATA) public data: any) { @Inject(MAT_DIALOG_DATA) public data: any) {
...@@ -37,7 +35,6 @@ export class SubmitCommentComponent implements OnInit { ...@@ -37,7 +35,6 @@ export class SubmitCommentComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.translateService.use(localStorage.getItem('currentLang')); this.translateService.use(localStorage.getItem('currentLang'));
this.user = this.authenticationService.getUser();
} }
onNoClick(): void { onNoClick(): void {
......
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Comment } from '../../../models/comment'; import { Comment } from '../../../models/comment';
import { User } from '../../../models/user';
import { CommentService } from '../../../services/http/comment.service'; import { CommentService } from '../../../services/http/comment.service';
import { NotificationService } from '../../../services/util/notification.service'; import { NotificationService } from '../../../services/util/notification.service';
import { CommentListComponent } from '../comment-list/comment-list.component'; import { CommentListComponent } from '../comment-list/comment-list.component';
import { AuthenticationService } from '../../../services/http/authentication.service';
import { MatDialog } from '@angular/material'; import { MatDialog } from '@angular/material';
import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-comment.component'; import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-comment.component';
import { RxStompService } from '@stomp/ng2-stompjs';
import { CreateComment } from '../../../models/messages/create-comment';
@Component({ @Component({
selector: 'app-comment-page', selector: 'app-comment-page',
...@@ -13,20 +17,29 @@ import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-commen ...@@ -13,20 +17,29 @@ import { SubmitCommentComponent } from '../_dialogs/submit-comment/submit-commen
styleUrls: ['./comment-page.component.scss'] styleUrls: ['./comment-page.component.scss']
}) })
export class CommentPageComponent implements OnInit { export class CommentPageComponent implements OnInit {
roomId: string;
user: User;
@ViewChild(CommentListComponent) child: CommentListComponent; @ViewChild(CommentListComponent) child: CommentListComponent;
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private commentService: CommentService, private commentService: CommentService,
private notification: NotificationService, private notification: NotificationService,
public dialog: MatDialog) { } public dialog: MatDialog,
private rxStompService: RxStompService,
private authenticationService: AuthenticationService) { }
ngOnInit(): void { ngOnInit(): void {
this.roomId = localStorage.getItem("roomId");
this.user = this.authenticationService.getUser();
} }
openSubmitDialog(): void { openSubmitDialog(): void {
const dialogRef = this.dialog.open(SubmitCommentComponent, { const dialogRef = this.dialog.open(SubmitCommentComponent, {
width: '400px' width: '400px'
}); });
dialogRef.componentInstance.user = this.user;
dialogRef.componentInstance.roomId = this.roomId;
dialogRef.afterClosed() dialogRef.afterClosed()
.subscribe(result => { .subscribe(result => {
if (result) { if (result) {
...@@ -38,7 +51,7 @@ export class CommentPageComponent implements OnInit { ...@@ -38,7 +51,7 @@ export class CommentPageComponent implements OnInit {
} }
send(comment: Comment): void { send(comment: Comment): void {
this.commentService.addComment({ /*this.commentService.addComment({
id: '', id: '',
roomId: comment.roomId, roomId: comment.roomId,
userId: comment.userId, userId: comment.userId,
...@@ -50,6 +63,14 @@ export class CommentPageComponent implements OnInit { ...@@ -50,6 +63,14 @@ export class CommentPageComponent implements OnInit {
} as Comment).subscribe(() => { } as Comment).subscribe(() => {
this.child.getComments(); this.child.getComments();
this.notification.show(`Comment '${comment.subject}' successfully created.`); this.notification.show(`Comment '${comment.subject}' successfully created.`);
});*/
const message = new CreateComment(comment.roomId, comment.userId, comment.subject, comment.body);
this.rxStompService.publish({
destination: `/queue/comment.command`,
body: JSON.stringify(message),
headers: {
'content-type': 'application/json'
}
}); });
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment