mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
added the edit and delete event offline
This commit is contained in:
@@ -346,7 +346,7 @@ export class EventsService {
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event, options).pipe(
|
||||
catchError(err => {
|
||||
this.offlinemanager.storeRequest(puturl, 'PUT', arrayReq);
|
||||
this.offlinemanager.storeRequestData('eventEdit', arrayReq);
|
||||
throw new Error(err);
|
||||
})
|
||||
)
|
||||
@@ -432,6 +432,13 @@ export class EventsService {
|
||||
}
|
||||
|
||||
deleteEvent(eventid: string, eventDeleteType: number, calendarName: string) {
|
||||
let arrayReq = [];
|
||||
let Object = {
|
||||
eventid: eventid,
|
||||
eventDeleteType: eventDeleteType,
|
||||
calendarName: calendarName
|
||||
}
|
||||
arrayReq.push(Object)
|
||||
const puturl = environment.apiURL + 'calendar/DeleteEvent';
|
||||
let params = new HttpParams();
|
||||
|
||||
@@ -472,7 +479,12 @@ export class EventsService {
|
||||
break;
|
||||
}
|
||||
|
||||
return this.http.delete(`${puturl}`, options)
|
||||
return this.http.delete(`${puturl}`, options).pipe(
|
||||
catchError(err => {
|
||||
this.offlinemanager.storeRequestData('eventDelete', arrayReq);
|
||||
throw new Error(err);
|
||||
})
|
||||
)
|
||||
}
|
||||
postExpedientEvent(docId: any, body: any, sharedagenda: string, serialNumber: any, applicationID: any) {
|
||||
const geturl = environment.apiURL + 'calendar/' + ((sharedagenda != '') ? sharedagenda : 'CreateEventExpediente') + '/event';
|
||||
|
||||
@@ -4,91 +4,40 @@ import { Observable, from, of, forkJoin } from 'rxjs';
|
||||
import { switchMap, finalize } from 'rxjs/operators';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ToastController } from '@ionic/angular';
|
||||
const STORAGE_REQ_KEY = 'storedreq';
|
||||
|
||||
interface StoredRequest {
|
||||
url: string,
|
||||
type: string,
|
||||
data: any,
|
||||
time: number,
|
||||
id: string
|
||||
}
|
||||
|
||||
import { BackgroundService } from 'src/app/services/background.service';
|
||||
import { EventsService } from 'src/app/services/events.service';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class OfflineManagerService {
|
||||
|
||||
/* eventservice: EventsService */
|
||||
|
||||
|
||||
constructor(
|
||||
private storage: Storage,
|
||||
private http: HttpClient,
|
||||
private toastController: ToastController) { }
|
||||
|
||||
checkForEvents(): Observable<any> {
|
||||
return from(this.storage.get(STORAGE_REQ_KEY)).pipe(
|
||||
switchMap(storedOperations => {
|
||||
let storedObj = JSON.parse(storedOperations);
|
||||
if (storedObj && storedObj.length > 0) {
|
||||
return this.sendRequests(storedObj).pipe(
|
||||
finalize(() => {
|
||||
let toast = this.toastController.create({
|
||||
message: `Local data succesfully synced to API!`,
|
||||
duration: 3000,
|
||||
position: 'bottom'
|
||||
});
|
||||
toast.then(toast => toast.present());
|
||||
|
||||
this.storage.remove(STORAGE_REQ_KEY);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
console.log('no local events to sync');
|
||||
return of(false);
|
||||
}
|
||||
private storage: Storage,
|
||||
/* private backgroundservice: BackgroundService */) { }
|
||||
|
||||
synchnize() {
|
||||
/* this.backgroundservice.registerBackService('Online', () => {
|
||||
this.storage.get('eventEdit').then((req) => {
|
||||
JSON.parse(req).forEach(element => {
|
||||
this.eventservice.editEvent(element, 2, 3).subscribe((res) => {
|
||||
this.storage.remove('eventEdit')
|
||||
console.log('eventEdit synchnize', res)
|
||||
})
|
||||
});
|
||||
})
|
||||
)
|
||||
}) */
|
||||
}
|
||||
|
||||
storeRequest(url, type, data) {
|
||||
let toast = this.toastController.create({
|
||||
message: `Your data is stored locally because you seem to be offline.`,
|
||||
duration: 3000,
|
||||
position: 'bottom'
|
||||
});
|
||||
toast.then(toast => toast.present());
|
||||
|
||||
let action: StoredRequest = {
|
||||
url: url,
|
||||
type: type,
|
||||
data: data,
|
||||
time: new Date().getTime(),
|
||||
id: Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5)
|
||||
};
|
||||
|
||||
return this.storage.get(STORAGE_REQ_KEY).then(storedOperations => {
|
||||
let storedObj = JSON.parse(storedOperations);
|
||||
|
||||
if (storedObj) {
|
||||
storedObj.push(action);
|
||||
} else {
|
||||
storedObj = [action];
|
||||
}
|
||||
// Save old & new local transactions back to Storage
|
||||
return this.storage.set(STORAGE_REQ_KEY, JSON.stringify(storedObj));
|
||||
});
|
||||
|
||||
storeRequestData(key, data) {
|
||||
return this.storage.set(key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
sendRequests(operations: StoredRequest[]) {
|
||||
let obs = [];
|
||||
|
||||
for (let op of operations) {
|
||||
console.log('Make one request: ', op);
|
||||
let oneObs = this.http.request(op.type, op.url, op.data);
|
||||
|
||||
obs.push(oneObs);
|
||||
}
|
||||
|
||||
// Send out all local events and return once they are finished
|
||||
return forkJoin(obs);
|
||||
|
||||
sendRequestData(key) {
|
||||
return this.storage.get(key)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,13 +26,15 @@ export class SqliteService {
|
||||
}
|
||||
|
||||
databaseConn() {
|
||||
this.platform.ready().then(async () => {
|
||||
await this.sqlite.create({
|
||||
name: this.db_name,
|
||||
location: 'default'
|
||||
}).then(async (sqLite: SQLiteObject) => {
|
||||
this.dbInstance = sqLite;
|
||||
await sqLite.executeSql(`
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
} else {
|
||||
this.platform.ready().then(async () => {
|
||||
await this.sqlite.create({
|
||||
name: this.db_name,
|
||||
location: 'default'
|
||||
}).then(async (sqLite: SQLiteObject) => {
|
||||
this.dbInstance = sqLite;
|
||||
await sqLite.executeSql(`
|
||||
CREATE TABLE IF NOT EXISTS ${this.events} (
|
||||
EventId varchar(255) PRIMARY KEY,
|
||||
Subject varchar(255),
|
||||
@@ -57,12 +59,12 @@ export class SqliteService {
|
||||
Profile varchar(255),
|
||||
HumanDate varchar(255)
|
||||
)`, [])
|
||||
.then((res) => {
|
||||
console.log("Sucess Events Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
.then((res) => {
|
||||
console.log("Sucess Events Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
|
||||
await sqLite.executeSql(`
|
||||
await sqLite.executeSql(`
|
||||
CREATE TABLE IF NOT EXISTS ${this.expedientes} (
|
||||
serialNumber varchar(255) PRIMARY KEY,
|
||||
workflowInstanceFolio varchar(255),
|
||||
@@ -79,12 +81,12 @@ export class SqliteService {
|
||||
workflowInstanceID INTERGER,
|
||||
workflowName varchar(255)
|
||||
)`, [])
|
||||
.then((res) => {
|
||||
console.log("Sucess Espedientes Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
.then((res) => {
|
||||
console.log("Sucess Espedientes Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
|
||||
await sqLite.executeSql(`
|
||||
await sqLite.executeSql(`
|
||||
CREATE TABLE IF NOT EXISTS ${this.allprocess} (
|
||||
serialNumber varchar(255) PRIMARY KEY,
|
||||
workflowInstanceFolio varchar(255),
|
||||
@@ -102,12 +104,12 @@ export class SqliteService {
|
||||
workflowName varchar(255),
|
||||
interveners Text
|
||||
)`, [])
|
||||
.then((res) => {
|
||||
console.log("Sucess AllProcess Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
.then((res) => {
|
||||
console.log("Sucess AllProcess Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
|
||||
await sqLite.executeSql(`
|
||||
await sqLite.executeSql(`
|
||||
CREATE TABLE IF NOT EXISTS ${this.actions} (
|
||||
ProcessId INTERGER PRIMARY KEY,
|
||||
ActionType varchar(255),
|
||||
@@ -117,13 +119,14 @@ export class SqliteService {
|
||||
Description varchar(255),
|
||||
publications Text
|
||||
)`, [])
|
||||
.then((res) => {
|
||||
console.log("Sucess action Table created: ", res)
|
||||
})
|
||||
.then((res) => {
|
||||
console.log("Sucess action Table created: ", res)
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
})
|
||||
.catch((error) => console.log(JSON.stringify(error)));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//addactions
|
||||
@@ -182,8 +185,8 @@ export class SqliteService {
|
||||
});
|
||||
}
|
||||
|
||||
//updateevent
|
||||
public updateEvent(data) {
|
||||
//updateevent
|
||||
public updateEvent(data) {
|
||||
this.dbInstance.executeSql(`
|
||||
INSERT OR REPLACE INTO ${this.events} (EventId,Subject,HasAttachments,Location,CalendarId,CalendarName,StartDate,EndDate,EventType,Attendees,IsMeeting,IsRecurring,IsAllDayEvent,AppointmentState,TimeZone,Organizer,Category,EventRecurrence,Attachments,Body,Profile,HumanDate )
|
||||
VALUES ('${data.EventId}','${data.Subject}','${data.HasAttachments}','${data.Location}','${data.CalendarId}','${data.CalendarName}','${data.StartDate}','${data.EndDate}','${data.EventType}','${data.Attendees}','${data.IsMeeting}','${data.IsRecurring}',
|
||||
@@ -197,10 +200,10 @@ export class SqliteService {
|
||||
}
|
||||
|
||||
//updateActions
|
||||
public updateactions(id,data) {
|
||||
console.log("update action data", data )
|
||||
public updateactions(id, data) {
|
||||
console.log("update action data", data)
|
||||
this.dbInstance.executeSql(`
|
||||
UPDATE ${this.actions} SET publications = ? WHERE ProcessId = ${id}`,[data])
|
||||
UPDATE ${this.actions} SET publications = ? WHERE ProcessId = ${id}`, [data])
|
||||
.then(() => {
|
||||
console.log("action update with Success");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user