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

282 lines
8.4 KiB
TypeScript
Raw Normal View History

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';
2021-08-30 10:24:46 +01:00
import { AlertController, Platform } from '@ionic/angular';
2022-04-26 16:53:10 +01:00
import { Router } 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 { ExpedienteGdStore } from '../store/expedientegd-store.service';
2021-08-27 17:11:05 +01:00
import { SessionStore } from '../store/session.service';
2022-03-28 15:46:07 +01:00
import { PermissionService } from '../services/permission.service';
2021-10-07 16:22:31 +01:00
import { BackgroundService } from 'src/app/services/background.service';
2021-10-18 07:44:24 +01:00
import { Storage } from '@ionic/storage';
2021-10-20 11:06:00 +01:00
import { EventsService } from 'src/app/services/events.service';
2023-01-09 17:07:02 +01:00
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';
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';
2023-01-09 17:07:02 +01:00
import { NetworkServiceService, ConnectionStatus } from 'src/app/services/network-service.service';
2022-01-26 17:28:55 +01:00
import { NativeNotificationService } from 'src/app/services/native-notification.service';
2022-03-28 13:34:01 +01:00
import { UserSession } from '../models/user.model';
2022-03-30 15:08:23 +01:00
import { PermissionList } from '../models/permission/permissionList';
2021-10-07 16:22:31 +01:00
2022-04-08 13:52:00 +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[];
2021-01-26 17:00:41 +01:00
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-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
}
2022-01-04 15:34:03 +01:00
tabButton = {
home: false,
agenda: false,
gabinete: false,
actions: false,
chat: false,
}
2021-04-08 22:54:15 +01:00
eventToaprove: any = {
back: false,
serialNumber: "",
saveData: {}
}
selectedEvent: Event;
postEvent: any;
folderId: string;
2021-10-07 16:22:31 +01:00
status: string = "";
audioName: string = "";
2022-03-28 13:34:01 +01:00
public user: UserSession;
2022-03-28 15:46:07 +01:00
permissionList = new PermissionList();
2022-10-12 17:01:09 +01:00
SessionStore = SessionStore
2022-01-07 15:48:35 +01:00
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,
2022-04-08 12:31:23 +01:00
public platform: Platform,
2021-08-25 08:51:52 +01:00
public p: PermissionService,
2021-10-18 07:44:24 +01:00
private backgroundservice: BackgroundService,
private storage: Storage,
2021-10-28 09:30:28 +01:00
private eventservice: EventsService,
private processservice: ProcessesService,
2022-02-16 15:52:59 +01:00
public RouteService: RouteService,
2022-04-26 16:53:10 +01:00
private NativeNotificationService: NativeNotificationService,
private sqliteservice: SqliteService,
2023-01-09 17:07:02 +01:00
private RochetChatConnectorService: RochetChatConnectorService,
2023-02-01 09:08:46 +01:00
private NetworkServiceService: NetworkServiceService,
public eventService: EventsService,
2022-03-28 15:46:07 +01:00
) {
2022-03-28 13:34:01 +01:00
if (SessionStore.exist) {
this.user = SessionStore.user;
}
2022-01-07 16:39:46 +01:00
2022-06-24 16:18:25 +01:00
this.NativeNotificationService.askForPermission()
2021-04-08 22:54:15 +01:00
2022-06-24 16:18:25 +01:00
this.router.events.subscribe((val) => {
document.querySelectorAll('ion-modal').forEach((e: any) => e.remove())
document.querySelectorAll('popover-viewport').forEach((e: any) => e.remove())
2022-12-26 15:41:11 +01:00
document.querySelectorAll('.loading-blocker').forEach((e: any) => e.remove())
2022-06-24 16:18:25 +01:00
});
2022-03-28 13:34:01 +01:00
2022-06-24 16:18:25 +01:00
window['platform'] = platform
2021-04-08 22:54:15 +01:00
2022-06-24 16:18:25 +01:00
window['inactivity/function'] = () => {
2021-11-29 14:50:57 +01:00
2023-01-09 10:49:58 +01:00
if (window.location.pathname != '/inactivity' && window.location.pathname != '/') {
2021-08-30 11:41:21 +01:00
2023-01-02 14:36:57 +01:00
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());
2021-08-27 17:11:05 +01:00
2022-06-24 16:18:25 +01:00
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
if (this.platform.is('mobileweb')) {
2023-01-09 10:49:58 +01:00
// this.router.navigate(['/inactivity']);
window.location.pathname = '/inactivity'
2023-01-02 14:36:57 +01:00
} else {
2023-01-09 10:49:58 +01:00
// this.router.navigate(['/']);
window.location.pathname = '/'
2022-06-24 16:18:25 +01:00
}
2022-06-10 14:52:05 +01:00
}
2021-08-24 11:15:13 +01:00
2022-06-24 16:18:25 +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) {
2022-12-19 17:04:21 +01:00
// this.router.navigateByUrl('/home/events', { replaceUrl: true });
this.router.navigate([url], { replaceUrl: true })
2021-09-03 12:19:21 +01:00
}
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();
2022-12-26 14:47:51 +01:00
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', () => {
this.backgroundservice.online()
2021-10-20 11:06:00 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
} else {
this.synchWhenOnline()
2021-10-20 11:06:00 +01:00
}
2021-10-18 17:42:25 +01:00
});
2023-01-09 17:07:02 +01:00
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async () => {
this.backgroundservice.online()
}
})
this.NetworkServiceService.onNetworkChange().subscribe((status) => {
if(status == ConnectionStatus.Online) {
this.backgroundservice.online()
}
})
2021-10-18 17:42:25 +01:00
window.addEventListener('offline', () => {
2022-06-29 15:51:28 +01:00
// console.log('Became offline')
2021-10-18 17:42:25 +01:00
this.backgroundservice.offline()
});
2021-08-31 13:11:46 +01:00
this.updateList()
2023-02-01 09:08:46 +01:00
this.clearTabButtonSelection();
2021-08-31 13:11:46 +01:00
2023-02-01 09:08:46 +01:00
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');
}
2021-08-31 13:11:46 +01:00
2023-02-01 09:08:46 +01:00
if(this.p.userPermission([this.p.permissionList.Agenda.access]) && !this.eventService.hasAnyCalendar) {
throw('User '+SessionStore.user.FullName + 'has No calendar');
}
}, 1000)
2022-03-30 15:08:23 +01:00
2022-01-04 15:34:03 +01:00
}
2023-01-02 15:42:15 +01:00
clearTabButtonSelection() {
2022-01-04 15:34:03 +01:00
this.tabButton.home = false;
this.tabButton.agenda = false;
this.tabButton.gabinete = false;
this.tabButton.actions = false;
this.tabButton.chat = false;
}
2023-01-12 15:27:09 +01:00
selectedTab(url?:string) {
2022-01-04 15:34:03 +01:00
this.clearTabButtonSelection();
if(url =='/home/events'){
this.tabButton.home = true;
}
else if(url == '/home/agenda'){
this.tabButton.agenda = true;
}
2023-01-02 15:42:15 +01:00
else if(url =='/home/gabinete-digital') {
2022-01-04 15:34:03 +01:00
this.tabButton.gabinete = true;
}
2023-01-02 15:42:15 +01:00
else if(url =='/home/publications') {
2022-01-04 15:34:03 +01:00
this.tabButton.actions = true;
}
2023-01-02 15:42:15 +01:00
else if(url == '/home/chat') {
2022-01-04 15:34:03 +01:00
this.tabButton.chat = true;
}
else{
this.clearTabButtonSelection();
}
}
2023-01-02 15:42:15 +01:00
logDeviceInfo = async () => {
2021-11-25 15:50:41 +01:00
const info = await Device.getInfo();
2022-01-06 11:21:20 +01:00
}
2023-01-02 15:42:15 +01:00
get pathname() {
return window.location.pathname
2022-01-06 11:21:20 +01:00
}
updateList() {
2021-07-22 16:06:52 +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-07 16:39:46 +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();
})
});
})
} catch (error) {
2022-04-28 09:32:27 +01:00
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) {
2022-04-28 09:32:27 +01:00
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) {
2022-04-28 09:32:27 +01:00
console.log(error)
}
2021-12-02 10:09:04 +01:00
this.sqliteservice.deleteAllTables();
}
2023-01-02 15:42:15 +01:00
}