diff --git a/boulder_base.libraries.yml b/boulder_base.libraries.yml index cf35f923..31c4c4fb 100644 --- a/boulder_base.libraries.yml +++ b/boulder_base.libraries.yml @@ -257,7 +257,7 @@ ucb-current-issue: js/ucb-current-issue-block.js: {} css: theme: - css/ucb-current-issue-block.css: {} + css/block/ucb-current-issue-block.css: {} ucb-category-cloud: version: 1.x @@ -281,7 +281,7 @@ ucb-latest-issue: js/ucb-latest-issue-block.js: {} css: theme: - css/ucb-latest-issue-block.css: {} + css/block/ucb-latest-issue-block.css: {} ucb-issue-archive: version: 1.x js: diff --git a/css/ucb-current-issue-block.css b/css/block/ucb-current-issue-block.css similarity index 100% rename from css/ucb-current-issue-block.css rename to css/block/ucb-current-issue-block.css diff --git a/css/ucb-latest-issue-block.css b/css/block/ucb-latest-issue-block.css similarity index 89% rename from css/ucb-latest-issue-block.css rename to css/block/ucb-latest-issue-block.css index 4cbcb976..2bdbd55b 100644 --- a/css/ucb-latest-issue-block.css +++ b/css/block/ucb-latest-issue-block.css @@ -8,6 +8,9 @@ .ucb-latest-issue-card{ max-width: 20%; margin-right: 20px; + display: flex; + align-items: center; + flex-direction: column; } .ucb-latest-issue-title{ diff --git a/js/ucb-current-issue-block.js b/js/ucb-current-issue-block.js index 48379182..7ab95c84 100644 --- a/js/ucb-current-issue-block.js +++ b/js/ucb-current-issue-block.js @@ -10,10 +10,13 @@ class CurrentIssueElement extends HTMLElement { } }; - fetch(`/jsonapi/node/ucb_issue?include=field_ucb_issue_image&fields[file--file]=uri,url&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published&sort=-created`) + fetch(`/jsonapi/node/ucb_issue?include=field_ucb_issue_cover_image.field_media_image&fields[file--file]=uri,url&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published&sort=-created`) .then(handleError) .then((data) => this.build(data)) - .catch(Error=> this.handleError(Error)); + .catch(Error=> { + this.toggleMessage('ucb-al-loading'); + this.handleError(Error) + }); } build(data){ @@ -21,7 +24,7 @@ class CurrentIssueElement extends HTMLElement { this.handleError({name : "No Issues Retrieved", message : "There are no Issues created"} , 'No Issues Found') } else { const title = data.data[0].attributes.title - const imgURL = data.included[0].attributes.uri.url + let imgURL const issueURL = data.data[0].attributes.path.alias const imgLinkEL = document.createElement('a') @@ -40,24 +43,50 @@ class CurrentIssueElement extends HTMLElement { const titleEl = document.createElement('h3') titleEl.classList = "ucb-current-issue-block-title" titleEl.innerText = title - - const imgEL = document.createElement('img') - imgEL.classList = 'ucb-current-issue-block-img' - imgEL.src = imgURL - + + // Image + const urlObj = {}; // key from data.data to key from data.includes + const idObj = {}; // key from data.includes to URL + // Remove any blanks from our articles before map + if (data['included']) { + const filteredData = data['included'].filter(url => !!url['attributes']['uri']); + // creates the urlObj, key: data id, value: url + filteredData.map((pair) => { + // checks if consumer is working, else default to standard image instead of focal image + if(pair['links']['large_image_style']) + urlObj[pair['id']] = pair['links']['large_image_style']['href']; + else + urlObj[pair['id']] = pair['attributes']['uri']['url']; + }); + // removes all other included data besides images in our included media + const idFilterData = data['included'].filter(item => item['type'] == 'media--image'); + // using the image-only data, creates the idObj => key: thumbnail id, value : data id + idFilterData.map(pair => idObj[pair['id']] = pair['relationships']['thumbnail']['data']['id']); + } + + const issue = data.data[0] ? data.data[0] : null const linkEl = document.createElement('a') linkEl.href = issueURL linkEl.appendChild(titleEl) titleDiv.appendChild(linkEl) + + if(issue.relationships.field_ucb_issue_cover_image.data){ + const issueId = issue.relationships.field_ucb_issue_cover_image.data.id; + imgURL = urlObj[idObj[issueId]] + const imgEL = document.createElement('img') + imgEL.classList = 'ucb-current-issue-block-img' + imgEL.src = imgURL + imgEL.alt = `${title} cover image` + imgLinkEL.appendChild(imgEL) + imgDiv.appendChild(imgLinkEL) + } - imgLinkEL.appendChild(imgEL) - imgDiv.appendChild(imgLinkEL) blockDiv.appendChild(imgDiv) blockDiv.appendChild(titleDiv) - + this.toggleMessage('ucb-al-loading'); this.appendChild(blockDiv) } } @@ -79,10 +108,22 @@ class CurrentIssueElement extends HTMLElement { span.appendChild(message) this.appendChild(container) - - console.error(Error) + console.error(Error) } + + toggleMessage(id, display = "none") { + if (id) { + var toggle = this.querySelector(`#${id}`); + if (toggle) { + if (display === "block") { + toggle.style.display = "block"; + } else { + toggle.style.display = "none"; + } + } + } + } } diff --git a/js/ucb-issue-archive.js b/js/ucb-issue-archive.js index 2f871f32..9a8705e4 100644 --- a/js/ucb-issue-archive.js +++ b/js/ucb-issue-archive.js @@ -11,41 +11,64 @@ class IssueArchiveElement extends HTMLElement { }; // Pagination &page[limit]=5 - fetch(`/jsonapi/node/ucb_issue?include=field_ucb_issue_image&fields[file--file]=uri,url&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published&sort=-created`) - .then(handleError) + fetch(`/jsonapi/node/ucb_issue?include=field_ucb_issue_cover_image.field_media_image&fields[file--file]=uri,url&filter[published][group][conjunction]=AND&filter[publish-check][condition][path]=status&filter[publish-check][condition][value]=1&filter[publish-check][condition][memberOf]=published&sort=-created`) + .then(handleError) .then((data) => this.build(data)) - .catch(Error=> this.handleError(Error)); + .catch(Error=> { + this.toggleMessage('ucb-al-loading'); + this.handleError(Error) + }); } build(data){ if(data.data.length == 0){ + this.toggleMessage('ucb-al-loading') this.handleError({name : "No Issues Retrieved", message : "There are no Issues created"} , 'Create Issues for All Issues to appear here') } else { - console.log(data) const archiveContainer = document.createElement('div') archiveContainer.classList='ucb-issue-archive-container col-lg-12 col-md-12 col-sm-12 col-xs-12' const issues = data.data - const issuesArt = data.included + // Media Image + const urlObj = {}; // key from data.data to key from data.includes + const idObj = {}; // key from data.includes to URL + // Remove any blanks from our articles before map + if (data['included']) { + const filteredData = data['included'].filter(url => !!url['attributes']['uri']); + // creates the urlObj, key: data id, value: url + filteredData.map((pair) => { + // checks if consumer is working, else default to standard image instead of focal image + if(pair['links']['large_image_style']) + urlObj[pair['id']] = pair['links']['large_image_style']['href']; + else + urlObj[pair['id']] = pair['attributes']['uri']['url']; + }); + // removes all other included data besides images in our included media + const idFilterData = data['included'].filter(item => item['type'] == 'media--image'); + // using the image-only data, creates the idObj => key: thumbnail id, value : data id + idFilterData.map(pair => idObj[pair['id']] = pair['relationships']['thumbnail']['data']['id']); + } for(let i=0;i this.build(data)) - .catch(Error=> this.handleError(Error)); + .catch(Error=> { + this.toggleMessage('ucb-al-loading'); + this.handleError(Error) + }); } build(data){ @@ -21,30 +24,50 @@ class LatestIssueElement extends HTMLElement { this.handleError({name : "No Issues Retrieved", message : "There are no Issues created"} , 'No Issues Found') } else { const issues = data.data - const issuesArt = data.included - const latestIssueContainer = document.createElement('div') latestIssueContainer.classList = 'ucb-latest-issue-container' + // Media Image + const urlObj = {}; // key from data.data to key from data.includes + const idObj = {}; // key from data.includes to URL + // Remove any blanks from our articles before map + if (data['included']) { + const filteredData = data['included'].filter(url => !!url['attributes']['uri']); + // creates the urlObj, key: data id, value: url + filteredData.map((pair) => { + // checks if consumer is working, else default to standard image instead of focal image + if(pair['links']['large_image_style']) + urlObj[pair['id']] = pair['links']['large_image_style']['href']; + else + urlObj[pair['id']] = pair['attributes']['uri']['url']; + }); + // removes all other included data besides images in our included media + const idFilterData = data['included'].filter(item => item['type'] == 'media--image'); + // using the image-only data, creates the idObj => key: thumbnail id, value : data id + idFilterData.map(pair => idObj[pair['id']] = pair['relationships']['thumbnail']['data']['id']); + } for(let i=0;i=4 @@ -94,10 +116,21 @@ class LatestIssueElement extends HTMLElement { span.appendChild(message) this.appendChild(container) - - console.error(Error) + console.error(Error) } + toggleMessage(id, display = "none") { + if (id) { + var toggle = this.querySelector(`#${id}`); + if (toggle) { + if (display === "block") { + toggle.style.display = "block"; + } else { + toggle.style.display = "none"; + } + } + } + } } diff --git a/templates/block/block--ucb-current-issue-block.html.twig b/templates/block/block--ucb-current-issue-block.html.twig index de1beeea..cae6d18a 100644 --- a/templates/block/block--ucb-current-issue-block.html.twig +++ b/templates/block/block--ucb-current-issue-block.html.twig @@ -17,5 +17,9 @@ {{ label }} {{ title_suffix }} - + +
+ +
+
\ No newline at end of file diff --git a/templates/block/block--ucb-latest-issues-block.html.twig b/templates/block/block--ucb-latest-issues-block.html.twig index bff09faa..90cca9e7 100644 --- a/templates/block/block--ucb-latest-issues-block.html.twig +++ b/templates/block/block--ucb-latest-issues-block.html.twig @@ -17,5 +17,9 @@ {{ label }} {{ title_suffix }} - + +
+ +
+
\ No newline at end of file diff --git a/templates/content/node--ucb-issue-archive.html.twig b/templates/content/node--ucb-issue-archive.html.twig index 332d3f26..1cbbec0d 100644 --- a/templates/content/node--ucb-issue-archive.html.twig +++ b/templates/content/node--ucb-issue-archive.html.twig @@ -22,5 +22,9 @@ {{ content.body }} {% endif %} - + +
+ +
+
diff --git a/templates/content/node--ucb-issue.html.twig b/templates/content/node--ucb-issue.html.twig index 0855859c..410677aa 100644 --- a/templates/content/node--ucb-issue.html.twig +++ b/templates/content/node--ucb-issue.html.twig @@ -18,7 +18,7 @@
- {{ content.field_ucb_issue_image|render }} + {{ content.field_ucb_issue_cover_image|render }}
{{ content.field_ucb_issue_secondary_image }}