mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
331 lines
9.3 KiB
TypeScript
331 lines
9.3 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
import { ProcessesService } from 'src/app/services/processes.service';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { ApproveEventModalPage } from './approve-event-modal/approve-event-modal.page';
|
|
import { NavigationStart, Router } from '@angular/router';
|
|
import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.service';
|
|
import { TaskService } from 'src/app/services/task.service'
|
|
import { BackgroundService } from '../../../services/background.service';
|
|
import { SortService } from 'src/app/services/functions/sort.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { RouteService } from 'src/app/services/route.service';
|
|
import { EventsService } from 'src/app/services/events.service';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { environment } from 'src/environments/environment';
|
|
import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service';
|
|
import { map } from 'rxjs/operators';
|
|
import { Observable } from 'rxjs';
|
|
import { TableSharedCalendar } from 'src/app/services/Repositorys/Agenda/agenda-local-data-source.service';
|
|
import { RoleIdService } from 'src/app/services/role-id.service'
|
|
import { EEventFilterStatus } from 'src/app/services/Repositorys/Agenda/model/enums';
|
|
import { isHttpError } from 'src/app/services/http.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-event-list',
|
|
templateUrl: './event-list.page.html',
|
|
styleUrls: ['./event-list.page.scss'],
|
|
})
|
|
export class EventListPage implements OnInit {
|
|
// [desktop] event list to approve
|
|
|
|
profile: string;
|
|
segment: any;
|
|
showLoader: boolean;
|
|
eventPerson: EventPerson;
|
|
eventBody: EventBody;
|
|
categories: string[];
|
|
serialnumber: string;
|
|
|
|
skeletonLoader = true
|
|
eventoaprovacaostore = EventoAprovacaoStore;
|
|
color: 'pr' | 'mdgpr'
|
|
environment = environment
|
|
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
|
|
showFilter = false
|
|
|
|
showSearch = false
|
|
searchSubject = ''
|
|
list = []
|
|
ordinance: string = 'old'
|
|
|
|
listSubscription : {
|
|
delete(): void;
|
|
}
|
|
|
|
SessionStore = SessionStore;
|
|
sharedCalendar: Observable<TableSharedCalendar[]>
|
|
selectedUserCalendar:any;
|
|
|
|
constructor(
|
|
private processes: ProcessesService,
|
|
private modalController: ModalController,
|
|
private router: Router,
|
|
private sortService: SortService,
|
|
private backgroundservice: BackgroundService,
|
|
public ThemeService: ThemeService,
|
|
private RouteService: RouteService,
|
|
public eventService: EventsService,
|
|
public TaskService: TaskService,
|
|
public AgendaDataRepositoryService: AgendaDataRepositoryService,
|
|
public RoleIdService: RoleIdService,
|
|
private toastService: ToastService,
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
|
|
if(window.location.pathname.includes('gabinete-digital')) {
|
|
this.showFilter = true
|
|
}
|
|
|
|
|
|
this.eventService.onCalendarFinishLoad.subscribe(() => {
|
|
if(!this.segment) {
|
|
if(this.eventService.calendarNamesAry.includes('Meu calendario')) {
|
|
this.segment = 'Meu calendario';
|
|
} else {
|
|
this.segment = this.eventService.calendarNamesAry[0].OwnerUserId
|
|
}
|
|
|
|
// select pr by default
|
|
const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')
|
|
if(pr) {
|
|
this.segment = pr.OwnerUserId
|
|
}
|
|
|
|
this.dynamicSearch()
|
|
} else {
|
|
this.dynamicSearch()
|
|
}
|
|
})
|
|
|
|
this.listSubscription = this.eventoaprovacaostore.registerCallback({
|
|
id: import.meta.url,
|
|
funx:() => {
|
|
|
|
this.dynamicSearch()
|
|
|
|
}
|
|
})
|
|
|
|
|
|
|
|
const location = window.location
|
|
const pathname = location.pathname + location.search
|
|
|
|
this.LoadToApproveEvents()
|
|
|
|
this.router.events.forEach((event) => {
|
|
if (event instanceof NavigationStart && event.url.startsWith(pathname)) {
|
|
if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
|
|
this.refreshing()
|
|
} else {
|
|
this.LoadToApproveEvents()
|
|
}
|
|
}
|
|
});
|
|
|
|
this.backgroundservice.registerBackService('Online', () => {
|
|
this.LoadToApproveEvents();
|
|
});
|
|
|
|
window.onresize = (event) => {
|
|
// if not mobile remove all component
|
|
if (window.innerWidth < 701) {
|
|
this.modalController.dismiss();
|
|
}
|
|
};
|
|
|
|
|
|
// Define the role priorities
|
|
const rolePriorities: { [key: number]: number } = {
|
|
100000014: 1, // Presidente da República
|
|
100000011: 2, // Vice Presidente (example role ID)
|
|
// Add other roles with their priorities here
|
|
};
|
|
|
|
this.sharedCalendar = this.AgendaDataRepositoryService.getShareCalendarItemsLive().pipe(
|
|
map(data => data.sort((a, b) => {
|
|
console.log('Raw data:', data); // Debug line
|
|
const priorityA = rolePriorities[a.roleId] || Infinity;
|
|
const priorityB = rolePriorities[b.roleId] || Infinity;
|
|
return priorityA - priorityB;
|
|
}))
|
|
)
|
|
|
|
this.eventService.onCalendarFinishLoad.subscribe(async() => {
|
|
this.setCalendarByDefault()
|
|
})
|
|
|
|
}
|
|
|
|
async setCalendarByDefault() {
|
|
const data = await this.AgendaDataRepositoryService.geCalendars()
|
|
|
|
const prObject = data.find(e => e?.roleId == 100000014)
|
|
|
|
if(prObject) {
|
|
this.selectedUserCalendar = prObject.wxUserId
|
|
} else {
|
|
this.selectedUserCalendar = SessionStore.user.UserId
|
|
}
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.listSubscription.delete()
|
|
}
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
|
}
|
|
|
|
reorderList(orderBy: string) {
|
|
|
|
this.ordinance = orderBy;
|
|
|
|
this.dynamicSearch();
|
|
}
|
|
|
|
|
|
async dynamicSearch() {
|
|
|
|
if(this.showSearch && this.searchSubject) {
|
|
|
|
const list = this.eventoaprovacaostore.get(this.segment).filter((task) => {
|
|
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
|
|
subject = subject.toLowerCase();
|
|
return subject.includes(this.searchSubject.toLowerCase())
|
|
})
|
|
|
|
this.list = this.TaskService.reorderList(this.ordinance, list)
|
|
} else {
|
|
const list = this.eventoaprovacaostore.get(this.segment)
|
|
|
|
this.list = this.TaskService.reorderList(this.ordinance, list)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
segmentChanged(ev: any) {
|
|
this.LoadToApproveEvents();
|
|
}
|
|
|
|
@XTracerAsync({name:'EventListPage/LoadToApproveEvents', bugPrint: true})
|
|
async LoadToApproveEvents(tracing?: TracingType) {
|
|
console.log('aprove event')
|
|
this.showLoader = true;
|
|
this.skeletonLoader = true
|
|
|
|
const segment: any = this.segment
|
|
let userId;
|
|
|
|
if(this.segment == 'Meu calendario') {
|
|
if(SessionStore.user.Profile == 'PR') {
|
|
this.color = 'pr'
|
|
} else {
|
|
this.color = 'mdgpr'
|
|
}
|
|
userId = SessionStore.user.UserId
|
|
|
|
} else if(segment) {
|
|
this.color = 'pr'
|
|
userId = segment
|
|
}
|
|
|
|
|
|
let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({
|
|
userId,
|
|
status: EEventFilterStatus.Pending
|
|
}, tracing)
|
|
|
|
if(allEvents.isOk()) {
|
|
tracing.setAttribute('outcome', 'success')
|
|
|
|
if(allEvents.value.length >= 1) {
|
|
const eventsList = this.sortService.sortArrayByDate(allEvents.value).reverse();
|
|
this.eventoaprovacaostore.save(segment, eventsList)
|
|
} else {
|
|
this.eventoaprovacaostore.save(segment, [])
|
|
}
|
|
} else {
|
|
|
|
tracing.setAttribute('outcome', 'failed')
|
|
tracing.bugFlag()
|
|
if(!isHttpError(allEvents.error)) {
|
|
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #4')
|
|
}
|
|
this.eventoaprovacaostore.save(segment, [])
|
|
// this.showLoader = false;
|
|
}
|
|
|
|
this.showLoader = false;
|
|
this.skeletonLoader = false
|
|
|
|
}
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
async openApproveModal(eventSerialNumber, event) {
|
|
const modal = await this.modalController.create({
|
|
component: ApproveEventModalPage,
|
|
componentProps: {
|
|
serialNumber: eventSerialNumber,
|
|
},
|
|
cssClass: 'event-list cal-modal modal modal-desktop',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
}
|
|
|
|
goToEventToApproveDetail(serialNumber: string) {
|
|
|
|
|
|
/* let navigationExtras: NavigationExtras = {
|
|
queryParams: {
|
|
"serialNumber": serialNumber,
|
|
}
|
|
}; */
|
|
|
|
if (this.router.url == '/home/agenda/event-list') {
|
|
this.router.navigate(['/home/agenda/event-list/approve-event', serialNumber, 'agenda'])
|
|
}
|
|
else if (this.router.url == '/home/gabinete-digital/event-list') {
|
|
this.router.navigate(['/home/gabinete-digital/event-list/approve-event', serialNumber, 'gabinete-digital'])
|
|
}
|
|
|
|
//this.router.navigate(['/home/gabinete-digital/event-list/approve-event'], navigationExtras)
|
|
}
|
|
|
|
refreshing() {
|
|
setTimeout(() => {
|
|
this.LoadToApproveEvents();
|
|
}, 1000);
|
|
}
|
|
|
|
doRefresh(event) {
|
|
|
|
setTimeout(() => {
|
|
this.LoadToApproveEvents();
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 1000);
|
|
}
|
|
|
|
|
|
goBack() {
|
|
this.RouteService.goBack()
|
|
}
|
|
|
|
|
|
}
|