From 3485ac8cf00e931ed4380507c1c4f5359d123805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 7 Nov 2023 12:07:54 +0100 Subject: [PATCH] merge with developer-prod changes --- src/app/pages/agenda/agenda.page.html | 46 ++--- src/app/pages/agenda/agenda.page.scss | 9 +- src/app/pages/agenda/agenda.page.ts | 151 ++++++++-------- src/app/services/agenda/list-box.service.ts | 182 ++++++++++++++++++-- 4 files changed, 268 insertions(+), 120 deletions(-) diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index a02f450b3..b09f566ec 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -59,10 +59,10 @@
-
PR
+
PR
MDGPR
-
Agenda do {{calendars.Fullname}}
-
+
Agenda do {{calendars.Fullname}}
+
@@ -71,9 +71,9 @@
-
{{ environment.agendaPR}}
+
{{ environment.agendaPR}}
{{ environment.agendaVP}}
-
Agenda do {{calendars.Fullname}}
+
Agenda do {{calendars.Fullname}}
Minha agenda
@@ -90,7 +90,7 @@
-
-
+
- - +
+
+ +
+ + -
+
-
-
- {{ TimelineDay(events.key)}}
{{ events.value[0].start | date: 'MMMM'}}
-
+
+ {{ day.daysInfo.dayName }}
{{month.monthInfo.monthName}}
+
-
- -
+
-
Início
+
Início
Fim
{{event.event.StartDate | date: 'HH:mm'}}
@@ -263,10 +264,11 @@
{{SessionStore.user.FullName}}
{{eventService.getCalendarOwnNameByCalendarId(event.event.CalendarId)}}
+
-
+
diff --git a/src/app/pages/agenda/agenda.page.scss b/src/app/pages/agenda/agenda.page.scss index 02ecb1522..94edd8f82 100644 --- a/src/app/pages/agenda/agenda.page.scss +++ b/src/app/pages/agenda/agenda.page.scss @@ -875,13 +875,12 @@ $font-size: rem(15); font-weight: bold !important; } -.ss-timeline > :nth-child(2) .dayShow { - display: none; +.header-day .dayShow:nth-child(1) { + display: none !important; } -.ss-timeline > :nth-child(1) .dayShow { - margin-top: 0px !important; -} + + .calendar-options { position: relative; diff --git a/src/app/pages/agenda/agenda.page.ts b/src/app/pages/agenda/agenda.page.ts index f90403029..e9f89a0a2 100644 --- a/src/app/pages/agenda/agenda.page.ts +++ b/src/app/pages/agenda/agenda.page.ts @@ -105,7 +105,7 @@ export class AgendaPage implements OnInit { selectedEvent: Event; selectedEventId: string | number; - selectedEventCalendarId : string | number; + selectedEventCalendarId: string | number; postEvent: any; // temporary data @@ -213,7 +213,7 @@ export class AgendaPage implements OnInit { } else if (this.loggeduser.Profile == 'PR') { this.profile = "pr"; } else { - if(this.eventService.usersCalendarIds.length >= 2) { + if (this.eventService.usersCalendarIds.length >= 2) { this.profile = "mdgpr"; } else if (this.eventService.hasOwnCalendar) { this.profile = "mdgpr"; @@ -309,8 +309,8 @@ export class AgendaPage implements OnInit { let weekNum = 0; function Week(a) { - for(let b of a.querySelectorAll('td')) { - if(!b.className.includes('text-muted')) { + for (let b of a.querySelectorAll('td')) { + if (!b.className.includes('text-muted')) { weekNum++; return true } @@ -320,18 +320,18 @@ export class AgendaPage implements OnInit { const dayBoxHeight = document.querySelector('.monthview-container .swiper-container .swiper-slide-active table tbody tr td').clientHeight const weeks = document.querySelectorAll('.monthview-container .swiper-container .swiper-slide-active table tbody tr'); - for (let week of weeks as any ){ + for (let week of weeks as any) { Week(week) } this.showCalendar = true - this.listBoxService.height = (weekNum * dayBoxHeight) +'px' + this.listBoxService.height = (weekNum * dayBoxHeight) + 'px' - if(dayBoxHeight == 0) { + if (dayBoxHeight == 0) { this.weekToShow() } } catch (e) { - setTimeout(()=> { + setTimeout(() => { this.weekToShow() }, 100) } @@ -339,8 +339,8 @@ export class AgendaPage implements OnInit { } setCalendarByDefault() { - if(!this.CalendarName) { - if(this.eventService.calendarNamesAry.includes('Meu calendario')) { + if (!this.CalendarName) { + if (this.eventService.calendarNamesAry.includes('Meu calendario')) { this.CalendarName = 'Meu calendario'; } else { this.CalendarName = this.eventService.calendarNamesAry[0] @@ -421,13 +421,16 @@ export class AgendaPage implements OnInit { onDropDownScrollWeal() { - setTimeout(() => { - document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); + try { setTimeout(() => { - document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[1].scrollIntoView({ behavior: 'smooth', block: 'center' }); - }, 300) - }, 10) - + document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); + setTimeout(() => { + document.querySelector('.dropdown-scroll-weel').querySelectorAll('.active')[1].scrollIntoView({ behavior: 'smooth', block: 'center' }); + }, 300) + }, 10) + } catch (error) { + console.log(error) + } } @@ -445,7 +448,7 @@ export class AgendaPage implements OnInit { this.rangeStartDate = ev.startTime; this.rangeEndDate = ev.endTime; - if(this.currentMoth.rangeEndDate == null) { + if (this.currentMoth.rangeEndDate == null) { this.currentMoth = { rangeStartDate: ev.startTime, rangeEndDate: ev.endTime @@ -579,7 +582,7 @@ export class AgendaPage implements OnInit { loadRangeEvents(startTime: Date, endTime: Date) { this.weekToShow() - if(!this.eventService.hasAnyCalendar) { + if (!this.eventService.hasAnyCalendar) { return false } @@ -589,9 +592,9 @@ export class AgendaPage implements OnInit { this.showLoader = true; const index = `${startTime}${endTime}` - if(!this.loadRequest[index]) { - this.loadRequest[index] = {startTime, endTime} - this.loadRequestHistory[index] = {lastTimeUpdate: new Date()} + if (!this.loadRequest[index]) { + this.loadRequest[index] = { startTime, endTime } + this.loadRequestHistory[index] = { lastTimeUpdate: new Date() } this.loadRangeEventRun(startTime, endTime) } else { @@ -606,7 +609,7 @@ export class AgendaPage implements OnInit { loadRangeEventRun(startTime: Date, endTime: Date) { - if(SessionStore.user.OwnerCalendars.length == 0 && SessionStore.user.SharedCalendars.length == 0) { + if (SessionStore.user.OwnerCalendars.length == 0 && SessionStore.user.SharedCalendars.length == 0) { return false } @@ -628,16 +631,16 @@ export class AgendaPage implements OnInit { } - let load = 0; + let load = 0; - for ( const selectedCalendar of selectedCalendarIds) { + for (const selectedCalendar of selectedCalendarIds) { this.eventService.getEventsByCalendarId(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59'), selectedCalendar.CalendarId).then((response: any) => { let label; - if(SessionStore.user.Profile == 'PR') { + if (SessionStore.user.Profile == 'PR') { label = "pr" - } else if(SessionStore.user.OwnerCalendars.find(e => e.CalendarId == selectedCalendar.CalendarId)) { + } else if (SessionStore.user.OwnerCalendars.find(e => e.CalendarId == selectedCalendar.CalendarId)) { label = 'md' } else { label = "pr" @@ -656,7 +659,7 @@ export class AgendaPage implements OnInit { this.deleteLoadRangeEvent(startTime, endTime); load++ - if(load == selectedCalendarIds.length) { + if (load == selectedCalendarIds.length) { this.showLoader = false; } @@ -669,9 +672,9 @@ export class AgendaPage implements OnInit { selectedAgenda = {} - getSelectedAgendaCalendars () { + getSelectedAgendaCalendars() { - if(this.CalendarName == 'PR+MDGPR') { + if (this.CalendarName == 'PR+MDGPR') { let result = this.SessionStore.user.OwnerCalendars @@ -682,46 +685,46 @@ export class AgendaPage implements OnInit { return result.concat(join) } else { - const calendar = this.eventService.calendarNamesType[this.CalendarName]; - let Oficial = calendar?.['OficialId'] - let Pessoal = calendar?.['PessoalId'] + const calendar = this.eventService.calendarNamesType[this.CalendarName]; + let Oficial = calendar?.['OficialId'] + let Pessoal = calendar?.['PessoalId'] - if(Oficial && Pessoal) { + if (Oficial && Pessoal) { - return [ - { - CalendarId : Oficial, - OwnerId: calendar.OwnerId, - CalendarName: calendar.CalendarName - }, - { - OwnerId: calendar.OwnerId, - CalendarId : Pessoal, - CalendarName: calendar.CalendarName + return [ + { + CalendarId: Oficial, + OwnerId: calendar.OwnerId, + CalendarName: calendar.CalendarName + }, + { + OwnerId: calendar.OwnerId, + CalendarId: Pessoal, + CalendarName: calendar.CalendarName + } + ] + + } else if (Oficial) { + try { + return [{ + OwnerId: calendar.OwnerId, + CalendarId: Oficial, + CalendarName: calendar.CalendarName + }] + } catch (error) { + console.log(error) + } + } else { + try { + return [{ + OwnerId: calendar.OwnerId, + CalendarId: Pessoal, + CalendarName: calendar.CalendarName + }] + } catch (error) { + console.log(error) } - ] - - } else if (Oficial) { - try { - return [{ - OwnerId: calendar.OwnerId, - CalendarId : Oficial, - CalendarName: calendar.CalendarName - }] - } catch (error) { - console.log(error) } - } else { - try { - return [{ - OwnerId: calendar.OwnerId, - CalendarId : Pessoal, - CalendarName: calendar.CalendarName - }] - } catch (error) { - console.log(error) - } - } } @@ -737,8 +740,8 @@ export class AgendaPage implements OnInit { this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) const selectedDay = momentG(this.eventSelectedDate, 'dd', 'pt'); - if(this.TimelineMDList[selectedDay]) { - if(momentG(new Date(this.TimelineMDList[selectedDay][0].start), 'MMMM', 'pt') == momentG(this.eventSelectedDate, 'MMMM', 'pt')) { + if (this.TimelineMDList[selectedDay]) { + if (momentG(new Date(this.TimelineMDList[selectedDay][0].start), 'MMMM', 'pt') == momentG(this.eventSelectedDate, 'MMMM', 'pt')) { this.hasEventToday = true } @@ -769,7 +772,7 @@ export class AgendaPage implements OnInit { } catch (e) { } this.updateEventListBox() - } else {} + } else { } } @@ -908,7 +911,7 @@ export class AgendaPage implements OnInit { this.myCal.loadEvents(); this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); } - } catch (error) { + } catch (error) { } @@ -923,7 +926,7 @@ export class AgendaPage implements OnInit { let navigationExtras: NavigationExtras = { queryParams: { CalendarId } } - this.router.navigate(['/home/agenda/',eventId,'agenda'], navigationExtras); + this.router.navigate(['/home/agenda/', eventId, 'agenda'], navigationExtras); } @@ -938,13 +941,13 @@ export class AgendaPage implements OnInit { this.postEvent = data.event; this.mobileComponent.showEditEvent = true; - } else if(data.type == 'delete') { + } else if (data.type == 'delete') { } this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate); - setTimeout(()=>{ + setTimeout(() => { this.onCurrentChanged(this.eventSelectedDate) }, 500) @@ -1173,10 +1176,10 @@ export class AgendaPage implements OnInit { } -function endOfMonth(myDate){ +function endOfMonth(myDate) { let date = new Date(myDate); date.setDate(1); // Avoids edge cases on the 31st day of some months - date.setMonth(date.getMonth() +1); + date.setMonth(date.getMonth() + 1); date.setDate(0); date.setHours(23); date.setMinutes(59); diff --git a/src/app/services/agenda/list-box.service.ts b/src/app/services/agenda/list-box.service.ts index 758868e2c..656c39d44 100644 --- a/src/app/services/agenda/list-box.service.ts +++ b/src/app/services/agenda/list-box.service.ts @@ -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 \ No newline at end of file