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

DXI- 29263 #180

Merged
merged 12 commits into from
Nov 19, 2024
69 changes: 47 additions & 22 deletions blocks/gmo-program-details/gmo-program-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default async function decorate(block) {
),
);


// deliverables tab
const deliverablesTab = div(
{ id: 'tab2', class: 'deliverables tab inactive'},
Expand Down Expand Up @@ -328,13 +329,21 @@ async function addProgramStats(block) {

// Populate the map
programData.data.deliverableList.items.forEach(item => {
const deliverableType = item.deliverableType; //deliverableType
const deliverableType = item.deliverableType; //array of deliverableType
const platforms = item.platforms; // array of platform strings

// If deliverableType or platforms is null, skip the iteration
if (deliverableType === null || deliverableType === undefined || platforms === null || platforms === undefined) {
return;
}
//if deliverableType or Platforms has same value, show both buttons
if (deliverableType.value === 0 || platforms.value === 0) {
return;
}
platforms.forEach(async platform => {
let assetResult = {imageUrl : '', imageAltText: '', assetCount: 0};
assetResult = await searchAsset(programName, programName.campaignName, deliverableType, platform);
let assetCount = assetResult.assetCount;

// deliverableType, platform, assetCount
if (!deliverableTypeToPlatformsMap.has(deliverableType)) {
// Case: If the deliverable type is not in the map, create a new entry with the platform added to the new map.
Expand Down Expand Up @@ -522,24 +531,31 @@ async function buildFieldScopes(scopeTypeId, scopes, block, associationMap) {

tag.addEventListener('click', async () => {
if (isSelected) {
let headingDiv1 = document.getElementById((scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
// Fetch all .scope-tag class from headingDiv1
let alternativeTags = headingDiv1.querySelectorAll('.scope-tag');

// Clear the selection
const allTags = document.querySelectorAll('.scope-tag');
allTags.forEach(t => {
t.style.display = 'inline-block';
t.classList.remove('selected'); // Remove the selected class
});
const associatedItems = associationMap.get(scope);
console.log('Associated Items:', associatedItems);

// Reset the associated buttons
associatedItems.forEach(async (_count, key) => {
const associatedTag = Array.from(allTags).find(t => t.id.includes(key));
if (associatedTag) {
let alternateTextContent = await lookupType(associatedTag.id, (scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
associatedTag.textContent = `${alternateTextContent}`;
associatedTag.style.display = 'inline-block';
associatedTag.style.pointerEvents = 'auto'; // Make the clickable
}
});
if (associatedItems) {
associatedItems.forEach(async (_count, key) => {
const associatedTag = Array.from(alternativeTags).find(t => t.id.includes(key));
if (associatedTag) {
let alternateTextContent = await lookupType(associatedTag.id, (scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
associatedTag.textContent = `${alternateTextContent}`;
associatedTag.style.display = 'inline-block';
associatedTag.style.pointerEvents = 'auto'; // Make the clickable
}
});
}

tag.textContent = await lookupType(scope, scopeTypeId);
isSelected = false;
Expand All @@ -560,6 +576,11 @@ async function buildFieldScopes(scopeTypeId, scopes, block, associationMap) {
const allTags = document.querySelectorAll('.scope-tag');
console.log('All Tags:', allTags);
allTags.forEach(t => t.style.display = 'none');

let associatedHeadingDiv = document.getElementById((scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
// Fetch all .scope-tag class from associatedHeadingDiv
let alternativeTags = associatedHeadingDiv.querySelectorAll('.scope-tag');
console.log('All Tags1:', alternativeTags);

// Get the associated items
const associatedItems = associationMap.get(scope);
Expand All @@ -573,17 +594,21 @@ async function buildFieldScopes(scopeTypeId, scopes, block, associationMap) {
let totalAssociatedAssetCount = 0;

// Show the associated buttons
associatedItems.forEach(async (count, key) => {
totalAssociatedAssetCount = totalAssociatedAssetCount + count;
const associatedTag = Array.from(allTags).find(t => t.id.includes(key));
console.log('Associated Tag:', associatedTag);
let alternateTextContent = await lookupType(associatedTag.id, (scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
if (associatedTag) {
associatedTag.textContent = `${await lookupType(scope, scopeTypeId)}: ${alternateTextContent} (${count})`;
associatedTag.style.display = 'inline-block';
associatedTag.style.pointerEvents = 'none'; // Make the tag non-clickable
}
});
if (associatedItems) {
associatedItems.forEach(async (count, key) => {
totalAssociatedAssetCount = totalAssociatedAssetCount + count;
const associatedTag = Array.from(alternativeTags).find(t => t.id.includes(key));
console.log('Associated Tag:', associatedTag);
let alternateTextContent = await lookupType(associatedTag.id, (scopeTypeId === 'deliverable-type') ? 'platforms' : 'deliverable-type');
console.log('Alternate Text Content:', alternateTextContent);
if (associatedTag) {
associatedTag.textContent = `${await lookupType(scope, scopeTypeId)}: ${alternateTextContent} (${count})`;
associatedTag.style.display = 'inline-block';
associatedTag.style.pointerEvents = 'none'; // Make the tag non-clickable

}
});
}
// Add the selected class to the clicked button
tag.classList.add('selected');
isSelected = true;
Expand Down
Loading