From 88466b08ebe3c5969b598a7fe871792940e646f0 Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Mon, 24 Aug 2020 21:59:18 +0200 Subject: [PATCH] [frontend] Add trigger and badword functionality --- .../src/app/auth/login/login.component.ts | 2 +- .../badwords/badwords.component.html | 16 ++++++- .../badwords/badwords.component.scss | 31 ++++++++---- .../badwords/badwords.component.ts | 45 +++++++++++++++++- .../hoodsettings/hoodsettings.component.scss | 4 +- .../trigger/trigger.component.html | 15 +++++- .../trigger/trigger.component.scss | 31 ++++++++---- .../hoodsettings/trigger/trigger.component.ts | 47 ++++++++++++++++++- .../app/shared/material/material.module.ts | 3 ++ .../src/app/shared/shared.module.ts | 10 +++- 10 files changed, 175 insertions(+), 29 deletions(-) diff --git a/kibicara-frontend/src/app/auth/login/login.component.ts b/kibicara-frontend/src/app/auth/login/login.component.ts index e1b1f4b..82f3072 100644 --- a/kibicara-frontend/src/app/auth/login/login.component.ts +++ b/kibicara-frontend/src/app/auth/login/login.component.ts @@ -37,7 +37,7 @@ export class LoginComponent implements OnInit { this.route.snapshot.queryParams['returnUrl'] || '/dashboard'; if (this.route.snapshot.queryParams['registered'] === true) { - this.info = 'Registration infoful'; + this.info = 'Registration successful'; } } diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.html b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.html index 9055002..6d9d742 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.html +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.html @@ -1,11 +1,23 @@ Badwords Discards an incoming message that matches the pattern (spam-protection, insult-filtering)Discards an incoming message that matches the pattern (spam-protection, + insult-filtering) +
+ + Add badword + + Invalid regex + + +
+
@@ -16,6 +28,7 @@ color="primary" aria-label="Edit" class="button" + (click)="onEdit(badword.id)" > edit @@ -24,6 +37,7 @@ color="warn" aria-label="Delete" class="button" + (click)="onDelete(badword.id)" > delete diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.scss b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.scss index cb2e043..4788fef 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.scss +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.scss @@ -1,20 +1,31 @@ .entry { - display: grid; - grid-template-columns: 4fr 50px 50px; - width: 100%; + display: grid; + grid-template-columns: 4fr 50px 50px; + width: 100%; +} + +.input { + display: grid; + grid-template-columns: 4fr 50px; + width: 100%; + margin: 10px; +} + +.mat-form-field { + width: 100%; } .regex { - margin: 5px; - margin-top: 10px; - font-size: medium; + margin: 5px; + margin-top: 10px; + font-size: medium; } .button { - align-self: stretch; + align-self: stretch; } .error-msg { - display: flex; - font-style: italic; -} \ No newline at end of file + display: flex; + font-style: italic; +} diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.ts b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.ts index 00b5af9..882bd96 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.ts +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/badwords/badwords.component.ts @@ -1,6 +1,8 @@ import { Component, OnInit, Input } from '@angular/core'; import { BadwordsService, BodyBadWord } from 'src/app/core/api'; import { Observable } from 'rxjs'; +import { FormGroup, Validators, FormBuilder } from '@angular/forms'; +import { first } from 'rxjs/operators'; @Component({ selector: 'app-badwords', @@ -10,10 +12,51 @@ import { Observable } from 'rxjs'; export class BadwordsComponent implements OnInit { @Input() hoodId; badwords$: Observable>; + regexForm: FormGroup; - constructor(private badwordService: BadwordsService) {} + constructor( + private badwordService: BadwordsService, + private formBuilder: FormBuilder + ) {} ngOnInit(): void { + this.reload(); + this.regexForm = this.formBuilder.group({ + regex: ['', Validators.required], + }); + } + + private reload() { this.badwords$ = this.badwordService.getBadwords(this.hoodId); } + + onEdit(triggerId) {} + + onDelete(triggerId) { + this.badwordService.deleteBadword(triggerId, this.hoodId).subscribe(() => { + this.reload(); + }); + } + + onSubmit() { + if (this.regexForm.invalid) { + return; + } + + this.badwordService + .createBadword(this.hoodId, { + pattern: this.regexForm.controls.regex.value, + }) + .pipe(first()) + .subscribe( + (data) => { + this.regexForm.reset(); + this.reload(); + }, + (error) => { + console.log(error); + this.regexForm.controls['regex'].setErrors({ incorrect: true }); + } + ); + } } diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss index 8874fba..ee88fd1 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/hoodsettings.component.scss @@ -14,6 +14,6 @@ } .explanation { - margin-top: 10px; - margin-bottom: 10px; + margin-top: 20px; + margin-bottom: 20px; } diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.html b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.html index ccb857a..afcbccf 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.html +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.html @@ -1,12 +1,23 @@ Triggers Only shares an incoming message if it matches a pattern (topic-setting).
+ >Only shares an incoming message if it matches a pattern (topic-setting). Add at least one trigger!
+
+ + Add trigger + + Invalid regex + + +
+
@@ -17,6 +28,7 @@ color="primary" aria-label="Edit" class="button" + (click)="onEdit(trigger.id)" > edit @@ -25,6 +37,7 @@ color="warn" aria-label="Delete" class="button" + (click)="onDelete(trigger.id)" > delete diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.scss b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.scss index cb2e043..4788fef 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.scss +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.scss @@ -1,20 +1,31 @@ .entry { - display: grid; - grid-template-columns: 4fr 50px 50px; - width: 100%; + display: grid; + grid-template-columns: 4fr 50px 50px; + width: 100%; +} + +.input { + display: grid; + grid-template-columns: 4fr 50px; + width: 100%; + margin: 10px; +} + +.mat-form-field { + width: 100%; } .regex { - margin: 5px; - margin-top: 10px; - font-size: medium; + margin: 5px; + margin-top: 10px; + font-size: medium; } .button { - align-self: stretch; + align-self: stretch; } .error-msg { - display: flex; - font-style: italic; -} \ No newline at end of file + display: flex; + font-style: italic; +} diff --git a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.ts b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.ts index 009fb24..1ad2030 100644 --- a/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.ts +++ b/kibicara-frontend/src/app/dashboard/board/hoodsettings/trigger/trigger.component.ts @@ -1,6 +1,10 @@ import { Component, OnInit, Input } from '@angular/core'; import { TriggersService, BodyTrigger } from 'src/app/core/api'; import { Observable } from 'rxjs'; +import { ResourceLoader } from '@angular/compiler'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { first } from 'rxjs/operators'; +import { invalid } from '@angular/compiler/src/render3/view/util'; @Component({ selector: 'app-trigger', @@ -10,10 +14,51 @@ import { Observable } from 'rxjs'; export class TriggerComponent implements OnInit { @Input() hoodId: number; triggers$: Observable>; + regexForm: FormGroup; - constructor(private triggersService: TriggersService) {} + constructor( + private triggersService: TriggersService, + private formBuilder: FormBuilder + ) {} ngOnInit(): void { + this.reload(); + this.regexForm = this.formBuilder.group({ + regex: ['', Validators.required], + }); + } + + private reload() { this.triggers$ = this.triggersService.getTriggers(this.hoodId); } + + onEdit(triggerId) {} + + onDelete(triggerId) { + this.triggersService.deleteTrigger(triggerId, this.hoodId).subscribe(() => { + this.reload(); + }); + } + + onSubmit() { + if (this.regexForm.invalid) { + return; + } + + this.triggersService + .createTrigger(this.hoodId, { + pattern: this.regexForm.controls.regex.value, + }) + .pipe(first()) + .subscribe( + (data) => { + this.regexForm.reset(); + this.reload(); + }, + (error) => { + console.log(error); + this.regexForm.controls['regex'].setErrors({ incorrect: true }); + } + ); + } } diff --git a/kibicara-frontend/src/app/shared/material/material.module.ts b/kibicara-frontend/src/app/shared/material/material.module.ts index 061ca61..ae9bb58 100644 --- a/kibicara-frontend/src/app/shared/material/material.module.ts +++ b/kibicara-frontend/src/app/shared/material/material.module.ts @@ -7,6 +7,7 @@ import { MatTabsModule } from '@angular/material/tabs'; import { MatCardModule } from '@angular/material/card'; import { MatExpansionModule } from '@angular/material/expansion'; import { MatListModule } from '@angular/material/list'; +import { MatInputModule } from '@angular/material/input'; @NgModule({ declarations: [], @@ -19,6 +20,7 @@ import { MatListModule } from '@angular/material/list'; MatCardModule, MatExpansionModule, MatListModule, + MatInputModule, ], exports: [ MatButtonModule, @@ -29,6 +31,7 @@ import { MatListModule } from '@angular/material/list'; MatCardModule, MatExpansionModule, MatListModule, + MatInputModule, ], }) export class MaterialModule {} diff --git a/kibicara-frontend/src/app/shared/shared.module.ts b/kibicara-frontend/src/app/shared/shared.module.ts index 163d34b..8b6b4d6 100644 --- a/kibicara-frontend/src/app/shared/shared.module.ts +++ b/kibicara-frontend/src/app/shared/shared.module.ts @@ -2,10 +2,16 @@ import { NgModule } from '@angular/core'; import { ToolbarComponent } from './toolbar/toolbar.component'; import { MaterialModule } from './material/material.module'; import { NotFoundComponent } from './not-found/not-found.component'; +import { ReactiveFormsModule } from '@angular/forms'; @NgModule({ declarations: [ToolbarComponent, NotFoundComponent], - imports: [MaterialModule], - exports: [ToolbarComponent, NotFoundComponent, MaterialModule], + imports: [MaterialModule, ReactiveFormsModule], + exports: [ + ToolbarComponent, + NotFoundComponent, + MaterialModule, + ReactiveFormsModule, + ], }) export class SharedModule {}