Offline web almost done

This commit is contained in:
Eudes Inácio
2022-01-31 15:02:26 +01:00
parent e4f335b805
commit 629b8a71c7
4 changed files with 192 additions and 75 deletions
+53 -16
View File
@@ -9,6 +9,7 @@ import { momentG } from 'src/plugin/momentG';
import { DomSanitizer } from "@angular/platform-browser";
import { EventPerson } from 'src/app/models/eventperson.model';
import { removeDuplicate } from 'src/plugin/removeDuplicate.js';
import { Storage } from '@ionic/storage';
// showTimeline
import { setHours, setMinutes } from 'date-fns';
@@ -179,7 +180,8 @@ export class AgendaPage implements OnInit {
private sqliteservice: SqliteService,
private platform: Platform,
private backgroundservice: BackgroundService,
public ThemeService: ThemeService
public ThemeService: ThemeService,
private storage:Storage
) {
this.dateAdapter.setLocale('es');
@@ -770,6 +772,27 @@ export class AgendaPage implements OnInit {
addEventToDB(response, profile) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
let responseArray = [];
response.forEach(element => {
let event = {
CalendarId: element.CalendarId,
CalendarName: element.CalendarName,
EndDate: element.EndDate,
EventId: element.EventId,
HasAttachments: element.HasAttachments,
HumanDate: element.HumanDate,
IsAllDayEvent: element.IsAllDayEvent,
Location: element.Location,
StartDate: element.StartDate,
Subject: element.Subject,
Profile: profile
}
responseArray.push(event)
});
this.storage.set('agendaResponse',responseArray).then(() => {
console.log('Agenda data saved')
})
} else {
if (response.length > 0) {
@@ -796,21 +819,35 @@ export class AgendaPage implements OnInit {
getFromDB() {
console.log('ALL EVENTS FROM DB AGENDA OFFLINE')
this.sqliteservice.getAllEvents().then((events: any[]) => {
console.log('ALL EVENTS FROM DB', events)
let eventArray = [];
this.trasnformDataDB(events)
this.updateEventListBox()
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
})
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('agendaResponse').then((events) => {
this.trasnformDataDB(events)
this.updateEventListBox()
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
})
} else {
this.sqliteservice.getAllEvents().then((events: any[]) => {
console.log('ALL EVENTS FROM DB', events)
let eventArray = [];
this.trasnformDataDB(events)
this.updateEventListBox()
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
})
}
}
updateEventListBox() {