Skip to content
Snippets Groups Projects
Commit 2811dbc8 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Merge branch 'comment-dialog' into 'master'

Improve comment creation

See merge request swtp-2019/arsnova-lite!10
parents 0a554de4 18780c3c
Branches
Tags
No related merge requests found
...@@ -2,18 +2,20 @@ ...@@ -2,18 +2,20 @@
<div fxLayout="row" fxLayoutAlign="center"> <div fxLayout="row" fxLayoutAlign="center">
<form> <form>
<mat-form-field class="input-block"> <mat-form-field class="input-block">
<input matInput #commentSubject type="text" maxlength="24" placeholder="{{ 'comment-page.enter-title' | translate}}"> <input matInput #commentSubject type="text" maxlength="25"
placeholder="{{ 'comment-page.enter-title' | translate}}" onkeypress="return event.keyCode !=13;"
[formControl]="emptySubject">
<mat-hint align="end" *ngIf="!emptyInputs">{{commentSubject.value.length}} / 25</mat-hint>
</mat-form-field> </mat-form-field>
<mat-form-field class="input-block"> <mat-form-field class="input-block">
<input matInput #commentBody> <textarea matInput #commentBody placeholder="{{ 'comment-page.enter-comment' | translate}}" matTextareaAutosize
<textarea matInput></textarea> matAutosizeMinRows=1 matAutosizeMaxRows=5 [formControl]="emptyBody"></textarea>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" (click)="goBack()">{{ 'comment-page.back' | translate}}</button> <button mat-raised-button color="accent"
<button mat-raised-button color="accent" (click)="send(commentSubject.value, commentBody.value)">{{ 'comment-page.send' | translate}}</button> (click)="send(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>
\ No newline at end of file
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 { Location } from '@angular/common'; import { Location } from '@angular/common';
import { FormControl, Validators } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';
import { Comment } from '../../../models/comment'; import { Comment } from '../../../models/comment';
import { RoomService } from '../../../services/http/room.service'; import { RoomService } from '../../../services/http/room.service';
import { CommentService } from '../../../services/http/comment.service'; import { CommentService } from '../../../services/http/comment.service';
...@@ -20,6 +22,8 @@ export class CommentCreatePageComponent implements OnInit { ...@@ -20,6 +22,8 @@ export class CommentCreatePageComponent implements OnInit {
roomShortId: string; roomShortId: string;
user: User; user: User;
private date = new Date(Date.now()); private date = new Date(Date.now());
private emptySubject = new FormControl('', [Validators.required]);
private emptyBody = new FormControl('', [Validators.required]);
constructor( constructor(
protected authenticationService: AuthenticationService, protected authenticationService: AuthenticationService,
...@@ -27,7 +31,8 @@ export class CommentCreatePageComponent implements OnInit { ...@@ -27,7 +31,8 @@ export class CommentCreatePageComponent implements OnInit {
private roomService: RoomService, private roomService: RoomService,
private commentService: CommentService, private commentService: CommentService,
private location: Location, private location: Location,
private notification: NotificationService) { } private notification: NotificationService,
private translationService: TranslateService) { }
ngOnInit(): void { ngOnInit(): void {
this.user = this.authenticationService.getUser(); this.user = this.authenticationService.getUser();
...@@ -40,7 +45,22 @@ export class CommentCreatePageComponent implements OnInit { ...@@ -40,7 +45,22 @@ export class CommentCreatePageComponent implements OnInit {
send(subject: string, body: string): void { send(subject: string, body: string): void {
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.notification.show(message);
});
return;
}
if (!subject) {
this.translationService.get('comment-page.error-title').subscribe(message => {
this.notification.show(message);
});
return;
}
if (!body) {
this.translationService.get('comment-page.error-comment').subscribe(message => {
this.notification.show(message);
});
return; return;
} }
this.commentService.addComment({ this.commentService.addComment({
......
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
"description": "Beschreibung" "description": "Beschreibung"
}, },
"comment-page": { "comment-page": {
"enter-title": "Geben Sie einen Titel ein", "enter-title": "Titel",
"back": "Zurück", "enter-comment": "Kommentar",
"send": "Senden" "send": "Senden",
"error-comment": "Bitte geben Sie ein Kommentar ein!",
"error-title": "Bitte geben Sie einen Titel ein!",
"error-both-fields": "Bitte füllen Sie alle Felder aus!"
}, },
"answer": { "answer": {
"submit": "Absenden", "submit": "Absenden",
...@@ -40,4 +43,4 @@ ...@@ -40,4 +43,4 @@
"improvable": "Luft nach oben", "improvable": "Luft nach oben",
"no-answers": "Keine Antworten" "no-answers": "Keine Antworten"
} }
} }
\ No newline at end of file
...@@ -15,9 +15,12 @@ ...@@ -15,9 +15,12 @@
"description": "Description" "description": "Description"
}, },
"comment-page": { "comment-page": {
"enter-title": "Enter a title", "enter-title": "Title",
"back": "Back", "enter-comment": "Comment",
"send": "Send" "send": "Send",
"error-title": "Please enter a title!",
"error-comment": "Please enter a comment!",
"error-both-fields": "Please fill in all fields!"
}, },
"answer": { "answer": {
"submit": "Submit", "submit": "Submit",
......
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