import { Component, OnInit } from '@angular/core'; import { NbDialogRef, NbToastrService } from '@nebular/theme'; import { first } from 'rxjs/operators'; import { environment } from '../../../../environments/environment'; import { HappinessBEST } from '../../../entity/HappinessGroup'; import { PastoralDomain } from '../../../entity/PastoralDomain'; import { BestService } from '../../../services/crudServices/best.service'; import { HappinessGroupService } from '../../../services/crudServices/happiness-group.service'; import { LineGroup, LineService } from '../../../services/line.service'; import { MsgBoxService } from '../../../services/msg-box.service'; import { ADButtons, AlertDlgComponent } from '../../../ui/alert-dlg/alert-dlg.component'; @Component({ selector: 'ngx-best-list-dlg', templateUrl: './best-list-dlg.component.html', styleUrls: ['./best-list-dlg.component.scss'] }) export class BestListDlgComponent implements OnInit { processing: boolean = false; isAdding: boolean = false; group: PastoralDomain; datum: HappinessBEST; constructor( private dlgRef: NbDialogRef, private msgBpxService: MsgBoxService, private happinessGroupService: HappinessGroupService, private toastrService: NbToastrService, private bestService: BestService, private lineService: LineService ) { } ngOnInit(): void { this.group.bests = this.group.bests.sort((a, b) => 0 - (a.name < b.name ? 1 : -1)); } close() { this.dlgRef.close(); } update() { this.dlgRef.close(this.datum); } addBest() { this.msgBpxService.showInputbox('Add Best', 'Please input Best\'s Name').pipe(first()).subscribe(result => { if (result) { let obj = { groupId: this.group.id, id: '', name: result } as HappinessBEST; this.bestService.createOrUpdate(obj).pipe(first()).subscribe(result => { this.dlgRef.close(); }); } }); } copyBestUrl(best: HappinessBEST) { var dummy = document.createElement("textarea"); document.body.appendChild(dummy); dummy.value = `${environment.invitationUrl}${best.id}`; dummy.select(); document.execCommand("copy"); document.body.removeChild(dummy); this.toastrService.success(dummy.value, "複製地址至剪貼簿!"); } copyBestList() { let list = "".concat(...this.group.bests.map(b => `${b.name}\t\t: ${environment.invitationUrl}${b.id}\r\n`)); var dummy = document.createElement("textarea"); document.body.appendChild(dummy); dummy.value = list; dummy.select(); document.execCommand("copy"); document.body.removeChild(dummy); this.toastrService.success(dummy.value, "複製地址至剪貼簿!"); this.lineService.pushLineMessage(LineGroup.Chris, list); } downloadBestQRCode(best: HappinessBEST) { this.happinessGroupService.getBestQrCode(best.name + ".png", best.id); } }