Skip to content
Snippets Groups Projects
Commit ad340e2c authored by Sebastian Wittek's avatar Sebastian Wittek
Browse files

clean up code

parent b8f3904f
No related merge requests found
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
<mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint> <mat-hint align="end">{{commentBody.value.length}} / 255</mat-hint>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="accent" <button mat-raised-button color="accent"
(click)="send(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> (click)="pressSend(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button>
</form> </form>
</div> </div>
<div fxLayout="row" fxLayoutAlign="center"> <div fxLayout="row" fxLayoutAlign="center">
<app-comment-list></app-comment-list> <app-comment-list></app-comment-list>
</div> </div>
</div> </div>
...@@ -8,6 +8,8 @@ import { NotificationService } from '../../../services/util/notification.service ...@@ -8,6 +8,8 @@ import { NotificationService } from '../../../services/util/notification.service
import { AuthenticationService } from '../../../services/http/authentication.service'; import { AuthenticationService } from '../../../services/http/authentication.service';
import { User } from '../../../models/user'; import { User } from '../../../models/user';
import { CommentListComponent } from '../../shared/comment-list/comment-list.component'; import { CommentListComponent } from '../../shared/comment-list/comment-list.component';
import { MatDialog } from '@angular/material';
import { SubmitCommentComponent } from '../_diaglogs/submit-comment/submit-comment.component';
@Component({ @Component({
selector: 'app-comment-create-page', selector: 'app-comment-create-page',
...@@ -29,6 +31,7 @@ export class CommentCreatePageComponent implements OnInit { ...@@ -29,6 +31,7 @@ export class CommentCreatePageComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private commentService: CommentService, private commentService: CommentService,
private notification: NotificationService, private notification: NotificationService,
public dialog: MatDialog,
private translationService: TranslateService) { } private translationService: TranslateService) { }
ngOnInit(): void { ngOnInit(): void {
...@@ -37,27 +40,55 @@ export class CommentCreatePageComponent implements OnInit { ...@@ -37,27 +40,55 @@ export class CommentCreatePageComponent implements OnInit {
this.roomId = localStorage.getItem(`roomId`); this.roomId = localStorage.getItem(`roomId`);
} }
send(subject: string, body: string): void { pressSend(subject: string, body: string): void{
if (this.checkInputData(subject, body)) {
this.openSubmitDialog(subject, body);
}
}
openSubmitDialog(subject: string, body: string): void {
const dialogRef = this.dialog.open(SubmitCommentComponent, {
width: '400px'
});
dialogRef.componentInstance.comment = new Comment();
dialogRef.componentInstance.comment.subject = subject;
dialogRef.componentInstance.comment.body = body;
dialogRef.afterClosed()
.subscribe(result => {
if (result === 'send') {
this.send(subject, body);
} else {
return;
}
});
}
checkInputData(subject: string, body: string): boolean {
subject = subject.trim(); subject = subject.trim();
body = body.trim(); body = body.trim();
if (!subject && !body) { if (!subject && !body) {
this.translationService.get('comment-page.error-both-fields').subscribe(message => { this.translationService.get('comment-page.error-both-fields').subscribe(message => {
this.notification.show(message); this.notification.show(message);
}); });
return; return false;
} }
if (!subject) { if (!subject) {
this.translationService.get('comment-page.error-title').subscribe(message => { this.translationService.get('comment-page.error-title').subscribe(message => {
this.notification.show(message); this.notification.show(message);
}); });
return; return false;
} }
if (!body) { if (!body) {
this.translationService.get('comment-page.error-comment').subscribe(message => { this.translationService.get('comment-page.error-comment').subscribe(message => {
this.notification.show(message); this.notification.show(message);
}); });
return; return false;
} }
}
send(subject: string, body: string): void {
this.commentService.addComment({ this.commentService.addComment({
id: '', id: '',
roomId: this.roomId, roomId: this.roomId,
......
...@@ -11,6 +11,7 @@ import { ParticipantContentCarouselPageComponent } from './participant-content-c ...@@ -11,6 +11,7 @@ import { ParticipantContentCarouselPageComponent } from './participant-content-c
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { SubmitCommentComponent } from './_diaglogs/submit-comment/submit-comment.component';
@NgModule({ @NgModule({
imports: [ imports: [
...@@ -32,7 +33,11 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader'; ...@@ -32,7 +33,11 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
ContentTextParticipantComponent, ContentTextParticipantComponent,
HomeParticipantPageComponent, HomeParticipantPageComponent,
RoomParticipantPageComponent, RoomParticipantPageComponent,
ParticipantContentCarouselPageComponent ParticipantContentCarouselPageComponent,
SubmitCommentComponent
],
entryComponents: [
SubmitCommentComponent
] ]
}) })
export class ParticipantModule { export class ParticipantModule {
......
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