Bug on synch event edit and delete and added offline synch to event to aprove REver

This commit is contained in:
Eudes Inácio
2021-11-16 13:12:25 +01:00
parent 487fe4ae6d
commit e7c3bbf3ae
6 changed files with 103 additions and 7 deletions
+52 -3
View File
@@ -22,7 +22,9 @@ import { BackgroundService } from 'src/app/services/background.service';
import { OfflineManagerService } from 'src/app/services/offline-manager.service'; import { OfflineManagerService } from 'src/app/services/offline-manager.service';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { EventsService } from 'src/app/services/events.service'; import { EventsService } from 'src/app/services/events.service';
import { ProcessesService } from 'src/app/services/processes.service';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx'; import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
import { SqliteService } from 'src/app/services/sqlite.service';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@@ -83,7 +85,9 @@ export class HomePage implements OnInit {
private offlinemanager: OfflineManagerService, private offlinemanager: OfflineManagerService,
private storage: Storage, private storage: Storage,
private eventservice: EventsService, private eventservice: EventsService,
private screenOrientation: ScreenOrientation,) { private processservice: ProcessesService,
private screenOrientation: ScreenOrientation,
private sqliteservice: SqliteService) {
/* this.webNotificationPopupService.askNotificationPermission() */ /* this.webNotificationPopupService.askNotificationPermission() */
@@ -121,8 +125,7 @@ export class HomePage implements OnInit {
this.backgroundservice.online() this.backgroundservice.online()
if (this.platform.is('desktop') || this.platform.is('mobileweb')) { if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else { } else {
/* this.notificationsService.onReceviNotification(); */ this.synchWhenOnline()
this.offlinemanager.synchnize()
} }
}); });
window.addEventListener('offline', () => { window.addEventListener('offline', () => {
@@ -160,4 +163,50 @@ export class HomePage implements OnInit {
} }
async synchWhenOnline() {
try {
await this.storage.get('eventEdit').then((req) => {
JSON.parse(req).forEach(element => {
this.eventservice.editEvent(element, 2, 3).subscribe((res) => {
this.storage.remove('eventEdit')
this.sqliteservice.deleteEventTable();
console.log('eventEdit synchnize', res)
})
});
})
} catch (error) {
console.log('error synch eventedit')
}
try {
await this.storage.get('eventDelete').then((req) => {
JSON.parse(req).forEach(element => {
console.log('DELETE data SYNC', element)
this.eventservice.deleteEvent(element.eventid, element.eventDeleteType, element.calendarName).subscribe((res) => {
this.storage.remove('eventDelete')
this.sqliteservice.deleteEventTable();
console.log('eventDelete synchnize', res)
})
});
})
} catch (error) {
console.log('error delete event synch')
}
try {
await this.storage.get('event-listRever').then((req) => {
JSON.parse(req).forEach(element => {
console.log('REVER data SYNC', element)
this.processservice.PostTaskAction(element).subscribe((res) => {
this.storage.remove('event-listRever')
this.sqliteservice.deleteEventTable();
console.log('event-listRever synchnize', res)
})
});
})
} catch (error) {
console.log('error event-list rever synch')
}
}
} }
@@ -171,9 +171,9 @@ export class ViewEventPage implements OnInit {
loader.remove() loader.remove()
}, (error) => { }, (error) => {
console.log('errorstatus',error.status) console.log('errorstatus ss',error.status)
if (error.status == 0) { if (error.status === 0) {
this.getFromDb(); this.getFromDb();
} else { } else {
this.toastService.badRequest('Este evento já não existe na sua agenda') this.toastService.badRequest('Este evento já não existe na sua agenda')
@@ -205,6 +205,8 @@ export class ViewEventPage implements OnInit {
() => { () => {
loader.remove(); loader.remove();
}); });
loader.remove();
} }
@@ -421,8 +423,9 @@ export class ViewEventPage implements OnInit {
const loader = this.toastService.loading(); const loader = this.toastService.loading();
this.sqliteservice.getEventById(this.eventId).then((event) => { this.sqliteservice.getEventById(this.eventId).then((event) => {
let arrayevent = []; let arrayevent = [];
console.log('EVENT ATTENDEES',event[0].Attendees)
let elemet = { let elemet = {
Attendees: JSON.parse(event[0].Attendees) || "", Attendees: (typeof JSON.parse(event[0].Attendees) === 'undefined') ? "" : JSON.parse(event[0].Attendees),
Body: JSON.parse(event[0].Body) || "", Body: JSON.parse(event[0].Body) || "",
CalendarId: event[0].CalendarId, CalendarId: event[0].CalendarId,
CalendarName: event[0].CalendarName, CalendarName: event[0].CalendarName,
+30
View File
@@ -318,6 +318,36 @@ export class EventsPage implements OnInit {
if (list.length > 0) { if (list.length > 0) {
list.forEach(element => { list.forEach(element => {
this.sqliteservice.addEvent(element) this.sqliteservice.addEvent(element)
this.sqliteservice.getAllEvents().then((event: any[]) => {
let todayEvents = new Array()
event.forEach((element) => {
let eventObject = {
AppointmentState: element.AppointmentState,
Attachments: element.Attachments,
Attendees: element.Attendees,
CalendarId: element.CalendarId,
CalendarName: element.CalendarName,
Category: element.Category,
EndDate: element.EndDate,
EventId: element.EventId,
EventRecurrence: element.EventRecurrence,
EventType: element.EventType,
HasAttachments: element.HasAttachments,
HumanDate: element.HumanDate,
IsAllDayEvent: element.IsAllDayEvent,
IsMeeting: element.IsMeeting,
IsRecurring: element.IsRecurring,
Location: element.Location,
Organizer: element.Organizer,
Profile: element.Profile,
StartDate: element.StartDate,
Subject: element.Subject
}
todayEvents.push(eventObject);
})
console.log('JIFJSOSDJSDONS',todayEvents)
})
}); });
} }
} }
@@ -17,6 +17,7 @@ import { SqliteService } from '../../../../services/sqlite.service';
import { BackgroundService } from '../../../../services/background.service'; import { BackgroundService } from '../../../../services/background.service';
import { Platform } from '@ionic/angular'; import { Platform } from '@ionic/angular';
import { ThemeService } from 'src/app/services/theme.service' import { ThemeService } from 'src/app/services/theme.service'
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
@Component({ @Component({
@@ -62,6 +63,7 @@ export class ApproveEventPage implements OnInit {
private platform: Platform, private platform: Platform,
private backgroundservice: BackgroundService, private backgroundservice: BackgroundService,
public ThemeService: ThemeService, public ThemeService: ThemeService,
private offlineManager: OfflineManagerService
) { ) {
this.activatedRoute.paramMap.subscribe(params => { this.activatedRoute.paramMap.subscribe(params => {
// console.log(params["params"]); // console.log(params["params"]);
@@ -255,7 +257,11 @@ export class ApproveEventPage implements OnInit {
const loader = this.toastService.loading() const loader = this.toastService.loading()
try { try {
await this.processes.PostTaskAction(body).toPromise(); await this.processes.PostTaskAction(body).toPromise()
.catch(() => {
console.log('Send event to approve for revition')
this.offlineManager.storeRequestData('event-listRever', body);
});
this.toastService._successMessage('Pedido enviado'); this.toastService._successMessage('Pedido enviado');
this.goBack(); this.goBack();
} catch (error) { } catch (error) {
+2
View File
@@ -346,6 +346,7 @@ export class EventsService {
return this.http.put<Event>(`${puturl}`, event, options).pipe( return this.http.put<Event>(`${puturl}`, event, options).pipe(
catchError(err => { catchError(err => {
console.log('Event edit saved offline')
this.offlinemanager.storeRequestData('eventEdit', arrayReq); this.offlinemanager.storeRequestData('eventEdit', arrayReq);
throw new Error(err); throw new Error(err);
}) })
@@ -481,6 +482,7 @@ export class EventsService {
return this.http.delete(`${puturl}`, options).pipe( return this.http.delete(`${puturl}`, options).pipe(
catchError(err => { catchError(err => {
console.log('Event edit saved offline')
this.offlinemanager.storeRequestData('eventDelete', arrayReq); this.offlinemanager.storeRequestData('eventDelete', arrayReq);
throw new Error(err); throw new Error(err);
}) })
+6
View File
@@ -512,4 +512,10 @@ export class SqliteService {
console.log(" Get events by id error", JSON.stringify(e)); console.log(" Get events by id error", JSON.stringify(e));
}); });
} }
deleteEventTable() {
this.dbInstance.executeSql("delete from "+ this.events).then((res) => {
console.log('DELETE EVENT TABLE RESULT ', res)
});
}
} }