Files
doneit-web/src/app/home/home.page.ts
T
Peter Maquiran b3a8379276 fix
2023-02-01 09:08:46 +01:00

282 lines
8.4 KiB
TypeScript

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 { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.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 { NetworkServiceService, ConnectionStatus } from 'src/app/services/network-service.service';
import { NativeNotificationService } from 'src/app/services/native-notification.service';
import { UserSession } from '../models/user.model';
import { PermissionList } from '../models/permission/permissionList';
@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();
SessionStore = SessionStore
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 NativeNotificationService: NativeNotificationService,
private sqliteservice: SqliteService,
private RochetChatConnectorService: RochetChatConnectorService,
private NetworkServiceService: NetworkServiceService,
public eventService: EventsService,
) {
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())
document.querySelectorAll('.loading-blocker').forEach((e: any) => e.remove())
});
window['platform'] = platform
window['inactivity/function'] = () => {
if (window.location.pathname != '/inactivity' && window.location.pathname != '/') {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove());
document.querySelectorAll('.popover-viewport').forEach((e: any) => e.remove());
document.querySelectorAll('.loading-blocker').forEach((e: any) => e.remove());
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
if (this.platform.is('mobileweb')) {
// this.router.navigate(['/inactivity']);
window.location.pathname = '/inactivity'
} else {
// this.router.navigate(['/']);
window.location.pathname = '/'
}
}
}
}
goto(url) {
// this.router.navigateByUrl('/home/events', { replaceUrl: true });
this.router.navigate([url], { replaceUrl: true })
}
refreshing() { }
ngOnInit() {
this.logDeviceInfo();
this.notificationsService.onReciveForeground();
this.notificationsService.onReciveBackground();
window.addEventListener('online', () => {
this.backgroundservice.online()
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.synchWhenOnline()
}
});
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async () => {
this.backgroundservice.online()
}
})
this.NetworkServiceService.onNetworkChange().subscribe((status) => {
if(status == ConnectionStatus.Online) {
this.backgroundservice.online()
}
})
window.addEventListener('offline', () => {
// console.log('Became offline')
this.backgroundservice.offline()
});
this.updateList()
this.clearTabButtonSelection();
setTimeout(() => {
if(this.p.userPermission([this.p.permissionList.Gabinete.md_tasks]) && this.p.userPermission([this.p.permissionList.Gabinete.pr_tasks])) {
throw(SessionStore.user.FullName + 'cant have MD and PR authorization at same time');
}
if(this.p.userPermission([this.p.permissionList.Chat.access]) && !SessionStore.user?.ChatData?.data) {
throw('Chat temporarily unavailable for '+SessionStore.user.FullName + '. No ChatData');
}
if(this.p.userPermission([this.p.permissionList.Agenda.access]) && !this.eventService.hasAnyCalendar) {
throw('User '+SessionStore.user.FullName + 'has No calendar');
}
}, 1000)
}
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
}
updateList() {
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();
}
}