From 3cd71311916f9677931d5e9085f4f9630712e1cb Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Mon, 31 Aug 2020 19:13:40 +0200 Subject: [PATCH] [frontend] Add telegram wiring (add, delete) --- .../src/app/platforms/platforms.module.ts | 8 +++ .../telegram-dialog.component.html | 28 ++++++++++ .../telegram-dialog.component.scss | 5 ++ .../telegram-dialog.component.spec.ts | 24 ++++++++ .../telegram-dialog.component.ts | 56 +++++++++++++++++++ .../telegram-info-dialog.component.html | 42 ++++++++++++++ .../telegram-info-dialog.component.scss | 0 .../telegram-info-dialog.component.spec.ts | 24 ++++++++ .../telegram-info-dialog.component.ts | 12 ++++ .../telegram-settings.component.html | 39 +++++++------ .../telegram-settings.component.ts | 44 ++++++++++++++- 11 files changed, 264 insertions(+), 18 deletions(-) create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.html create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.scss create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.spec.ts create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.ts create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.html create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.scss create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.spec.ts create mode 100644 kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.ts diff --git a/kibicara-frontend/src/app/platforms/platforms.module.ts b/kibicara-frontend/src/app/platforms/platforms.module.ts index 91786c2..d32b882 100644 --- a/kibicara-frontend/src/app/platforms/platforms.module.ts +++ b/kibicara-frontend/src/app/platforms/platforms.module.ts @@ -6,6 +6,10 @@ import { TwitterSettingsComponent } from './twitter/twitter-settings/twitter-set import { EmailSettingsComponent } from './email/email-settings/email-settings.component'; import { EmailDialogComponent } from './email/email-dialog/email-dialog.component'; import { EmailInfoDialogComponent } from './email/email-info-dialog/email-info-dialog.component'; +import { TelegramInfoDialogComponent } from './telegram/telegram-info-dialog/telegram-info-dialog.component'; +import { TelegramDialogComponent } from './telegram/telegram-dialog/telegram-dialog.component'; +import { TwitterDialogComponent } from './twitter/twitter-dialog/twitter-dialog.component'; +import { TwitterInfoDialogComponent } from './twitter/twitter-info-dialog/twitter-info-dialog.component'; @NgModule({ declarations: [ @@ -14,6 +18,10 @@ import { EmailInfoDialogComponent } from './email/email-info-dialog/email-info-d EmailSettingsComponent, EmailDialogComponent, EmailInfoDialogComponent, + TelegramInfoDialogComponent, + TelegramDialogComponent, + TwitterDialogComponent, + TwitterInfoDialogComponent, ], imports: [CommonModule, SharedModule], exports: [ diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.html b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.html new file mode 100644 index 0000000..23b2ecc --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.html @@ -0,0 +1,28 @@ +

Create new inbox

+ + +
+ + Telegram API Token + + API Token is required + + + Welcome message + + +
+
+ + + + + diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.scss b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.scss new file mode 100644 index 0000000..a865ed1 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.scss @@ -0,0 +1,5 @@ +.input { + display: grid; + grid-template-rows: 1fr 3fr; + width: 100%; +} diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.spec.ts b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.spec.ts new file mode 100644 index 0000000..38c61b4 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TelegramDialogComponent } from './telegram-dialog.component'; + +describe('TelegramDialogComponent', () => { + let component: TelegramDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [TelegramDialogComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TelegramDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.ts b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.ts new file mode 100644 index 0000000..6bb10e4 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-dialog/telegram-dialog.component.ts @@ -0,0 +1,56 @@ +import { Component, OnInit, Inject } from '@angular/core'; +import { Validators, FormBuilder, FormGroup } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { TelegramService } from 'src/app/core/api'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { first } from 'rxjs/operators'; + +@Component({ + selector: 'app-telegram-dialog', + templateUrl: './telegram-dialog.component.html', + styleUrls: ['./telegram-dialog.component.scss'], +}) +export class TelegramDialogComponent implements OnInit { + form: FormGroup; + + constructor( + public dialogRef: MatDialogRef, + private formBuilder: FormBuilder, + private telegramService: TelegramService, + private snackBar: MatSnackBar, + @Inject(MAT_DIALOG_DATA) public data + ) {} + + ngOnInit(): void { + this.form = this.formBuilder.group({ + api_token: ['', Validators.required], + welcome_message: '', + }); + } + + onCancel() { + this.dialogRef.close(); + } + + onSubmit() { + if (this.form.invalid) { + return; + } + this.telegramService + .createTelegram(this.data.hoodId, { + api_token: this.form.controls.api_token.value, + welcome_message: this.form.controls.welcome_message.value, + }) + .pipe(first()) + .subscribe( + (data) => { + this.dialogRef.close(); + }, + (error) => { + this.snackBar.open('Invalid API Key. Try again!', 'Close', { + duration: 2000, + }); + } + ); + } +} diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.html b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.html new file mode 100644 index 0000000..b6557e7 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.html @@ -0,0 +1,42 @@ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras maximus arcu at + magna euismod sollicitudin. Vestibulum ut auctor libero. Etiam volutpat, nisl + sed efficitur hendrerit, nunc risus hendrerit nulla, sollicitudin malesuada + neque sem sed tortor. Vestibulum laoreet elementum nibh ultrices ullamcorper. + Sed porta gravida lectus, suscipit dictum ligula pharetra posuere. Vivamus + pellentesque ex eget lacus consectetur, at pulvinar est pellentesque. + Phasellus a elit tempor, tristique tortor auctor, maximus eros. Duis magna + sapien, accumsan nec massa nec, porta auctor leo. Nam nibh nisl, hendrerit nec + convallis in, porttitor nec sapien. Morbi in lacus convallis, elementum turpis + in, venenatis mi. Vestibulum bibendum rhoncus pulvinar. Sed hendrerit ipsum + eget varius venenatis. Maecenas consectetur felis libero, fringilla fringilla + justo pellentesque non. Quisque congue dictum arcu ut fermentum. Aliquam + egestas, lectus at mollis pulvinar, diam libero sagittis eros, a lobortis + neque ligula eget odio. Praesent a tortor consequat, viverra odio id, feugiat + sem. Mauris orci velit, molestie sit amet urna laoreet, aliquet consectetur + risus. Cras tristique odio nec placerat viverra. Suspendisse id pretium risus, + sit amet consectetur turpis. Nunc mattis, felis a iaculis varius, est nulla + aliquam massa, aliquet dictum ipsum est nec erat. Integer tristique tellus + felis, ut porttitor nisi blandit nec. Pellentesque habitant morbi tristique + senectus et netus et malesuada fames ac turpis egestas. Integer sagittis justo + ut elit gravida, vitae dignissim urna vehicula. Ut in ante non neque dignissim + scelerisque non id nisi. Sed sit amet posuere felis. Integer eget eros auctor, + ultrices arcu vel, feugiat erat. Curabitur rhoncus porta erat ut ullamcorper. + Duis in dictum tortor. Nam rutrum volutpat libero id interdum. Vestibulum vel + ante eget risus elementum iaculis eget ut mauris. Vestibulum ultrices nunc + quis leo venenatis, id tristique purus tempus. Fusce nec tellus dui. Nulla + bibendum nisi ut posuere pellentesque. Vivamus malesuada mollis dui a posuere. + Curabitur et lacus at augue posuere facilisis. Ut posuere orci mauris, at + hendrerit elit dignissim vel. Quisque vitae ipsum sed sem mattis hendrerit. + Pellentesque consectetur convallis consectetur. Praesent sit amet augue in dui + congue efficitur ac gravida metus. Sed nibh urna, facilisis at urna vitae, + tristique vestibulum velit. Maecenas et aliquet purus, non rutrum eros. Donec + maximus orci vel tortor maximus, finibus porttitor mauris convallis. Maecenas + eget quam vel nulla dapibus hendrerit. Vivamus malesuada neque ut elit + commodo, non viverra magna facilisis. Maecenas finibus ante non dui posuere, + sed varius leo elementum. Nullam eget vestibulum mauris. Maecenas in ipsum + lectus. Sed tempus at dolor sed posuere. Proin eget nulla dignissim, finibus + arcu eu, fringilla tellus. Nullam bibendum felis sed nulla lobortis sodales. + Nunc in elementum felis, quis aliquam velit. Morbi sodales sollicitudin + mollis. +

diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.scss b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.spec.ts b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.spec.ts new file mode 100644 index 0000000..ec938f2 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.spec.ts @@ -0,0 +1,24 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TelegramInfoDialogComponent } from './telegram-info-dialog.component'; + +describe('TelegramInfoDialogComponent', () => { + let component: TelegramInfoDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [TelegramInfoDialogComponent], + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(TelegramInfoDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.ts b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.ts new file mode 100644 index 0000000..bf522f0 --- /dev/null +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-info-dialog/telegram-info-dialog.component.ts @@ -0,0 +1,12 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-telegram-info-dialog', + templateUrl: './telegram-info-dialog.component.html', + styleUrls: ['./telegram-info-dialog.component.scss'], +}) +export class TelegramInfoDialogComponent implements OnInit { + constructor() {} + + ngOnInit(): void {} +} diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.html b/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.html index 987b3be..cf7ef94 100644 --- a/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.html +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.html @@ -5,14 +5,19 @@ Telegram - @@ -20,7 +25,7 @@
- Telegramdummy + @{{ telegram.username }}
+ + + + +
- - - - -
diff --git a/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.ts b/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.ts index 96b9dc6..2b8ba1b 100644 --- a/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.ts +++ b/kibicara-frontend/src/app/platforms/telegram/telegram-settings/telegram-settings.component.ts @@ -1,6 +1,9 @@ import { Component, OnInit, Input } from '@angular/core'; import { TelegramService } from 'src/app/core/api'; import { Observer, Observable } from 'rxjs'; +import { TelegramInfoDialogComponent } from '../telegram-info-dialog/telegram-info-dialog.component'; +import { MatDialog } from '@angular/material/dialog'; +import { TelegramDialogComponent } from '../telegram-dialog/telegram-dialog.component'; @Component({ selector: 'app-telegram-settings', @@ -11,9 +14,48 @@ export class TelegramSettingsComponent implements OnInit { @Input() hoodId; telegrams$: Observable>; - constructor(private telegramService: TelegramService) {} + constructor( + private telegramService: TelegramService, + public dialog: MatDialog + ) {} ngOnInit(): void { + this.reload(); + } + + private reload() { this.telegrams$ = this.telegramService.getTelegrams(this.hoodId); } + + onInfoClick() { + this.dialog.open(TelegramInfoDialogComponent); + } + + onDelete(telegramId) { + this.telegramService + .deleteTelegram(telegramId, this.hoodId) + .subscribe(() => { + this.reload(); + }); + } + + onCreate() { + const dialogRef = this.dialog.open(TelegramDialogComponent, { + data: { hoodId: this.hoodId }, + }); + + dialogRef.afterClosed().subscribe(() => { + this.reload(); + }); + } + + onEdit(telegramId) { + const dialogRef = this.dialog.open(TelegramDialogComponent, { + data: { hoodId: this.hoodId, telegramId: telegramId }, + }); + + dialogRef.afterClosed().subscribe(() => { + this.reload(); + }); + } }