Fix agenda event list

This commit is contained in:
Peter Maquiran
2021-07-18 19:03:01 +01:00
parent 9fed35f8df
commit b6b95d929f
4 changed files with 301 additions and 173 deletions
+1 -1
View File
@@ -85,7 +85,7 @@
<calendar
class="calendar-component"
[eventSource]="calendarService.eventSource"
[eventSource]="eventSource"
[calendarMode]="calendar.mode"
[currentDate]="calendar.currentDate"
(onEventSelected)="onEventSelected($event)"
+300 -66
View File
@@ -27,7 +27,6 @@ import { DateAdapter } from '@angular/material/core';
import { ToastService } from 'src/app/services/toast.service';
import { eventSource } from 'src/app/models/agenda/eventSource';
import { eventListBox as eventListBoxComponent } from './eventListBox'
import { CalendarService } from 'src/app/store/calendar.service';
@Component({
selector: 'app-agenda',
templateUrl: './agenda.page.html',
@@ -81,6 +80,8 @@ export class AgendaPage implements OnInit {
/* List of events of our calendar */
eventSource : eventSource[] = []
/* The title of the calendar */
viewTitle: string;
@@ -161,8 +162,7 @@ export class AgendaPage implements OnInit {
private sanitizer: DomSanitizer,
authService: AuthService,
private dateAdapter: DateAdapter<any>,
private toastService: ToastService,
public calendarService: CalendarService
private toastService: ToastService
) {
this.dateAdapter.setLocale('es');
@@ -181,10 +181,6 @@ export class AgendaPage implements OnInit {
if(this.loggeduser.Profile == 'MDGPR') {
this.mobileComponent.showEventList = true;
}
setTimeout(()=>{
this.updateEventListBox()
}, 4000)
}
@@ -318,8 +314,22 @@ export class AgendaPage implements OnInit {
events.forEach(element => {
const startTimeSamp = new Date(element.startTime).toLocaleDateString()
const endTimeSamp = new Date(element.endTime).toLocaleDateString()
const endMinutes = new Date(element.endTime).getMinutes()
const endHours = new Date(element.endTime).getHours()
const endDay: number = new Date(element.endTime).getDate()
const startDay = new Date(element.startTime).getDate()
const profile_ = element.profile == 'md'? 'mdgpr': 'pr';
const eventtype = element.event.CalendarName;
// if (startTimeSamp < endTimeSamp && endDay == 29 && (endMinutes + endHours) == 0) {
// // console.log(id, (endMinutes + endHours))
// classs.push(`calendar-event-border`);
// }
classs.push(`calendar-event-border calendar-${profile_}-event-type-${eventtype}`);
@@ -335,6 +345,8 @@ export class AgendaPage implements OnInit {
get CalendarCurrentDay ():any {
/* console.log(this.viewDate.getDate(), '0_0') */
// console.log(this.viewDate.getDate(), '0_0')
return this.viewDate.getDate()
}
@@ -428,6 +440,7 @@ export class AgendaPage implements OnInit {
switch (this.segment) {
case "Combinado":
//Inicializa o array eventSource
//this.eventSource=[];
if(this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR' ) {
this.eventService.getAllMdEvents( momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59') ).then(
@@ -435,12 +448,42 @@ export class AgendaPage implements OnInit {
(response:any) => {
// calendar
this.calendarService.removeRange(startTime, endTime, 'md')
// this.eventSource=[];
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'md') {
return false
}
return true
})
const eventsList = response;
// loop
this.calendarService.pushEvent(response, 'md');
eventsList.forEach((element, eventIndex) => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: 'md',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', startTime, endTime, 'date')
const list = this.timelineFilter(this.timelineFilterState, eventsList, 'mdgpr');
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', startTime, endTime, 'date')
this.events = list;
// optional
this.TimelineMD = list;
console.log('TimelineMD', this.TimelineMD)
this.myCal.update();
this.myCal.loadEvents();
@@ -448,31 +491,60 @@ export class AgendaPage implements OnInit {
this.showLoader = false;
this.showTimeline = true;
}).finally(()=>{
this.showLoader = false;
})
}
else if(this.profile == "pr" && this.loggeduser.Profile == 'MDGPR') {
this.eventService.getAllSharedEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((response:any) => {
this.calendarService.removeRange(startTime, endTime, 'pr')
console.log('HERE PR');
this.eventService.getAllSharedEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then(
(response:any) => {
// calendar
this.calendarService.pushEvent(response, 'pr');
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
//this.eventSource=[];
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
return false
}
return true
})
const eventsList = response;
// calendar
eventsList.forEach((element, eventIndex) => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: 'pr',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
this.showLoader = false;
this.showTimeline = true;
}).finally(()=>{
this.showLoader = false;
})
})
}
else if(this.loggeduser.Profile == 'PR') {
@@ -483,13 +555,32 @@ export class AgendaPage implements OnInit {
// this.eventSource=[];
// clear the current month only
this.calendarService.removeRange(startTime, endTime, 'pr')
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
return false
}
return true
})
this.calendarService.pushEvent(response, 'pr');
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
const eventsList = response;
// calendar
eventsList.forEach((element, eventIndex) => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: 'pr',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -497,7 +588,7 @@ export class AgendaPage implements OnInit {
this.showLoader = false;
this.showTimeline = true;
}).finally(()=>{
this.showLoader = false;
})
@@ -509,15 +600,36 @@ export class AgendaPage implements OnInit {
if(this.profile == "mdgpr" && this.loggeduser.Profile == 'MDGPR') {
this.eventService.getAllMdPessoalEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((response:any) => {
this.calendarService.removeRange(startTime, endTime, 'md')
// this.eventSource=[];
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'md') {
return false
}
return true
})
const eventsList = response.filter(data => data.CalendarName == "Pessoal");
// loop
this.calendarService.pushEvent(eventsList, 'md');
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', startTime, endTime, 'date')
eventsList.forEach((element, eventIndex) => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: 'md',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -533,15 +645,30 @@ export class AgendaPage implements OnInit {
//this.eventSource=[];
// clear the current month only
this.calendarService.removeRange(startTime, endTime, 'pr')
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
return false
}
return true
})
const eventsList = response.filter(data => data.CalendarName == "Pessoal");
this.calendarService.pushEvent(eventsList, 'pr');
eventsList.forEach(element => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
profile: 'pr',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -563,14 +690,32 @@ export class AgendaPage implements OnInit {
this.eventService.getAllMdEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((res:any) => {
this.calendarService.removeRange(startTime, endTime, 'md')
// this.eventSource=[];
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'md') {
return false
}
return true
})
const eventsList = res.filter(data => data.CalendarName == "Oficial");
this.calendarService.pushEvent(eventsList, 'md');
eventsList.forEach(element => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
profile: 'md',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', startTime, endTime, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -586,14 +731,31 @@ export class AgendaPage implements OnInit {
// this.eventSource=[];
this.calendarService.removeRange(startTime, endTime, 'pr')
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
return false
}
return true
})
const eventsList = res.filter(data => data.CalendarName == "Oficial");
this.calendarService.pushEvent(eventsList, 'pr');
eventsList.forEach(element => {
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
profile: 'pr',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -612,18 +774,43 @@ export class AgendaPage implements OnInit {
let counter = 0;
if(this.loggeduser.Profile == 'MDGPR') {
console.log('MDGPR');
this.eventService.getAllMdEvents( momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59') ).then( (response:any) => {
let eventsList = response;
this.calendarService.removeRange(startTime, endTime, 'md')
// clear the current month only
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'md') {
return false
}
return true
})
// loop
this.calendarService.pushEvent(eventsList, 'md');
eventsList.forEach((element, eventIndex) => {
// calendar
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: this.EventTretment({
startTime: element.StartDate,
endTime: element.EndDate
}),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile: 'md',
id: element.EventId,
});
});
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', startTime, endTime, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -646,13 +833,31 @@ export class AgendaPage implements OnInit {
let eventsList = response;
// clear the current month only
this.calendarService.removeRange(startTime, endTime, 'pr')
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
return false
}
return true
})
this.calendarService.pushEvent(eventsList, 'pr');
eventsList.forEach((element, eventIndex) => {
// calendar
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile:'pr',
id: element.EventId
});
});
this.TimelinePRList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.TimelinePRList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -671,6 +876,7 @@ export class AgendaPage implements OnInit {
}
})
} else {
this.eventService.getAllPrEvents(momentG(new Date(startTime),'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime),'yyyy-MM-dd 23:59:59')).then((response:any) => {
@@ -685,13 +891,36 @@ export class AgendaPage implements OnInit {
}
// clear the current month only
this.calendarService.removeRange(startTime, endTime, 'pr')
this.eventSource = this.eventSource.filter((e)=> {
if(new Date(startTime).getTime() <= new Date(e.startTime).getTime() &&
new Date(endTime).getTime() >= new Date(e.endTime).getTime() && e.profile == 'pr') {
console.log('remove from agenda')
return false
}
return true
})
this.calendarService.pushEvent(eventsList, 'pr');
eventsList.forEach((element, eventIndex) => {
this.TimelinePRList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', startTime, endTime, 'date')
// calendar
this.eventSource.push({
title: element.Subject,
startTime: new Date(element.StartDate),
endTime: new Date(element.EndDate),
allDay: false,
event: element,
calendarName: element.CalendarName,
profile:'pr',
id: element.EventId,
});
});
this.TimelinePR = this.timelineFilter(this.timelineFilterState, eventsList, 'pr');
this.TimelinePRList = this.eventListBoxComponent.list(this.eventSource, 'pr', startTime, endTime, 'date')
this.myCal.update();
this.myCal.loadEvents();
@@ -715,8 +944,8 @@ export class AgendaPage implements OnInit {
}
updateEventListBox() {
this.TimelinePRList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date')
this.TimelinePRList = this.eventListBoxComponent.list(this.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date')
}
eventListBox(list, nice?) {
@@ -746,12 +975,17 @@ export class AgendaPage implements OnInit {
if (new Date(startDate).toLocaleDateString() != new Date(endDate).toLocaleDateString()) {
console.log(new Date(startDate).toLocaleDateString(),'!=' , new Date(endDate).toLocaleDateString())
console.log(startDate.toISOString(),'iso' , endDate.toISOString() )
console.log(new Date(startDate).toLocaleTimeString('pt'),'time' , new Date(endDate).toLocaleTimeString('pt'))
// difference
const diffTime = Math.abs(endDate - startDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays <= 150 && !event.event.IsAllDayEvent ) {
console.log(event)
if (diffDays >= 1) {
@@ -914,13 +1148,13 @@ export class AgendaPage implements OnInit {
if(this.profile == "mdgpr") {
this.profile ="pr";
this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'pr', this.rangeStartDate, this.rangeEndDate, 'date')
}
else {
this.profile ="mdgpr";
this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
this.TimelineMDList = this.eventListBoxComponent.list(this.calendarService.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date')
this.TimelineMDList = this.eventListBoxComponent.list(this.eventSource, 'md', this.rangeStartDate, this.rangeEndDate, 'date')
}
}
@@ -983,7 +1217,7 @@ export class AgendaPage implements OnInit {
// open component
async viewEventDetail(eventId:any) {
console.log('View event '+eventId)
this.router.navigate(['/home/agenda', eventId, 'agenda']);
/* console.log(this.profile);
@@ -1225,7 +1459,7 @@ export class AgendaPage implements OnInit {
}
async showEventBox(event) {
if ( event.event.CalendarName == this.segment || this.segment == 'Combinado') {
return true
}