mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
226 lines
6.5 KiB
TypeScript
226 lines
6.5 KiB
TypeScript
import { Component, OnInit, Input, EventEmitter, Output } 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 { NavigationEnd, Router } from '@angular/router';
|
|
import { UserSession } from 'src/app/models/user.model';
|
|
import { SortService } from 'src/app/services/functions/sort.service';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.service';
|
|
import { environment } from 'src/environments/environment';
|
|
import { AgendaDataRepositoryService } from 'src/app/module/agenda/data/repository/agenda-data-repository.service';
|
|
import { EventToApproveList } from 'src/app/models/entiry/agenda/eventToApproveList';
|
|
import { RoleIdService } from 'src/app/services/role-id.service'
|
|
import { map } from 'rxjs/operators';
|
|
import { Observable } from 'rxjs';
|
|
import { TableSharedCalendar } from 'src/app/module/agenda/data/data-source/agenda-local-data-source.service';
|
|
import { EEventFilterStatus } from 'src/app/module/agenda/data/dto/enums';
|
|
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
|
import { isHttpError } from 'src/app/services/http.service';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
@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
|
|
|
|
showLoader: boolean;
|
|
eventsList: EventToApproveList = []
|
|
|
|
eventPerson: EventPerson;
|
|
eventBody: EventBody;
|
|
categories: string[];
|
|
serialnumber:string;
|
|
loggeduser: UserSession;
|
|
segment:string;
|
|
eventoaprovacaostore = EventoAprovacaoStore;
|
|
environment = environment
|
|
color: 'pr' | 'mdgpr'
|
|
SessionStore = SessionStore;
|
|
|
|
@Input() profile:string;
|
|
@Input() showComponent:string;
|
|
@Output() cloneAllmobileComponent = new EventEmitter<any>();
|
|
@Output() approveEventDismiss = new EventEmitter<any>();
|
|
sharedCalendar: Observable<TableSharedCalendar[]>
|
|
selectedUserCalendar:any;
|
|
|
|
constructor(
|
|
private processes:ProcessesService,
|
|
private router: Router,
|
|
private sortService: SortService,
|
|
public AgendaDataRepositoryService: AgendaDataRepositoryService,
|
|
public RoleIdService: RoleIdService,
|
|
private toastService: ToastService,
|
|
) {
|
|
this.loggeduser = SessionStore.user;
|
|
|
|
// 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) => {
|
|
const priorityA = rolePriorities[a.roleId] || Infinity;
|
|
const priorityB = rolePriorities[b.roleId] || Infinity;
|
|
return priorityA - priorityB;
|
|
}))
|
|
)
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
ngAfterViewInit(): void {}
|
|
|
|
ngOnInit() {
|
|
|
|
const pathname = window.location.pathname
|
|
|
|
this.router.events.forEach((event) => {
|
|
if(event instanceof NavigationEnd && event.url == pathname) {
|
|
this.LoadToApproveEvents();
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnChanges() {
|
|
this.LoadToApproveEvents();
|
|
setTimeout(() => {
|
|
this.LoadToApproveEventsNoLoader();
|
|
}, 3000)
|
|
}
|
|
|
|
segmentChanged(ev: any) {
|
|
this.LoadToApproveEvents();
|
|
}
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
@XTracerAsync({name:'EventListPageShared/LoadToApproveEvents', bugPrint: true})
|
|
async LoadToApproveEvents(tracing?: TracingType) {
|
|
|
|
this.showLoader = true;
|
|
const segment = this.selectedUserCalendar
|
|
|
|
|
|
let userId;
|
|
|
|
if(this.selectedUserCalendar == SessionStore.user.UserId) {
|
|
// color
|
|
if(SessionStore.user.Profile == 'PR') {
|
|
this.color = 'pr'
|
|
} else {
|
|
this.color = 'mdgpr'
|
|
}
|
|
userId = SessionStore.user.UserId
|
|
|
|
} else if(segment) {
|
|
this.color = 'pr'
|
|
userId = this.selectedUserCalendar
|
|
}
|
|
|
|
if(userId) {
|
|
let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({
|
|
userId,
|
|
status: EEventFilterStatus.Pending
|
|
}, tracing)
|
|
if(allEvents.isOk()) {
|
|
|
|
tracing.setAttribute('outcome', 'success')
|
|
|
|
if(allEvents.value.length >= 1) {
|
|
this.eventsList = this.sortService.sortArrayByDate(allEvents.value).reverse();
|
|
this.eventoaprovacaostore.save(this.selectedUserCalendar, this.eventsList)
|
|
} else {
|
|
this.eventoaprovacaostore.save(this.selectedUserCalendar, [])
|
|
}
|
|
} else {
|
|
|
|
tracing.setAttribute('outcome', 'failed')
|
|
|
|
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. #3')
|
|
console.log(allEvents.error)
|
|
}
|
|
|
|
this.eventsList = [];
|
|
}
|
|
|
|
this.showLoader = false;
|
|
} else {
|
|
this.showLoader = false;
|
|
tracing.setAttribute('run', 'to early')
|
|
console.warn('calling to early eventlistpageshared/loadtoapproveevents')
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
async LoadToApproveEventsNoLoader() {
|
|
|
|
this.LoadToApproveEvents()
|
|
|
|
}
|
|
|
|
async openApproveModal(eventSerialNumber, data) {
|
|
if (window.innerWidth <= 1024) {
|
|
if (this.router.url == '/home/agenda/event-list') {
|
|
this.router.navigate(['/home/agenda/event-list/approve-event', eventSerialNumber, 'agenda'])
|
|
}
|
|
else if (this.router.url == '/home/gabinete-digital/event-list') {
|
|
this.router.navigate(['/home/gabinete-digital/event-list/approve-event', eventSerialNumber, 'gabinete-digital'])
|
|
}
|
|
}
|
|
else {
|
|
this.approveEventDismiss.emit({
|
|
"serialNumber": eventSerialNumber,
|
|
"action": "Aprovar",
|
|
"saveData": data
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
refreshing() {
|
|
this.LoadToApproveEvents();
|
|
}
|
|
|
|
doRefresh(event) {
|
|
this.LoadToApproveEvents();
|
|
|
|
setTimeout(() => {
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 2000);
|
|
}
|
|
|
|
close() {
|
|
|
|
this.cloneAllmobileComponent.emit();
|
|
}
|
|
|
|
|
|
}
|