mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 13:26:08 +00:00
Sql bug fixed
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Event, EventToApproveEdit } from '../models/event.model';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Observable, from} from 'rxjs';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
import { UserSession } from '../models/user.model';
|
||||
import { EventList } from '../models/agenda/AgendaEventList';
|
||||
import { ChangeProfileService } from './change-profile.service';
|
||||
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
|
||||
import { synchro } from 'src/app/services/socket/synchro.service';
|
||||
import { catchError } from "rxjs/operators";
|
||||
import { Storage } from '@ionic/storage';
|
||||
|
||||
|
||||
@Injectable({
|
||||
@@ -30,7 +34,9 @@ export class EventsService {
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
public user: AuthService,
|
||||
private changeProfileService: ChangeProfileService)
|
||||
private changeProfileService: ChangeProfileService,
|
||||
private offlinemanager: OfflineManagerService,
|
||||
private storage: Storage)
|
||||
{
|
||||
|
||||
this.loggeduser = this.user.ValidatedUser;
|
||||
@@ -306,40 +312,50 @@ export class EventsService {
|
||||
|
||||
editEvent(event: Event, conflictResolutionMode:number, sendInvitationsOrCancellationsMode:number): Observable<Event>
|
||||
{
|
||||
let arrayReq = [];
|
||||
const puturl = environment.apiURL + 'calendar/PutEvent';
|
||||
if(synchro.connected === false) {
|
||||
arrayReq.push(event)
|
||||
return from(this.storage.set('storedreq', arrayReq))
|
||||
} else {
|
||||
let params = new HttpParams();
|
||||
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("conflictResolutionMode", conflictResolutionMode.toString());
|
||||
params = params.set("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
|
||||
params.set('CalendarId', event.CalendarId)
|
||||
params.set('CalendarName', event.CalendarName)
|
||||
this.headers['CalendarId'] = event.CalendarId
|
||||
this.headers['CalendarName'] = event.CalendarName
|
||||
|
||||
if(event.CalendarName == 'Oficial'){
|
||||
if(this.loggeduser.Profile == 'MDGPR'){
|
||||
this.headers = this.headersMdOficial;
|
||||
params = params.set("conflictResolutionMode", conflictResolutionMode.toString());
|
||||
params = params.set("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
|
||||
params.set('CalendarId', event.CalendarId)
|
||||
params.set('CalendarName', event.CalendarName)
|
||||
this.headers['CalendarId'] = event.CalendarId
|
||||
this.headers['CalendarName'] = event.CalendarName
|
||||
|
||||
if(event.CalendarName == 'Oficial'){
|
||||
if(this.loggeduser.Profile == 'MDGPR'){
|
||||
this.headers = this.headersMdOficial;
|
||||
}
|
||||
else if(this.loggeduser.Profile == 'PR'){
|
||||
this.headers = this.headersPrOficial;
|
||||
}
|
||||
}
|
||||
else if(this.loggeduser.Profile == 'PR'){
|
||||
this.headers = this.headersPrOficial;
|
||||
else{
|
||||
if(this.loggeduser.Profile == 'MDGPR'){
|
||||
this.headers = this.headersMdPessoal;
|
||||
}
|
||||
else if(this.loggeduser.Profile == 'PR'){
|
||||
this.headers = this.headersPrPessoal;
|
||||
}
|
||||
}
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event, options).pipe(
|
||||
catchError(err => {
|
||||
this.offlinemanager.storeRequest(puturl, 'PUT', event);
|
||||
throw new Error(err);
|
||||
})
|
||||
)
|
||||
}
|
||||
else{
|
||||
if(this.loggeduser.Profile == 'MDGPR'){
|
||||
this.headers = this.headersMdPessoal;
|
||||
}
|
||||
else if(this.loggeduser.Profile == 'PR'){
|
||||
this.headers = this.headersPrPessoal;
|
||||
}
|
||||
}
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
return this.http.put<Event>(`${puturl}`, event, options)
|
||||
}
|
||||
|
||||
changeAgenda(body:any){
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NetworkConnectionService } from './network-connection.service';
|
||||
|
||||
describe('NetworkConnectionService', () => {
|
||||
let service: NetworkConnectionService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NetworkConnectionService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, Observable } from 'rxjs'
|
||||
import { Platform } from '@ionic/angular'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
export class NetworkConnectionService {
|
||||
online: boolean = true;
|
||||
|
||||
constructor(){}
|
||||
|
||||
checkOnline() {
|
||||
window.addEventListener('online', (on) => {
|
||||
this.online === true;
|
||||
console.log('Became online');
|
||||
});
|
||||
}
|
||||
|
||||
checkOffline() {
|
||||
window.addEventListener('offline', (off) => {
|
||||
this.online === false;
|
||||
console.log('Became offline')
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OfflineManagerService } from './offline-manager.service';
|
||||
|
||||
describe('OfflineManagerService', () => {
|
||||
let service: OfflineManagerService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(OfflineManagerService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Storage } from '@ionic/storage';
|
||||
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
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class OfflineManagerService {
|
||||
|
||||
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);
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,20 @@ export class SqliteService {
|
||||
});
|
||||
}
|
||||
|
||||
//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}',
|
||||
'${data.IsAllDayEvent}','${data.AppointmentState}','${data.TimeZone}','${data.Organizer}','${data.Category}','${data.EventRecurrence}','${data.Attachments}','${data.Body}','${data.Profile}','${data.HumanDate}')`, [])
|
||||
.then(() => {
|
||||
console.log("event update with Success");
|
||||
|
||||
}, (e) => {
|
||||
console.log(JSON.stringify(e));
|
||||
});
|
||||
}
|
||||
|
||||
//updateActions
|
||||
public updateactions(id,data) {
|
||||
console.log("update action data", data )
|
||||
@@ -359,6 +373,7 @@ export class SqliteService {
|
||||
if (res.rows.length > 0) {
|
||||
for (var i = 0; i < res.rows.length; i++) {
|
||||
this.ALLPROCESS.push(res.rows.item(i));
|
||||
console.log('getEXPEDIENTE DB LOOP')
|
||||
}
|
||||
return this.ALLPROCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user