Skip to content

Commit

Permalink
Merge pull request #178 from GSA/add-geoplatform-link
Browse files Browse the repository at this point in the history
Add geoplatform link section
  • Loading branch information
rshewitt authored Dec 11, 2023
2 parents 7df2949 + e2f2cd1 commit 62935c6
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ syntax: glob
.vscode/

# Cypress
cypress/e2e/videos/*
cypress/videos/*
cypress/e2e/screenshots/*
cypress/e2e/results/output.xml
node_modules
Expand Down
41 changes: 41 additions & 0 deletions ckanext/datagovtheme/fanstatic_library/scripts/geoplatform.js
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();
});
1 change: 1 addition & 0 deletions ckanext/datagovtheme/fanstatic_library/webassets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ js:
- scripts/tracking.js
- scripts/hideMaxListItem.js
- scripts/sorting.js
- scripts/geoplatform.js

styles:
# This name is used in development/debug mode, must match the css file in test_datagovtheme.py
Expand Down
2 changes: 2 additions & 0 deletions ckanext/datagovtheme/templates/package/read.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ <h3>{{ _('Metadata Source') }}</h3>
</section>
{% endif %}
{% endif %}

{% include 'package/snippets/geoplatform_link.html' %}

{% set graphic_preview_file =h.get_pkg_dict_extra(pkg, 'graphic-preview-file', None) %}
{% if graphic_preview_file and graphic_preview_file.lower()[:4] == 'http' %}
Expand Down
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>
40 changes: 40 additions & 0 deletions cypress/e2e/geoplatform.cy.js
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"
);
});
});
9 changes: 9 additions & 0 deletions docker-entrypoint.d/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,12 @@ def get_base_dataset():
print(f'Dataset {x} created')
except Exception as er:
print(f'exception: {er}')

# Create our test geoplatform datasets
dataset = get_base_dataset()
dataset['name'] = 'test_mock_geoplatform_data'
factories.Dataset(**dataset)

dataset = get_base_dataset()
dataset['name'] = 'test_bad_mock_geoplatform_data'
factories.Dataset(**dataset)
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"cypress": "^13.6.1"
}
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="ckanext-datagovtheme",
version="0.2.8",
version="0.2.9",
description="CKAN Extension to manage data.gov theme",
long_description=long_description,
classifiers=[
Expand Down

0 comments on commit 62935c6

Please sign in to comment.