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

Assets 98992 #153

Merged
merged 7 commits into from
Aug 9, 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
7 changes: 7 additions & 0 deletions blocks/gmo-program-details/gmo-program-details.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,17 @@ body {
transform: rotate(180deg);
}
}
&.disabled {
background-color: #c6c6c6;
cursor: default;
}
}
& .current-year {
line-height: 32px;
margin-left: 20px;
&.single {
margin-left: unset;
}
}
}
& .right-controls {
Expand Down
2 changes: 1 addition & 1 deletion blocks/gmo-program-details/gmo-program-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export default async function decorate(block) {
<div class="today-button">Today</div>
<div class="filter-dropdown-wrapper">
<div class="filter-dropdown-button">
<div class="label">Filter</div>
<div class="label">Selected View: Year</div>
<span class="icon icon-chevronDown"></span>
<span class="icon icon-chevronUp inactive"></span>
</div>
Expand Down
31 changes: 22 additions & 9 deletions scripts/program-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { searchAsset } from '../../scripts/assets.js';

let deliverables, deliverableMapping;
let viewStart, viewEnd;
const startDateProp = 'deliverableProjectStartDate';
const endDateProp = 'deliverableProjectEndDate';

const startDateProp = 'taskPlannedStartDate';
const endDateProp = 'taskPlannedEndDate';
const taskStatusMappings = await getMappingArray('taskStatus');

// Helper function to get task status mapping
Expand All @@ -30,7 +31,7 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)

// get start of the view
viewStart = getTimeBounds(deliverables, "start", startDateProp);
viewStart = (viewStart.getFullYear() === 1969) ? programLaunchDate : viewStart;
viewStart = (!(isValidDate(viewStart)) || viewStart.getFullYear() === 1969) ? programLaunchDate : viewStart;
const viewStartYear = viewStart.getUTCFullYear();

const displayYear = period ? period.year : viewStartYear;
Expand All @@ -42,7 +43,7 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)

// get end of the view
viewEnd = getTimeBounds(deliverables, "end", endDateProp);
if (viewEnd.getFullYear() === 1969) {
if (!(isValidDate(viewEnd)) || viewEnd.getFullYear() === 1969) {
viewEnd = new Date(viewStart);
viewEnd.setMonth(viewStart.getMonth() + 1);
}
Expand All @@ -51,6 +52,11 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)
// get array of all years to be included
let years = calendarYears(viewStartYear, viewEndYear);

// disable increment/decrement if only one year in view
if (years.length === 1) {
document.querySelector('.inc-dec-wrapper > .year-switch').classList.add('disabled');
}

// build the calendar background here as we already know the period and style
let calendarEl;
if (type === "year") {
Expand Down Expand Up @@ -82,10 +88,9 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)

// find the earliest date- this is how we set the position for the group against the calendar
let earliestStartDate = getTimeBounds(matchedItems, "start", startDateProp);
earliestStartDate = (earliestStartDate.getFullYear() === 1969) ? viewStart : earliestStartDate;
earliestStartDate = (!(isValidDate(earliestStartDate)) || earliestStartDate.getFullYear() === 1969) ? new Date(viewStart) : earliestStartDate;
let latestEndDate = getTimeBounds(matchedItems, "end", endDateProp);
latestEndDate = (latestEndDate.getFullYear() === 1969) ? viewEnd : latestEndDate;

latestEndDate = (!(isValidDate(latestEndDate)) || latestEndDate.getFullYear() === 1969) ? new Date(viewEnd) : latestEndDate;
const startMonth = (earliestStartDate.getUTCMonth()); // getMonth returns 0-11 but this is desirable
const startDay = (earliestStartDate.getUTCDate() - 1); // if at start of month, we don't want to add any more margin
const endMonth = (latestEndDate.getUTCMonth());
Expand Down Expand Up @@ -153,7 +158,7 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)
</div>
</div>
<div class="content-row bottom">
${itemEndDateStr ? '<div class="start-date" title="Task End Date: ' + itemEndDateStr + '">End Date: ' + itemEndDateStr + '</div>' : ''}
${itemEndDateStr ? '<div class="start-date" title="Task Planned End Date: ' + itemEndDateStr + '">End Date: ' + itemEndDateStr + '</div>' : ''}
<div class="link">
<a href="${item.reviewLink}">QA Files</a>
</div>
Expand Down Expand Up @@ -256,7 +261,9 @@ export async function buildCalendar(dataObj, block, type, mappingArray, period)
document.querySelector('.gmo-program-details.block').addEventListener('click', dismissDropdown);
block.querySelectorAll('.year-switch > .year-toggle').forEach((control) => {
control.removeEventListener('click', changePeriod);
control.addEventListener('click', changePeriod);
if (years.length > 1) {
control.addEventListener('click', changePeriod);
}
});
block.querySelector('.right-controls .today-button').addEventListener('click', () => {
const calendarWrapper = document.querySelector('.calendar-wrapper')
Expand Down Expand Up @@ -410,6 +417,8 @@ function filterDropdownSelection(event, viewStartYear, numYears) {
const calendarWrapper = document.querySelector('.calendar-wrapper');
scrollToPosition(calendarWrapper, scrollPct);
} else {
const viewStr = view.charAt(0).toUpperCase() + view.slice(1);
document.querySelector('.filter-dropdown-button > .label').textContent = `Selected View: ${viewStr}`;
refreshCalendar(period, view);
}
dismissDropdown();
Expand Down Expand Up @@ -617,3 +626,7 @@ function calculateScroll(type, viewStartYear, displayYear, displayQuarter, numYe
return (yearWidthOffsetPct).toFixed(2);
}
}

function isValidDate(dateObj) {
return dateObj instanceof Date && !isNaN(dateObj);
}
Loading