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

326 lines
9.8 KiB
TypeScript
Raw Normal View History

/* eslint-disable */
2021-07-08 14:45:38 +01:00
/* tslint:disable */
2021-11-23 17:11:23 +01:00
import { Component, OnInit } 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';
/*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';
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';
/* 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-10-18 07:44:24 +01:00
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
import { Storage } from '@ionic/storage';
import { EventsService } from 'src/app/services/events.service';
import { ProcessesService } from 'src/app/services/processes.service';
2021-10-28 09:30:28 +01:00
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
import { SqliteService } from 'src/app/services/sqlite.service';
2021-11-25 15:50:41 +01:00
import { Device } from '@capacitor/device';
2022-01-06 14:47:22 +01:00
import { RouteService } from 'src/app/services/route.service';
2022-01-07 09:03:15 +01:00
import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service';
import { environment } from 'src/environments/environment';
2022-01-07 11:21:14 +01:00
import { v4 as uuidv4 } from 'uuid'
import { RealTimeAPI } from "rocket.chat.realtime.api.rxjs";
2021-10-07 16:22:31 +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-10-07 16:22:31 +01:00
status: string = "";
audioName: string = "";
constructor(
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-11-04 06:39:39 +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,
/* private webNotificationPopupService: WebNotificationPopupService, */
2021-10-18 07:44:24 +01:00
private backgroundservice: BackgroundService,
private offlinemanager: OfflineManagerService,
private storage: Storage,
2021-10-28 09:30:28 +01:00
private eventservice: EventsService,
private processservice: ProcessesService,
private screenOrientation: ScreenOrientation,
2022-01-06 14:47:22 +01:00
private sqliteservice: SqliteService,
2022-01-07 09:03:15 +01:00
private RouteService: RouteService,
private RocketChatClientService: RocketChatClientService) {
2021-08-31 11:10:40 +01:00
2022-01-07 11:21:14 +01:00
// this.RocketChatClientService.connect()
// this.RocketChatClientService.login({
// username: 'paulo.pinto@gabinetedigital.local',
// password: 'tabteste@006'
// })
2022-01-07 14:29:41 +01:00
const url = 'wss://gabinetedigitalchat.dyndns.info/websocket'
const socket = new WebSocket(url);
socket.onopen = ()=> {
console.log('============================ welcome to rocket chat =========================================');
const connectRequest = {
msg: "connect",
version: "1",
support: ["1", "pre2", "pre1"]
}
// ======================= connect
socket.send(JSON.stringify(connectRequest ))
};
socket.onmessage = (event: any)=> {
console.log('event.data', JSON.parse(event.data))
const data = JSON.parse(event.data)
if(event.data=='{"msg":"ping"}') {
socket.send('{"msg":"pong"}')
const loginRequest = {
msg: "method",
method: "login",
id: uuidv4(),
params: [
{
"user": {
"username": "paulo.pinto"
},
"password": "tabteste@006"
}
]
}
// ======================== login
socket.send(JSON.stringify(loginRequest))
}
// login successfully
if(data.result) {
if(data.result.token) {
console.log('login successfully')
const requestId = uuidv4()
2022-01-07 14:32:58 +01:00
var requestMessage = {
2022-01-07 14:29:41 +01:00
msg: "method",
method: "sendMessage",
id: requestId,
params: [{
_id: "message-id" || uuidv4(),
rid: "room-id" || 444,
msg: "Hello World!"
}]
}
2022-01-07 14:32:58 +01:00
// socket.send(JSON.stringify(requestMessage ))
2022-01-07 14:29:41 +01:00
}
}
};
socket.onclose = (event: any)=> {
console.log(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`);
};
socket.onerror =(event: any)=> {
console.log(`[error] ${event.message}`);
};
2022-01-07 11:21:14 +01:00
// this.RocketChatClientService.send()
/* 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-11-22 15:46:17 +01:00
document.querySelectorAll('popover-viewport').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-11-29 14:50:57 +01:00
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
2021-11-22 15:46:17 +01:00
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
2021-11-29 16:21:29 +01:00
document.querySelectorAll('.popover-viewport').forEach((e: any) => e.remove())
2021-11-22 15:46:17 +01:00
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-11-29 14:50:57 +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-11-25 15:50:41 +01:00
this.logDeviceInfo();
this.notificationsService.onReciveForeground();
this.notificationsService.onReciveBackground();
2021-11-03 12:21:19 +01:00
2021-10-18 17:42:25 +01:00
window.addEventListener('online', () => {
console.log('Became online')
this.backgroundservice.online()
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.synchWhenOnline()
}
2021-10-18 17:42:25 +01:00
});
window.addEventListener('offline', () => {
console.log('Became offline')
this.backgroundservice.offline()
});
2021-08-31 13:11:46 +01:00
this.updateList()
2021-11-03 12:21:19 +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);
}
2021-11-03 12:21:19 +01:00
myWorker.postMessage('ali'); */
}
2021-11-25 15:50:41 +01:00
logDeviceInfo = async () => {
const info = await Device.getInfo();
console.log('Device info',info);
};
2022-01-06 11:21:20 +01:00
get pathname(){
return window.location.pathname
}
get color() {
return '#797979'
}
updateList() {
2021-07-22 16:06:52 +01:00
/* this.notificationsService.registerCallback(
'despachos',
() => {
this.despachoRule.getList({ updateStore: true })
}
) */
2021-08-13 17:09:37 +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
}
2022-01-06 11:21:20 +01:00
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')
2021-12-02 10:09:04 +01:00
//this.sqliteservice.deleteeventsTable();
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')
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')
console.log('event-listRever synchnize', res)
})
});
})
} catch (error) {
console.log('error event-list rever synch')
}
2021-12-02 10:09:04 +01:00
this.sqliteservice.deleteAllTables();
}
2020-08-05 15:39:16 +01:00
}
2022-01-07 09:03:15 +01:00