Files
doneit-web/src/app/home/home.page.ts
T
Eudes Inácio 6ed724877e Sql bug fixed
2021-10-18 07:44:24 +01:00

265 lines
8.0 KiB
TypeScript

/* eslint-disable */
/* tslint:disable */
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
import { Component, OnInit, NgZone } from '@angular/core';
import { Event } from '../models/event.model';
import { NotificationsService } from '../services/notifications.service';
import { WebNotificationsService } from '../services/webnotifications.service';
import { AlertController, Platform } from '@ionic/angular';
import { Router, ActivatedRoute } from '@angular/router';
import { ToDayEventStorage } from '../store/to-day-event-storage.service';
import { TotalDocumentStore } from '../store/total-document.service';
import { synchro } from '../services/socket/synchro.service';
import { DespachoService } from '../Rules/despacho.service';
import { ExpedienteGdStore } from '../store/expedientegd-store.service';
import { InativityService } from '../services/inativity.service';
import { SessionStore } from '../store/session.service';
import { StorageService } from '../services/storage.service';
import { File } from '@ionic-native/file/ngx';
import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service';
import { DocumentCounterService } from '../services/worker/document-counter.service';
import { PermissionService } from '../services/worker/permission.service';
import { Network } from '@ionic-native/network/ngx';
import { BackgroundService } from 'src/app/services/background.service';
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
import { Storage } from '@ionic/storage';
import { EventsService} from 'src/app/services/events.service';
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
totalEvent = 0;
totalExpediente = 0;
profile: string;
toDayEventStorage = ToDayEventStorage
totalDocumentStore = TotalDocumentStore
expedienteGdStore = ExpedienteGdStore
adding: "intervenient" | "CC" = "intervenient";
mobileComponent = {
showAddNewEvent: false,
showEditEvent: false,
showEventDetails: false,
showEventList: false,
transparentEventList: false,
transparentEventToApprove: false,
showEventToApprove: false,
showAttendees: false,
showAttendeeModal: false
}
eventToaprove: any = {
back: false,
serialNumber: "",
saveData: {}
}
selectedEvent: Event;
postEvent: any;
folderId: string;
synchro = synchro
status: string = "";
audioName: string = "";
constructor(
private zone: NgZone,
private router: Router,
public modalCtrl: AlertController,
private notificationsService: NotificationsService,
private platform: Platform,
private activeroute: ActivatedRoute,
private webnotification: WebNotificationsService,
public p: PermissionService,
public documentCounterService: DocumentCounterService,
private despachoRule: DespachoService,
private inativityService: InativityService,
private storageService: StorageService,
private webNotificationPopupService: WebNotificationPopupService,
private network: Network,
private backgroundservice: BackgroundService,
private offlinemanager: OfflineManagerService,
private storage: Storage,
private eventservice: EventsService ) {
this.webNotificationPopupService.askNotificationPermission()
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
});
window['platform'] = platform
window['inactivity/function'] = () => {
if (window.location.pathname != '/inactivity') {
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
this.router.navigate(['/inactivity']);
}
}
}
goto(url) {
this.router.navigate([url])
}
refreshing() { }
ngOnInit() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
window.addEventListener('online', () => {
console.log('Became online')
this.backgroundservice.online()
});
window.addEventListener('offline', () => {
console.log('Became offline')
this.backgroundservice.offline()
});
this.webnotification.webconnection();
this.webnotification.register();
} else {
window.addEventListener('online', (on) => {
console.log('Became online',on)
this.storage.get('storedreq').then((req) =>{
console.log('STORED REQUEST', req)
req.forEach(element => {
this.eventservice.editEvent(element,2,3).subscribe((res) =>{
console.log('REQUEST RESULT', res)
})
});
})
this.backgroundservice.online()
});
window.addEventListener('offline', (off) => {
console.log('Became offline',off)
this.backgroundservice.offline()
});
if(synchro.connected === true) {
//this.offlinemanager.checkForEvents().subscribe();
this.storage.get('storedreq').then((req) =>{
console.log('STORED REQUEST', req)
req.forEach(element => {
this.eventservice.editEvent(element,2,3).subscribe((res) =>{
console.log('REQUEST RESULT', res)
})
});
})
}
this.mobilefirstConnect();
this.notificationsService.onReceviNotification();
}
this.updateList()
var myWorker = new Worker(new URL('./nice.worker.js', import.meta.url));
myWorker.onmessage = function (oEvent) {
console.log('Worker said : ' + oEvent.data);
}
myWorker.postMessage('ali');
}
mobilefirstConnect() {
console.log("Mobileconecct");
if (window['WLAuthorizationManager']) {
if (window['WLAuthorizationManager'].obtainAccessToken) {
window['WLAuthorizationManager'].obtainAccessToken("").then((token) => {
console.log('MobileFirst Server connect: Success ' + token);
var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/",
WLResourceRequest.GET
);
resourceRequest.setQueryParameter("name", "world");
resourceRequest.send().then(
(response) => {
// Will display "Hello world" in an alert dialog.
console.log("Connect with JavaAdapter Success: " + response.responseText);
//this.MFPushNotification();
},
(error) => {
console.log("Connect with JavaAdapter Failure: " + JSON.stringify(error));
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure ' + error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
console.log("Bummer...");
console.log("Failed to connect to MobileFirst Server");
}); */
});
}
}
}
updateList() {
this.notificationsService.registerCallback(
'despachos',
() => {
this.despachoRule.getList({ updateStore: true })
}
)
synchro.registerCallback('Online', () => {
console.log('Onlineee')
})
synchro.registerCallback('Offline',()=>{
})
synchro.conected
synchro.registerCallback('Notification', (DataArray) => {
this.webNotificationPopupService.sendNotification(DataArray)
this.storageService.get('Notifications').then((data:any)=>{
data.push(DataArray)
this.storageService.store("Notifications", data)
}).catch(() => {
const a = []
a.push(DataArray)
this.storageService.store("Notifications", a)
})
}, 'any')
document.addEventListener('pause', function () {
// console.log('App going to background');
});
document.addEventListener('resume', function () {
// console.log('App coming to foreground');
});
}
}