Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix(Timeline):Please update to weekly range - from Mon to Fri P… #2500

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion marlo-web/src/main/webapp/crp/css/home/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ span.timelineControl:hover {
border-radius: 5px;
}

#timeline_timeRange{
position: absolute;
left: 50%;
top: 15%;
}

.timebox {
height: 80%;
position: relative;
Expand Down Expand Up @@ -587,12 +593,13 @@ span.timelineControl:hover {
.timelineAlert_item{
display: flex;
flex-direction: row;
align-items: flex-start;
align-items: flex-end;
gap: 0.5rem;
}

.timelineAlert_item p{
font-size: 10px;
margin: 0;
}

.timelineAlert_item_color{
Expand Down
59 changes: 52 additions & 7 deletions marlo-web/src/main/webapp/crp/js/home/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function initDashboard() {
$(".timelineRefresh").hide();
$(".timeline").show();
setTimelinePosition();
getIntersectedDatesInScreen();

$('.buttonRightTimeline').on("click", moveScrollRight);

Expand Down Expand Up @@ -158,6 +159,10 @@ function moveScrollRight() {

element.style.scrollBehavior = "smooth"
element.scrollLeft += (containerSize+(containerSize* (2/5)));

setTimeout(() => {
getIntersectedDatesInScreen();
}, 500);
}

function moveScrollLeft() {
Expand All @@ -168,6 +173,10 @@ function moveScrollLeft() {

element.style.scrollBehavior = "smooth"
element.scrollLeft -= (containerSize+(containerSize* (2/5)));

setTimeout(() => {
getIntersectedDatesInScreen();
}, 500);
}

const convertDateToAfricanDate = (date) => {
Expand Down Expand Up @@ -199,18 +208,52 @@ function getDateBasedOnASumOfDays(startDate, days) {
return newDate;
}

function getIntersectedDatesInScreen() {
const timeline_times = document.getElementsByClassName('timebox');
const list_times = Array.from(timeline_times);

const timeline_timeRange = document.getElementById('timeline_timeRange');
let rangeText = '';

const observer = new IntersectionObserver((entries) => {

let timesIntersected = [];

entries.forEach((entry) => {
if(entry.isIntersecting){
timesIntersected.push(entry.target.dataset.id);
}

});
console.log(timesIntersected);

rangeText = convertDateToText(timesIntersected[1]) + " - " + convertDateToText(timesIntersected[timesIntersected.length-1])

timeline_timeRange.innerHTML = rangeText;
},{});



list_times.forEach((time)=> {
observer.observe(time);
});



setTimeout(() => {
observer.disconnect();
}, 100);

}

function createDivTimes(totalDays, divClass, divIdPrefix){
let arrayDays = [];
for(let i=0; i < totalDays+1; i++){
let newDiv = document.createElement('div');
newDiv.id = `time_${i}`
newDiv.dataset.id = getDateBasedOnASumOfDays(divIdPrefix, i);
newDiv.className = divClass;
newDiv.style.width = setWidth();
newDiv.innerHTML = `
<p class="timeNumber">
${convertDateToText(getDateBasedOnASumOfDays(divIdPrefix,i))}
</p>
`;
arrayDays.push(newDiv);
}
return arrayDays;
Expand Down Expand Up @@ -286,7 +329,6 @@ function setDistances(startDate,isToday, isJS,endDate) {
const { firstDate, lastDate } = getFirstAndLastDates(timelineElements);
let today = convertDateToAfricanDate(new Date());

console.log(timelineElements);
today = today.getDate() > lastDate? convertDateToAfricanDate(lastDate): today;

const currentHour = today.getHours();
Expand Down Expand Up @@ -321,7 +363,7 @@ function setTimelinePosition(){
weekStart.setDate(weekStart.getDate() - weekStart.getDay())

const timelineContainer = document.getElementById("timelineContainer");
timelineContainer.scrollLeft += setDistances(weekStart, undefined,true);
timelineContainer.scrollLeft += (setDistances(weekStart, undefined,true)-10);

}

Expand Down Expand Up @@ -357,6 +399,9 @@ function createTimeline2() {
</section>
</div>
</div>
<p id="timeline_timeRange">
Provisional Text
</p>
<div id="timelineContainer">
<div id="timeline_times">
${createDivTimes(getTotalDays,"timebox",getFirstDate).reduce((acc, curr) => acc + curr.outerHTML, '')}
Expand Down
Loading