File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/pages/polls-list/polls-list.page.ts
import { Component, OnInit } from "@angular/core";
import { CityService } from "../../services/city.service";
import { RequestService } from "../../services/request.service";
import { AlertController } from "@ionic/angular";
import { TranslateService } from "@ngx-translate/core";
import { Router } from "@angular/router";
@Component({
selector: "app-polls-list",
templateUrl: "./polls-list.page.html",
styleUrls: ["./polls-list.page.scss"],
})
export class PollsListPage implements OnInit {
list_polls: any = [];
constructor(
public requestService: RequestService,
public cityProvider: CityService,
public alertController: AlertController,
public translateService: TranslateService,
private router: Router,
) { }
ngOnInit() {
this.getRequests();
}
doRefresh(event: any) {
this.list_polls = [];
this.getRequests(event);
}
getRequests(event?: any) {
this.requestService.getPolls().then((getRequests) => {
if (!getRequests["data"].length) {
this.alertIfTherePolls();
}
this.list_polls = getRequests["data"];
if (event) {
event.target.complete();
}
});
}
async alertIfTherePolls() {
const alert = await this.alertController.create({
header: this.translateService.instant("ALERT_SURVEYS"),
message: this.translateService.instant("ALERT_MESSAGE"),
buttons: [
{
text: "Ok",
role: "cancel",
cssClass: "secondary",
handler: (resp) => {
this.router.navigate(["/app/tabs/settings"]);
},
},
],
});
await alert.present();
}
}