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

357 lines
11 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';
2023-02-23 18:02:43 +01:00
import { RoleIdService } from 'src/app/services/role-id.service';
2023-02-08 09:53:21 +01:00
import { ActiveTabService } from 'src/app/services/active-tab.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-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
2023-09-14 11:58:24 +01:00
import { Plugins } from '@capacitor/core';
const { App } = Plugins;
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,
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,
2023-02-23 18:02:43 +01:00
public ActiveTabService: ActiveTabService,
private RoleIdService: RoleIdService
2023-09-14 11:58:24 +01:00
) {
if (SessionStore.exist) {
this.user = SessionStore.user;
}
2022-01-07 16:39:46 +01:00
2023-02-09 11:25:57 +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())
document.querySelectorAll('.loading-blocker').forEach((e: any) => e.remove())
document.querySelectorAll('ion-popover').forEach((e: any) => e.remove())
});
2022-03-28 13:34:01 +01:00
2023-02-09 11:25:57 +01:00
window['platform'] = platform
2021-04-08 22:54:15 +01:00
2023-02-09 11:25:57 +01:00
window['inactivity/function'] = () => {
2021-11-29 14:50:57 +01:00
2023-02-09 11:25:57 +01:00
if (window.location.pathname != '/inactivity' && window.location.pathname != '/') {
2021-08-30 11:41:21 +01:00
2023-02-09 11:25: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
2023-02-09 11:25:57 +01:00
const pathname = window.location.pathname
SessionStore.setUrlBeforeInactivity(pathname)
2021-08-24 11:15:13 +01:00
2023-02-09 11:25:57 +01:00
if (this.platform.is('mobileweb')) {
window.location.pathname = '/inactivity'
} else {
window.location.pathname = '/'
}
2022-06-24 16:18:25 +01:00
}
2021-11-29 14:50:57 +01:00
2023-02-09 11:25:57 +01:00
}
2023-08-10 16:46:55 +01:00
2023-09-14 11:58:24 +01:00
/* navigator.serviceWorker.ready.then((registration) => {
console.log('yes please')
registration.active.postMessage(
"Test message sent immediately after creation",
);
}); */
2023-08-22 14:39:33 +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) {
2023-09-22 15:17:25 +01:00
this.router.navigateByUrl(url)
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
2023-10-03 12:11:50 +01:00
if ("serviceWorker" in navigator) {
navigator.serviceWorker.onmessage = (event) => {
console.log('Mensagem recebida do Service Worker:', event.data.data);
let object = {
notification: event.data
}
2023-08-11 16:14:25 +01:00
2023-09-14 11:58:24 +01:00
2023-10-03 12:11:50 +01:00
// Implemente a lógica para lidar com a mensagem recebida do Service Worker
if (event.data.notificationClicked) {
console.log('Notificação push do Firebase clicada em segundo plano!');
// Implemente ações adicionais conforme necessário
}
};
}
2023-08-11 16:14:25 +01:00
2021-11-25 15:50:41 +01:00
this.logDeviceInfo();
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) => {
2023-02-09 11:25:57 +01:00
if (status == ConnectionStatus.Online) {
2023-01-09 17:07:02 +01:00
this.backgroundservice.online()
}
})
2021-10-18 17:42:25 +01:00
window.addEventListener('offline', () => {
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(() => {
2023-02-09 11:25:57 +01:00
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');
2023-02-01 09:08:46 +01:00
}
2023-02-09 11:25:57 +01:00
if (this.p.userPermission([this.p.permissionList.Chat.access]) && !SessionStore.user?.ChatData?.data) {
throw ('Chat temporarily unavailable for ' + SessionStore.user.FullName + '. No ChatData');
2023-02-01 09:08:46 +01:00
}
2021-08-31 13:11:46 +01:00
2023-02-09 11:25:57 +01:00
if (this.p.userPermission([this.p.permissionList.Agenda.access]) && !this.eventService.hasAnyCalendar) {
throw ('User ' + SessionStore.user.FullName + 'has No calendar');
2023-02-01 09:08:46 +01:00
}
2023-02-27 18:34:42 +01:00
if (this.p.userPermission([this.p.permissionList.Gabinete.pr_tasks]) && SessionStore.user.RoleID != this.RoleIdService.PRES) {
2023-02-23 18:02:43 +01:00
throw ('User has PRES permission but not roleId');
}
2023-02-27 19:52:30 +01:00
if (!this.p.userPermission([this.p.permissionList.Gabinete.pr_tasks]) && SessionStore.user.RoleID == this.RoleIdService.PRES) {
2023-04-05 15:15:42 +01:00
throw (`User doesn't have PRES permission but has roleId`);
}
if (this.p.userPermission([this.p.permissionList.Gabinete.md_tasks]) && SessionStore.user.RoleID != this.RoleIdService.PV) {
throw ('User has vice president permission but not roleId');
}
if (!this.p.userPermission([this.p.permissionList.Gabinete.md_tasks]) && SessionStore.user.RoleID == this.RoleIdService.PV) {
throw (`User doesn't has vice president permission but has roleId`);
2023-02-27 19:52:30 +01:00
}
2023-08-22 14:39:33 +01:00
2023-09-14 11:58:24 +01:00
(() => {
2023-08-22 14:39:33 +01:00
document.addEventListener('click', (e: any) => {
const closest = e.target.closest(".mat-datepicker-content");
2023-09-14 11:58:24 +01:00
if (closest) {
2023-08-22 14:39:33 +01:00
e.preventDefault()
2023-09-14 11:58:24 +01:00
document.activeElement['blur']();
2023-08-22 14:39:33 +01:00
}
2023-09-14 11:58:24 +01:00
})
2023-08-22 14:39:33 +01:00
})()
2023-02-01 09:08:46 +01:00
}, 1000)
2022-03-30 15:08:23 +01:00
2023-09-14 11:58:24 +01:00
2023-10-09 14:15:21 +01:00
/* if (!this.platform.is('desktop')) {
App.addListener('appStateChange', ({ isActive }) => {
if (isActive) {
// The app is in the foreground.
console.log('App is in the foreground');
this.RochetChatConnectorService.connect()
this.reloadComponent(true)
} else {
// The app is in the background.
console.log('App is in the background');
// You can perform actions specific to the background state here.
}
});
} */
2023-09-14 11:58:24 +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-02-09 11:25:57 +01:00
selectedTab(url?: string) {
2022-01-04 15:34:03 +01:00
this.clearTabButtonSelection();
2023-02-09 11:25:57 +01:00
if (url == '/home/events') {
2022-01-04 15:34:03 +01:00
this.tabButton.home = true;
}
2023-02-09 11:25:57 +01:00
else if (url == '/home/agenda') {
2022-01-04 15:34:03 +01:00
this.tabButton.agenda = true;
}
2023-02-09 11:25:57 +01:00
else if (url == '/home/gabinete-digital') {
2022-01-04 15:34:03 +01:00
this.tabButton.gabinete = true;
}
2023-02-09 11:25:57 +01:00
else if (url == '/home/publications') {
2022-01-04 15:34:03 +01:00
this.tabButton.actions = true;
}
2023-02-09 11:25:57 +01:00
else if (url == '/home/chat') {
2022-01-04 15:34:03 +01:00
this.tabButton.chat = true;
}
2023-02-09 11:25:57 +01:00
else {
2022-01-04 15:34:03 +01:00
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();
2023-07-26 09:47:31 +01:00
/* console.log('DEVICE INFO ',info); */
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 () {
2023-05-26 14:23:37 +01:00
2021-08-31 13:46:39 +01:00
});
2021-10-07 16:22:31 +01:00
2021-08-31 13:46:39 +01:00
document.addEventListener('resume', function () {
2023-05-26 14:23:37 +01:00
2021-08-31 13:46:39 +01:00
});
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) {
2023-05-26 14:23:37 +01:00
}
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) {
2023-05-26 14:23:37 +01:00
}
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) {
2023-05-26 14:23:37 +01:00
}
2021-12-02 10:09:04 +01:00
2023-06-11 13:36:27 +01:00
// this.sqliteservice.deleteAllTables();
}
2023-09-14 11:58:24 +01:00
2023-10-09 14:15:21 +01:00
reloadComponent(self: boolean, urlToNavigateTo?: string) {
2023-09-14 11:58:24 +01:00
//skipLocationChange:true means dont update the url to / when navigating
2023-10-09 14:15:21 +01:00
console.log("Current route I am on:", this.router.url);
const url = self ? this.router.url : urlToNavigateTo;
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.router.navigate([`/${url}`]).then(() => {
console.log(`After navigation I am on:${this.router.url}`)
})
})
}
2023-09-14 11:58:24 +01:00
2023-09-22 15:17:25 +01:00
}