Files
doneit-web/src/app/home/home.page.ts
T

230 lines
6.7 KiB
TypeScript
Raw Normal View History

/* eslint-disable */
2021-07-08 14:45:38 +01:00
/* tslint:disable */
2021-06-11 17:27:31 +01:00
///<reference path="../../../plugins/cordova-plugin-mfp/typings/worklight.d.ts" />
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
2021-08-25 10:40:17 +01:00
import { Component, OnInit, NgZone } from '@angular/core';
2020-09-08 11:17:07 +01:00
import { Event } from '../models/event.model';
2021-04-12 08:34:17 +01:00
import { NotificationsService } from '../services/notifications.service';
2021-08-25 16:29:15 +01:00
import { WebNotificationsService } from '../services/webnotifications.service';
2021-08-30 10:24:46 +01:00
import { AlertController, Platform } from '@ionic/angular';
2021-08-23 10:24:29 +01:00
import { Router, ActivatedRoute } from '@angular/router';
2021-07-21 22:44:24 +01:00
import { ToDayEventStorage } from '../store/to-day-event-storage.service';
2021-08-25 10:40:17 +01:00
import { TotalDocumentStore } from '../store/total-document.service';
2021-08-30 10:24:46 +01:00
import { synchro } from '../services/socket/synchro.service';
import { DespachoService } from '../Rules/despacho.service';
import { ExpedienteGdStore } from '../store/expedientegd-store.service';
2021-08-27 13:39:52 +01:00
import { InativityService } from '../services/inativity.service';
2021-08-27 17:11:05 +01:00
import { SessionStore } from '../store/session.service';
2021-08-30 10:24:46 +01:00
import { StorageService } from '../services/storage.service';
import { File } from '@ionic-native/file/ngx';
2021-08-31 11:10:40 +01:00
import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service';
2021-09-30 15:56:04 +01:00
import { DocumentCounterService } from '../services/worker/document-counter.service';
import { PermissionService } from '../services/worker/permission.service';
2021-10-07 16:22:31 +01:00
import { Network } from '@ionic-native/network/ngx';
import { BackgroundService } from 'src/app/services/background.service';
2021-07-26 11:34:46 +01:00
2020-08-05 15:39:16 +01:00
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
2020-09-08 11:17:07 +01:00
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
totalEvent = 0;
totalExpediente = 0;
profile: string;
2020-08-05 15:39:16 +01:00
2021-07-21 22:44:24 +01:00
toDayEventStorage = ToDayEventStorage
2021-08-18 18:31:35 +01:00
totalDocumentStore = TotalDocumentStore
expedienteGdStore = ExpedienteGdStore
2021-07-21 22:44:24 +01:00
2021-04-08 22:54:15 +01:00
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;
2021-08-30 10:24:46 +01:00
synchro = synchro
2021-08-25 10:40:17 +01:00
2021-10-07 16:22:31 +01:00
status: string = "";
audioName: string = "";
constructor(
private zone: NgZone,
2021-07-20 19:22:56 +01:00
private router: Router,
2021-06-16 08:37:31 +01:00
public modalCtrl: AlertController,
2021-08-25 11:51:02 +01:00
private notificationsService: NotificationsService,
2021-07-07 15:28:29 +01:00
private platform: Platform,
2021-07-30 14:01:50 +01:00
private activeroute: ActivatedRoute,
2021-08-25 16:29:15 +01:00
private webnotification: WebNotificationsService,
2021-08-25 08:51:52 +01:00
public p: PermissionService,
public documentCounterService: DocumentCounterService,
2021-08-27 13:39:52 +01:00
private despachoRule: DespachoService,
2021-08-30 10:24:46 +01:00
private inativityService: InativityService,
private storageService: StorageService,
2021-10-07 16:22:31 +01:00
private webNotificationPopupService: WebNotificationPopupService,
private network: Network,
private backgroundservice: BackgroundService) {
2021-08-31 11:10:40 +01:00
this.webNotificationPopupService.askNotificationPermission()
2021-04-08 22:54:15 +01:00
2021-07-08 10:43:40 +01:00
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
2021-03-04 16:07:09 +01:00
});
2021-04-08 22:54:15 +01:00
2021-08-30 10:24:46 +01:00
window['platform'] = platform
2021-08-27 13:39:52 +01:00
window['inactivity/function'] = () => {
2021-08-30 11:41:21 +01:00
2021-10-07 16:22:31 +01:00
if (window.location.pathname != '/inactivity') {
2021-08-27 17:11:05 +01:00
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
this.router.navigate(['/inactivity']);
}
2021-08-27 13:39:52 +01:00
}
2021-08-24 11:15:13 +01:00
2021-08-25 11:51:02 +01:00
}
2021-10-07 16:22:31 +01:00
2021-09-03 12:19:21 +01:00
goto(url) {
this.router.navigate([url])
}
2021-08-25 11:51:02 +01:00
2021-10-07 16:22:31 +01:00
refreshing() { }
2020-08-05 15:39:16 +01:00
ngOnInit() {
2021-10-07 16:22:31 +01:00
2021-07-31 22:04:09 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2021-10-07 16:22:31 +01:00
window.addEventListener('online', () => {
console.log('Became online')
this.backgroundservice.online()
});
window.addEventListener('offline', () => {
console.log('Became offline')
this.backgroundservice.offline()
});
2021-08-25 16:29:15 +01:00
this.webnotification.webconnection();
this.webnotification.register();
2021-06-25 14:37:52 +01:00
} else {
2021-07-31 22:04:09 +01:00
this.mobilefirstConnect();
2021-08-25 11:51:02 +01:00
this.notificationsService.onReceviNotification();
2021-06-25 14:37:52 +01:00
}
2021-08-31 13:11:46 +01:00
this.updateList()
2021-10-07 16:22:31 +01:00
var myWorker = new Worker(new URL('./nice.worker.js', import.meta.url));
2021-08-31 13:11:46 +01:00
2021-10-07 16:22:31 +01:00
myWorker.onmessage = function (oEvent) {
2021-08-31 13:11:46 +01:00
console.log('Worker said : ' + oEvent.data);
}
myWorker.postMessage('ali');
}
2021-06-25 10:04:41 +01:00
mobilefirstConnect() {
2021-07-22 16:06:52 +01:00
2021-09-21 06:09:41 +01:00
console.log("Mobileconecct");
2021-10-07 16:22:31 +01:00
if (window['WLAuthorizationManager']) {
if (window['WLAuthorizationManager'].obtainAccessToken) {
2021-08-13 17:09:37 +01:00
window['WLAuthorizationManager'].obtainAccessToken("").then((token) => {
2021-10-07 16:22:31 +01:00
2021-08-13 17:09:37 +01:00
console.log('MobileFirst Server connect: Success ' + token);
2021-10-07 16:22:31 +01:00
2021-08-13 17:09:37 +01:00
var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/",
WLResourceRequest.GET
);
2021-10-07 16:22:31 +01:00
2021-08-13 17:09:37 +01:00
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) => {
2021-08-18 15:42:36 +01:00
console.log("Connect with JavaAdapter Failure: " + JSON.stringify(error));
2021-08-13 17:09:37 +01:00
}
);
}, (error) => {
console.log('MobileFirst Server connect: failure ' + error.responseText);
console.log(JSON.stringify(error))
/* this.zone.run(() => {
2021-08-18 15:57:19 +01:00
console.log("Bummer...");
console.log("Failed to connect to MobileFirst Server");
2021-08-13 17:09:37 +01:00
}); */
});
}
2021-08-13 16:55:35 +01:00
}
}
2021-07-31 22:04:09 +01:00
updateList() {
2021-07-22 16:06:52 +01:00
this.notificationsService.registerCallback(
2021-08-30 12:17:20 +01:00
'despachos',
() => {
2021-10-07 16:22:31 +01:00
this.despachoRule.getList({ updateStore: true })
}
)
2021-08-13 17:09:37 +01:00
2021-08-31 10:19:45 +01:00
2021-10-07 16:22:31 +01:00
synchro.registerCallback('Online', () => {
2021-09-21 06:09:41 +01:00
console.log('Onlineee')
2021-08-31 09:16:59 +01:00
})
synchro.registerCallback('Offline',()=>{
2021-10-05 10:18:38 +01:00
2021-08-31 09:16:59 +01:00
})
2021-09-27 16:23:41 +01:00
synchro.conected
2021-08-31 09:16:59 +01:00
2021-10-07 16:22:31 +01:00
synchro.registerCallback('Notification', (DataArray) => {
2021-08-31 09:00:33 +01:00
2021-08-31 22:49:37 +01:00
this.webNotificationPopupService.sendNotification(DataArray)
2021-10-07 16:22:31 +01:00
2021-08-31 19:30:08 +01:00
this.storageService.get('Notifications').then((data:any)=>{
2021-08-31 09:00:33 +01:00
data.push(DataArray)
this.storageService.store("Notifications", data)
2021-10-07 16:22:31 +01:00
}).catch(() => {
2021-08-31 09:00:33 +01:00
const a = []
a.push(DataArray)
2021-10-07 16:22:31 +01:00
this.storageService.store("Notifications", a)
2021-08-31 09:00:33 +01:00
})
2021-10-07 16:22:31 +01:00
2021-08-30 12:17:20 +01:00
}, 'any')
2021-08-30 10:24:46 +01:00
2021-08-31 13:46:39 +01:00
document.addEventListener('pause', function () {
// console.log('App going to background');
});
2021-10-07 16:22:31 +01:00
2021-08-31 13:46:39 +01:00
document.addEventListener('resume', function () {
// console.log('App coming to foreground');
});
2021-06-25 10:04:41 +01:00
}
2020-08-05 15:39:16 +01:00
}