Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Adicionando pop-up de erro na rota" #25

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/tab1/tab1.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
</ion-button>

<div *ngIf="showSearchForm" class="search-form">
<ion-item>
<ion-item [ngClass]="{'error': hasError}">
<ion-label position="floating">Saída</ion-label>
<ion-input [(ngModel)]="saida"></ion-input>
</ion-item>

<ion-item>
<ion-item [ngClass]="{'error': hasError}">
<ion-label position="floating">Destino</ion-label>
<ion-input [(ngModel)]="destino"></ion-input>
</ion-item>

<div class="form-controls">
<ion-item>
<ion-item [ngClass]="{'error': hasError}">
<ion-label position="floating">Horário</ion-label>
<ion-input [(ngModel)]="horario" type="time"></ion-input>
</ion-item>
Expand Down
4 changes: 4 additions & 0 deletions src/app/tab1/tab1.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@
align-items: center;
justify-content: flex-end;
}

.error {
color: red;
}
18 changes: 17 additions & 1 deletion src/app/tab1/tab1.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Router } from '@angular/router';
import { DataService } from '../services/data.service';
import { AlertController } from '@ionic/angular';

@Component({
selector: 'app-tab1',
Expand All @@ -15,13 +16,15 @@ export class Tab1Page implements OnInit {
horario!: string;
center!: google.maps.LatLngLiteral;
zoom: number = 15;
hasError: boolean = false;

private geocoder = new google.maps.Geocoder();

constructor(
private http: HttpClient,
private router: Router,
private dataService: DataService
private dataService: DataService,
private alertController: AlertController
) {}

ngOnInit() {
Expand Down Expand Up @@ -65,6 +68,17 @@ export class Tab1Page implements OnInit {
this.showSearchForm = !this.showSearchForm;
}

async errorSearching() {
const alert = await this.alertController.create({
header: 'Rota não encontrada',
message: 'A rota especificada não foi encontrada, tente novamente.',
buttons: ['OK']
});

await alert.present();
await alert.onDidDismiss();
this.hasError = false;
}
onSearch() {
const params = new HttpParams()
.set('origin', this.saida)
Expand All @@ -87,6 +101,8 @@ export class Tab1Page implements OnInit {
},
error => {
console.error('Error sending request:', error);
this.hasError = true;
this.errorSearching();
}
);
}
Expand Down