All files / src/app/pages/detail.event.page detail.event.page.ts

100% Statements 19/19
90.9% Branches 10/11
83.33% Functions 5/6
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                        1x   7x     7x 7x 7x 7x     7x       1x     7x   2x 1x   1x     7x   3x 2x   1x   1x               1x 1x          
import { Component, inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonSpinner, IonItem, IonBackButton, IonButtons, IonLabel, IonButton } from '@ionic/angular/standalone';
import EventModel from '@shared/interfaces/event.model';
import pageIdentifier from '@shared/components/tabs/tabs.identifier';
import { NETWORK_REQUEST } from '@shared/interfaces/network.request.interface';
import IResponseDefault from '@shared/interfaces/response.default';
import ApiRequiriments from '@shared/services/network/api.requiriments';
import { Observable } from 'rxjs/internal/Observable';
import { AsyncPipe, DatePipe } from '@angular/common';
import { ToastController } from '@ionic/angular/standalone';
import { NavController } from '@ionic/angular';
 
@Component({
  selector: 'app-detail.event.page',
  templateUrl: 'detail.event.page.html',
  styleUrls: ['detail.event.page.scss'],
    standalone: true,
  imports: [IonSpinner, IonItem, IonList, IonBackButton, IonHeader, IonToolbar, IonTitle, IonContent, IonButtons, AsyncPipe, DatePipe, IonLabel, IonButton],
})
export class DetailEventPage {
 
  title = pageIdentifier["eventDetailPage"].title;
  currentEventId?: string | null;
  obsContent$?: Observable<IResponseDefault<EventModel[] | undefined>>;
  private networkRequest = inject(NETWORK_REQUEST);
  private actRouter = inject(ActivatedRoute);
  private toastController = inject(ToastController);
  private navigation = inject(NavController);
 
  constructor() {
    this.currentEventId = this.actRouter.snapshot.paramMap.get('id');
  }
 
  ionViewDidEnter() {
    this.requestPageContent(this.currentEventId);
  }
 
  requestPageContent = (id: string | undefined | null) => {
 
    if (id == null || id == undefined)
      return;
 
    this.obsContent$ = this.networkRequest.request<IResponseDefault<EventModel[] | undefined>>(ApiRequiriments.detailEvent(id));
  }
 
  deleteEvent = (id: string | undefined | null) => {
 
      if (id == undefined && id == null && (id ?? '') == '')
        return;
 
      this.networkRequest.request<IResponseDefault<undefined>>(ApiRequiriments.deleteEvent(id!)).subscribe(async response => {
 
        const toast = await this.toastController.create({
          message: response.message,
          duration: 5000,
          position: 'bottom',
          color: response.status == 200 ? 'primary': 'warning',
          buttons: [ { text: 'Fechar', role: 'cancel', handler: () => {} } ]
        });
 
        toast.present();
        this.navigation.back();
      });
 
    }
}