File

src/app/tab3/tab3.page.ts

Metadata

selector app-tab3
styleUrls tab3.page.scss
templateUrl tab3.page.html

Index

Properties
Methods

Constructor

constructor(lugaresS: LugaresService, loadingController: LoadingController, callNumber: CallNumber, modalController: ModalController, translate: TranslateService)

Llama al método que inicializa todos los elementos de la page

Parameters :
Name Type Optional Description
lugaresS LugaresService No

Servicio Propio encargado de hacer las operaciones relacionadas a lugares

loadingController LoadingController No

Controlador del loading

callNumber CallNumber No

Plugin nativo para hacer llamadas

modalController ModalController No

Controlador de las pages modales

translate TranslateService No

Methods

getFilteredItem
getFilteredItem(ev: any)

Método para filtrar los elementos del listado de lugares

Parameters :
Name Type Optional Description
ev any No

Evento del searchbar (cada vez que escribe)

Returns : void
hacerLlamada
hacerLlamada(numero)

Se encarga de llamar a la aplicación nativa del telefono

Parameters :
Name Optional Description
numero No

Número al que va a llamar

Returns : void
initializeItems
initializeItems()

Asigna al lista del panel lo elementos correctos del listado recuperado

Returns : void
ionViewDidEnter
ionViewDidEnter()

Recupera los lugares guardados llamando al servicio

Returns : void
Async mostrarMapa
mostrarMapa(mapax: any, mapay: any, titulo: any)

Método asíncrono que presenta el modal del mapa

Parameters :
Name Type Optional Description
mapax any No

Coordenada x del lugar

mapay any No

Coordenada y del lugar

titulo any No

Título de la localización

Returns : any
Async presentLoading
presentLoading(msg)

Método asíncrono que muestra el loading

Parameters :
Name Optional Description
msg No

Mensaje del loading

Returns : {}

Properties

Public loadingController
Type : LoadingController
Controlador del loading
lugares
Type : []
Default value : []
lugaresPanel
Type : []
Default value : []
import {Component} from '@angular/core';
import {LoadingController, ModalController} from '@ionic/angular';
import {LugaresService} from '../services/lugares.service';
import {CallNumber} from '@ionic-native/call-number/ngx';
import {ModalMapaPage} from '../modals/modal-mapa/modal-mapa.page';
import {TranslateService} from '@ngx-translate/core';

@Component({
    selector: 'app-tab3',
    templateUrl: 'tab3.page.html',
    styleUrls: ['tab3.page.scss']
})
export class Tab3Page {

    lugaresPanel = [];
    lugares = [];

    /**
     * Llama al método que inicializa todos los elementos de la page
     * @param lugaresS Servicio Propio encargado de hacer las operaciones relacionadas a lugares
     * @param loadingController Controlador del loading
     * @param callNumber Plugin nativo para hacer llamadas
     * @param modalController Controlador de las pages modales
     */
    constructor(private lugaresS: LugaresService,
                public loadingController: LoadingController,
                private callNumber: CallNumber,
                private modalController: ModalController,
                private translate: TranslateService) {

        this.initializeItems();
    }

    /**
     * Asigna al lista del panel lo elementos correctos del listado recuperado
     */
    initializeItems() {
        this.lugaresPanel = this.lugares;
    }

    /**
     * Recupera los lugares guardados llamando al servicio
     */
    ionViewDidEnter() {
        this.presentLoading(this.translate.instant('loading'));
        this.lugaresS.leeLugares().then(
            querySnapshot => {
                this.lugares = [];
                querySnapshot.forEach((doc) => {
                    this.lugares.push({id: doc.id, ...doc.data()});
                });
                this.lugaresPanel = this.lugares;
                this.loadingController.dismiss();
            }
        );
    }


    /**
     * Se encarga de llamar a la aplicación nativa del telefono
     * @param numero Número al que va a llamar
     */
    hacerLlamada(numero) {
        console.log(numero);

        this.callNumber.callNumber(numero, true)
            .then(() => console.log('Launched dialer!'))
            .catch(() => console.log('Error launching dialer'));

    }

    /**
     * Método asíncrono que presenta el modal del mapa
     * @param mapax Coordenada x del lugar
     * @param mapay Coordenada y del lugar
     * @param titulo Título de la localización
     */
    async mostrarMapa(mapax: any, mapay: any, titulo: any) {
        const modal = await this.modalController.create({
            component: ModalMapaPage,
            componentProps: {mapax: mapax, mapay: mapay, titulo: titulo}
        });
        await modal.present();
    }

    /**
     * Método para filtrar los elementos del listado de lugares
     * @param ev Evento del searchbar (cada vez que escribe)
     */
    getFilteredItem(ev: any) {
        // Reset items back to all of the items
        this.initializeItems();

        // set val to the value of the searchbar
        const val = ev.target.value;

        // if the value is an empty string don't filter the items
        if (val && val.trim() != '') {
            this.lugaresPanel = this.lugaresPanel.filter((item) => {
                return (item.localizacion.toLowerCase().indexOf(val.toLowerCase()) > -1);
            });
        }
    }


    /**
     * Método asíncrono que muestra el loading
     * @param msg Mensaje del loading
     */
    async presentLoading(msg) {
        const myloading = await this.loadingController.create({
            message: msg
        });
        return await myloading.present();
    }

}
<ion-header no-border color="primary">
    <ion-toolbar color="primary">
        <ion-buttons slot="start">
            <ion-menu-toggle>
                <ion-button>
                    <ion-icon name="menu" slot="icon-only"></ion-icon>
                </ion-button>
            </ion-menu-toggle>
        </ion-buttons>
        <ion-title>
            ShareAce
        </ion-title>
    </ion-toolbar>
</ion-header>

<ion-content padding="">
    <ion-searchbar #searchBar id="searchBar" showCancelButton
                   cancelButtonText="Cancelar" placeholder="{{'search'|translate}}"
                   (ionInput)="getFilteredItem($event)" (ionClear)="cleared()"
                   (ionCancel)="onCancel()"></ion-searchbar>
    <ion-card padding="" *ngFor="let item of lugaresPanel;let i = index">
        <ion-title>{{item.localizacion}}</ion-title>
        <ion-img  style="margin:auto" [src]="item.imagen"></ion-img>
        <ion-buttons float-right padding-bottom="5px" padding-end="5px">
            <ion-button (click)="mostrarMapa(item.mapax, item.mapay, item.localizacion)">
                <ion-icon name="locate" style="font-size:30px"></ion-icon>
            </ion-button>
            <ion-button (click)="hacerLlamada(item.telefono)">
                <ion-icon name="call" style="font-size:30px"></ion-icon>
            </ion-button>
        </ion-buttons>
    </ion-card>
</ion-content>

tab3.page.scss


Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""