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

Add geoplatform link section #178

Merged
merged 17 commits into from
Dec 11, 2023
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
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' %}
btylerburton marked this conversation as resolved.
Show resolved Hide resolved

{% 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
Loading