allerta-vvf/frontend/src/app/_components/list/list.component.ts

52 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-12-28 00:32:15 +01:00
import { Component, OnInit, ViewChild } from '@angular/core';
2021-12-27 20:50:10 +01:00
import { TableComponent } from '../table/table.component';
2021-12-28 00:32:15 +01:00
import { ModalAvailabilityScheduleComponent } from '../modal-availability-schedule/modal-availability-schedule.component';
2021-12-24 15:21:22 +01:00
import { ApiClientService } from 'src/app/_services/api-client.service';
import { ToastrService } from 'ngx-toastr';
2021-12-27 20:50:10 +01:00
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { AuthService } from 'src/app/_services/auth.service';
2021-12-04 21:36:11 +01:00
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.scss']
})
export class ListComponent implements OnInit {
2021-12-27 20:50:10 +01:00
scheduleModalRef?: BsModalRef;
@ViewChild('table') table!: TableComponent;
2021-12-04 21:36:11 +01:00
constructor(
private api: ApiClientService,
private auth: AuthService,
private toastr: ToastrService,
private modalService: BsModalService
) {}
2021-12-24 15:21:22 +01:00
changeAvailibility(available: 0|1, id?: number|undefined) {
this.api.post("availability", {
id: id,
available: available
2021-12-26 21:32:54 +01:00
}).then((response) => {
let changed_user_msg = parseInt(response.updated_user) === parseInt(this.auth.profile.auth_user_id) ? "La tua disponibilità" : `La disponibilità di ${response.updated_user_name}`;
let msg = available === 1 ? `${changed_user_msg} è stata impostata con successo.` : `${changed_user_msg} è stata rimossa con successo.`;
this.toastr.success(msg);
2021-12-26 21:32:54 +01:00
this.table.loadTableData();
2021-12-24 15:21:22 +01:00
});
}
2021-12-04 21:36:11 +01:00
2021-12-28 00:32:15 +01:00
openScheduleModal() {
this.scheduleModalRef = this.modalService.show(ModalAvailabilityScheduleComponent, Object.assign({}, { class: 'modal-custom' }));
2021-12-27 20:50:10 +01:00
}
2021-12-04 21:36:11 +01:00
ngOnInit(): void {
}
2022-01-05 00:51:59 +01:00
requestTelegramToken() {
this.api.post("telegram_login_token", {}).then((response) => {
console.log(response);
window.open(response.start_link, "_blank");
});
}
2021-12-04 21:36:11 +01:00
}