-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from GSA/add-geoplatform-link
Add geoplatform link section
- Loading branch information
Showing
9 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ckanext/datagovtheme/fanstatic_library/scripts/geoplatform.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
jQuery(function ($) { | ||
async function getGeoplatformLink() { | ||
let parentEl = document.getElementById("geoplatform-link-section"); | ||
if (parentEl == null) { | ||
return; | ||
} | ||
let datasetName = parentEl.getAttribute("data-package-name"); | ||
try { | ||
const response = await fetch( | ||
`https://api.geoplatform.gov/v3/public/lookups/data-gov/dataset?name=${datasetName}`, | ||
{ signal: AbortSignal.timeout(20000) } | ||
) | ||
.then((response) => { | ||
if (response.ok) { | ||
return response.json(); | ||
} | ||
if (response.status == 404) { | ||
console.log("dataset doesn't exist on geoplatform"); | ||
} | ||
if (response.status >= 500) { | ||
console.warn( | ||
"geoplatform couldn't fulfill the request" | ||
); | ||
} | ||
}) | ||
.then((data) => { | ||
let el = document.getElementById("geoplatform-link"); | ||
el.href = data.geoplatform_url; | ||
parentEl.classList.remove("hide"); | ||
}); | ||
} catch (error) { | ||
if (error.name === "TimeoutError") { | ||
console.error("request timeout. geoplatform not reachable"); | ||
} else { | ||
console.error(error); | ||
} | ||
} | ||
} | ||
|
||
getGeoplatformLink(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ckanext/datagovtheme/templates/package/snippets/geoplatform_link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<section id="geoplatform-link-section" class="resources module-content hide" data-package-name="{{ pkg_dict['name'] }}"> | ||
<h3>Other Data Resources</h3> | ||
<ul class="resource-list"> | ||
<li class="resource-item"> | ||
<span class="format-label" property="dc:format" data-format="geoplatform"></span> | ||
<strong class="heading">Geoplatform Metadata Information</strong> | ||
<p class="description"> | ||
<a id="geoplatform-link" target="_blank" href="">View this on Geoplatform</a> | ||
<svg class="usa-icon" aria-hidden="true" role="img"> | ||
<use xlink:href="#svg-launch"></use> | ||
<symbol viewBox="0 0 24 24" id="svg-launch" xmlns="http://www.w3.org/2000/svg"><path d="M19 19H5V5h7V3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"></path></symbol> | ||
</svg> | ||
</p> | ||
</li> | ||
</ul> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe("Geoplatform Link", () => { | ||
it("Check if other data resources section is visible", () => { | ||
cy.intercept( | ||
{ | ||
method: "GET", | ||
url: "https://api.geoplatform.gov/v3/public/lookups/data-gov/dataset?name=test_mock_geoplatform_data", | ||
}, | ||
{ | ||
statusCode: 200, | ||
body: { | ||
geoplatform_url: "https://www.youtube.com/", | ||
}, | ||
} | ||
); | ||
|
||
cy.visit("/dataset/test_mock_geoplatform_data"); | ||
cy.wait(10000); | ||
cy.get('section[id="geoplatform-link-section"]') | ||
.scrollIntoView() | ||
.should("be.visible"); | ||
}); | ||
|
||
it("Check if other data resources section is not visible", () => { | ||
cy.intercept( | ||
{ | ||
method: "GET", | ||
url: "https://api.geoplatform.gov/v3/public/lookups/data-gov/dataset?name=test_bad_mock_geoplatform_data", | ||
}, | ||
{ | ||
statusCode: 404, | ||
body: {}, | ||
} | ||
); | ||
|
||
cy.visit("/dataset/test_bad_mock_geoplatform_data"); | ||
cy.get('section[id="geoplatform-link-section"]').should( | ||
"not.be.visible" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"cypress": "^13.6.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters