merge with developer-prod changes

This commit is contained in:
Eudes Inácio
2023-11-07 12:07:54 +01:00
parent f4e0d56946
commit 3485ac8cf0
4 changed files with 268 additions and 120 deletions
+163 -19
View File
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { CustomCalendarEvent, EventListStore } from 'src/app/models/agenda/AgendaEventList';
import { DateService } from '../date.service';
import { momentG } from 'src/plugin/momentG';
@Injectable({
providedIn: 'root'
@@ -9,6 +10,7 @@ export class ListBoxService {
height = "unset"
constructor(
private dateService: DateService
){}
@@ -35,7 +37,7 @@ export class ListBoxService {
daysBetween(){ }
list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, {segment = 'Combinado', selectedDate= null}) {
list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, {segment = 'Combinado', selectedDate= null}): Year[] {
// // filter range
// if(selectedDate) {
@@ -45,7 +47,6 @@ export class ListBoxService {
// )
// }
if(segment!='Combinado') {
eventSource = this.filterSegment(eventSource, segment)
}
@@ -54,11 +55,32 @@ export class ListBoxService {
// eventSource = this.filterProfile(eventSource, profile)
// }
let newStracture:CustomCalendarEvent[];
let newStracture:CustomCalendarEvent[];
newStracture = this.encapsulation(eventSource);
return this.display(newStracture, selectedDate)
// const object = {}
// for (const e of newStracture.reverse()) {
// if(!object[momentG(new Date(e.start), 'MMMM yyyy')]) {
// object[momentG(new Date(e.start), 'MMMM yyyy')] = []
// }
// object[momentG(new Date(e.start), 'MMMM yyyy')].push(e)
// }
// console.log({object})
// const daysStringNum = Object.keys(object).reverse()
// const daysObject = {}
// for(const day of daysStringNum) {
// daysObject[day] = object[day]
// }
// console.log({daysObject})
return this.display(newStracture, selectedDate).year
// console.log({daysObject})
@@ -74,12 +96,19 @@ export class ListBoxService {
// return daysObject
}
sortArrayISODate(myArray: any): any[] {
return myArray.sort((a,b) =>
Date.parse(b.start )
-
Date.parse(a.start))
}
display(list: CustomCalendarEvent[], selectedDate) {
let days = {};
const year: Year[] = []
list.forEach( (event:CustomCalendarEvent, index) => {
this.sortArrayISODate(list).reverse().forEach( (event:CustomCalendarEvent, index) => {
var startDate: any = new Date(event.start);
@@ -109,7 +138,7 @@ export class ListBoxService {
const StartEvent = this.transForm(event, {startMany: true, endMany: false, middle: false})
if(this.CanPush(event, selectedDate)) days[day].push(StartEvent)
if(this.CanPush(event, selectedDate)) {days[day].push(StartEvent); this.push(StartEvent, year)}
let i = 1;
@@ -135,28 +164,28 @@ export class ListBoxService {
// last push
const EndEvent = this.transForm(event, {startMany: false, endMany: true, middle: false})
if(this.CanPush(event, selectedDate)) days[otherDays].push(EndEvent)
if(this.CanPush(event, selectedDate)) {days[otherDays].push(EndEvent) ; this.push(event, year)}
} else {
const EndEvent = this.transForm(event, {startMany: false,endMany: true, middle: true})
if(this.CanPush(event, selectedDate)) days[otherDays].push(EndEvent)
if(this.CanPush(event, selectedDate)) {days[otherDays].push(EndEvent) ; this.push(event, year)}
}
days[otherDays] = days[otherDays]
days[otherDays] = days[otherDays].reverse()
}
} else {
if(this.CanPush(event, selectedDate)) days[day].push(event)
if(this.CanPush(event, selectedDate)) { days[day].push(event) ; this.push(event, year) }
}
} else {
if(this.CanPush(event, selectedDate)) days[day].push(event)
if(this.CanPush(event, selectedDate)) { days[day].push(event) ; this.push(event, year) }
}
} else {
if(this.CanPush(event, selectedDate) && diffDays != 2) days[day].push(event)
if(this.CanPush(event, selectedDate) && diffDays != 2) { days[day].push(event) ; this.push(event, year) }
}
//
@@ -173,18 +202,69 @@ export class ListBoxService {
})
return days
return {days, year}
}
push(event: any, year: Year[]) {
const date = new Date(event.start)
const yearName = momentG(new Date(date), 'yyyy')
const monthName = momentG(new Date(date), 'MMMM')
const dayName = momentG(new Date(date), 'dd')
let YearIndex = year.findIndex( x => x.yearInfo.yearName == yearName)
if(YearIndex == -1) {
YearIndex = year.push({
yearInfo: {
yearName: yearName
},
months: []
})
YearIndex--
}
let MonthNameIndex = year[YearIndex].months.findIndex( x => x.monthInfo.monthName == monthName)
if(MonthNameIndex == -1) {
MonthNameIndex = year[YearIndex].months.push({
monthInfo: {
monthName: monthName
},
days: []
})
MonthNameIndex --
}
let DayNameIndex = year[YearIndex].months[MonthNameIndex].days.findIndex( x => x.daysInfo.dayName == dayName)
if(DayNameIndex == -1) {
year[YearIndex].months[MonthNameIndex].days.push({
daysInfo: {
dayName: dayName
},
events: [event]
})
} else {
year[YearIndex].months[MonthNameIndex].days[DayNameIndex].events.push(event)
}
}
CanPush(event: any, selectedDate: Date) {
const limite = this.endOfMonth(selectedDate)
limite.setDate(limite.getDate() + 10)
limite.setHours(0)
return new Date(event.start).getFullYear() >= selectedDate.getFullYear() &&
new Date(event.start).getMonth() >= selectedDate.getMonth() &&
new Date(event.start).getTime() >= selectedDate.getTime() &&
new Date(event.start).getTime() <= limite.getTime()
return (selectedDate.getTime() <= new Date(event.start).getTime() || selectedDate.getTime() <= new Date(event.end).getTime()) &&
(limite.getTime() >= new Date(event.start).getTime() || limite.getTime() >= new Date(event.end).getTime())
}
encapsulation(eventsList:EventListStore[]): CustomCalendarEvent[] {
@@ -262,3 +342,67 @@ export class ListBoxService {
return date;
}
}
interface DayInfo {
// Define properties for dayInfo here
dayName: string
}
interface Day {
// Define properties for day here
}
interface Month {
monthInfo: {
monthName: string
// Define properties for yearInfo inside months here
}
days: {
daysInfo: DayInfo;
events: Day[];
}[]
}
interface Year {
yearInfo: {
yearName: string
// Define properties for yearInfo here
};
months: Month[];
}
const years: Year[] = [
{
yearInfo: {
yearName: ""
// Define properties for yearInfo inside the first year here
},
months: [
{
monthInfo: {
monthName: "",
// Define properties for yearInfo inside the first month here
},
days: [
{
daysInfo: {
dayName: "",
// Define properties for dayInfo inside the first day here
},
events: [
{
// Define properties for the first day here
},
],
}
],
},
// Add more months here as needed
],
},
// Add more years here as needed
];
years[0].months[0].days[0].events