Files
doneit-web/src/app/home/home.page.ts
T
2022-06-29 15:51:28 +01:00

276 lines
7.4 KiB
TypeScript

/* eslint-disable */
/* tslint:disable */
import { Component, OnInit } from '@angular/core';
import { Event } from '../models/event.model';
import { NotificationsService } from '../services/notifications.service';
import { AlertController, Platform } from '@ionic/angular';
import { Router } from '@angular/router';
import { ToDayEventStorage } from '../store/to-day-event-storage.service';
import { TotalDocumentStore } from '../store/total-document.service';
import { ExpedienteGdStore } from '../store/expedientegd-store.service';
import { SessionStore } from '../store/session.service';
import { PermissionService } from '../services/permission.service';
import { BackgroundService } from 'src/app/services/background.service';
import { Storage } from '@ionic/storage';
import { EventsService } from 'src/app/services/events.service';
import { ProcessesService } from 'src/app/services/processes.service';
import { SqliteService } from 'src/app/services/sqlite.service';
import { Device } from '@capacitor/device';
import { RouteService } from 'src/app/services/route.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { UserSession } from '../models/user.model';
import { PermissionList } from '../models/permission/permissionList';
import { LoginUserRespose } from 'src/app/models/user.model';
import { AuthService } from 'src/app/services/auth.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
}
tabButton = {
home: false,
agenda: false,
gabinete: false,
actions: false,
chat: false,
}
eventToaprove: any = {
back: false,
serialNumber: "",
saveData: {}
}
selectedEvent: Event;
postEvent: any;
folderId: string;
status: string = "";
audioName: string = "";
public user: UserSession;
permissionList = new PermissionList();
loggeduser: LoginUserRespose;
constructor(
private router: Router,
public modalCtrl: AlertController,
private notificationsService: NotificationsService,
public platform: Platform,
public p: PermissionService,
private backgroundservice: BackgroundService,
private storage: Storage,
private eventservice: EventsService,
private processservice: ProcessesService,
public RouteService: RouteService,
private authService: AuthService,
private NativeNotificationService: NativeNotificationService,
private sqliteservice: SqliteService,
) {
this.loggeduser = authService.ValidatedUser;
if (SessionStore.exist) {
this.user = SessionStore.user;
}
this.NativeNotificationService.askForPermission()
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
document.querySelectorAll('popover-viewport').forEach((e: any) => e.remove())
});
window['platform'] = platform
window['inactivity/function'] = () => {
if (window.location.pathname != '/inactivity') {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
document.querySelectorAll('.popover-viewport').forEach((e: any) => e.remove())
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
if (this.platform.is('mobileweb')) {
this.router.navigate(['/inactivity']);
}else{
this.router.navigate(['/']);
}
}
}
}
goto(url) {
this.router.navigate([url])
}
refreshing() { }
ngOnInit() {
this.logDeviceInfo();
this.notificationsService.onReciveForeground();
this.notificationsService.onReciveBackground();
window.addEventListener('online', () => {
// console.log('Became online')
this.backgroundservice.online()
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.synchWhenOnline()
}
});
window.addEventListener('offline', () => {
// console.log('Became offline')
this.backgroundservice.offline()
});
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'); */
this.clearTabButtonSelection();
}
clearTabButtonSelection(){
this.tabButton.home = false;
this.tabButton.agenda = false;
this.tabButton.gabinete = false;
this.tabButton.actions = false;
this.tabButton.chat = false;
}
selectedTab(url?:string){
this.clearTabButtonSelection();
if(url =='/home/events'){
this.tabButton.home = true;
}
else if(url == '/home/agenda'){
this.tabButton.agenda = true;
}
else if(url =='/home/gabinete-digital'){
this.tabButton.gabinete = true;
}
else if(url =='/home/publications'){
this.tabButton.actions = true;
}
else if(url == '/home/chat'){
this.tabButton.chat = true;
}
else{
this.clearTabButtonSelection();
}
}
logDeviceInfo = async () => {
const info = await Device.getInfo();
};
get pathname(){
return window.location.pathname
}
get color() {
return '#797979'
}
updateList() {
/* this.notificationsService.registerCallback(
'despachos',
() => {
this.despachoRule.getList({ updateStore: true })
}
) */
document.addEventListener('pause', function () {
// console.log('App going to background');
});
document.addEventListener('resume', function () {
// console.log('App coming to foreground');
});
}
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')
//this.sqliteservice.deleteeventsTable();
})
});
})
} catch (error) {
console.log(error)
}
try {
await this.storage.get('eventDelete').then((req) => {
JSON.parse(req).forEach(element => {
this.eventservice.deleteEvent(element.eventid, element.eventDeleteType, element.calendarName).subscribe((res) => {
this.storage.remove('eventDelete')
})
});
})
} catch (error) {
console.log(error)
}
try {
await this.storage.get('event-listRever').then((req) => {
JSON.parse(req).forEach(element => {
this.processservice.PostTaskAction(element).subscribe((res) => {
this.storage.remove('event-listRever')
})
});
})
} catch (error) {
console.log(error)
}
this.sqliteservice.deleteAllTables();
}
}