[frontend] Implement telegram start, stop
This commit is contained in:
parent
c8d439f019
commit
7df86eee43
|
@ -26,7 +26,10 @@
|
|||
<mat-list-item *ngFor="let telegram of telegrams">
|
||||
<div class="entry">
|
||||
@{{ telegram.username }}
|
||||
<mat-slide-toggle></mat-slide-toggle>
|
||||
<mat-slide-toggle
|
||||
[checked]="telegram.enabled === 1"
|
||||
(change)="onChange(telegram)"
|
||||
></mat-slide-toggle>
|
||||
<button
|
||||
mat-icon-button
|
||||
[matMenuTriggerFor]="menu"
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Component, OnInit, Input } from '@angular/core';
|
||||
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 { MatDialog } from '@angular/material/dialog';
|
||||
import { TelegramDialogComponent } from '../telegram-dialog/telegram-dialog.component';
|
||||
import { YesNoDialogComponent } from 'src/app/shared/yes-no-dialog/yes-no-dialog.component';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
|
||||
@Component({
|
||||
selector: 'app-telegram-settings',
|
||||
|
@ -17,7 +18,8 @@ export class TelegramSettingsComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
private telegramService: TelegramService,
|
||||
public dialog: MatDialog
|
||||
public dialog: MatDialog,
|
||||
private snackBar: MatSnackBar
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
@ -71,4 +73,30 @@ export class TelegramSettingsComponent implements OnInit {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue