Skip to content

Commit fdcb2e5

Browse files
committed
handle missing Geonames connection more gracefully
1 parent f11adcc commit fdcb2e5

25 files changed

Lines changed: 559 additions & 216 deletions

OptimetaGeoPlugin.inc.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ public function register($category, $path, $mainContextId = NULL)
118118
$templateMgr->addStyleSheet("leafletControlGeocodeCSS", $urlLeafletControlGeocodeCSS, array('contexts' => array('frontend', 'backend')));
119119

120120
// plugins JS scripts and CSS
121-
$templateMgr->assign('optimetageo_submissionMetadataFormFieldsJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/submissionMetadataFormFields.js');
122-
$templateMgr->assign('optimetageo_article_detailsJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/article_details.js');
123-
$templateMgr->assign('optimetageo_issueJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/issue.js');
124-
$templateMgr->assign('optimetageo_markerBaseUrl', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/lib/leaflet-color-markers/img/');
121+
$templateMgr->assign('optimetageo_submissionJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/submission.js');
122+
$templateMgr->assign('optimetageo_article_detailsJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/article_details.js');
123+
$templateMgr->assign('optimetageo_issueJS', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/issue.js');
124+
$templateMgr->assign('optimetageo_markerBaseUrl', $request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/lib/leaflet-color-markers/img/');
125125

126126
$templateMgr->assign('optimetageo_mapUrlPath', MAP_URL_PATH);
127127
$templateMgr->assign('optimetageo_metadataLicense', '<a href="https://creativecommons.org/publicdomain/zero/1.0/">CC-0</a>');
@@ -254,7 +254,7 @@ public function extendSubmissionMetadataFormTemplate($hookName, $params)
254254

255255
/*
256256
Check if the user has entered an username in the plugin settings for the GeoNames API (https://www.geonames.org/login).
257-
The result is passed on accordingly to submissionMetadataFormFields.js as template variable.
257+
The result is passed on accordingly to submission.js as template variable.
258258
*/
259259
$usernameGeonames = $this->getSetting($context->getId(), 'optimetaGeo_geonames_username');
260260
$templateMgr->assign('usernameGeonames', $usernameGeonames);
@@ -265,7 +265,7 @@ public function extendSubmissionMetadataFormTemplate($hookName, $params)
265265
In case the user repeats the step "3. Enter Metadata" in the process 'Submit an Article' and comes back to this step to make changes again,
266266
the already entered data is read from the database, added to the template and displayed for the user.
267267
Data is loaded from the database, passed as template variable to the 'submissionMetadataFormFiels.tpl'
268-
and requested from there in the 'submissionMetadataFormFields.js' to display coordinates in a map, the date and coverage information if available.
268+
and requested from there in the 'submission.js' to display coordinates in a map, the date and coverage information if available.
269269
*/
270270
$publicationDao = DAORegistry::getDAO('PublicationDAO');
271271
$submissionId = $request->getUserVar('submissionId');
@@ -512,7 +512,7 @@ public function addToSchema($hookName, $params)
512512

513513
/**
514514
* Function which fills the new fields (created by the function addToSchema) in the schema.
515-
* The data is collected using the 'submissionMetadataFormFields.js', then passed as input to the 'submissionMetadataFormFields.tpl'
515+
* The data is collected using the 'submission.js', then passed as input to the 'submissionMetadataFormFields.tpl'
516516
* and requested from it in this php script by a POST-method.
517517
* @param hook Publication::edit
518518
*/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ npm install
8787
npx cypress open
8888

8989
# start compose configuration for desired OJS version, running on port 8080; OJS_VERSION is a image tag for pkpofficial/ojs
90-
export OJS_VERSION=3_3_0-11 && docker-compose --file cypress/docker-compose-mysql.yml down --volume && docker-compose --file cypress/docker-compose-mysql.yml up
90+
export OJS_VERSION=3_3_0-11 && docker-compose --file cypress/docker-compose-mysql.yml down --volume && docker-compose --file cypress/docker-compose-mysql.yml up
9191
export OJS_VERSION=3_2_1-4 && docker-compose --file cypress/docker-compose-mysql.yml down --volume && docker-compose --file cypress/docker-compose-mysql.yml up
9292

9393
# open/run Cypress tests with a given OJS version

css/optimetaGeo.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@
102102
color: #777;
103103
/* based on OJS @text-light */
104104
font-size: 13px;
105-
}
105+
}
106+
107+
.optimetageo_warning {
108+
border-left: 3px solid #ffa500;
109+
padding-left: 5px;
110+
background-color: rgba(255, 165, 0, 0.15);
111+
}

cypress/e2e/integration/20-configuration.cy.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,6 @@ describe('OPTIMETA Geo Plugin Configuration', function () {
3333
cy.get('div:contains(\'The plugin "OPTIMETA Geo Plugin" has been enabled.\')');
3434
});
3535

36-
it('Configure OPTIMETA Geo Plugin - Geonames', function () {
37-
cy.login('admin', 'admin', Cypress.env('contextPath'));
38-
cy.get('nav[class="app__nav"] a:contains("Website")').click();
39-
cy.get('button[id="plugins-button"]').click();
40-
41-
// Open the settings form
42-
cy.get('tr[id="component-grid-settings-plugins-settingsplugingrid-category-generic-row-optimetageoplugin"] a[class="show_extras"]').click();
43-
cy.get('a[id^="component-grid-settings-plugins-settingsplugingrid-category-generic-row-optimetageoplugin-settings-button"]').click();
44-
45-
// Fill out settings form
46-
cy.get('form[id="optimetaGeoSettings"] input[name="optimetaGeo_geonames_username"]')
47-
.clear().invoke('val', '') // https://stackoverflow.com/a/61101054
48-
.type('optimeta_geo');
49-
cy.get('form[id="optimetaGeoSettings"] input[name="optimetaGeo_geonames_baseurl"]')
50-
.clear()
51-
.type('http://api.geonames.org');
52-
53-
// submit settings form
54-
cy.get('form[id="optimetaGeoSettings"] button[id^="submitFormButton"]').click();
55-
cy.waitJQuery();
56-
});
57-
5836
it('Has a map in the third submissions step', function () {
5937
cy.login('admin', 'admin', Cypress.env('contextPath'));
6038

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @file cypress/tests/integration/configuration.cy.js
3+
*
4+
* Copyright (c) 2022 OPTIMETA project
5+
* Copyright (c) 2022 Daniel Nüst
6+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
7+
*
8+
*/
9+
10+
describe('OPTIMETA Geo Plugin Submission without Geonames', function () {
11+
12+
var submission;
13+
var sub1start = '2021-01-01';
14+
var sub1end = '2021-12-31';
15+
16+
before(function () {
17+
submission = {
18+
id: 0,
19+
//section: 'Articles',
20+
prefix: '',
21+
title: 'Vancouver is cool',
22+
subtitle: 'Surely',
23+
abstract: 'The city of Vancouver is home.',
24+
timePeriod: sub1start + ' - ' + sub1end,
25+
issue: '1'
26+
};
27+
});
28+
29+
it('Has no map on the empty current issue page', function () {
30+
cy.visit('/');
31+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
32+
cy.get('.pkp_structure_main').should('not.contain', 'Times & locations');
33+
cy.get('#mapdiv').should('not.exist');
34+
});
35+
36+
it('Has not yet a map on the current issue page after publishing a paper', function () {
37+
cy.login('aauthor');
38+
cy.get('a:contains("aauthor")').click();
39+
cy.get('a:contains("Dashboard")').click({ force: true });
40+
41+
cy.createSubmissionAndPublish(submission);
42+
43+
// go to journal index and check there is no map
44+
cy.visit('/');
45+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
46+
cy.get('.pkp_structure_main').should('contain', 'Vancouver is cool');
47+
cy.get('.pkp_structure_main').should('not.contain', 'Times & locations');
48+
cy.get('#mapdiv').should('not.exist');
49+
});
50+
51+
it('Has empty administrative unit in submission form because Geonames is not configured, but show warning message', function() {
52+
cy.login('aauthor');
53+
cy.get('a:contains("aauthor")').click();
54+
cy.get('a:contains("Dashboard")').click({ force: true });
55+
56+
cy.get('div#myQueue a:contains("New Submission")').click();
57+
cy.get('input[id^="checklist-"]').click({ multiple: true });
58+
cy.get('input[id="privacyConsent"]').click();
59+
cy.get('button.submitFormButton').click();
60+
cy.wait(1000);
61+
cy.get('button.submitFormButton').click();
62+
63+
cy.toolbarButton('marker').click();
64+
cy.get('#mapdiv').click(260, 110);
65+
cy.wait(3000); // a bit longer for GitHub action
66+
cy.get('input[id^="coverage-"').should('have.value', '');
67+
68+
cy.get('#submitStep3Form').should('contain', 'The gazetteer service is not available');
69+
});
70+
71+
it('Manual updates in the administrative unit field update the coverage field', function() {
72+
cy.login('aauthor');
73+
cy.get('a:contains("aauthor")').click();
74+
cy.get('a:contains("Dashboard")').click({ force: true });
75+
76+
cy.get('div#myQueue a:contains("New Submission")').click();
77+
cy.get('input[id^="checklist-"]').click({ multiple: true });
78+
cy.get('input[id="privacyConsent"]').click();
79+
cy.get('button.submitFormButton').click();
80+
cy.wait(1000);
81+
cy.get('button.submitFormButton').click();
82+
83+
cy.get('#administrativeUnitInput > .tagit-new > .ui-widget-content').type('Canada{enter}');
84+
cy.wait(100);
85+
cy.get('input[id^="coverage-"').should('have.value', 'Canada');
86+
});
87+
88+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @file cypress/tests/integration/html_head.cy.js
3+
*
4+
* Copyright (c) 2022 OPTIMETA project
5+
* Copyright (c) 2022 Daniel Nüst
6+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
7+
*
8+
*/
9+
10+
describe('OPTIMETA Geo Plugin Article View', function () {
11+
12+
it('The article page has the paper\'s geometry and no administrative unit on the map', function () {
13+
cy.visit('/');
14+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Archive")').click();
15+
cy.get('a:contains("Vol. 1 No. 2 (2022)")').click();
16+
cy.get('a:contains("Vancouver")').first().click();
17+
18+
cy.get('.pkp_structure_main').should('contain', 'Time and location');
19+
cy.get('#mapdiv').should('exist');
20+
21+
cy.mapHasFeatures(1);
22+
23+
cy.window().wait(200).then(({ map }) => {
24+
var foundAdminLayerBasedOnColor = false;
25+
map.eachLayer(function (layer) {
26+
if (layer.options.hasOwnProperty('color') && layer.options.color === 'black') {
27+
foundAdminLayerBasedOnColor = true;
28+
}
29+
});
30+
expect(foundAdminLayerBasedOnColor).to.be.false;
31+
});
32+
});
33+
34+
it('The article page has the time period in a text', function () {
35+
cy.visit('/');
36+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Archive")').click();
37+
cy.get('a:contains("Vol. 1 No. 2 (2022)")').click();
38+
cy.get('a:contains("Vancouver")').first().click();
39+
40+
cy.get('#optimeta_article_temporal').contains('from 2021-01-01');
41+
cy.get('#optimeta_article_temporal').contains('to 2021-12-31');
42+
});
43+
44+
it('The article page has the administrative unit in a text when added manually during submission', function () {
45+
cy.login('aauthor');
46+
cy.get('a:contains("aauthor")').click();
47+
cy.get('a:contains("Dashboard")').click({ force: true });
48+
49+
var submission = {
50+
id: 0,
51+
//section: 'Articles',
52+
prefix: '',
53+
title: 'Vancouver is hot',
54+
subtitle: 'Surely',
55+
abstract: 'The city of Vancouver is home.',
56+
timePeriod: '2021-12-30 - 2021-12-31',
57+
issue: '1',
58+
adminUnit: 'Earth, Canada, BC'
59+
};
60+
61+
cy.createSubmissionAndPublish(submission);
62+
63+
cy.visit('/');
64+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Archive")').click();
65+
cy.get('a:contains("Vol. 1 No. 2 (2022)")').click();
66+
cy.get('a:contains("Vancouver is hot")').last().click();
67+
68+
cy.get('#optimeta_article_administrativeUnit').should('contain', 'Earth, Canada, BC');
69+
});
70+
71+
});
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/**
2+
* @file cypress/tests/integration/configuration.cy.js
3+
*
4+
* Copyright (c) 2022 OPTIMETA project
5+
* Copyright (c) 2022 Daniel Nüst
6+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
7+
*
8+
*/
9+
10+
describe('OPTIMETA Geo Plugin Submission with incomplete Metadata', function () {
11+
12+
beforeEach(() => {
13+
cy.login('aauthor');
14+
cy.get('a:contains("aauthor")').click();
15+
cy.get('a:contains("Dashboard")').click({ force: true });
16+
});
17+
18+
it('Has no information on time period if it is missing', function () {
19+
var submission = {
20+
title: 'Vancouver has no time',
21+
subtitle: 'No no no',
22+
abstract: 'The city of Vancouver is timeless.',
23+
issue: '1',
24+
timePeriod: null
25+
};
26+
27+
cy.createSubmissionAndPublish(submission);
28+
29+
// go to journal index and check there is no map
30+
cy.visit('/');
31+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
32+
cy.get('a:contains("Vancouver has no time")').last().click();
33+
34+
cy.get('#optimeta_article_temporal').should('not.be.visible');
35+
cy.get('#optimeta_article_spatial_download').should('be.visible');
36+
cy.get('#mapdiv').should('be.visible');
37+
cy.get('#optimeta_article_administrativeUnit').should('not.be.visible');
38+
});
39+
40+
it('Has no information on location if it is missing', function () {
41+
var submission = {
42+
title: 'Vancouver has no place',
43+
subtitle: 'No no no',
44+
abstract: 'The city of Vancouver is lost.',
45+
issue: '1',
46+
timePeriod: '2000-02-20 - 2000-02-22',
47+
spatial: null
48+
};
49+
50+
cy.createSubmissionAndPublish(submission);
51+
52+
// go to journal index and check there is no map
53+
cy.visit('/');
54+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
55+
cy.get('a:contains("Vancouver has no place")').last().click();
56+
57+
cy.get('.pkp_structure_main').should('contain', 'Time and location');
58+
cy.get('.pkp_structure_main').should('contain', '2000-02-22');
59+
cy.get('#optimeta_article_spatial').should('not.be.visible');
60+
cy.get('#optimeta_article_spatial_download').should('not.be.visible');
61+
cy.get('#mapdiv').should('not.be.visible');
62+
cy.get('#optimeta_article_administrativeUnit').should('not.be.visible');
63+
});
64+
65+
it('Has only administrative unit', function () {
66+
var submission = {
67+
title: 'Vancouver has a region',
68+
subtitle: 'No no no',
69+
abstract: 'The city of Vancouver is part of something.',
70+
issue: '1',
71+
timePeriod: null,
72+
spatial: null,
73+
adminUnit: 'Oh Canada{enter}'
74+
};
75+
76+
cy.createSubmissionAndPublish(submission);
77+
78+
// go to journal index and check there is no map
79+
cy.visit('/');
80+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
81+
cy.get('a:contains("Vancouver has a region")').last().click();
82+
83+
cy.get('.pkp_structure_main').should('contain', 'Oh Canada');
84+
cy.get('#optimeta_article_temporal').should('not.be.visible');
85+
cy.get('#optimeta_article_spatial').should('not.be.visible');
86+
cy.get('#optimeta_article_spatial_download').should('not.be.visible');
87+
cy.get('#mapdiv').should('not.be.visible');
88+
});
89+
90+
it('Has no Time and location and no geodata download if all geospatial metadata is missing', function () {
91+
var submission = {
92+
title: 'Vancouver has nothing',
93+
subtitle: 'No no no',
94+
abstract: 'The city of Vancouver is gone.',
95+
issue: '1',
96+
timePeriod: null,
97+
spatial: null
98+
};
99+
100+
cy.createSubmissionAndPublish(submission);
101+
102+
// go to journal index and check there is no map
103+
cy.visit('/');
104+
cy.get('nav[class="pkp_site_nav_menu"] a:contains("Current")').click();
105+
cy.get('a:contains("Vancouver has nothing")').last().click();
106+
107+
cy.get('#optimeta_article_geospatialmetadata').should('not.be.visible');
108+
cy.get('#optimeta_article_temporal').should('not.be.visible');
109+
cy.get('#optimeta_article_spatial').should('not.be.visible');
110+
cy.get('#optimeta_article_spatial_download').should('not.be.visible');
111+
cy.get('#mapdiv').should('not.be.visible');
112+
cy.get('#optimeta_article_administrativeUnit').should('not.be.visible');
113+
});
114+
115+
});
File renamed without changes.

0 commit comments

Comments
 (0)