[frontend] Implement telegram start, stop

This commit is contained in:
Cathy Hu 2020-09-01 19:52:28 +02:00
parent c8d439f019
commit 7df86eee43
2 changed files with 34 additions and 3 deletions

View file

@ -26,7 +26,10 @@
<mat-list-item *ngFor="let telegram of telegrams"> <mat-list-item *ngFor="let telegram of telegrams">
<div class="entry"> <div class="entry">
@{{ telegram.username }} @{{ telegram.username }}
<mat-slide-toggle></mat-slide-toggle> <mat-slide-toggle
[checked]="telegram.enabled === 1"
(change)="onChange(telegram)"
></mat-slide-toggle>
<button <button
mat-icon-button mat-icon-button
[matMenuTriggerFor]="menu" [matMenuTriggerFor]="menu"

View file

@ -1,10 +1,11 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { TelegramService } from 'src/app/core/api'; import { TelegramService } from 'src/app/core/api';
import { Observer, Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { TelegramInfoDialogComponent } from '../telegram-info-dialog/telegram-info-dialog.component'; import { TelegramInfoDialogComponent } from '../telegram-info-dialog/telegram-info-dialog.component';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { TelegramDialogComponent } from '../telegram-dialog/telegram-dialog.component'; import { TelegramDialogComponent } from '../telegram-dialog/telegram-dialog.component';
import { YesNoDialogComponent } from 'src/app/shared/yes-no-dialog/yes-no-dialog.component'; import { YesNoDialogComponent } from 'src/app/shared/yes-no-dialog/yes-no-dialog.component';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({ @Component({
selector: 'app-telegram-settings', selector: 'app-telegram-settings',
@ -17,7 +18,8 @@ export class TelegramSettingsComponent implements OnInit {
constructor( constructor(
private telegramService: TelegramService, private telegramService: TelegramService,
public dialog: MatDialog public dialog: MatDialog,
private snackBar: MatSnackBar
) {} ) {}
ngOnInit(): void { ngOnInit(): void {
@ -71,4 +73,30 @@ export class TelegramSettingsComponent implements OnInit {
this.reload(); this.reload();
}); });
} }
onChange(telegram) {
if (telegram.enabled === 0) {
this.telegramService.startTelegram(telegram.id, this.hoodId).subscribe(
() => {},
(error) => {
this.snackBar.open('Could not start. Check your settings.', 'Close', {
duration: 2000,
});
}
);
} else if (telegram.enabled === 1) {
this.telegramService.stopTelegram(telegram.id, this.hoodId).subscribe(
() => {},
(error) => {
this.snackBar.open('Could not stop. Check your settings.', 'Close', {
duration: 2000,
});
}
);
}
// TODO yeah i know this is bad, implement disabling/enabling
setTimeout(() => {
this.reload();
}, 100);
}
} }