Inicio page is offline

This commit is contained in:
Eudes Inácio
2021-09-21 06:09:41 +01:00
parent 7fdb16c272
commit 42ae5de817
15 changed files with 702 additions and 437 deletions
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { AlertController, ModalController, PopoverController } from '@ionic/angular';
import { AlertController, ModalController, PopoverController, Platform } from '@ionic/angular';
import { EventBody } from 'src/app/models/eventbody.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { EventsService } from 'src/app/services/events.service';
@@ -12,6 +12,8 @@ import { ActivatedRoute, Router } from '@angular/router';
import { ToastService } from 'src/app/services/toast.service';
import { EliminateEventPage } from 'src/app/modals/eliminate-event/eliminate-event.page';
import { Location } from '@angular/common'
import { SqliteService } from 'src/app/services/sqlite.service';
import { synchro } from '../../../services/socket/synchro.service';
@Component({
selector: 'app-view-event',
@@ -42,6 +44,7 @@ export class ViewEventPage implements OnInit {
dicIndex = 0;
isModal = false
header = true
synch = synchro;
constructor(
private modalController: ModalController,
@@ -55,7 +58,11 @@ export class ViewEventPage implements OnInit {
private activatedRoute: ActivatedRoute,
private router: Router,
private toastService: ToastService,
private location: Location
private location: Location,
public platform: Platform,
private sqliteservice: SqliteService
)
{
this.isEventEdited = false;
@@ -88,8 +95,29 @@ export class ViewEventPage implements OnInit {
ngOnInit() {
this.loadEvent();
synchro.registerCallback('Online', () => {
this.loadEvent();
console.log('Onlineee view-event')
})
synchro.registerCallback('Offline', () => {
this.platform.ready().then(() => {
this.sqliteservice.getEventById(this.eventId).then((event) => {
this.loadedEvent = event[0];
console.log("Event ditails local,", event[0])
})
console.log('Offlineee')
})
})
/* this.sqliteservice.getEventById(this.eventId).then((event) => {
this.loadedEvent = event[0];
console.log("Event ditails local,", event[0])
})
this.loadEvent(); */
window.onresize = (event) => {
// if not mobile remove all component
@@ -126,6 +154,7 @@ export class ViewEventPage implements OnInit {
const loader = this.toastService.loading();
this.eventsService.getEvent(this.eventId).subscribe(res => {
this.loadedEvent = res;
this.sqliteservice.addEvent(res);
/* this.today = new Date(res.StartDate);
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]); */
loader.remove()
@@ -289,4 +318,25 @@ export class ViewEventPage implements OnInit {
this.dicIndex = index
}
getEventsFromLocalDb() {
console.log("event id details ", this.eventId)
synchro.registerCallback('Online', () => {
this.loadEvent();
console.log('Onlineee view-event')
})
synchro.registerCallback('Offline', () => {
this.platform.ready().then(() => {
this.sqliteservice.getEventById(this.eventId).then((event) => {
this.loadedEvent = event[0];
console.log("Event ditails local,", event[0])
})
console.log('Offlineee')
})
})
}
}