Skip to content

Commit 8fb53ec

Browse files
Merge branch 'fixMissingViewer-788' into 'main'
Corrige problemas que fazem o visualizador sumir See merge request softwares-pkp/plugins_ojs/pdfEmbedViewer!2
2 parents 34f29a8 + f3b647b commit 8fb53ec

File tree

4 files changed

+151
-34
lines changed

4 files changed

+151
-34
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ variables:
33

44
include:
55
- project: 'documentacao-e-tarefas/modelosparaintegracaocontinua'
6-
ref: main
6+
ref: stable-3_3_0
77
file:
88
- 'templates/groups/pkp_plugin.yml'
99
- 'templates/groups/ops/cypress_tests.yml'
Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,123 @@
11
import '../support/commands.js';
22

3+
function firstStep() {
4+
cy.get('input[id^="checklist-"]').click({multiple: true});
5+
cy.get('input[id=privacyConsent]').click();
6+
cy.get('#submitStep1Form button.submitFormButton').click();
7+
}
8+
9+
function addGalleyFile(file) {
10+
cy.get('a:contains("Add galley")').click();
11+
cy.wait(2000);
12+
cy.get('div.pkp_modal_panel').then($modalDiv => {
13+
cy.wait(3000);
14+
cy.get('div.pkp_modal_panel input[id^="label-"]').type('PDF', {delay: 0});
15+
cy.get('div.pkp_modal_panel button:contains("Save")').click();
16+
cy.wait(2000);
17+
});
18+
cy.get('select[id=genreId]').select(file.genre);
19+
cy.fixture(file.file, 'base64').then(fileContent => {
20+
cy.get('input[type=file]').upload(
21+
{fileContent, 'fileName': file.fileName, 'mimeType': 'application/pdf', 'encoding': 'base64'}
22+
);
23+
});
24+
cy.get('button').contains('Continue').click();
25+
cy.wait(2000);
26+
for (const field in file.metadata) {
27+
cy.get('input[id^="' + Cypress.$.escapeSelector(field) + '"]:visible,textarea[id^="' + Cypress.$.escapeSelector(field) + '"]').type(file.metadata[field], {delay: 0});
28+
cy.get('input[id^="language"').click({force: true});
29+
}
30+
cy.get('button').contains('Continue').click();
31+
cy.get('button').contains('Complete').click();
32+
}
33+
34+
function secondStep(submissionData) {
35+
for(let file of submissionData.files) {
36+
addGalleyFile(file);
37+
}
38+
cy.get('#submitStep2Form button.submitFormButton').click();
39+
}
40+
41+
function thirdStep(submissionData) {
42+
cy.get('input[id^="title-en_US-"').type(submissionData.title, {delay: 0});
43+
cy.get('label').contains('Title').click();
44+
cy.get('textarea[id^="abstract-en_US"]').then(node => {
45+
cy.setTinyMceContent(node.attr('id'), submissionData.abstract);
46+
});
47+
cy.get('ul[id^="en_US-keywords-"]').then(node => {
48+
for(let keyword of submissionData.keywords) {
49+
node.tagit('createTag', keyword);
50+
}
51+
});
52+
cy.waitJQuery();
53+
cy.get('#submitStep3Form button:contains("Save and continue"):visible').click();
54+
}
55+
56+
function fourthStep() {
57+
cy.waitJQuery();
58+
cy.get('form[id=submitStep4Form] button:contains("Finish Submission")').click();
59+
cy.wait(1000);
60+
cy.get('button.pkpModalConfirmButton').click();
61+
}
62+
63+
function createNewSubmission(submissionData) {
64+
cy.get('a:contains("Make a New Submission"), div#myQueue a:contains("New Submission")').click();
65+
66+
firstStep(submissionData);
67+
secondStep(submissionData);
68+
thirdStep(submissionData);
69+
fourthStep();
70+
cy.waitJQuery();
71+
cy.get('h2:contains("Submission complete")');
72+
}
73+
374
describe('Embed PDF viewer', function () {
4-
it('Checks presence of PDF embed viewer at workflows', function () {
75+
let submissionData;
76+
77+
before(function () {
78+
submissionData = {
79+
title: 'New designs for aircraft engines',
80+
abstract: 'An example abstract.',
81+
keywords: ['aircraft', 'engines', 'mechanical design'],
82+
files: [{
83+
'file': 'dummy.pdf',
84+
'fileName': 'design_aircraft_engines.pdf',
85+
'genre': Cypress.env('defaultGenre')
86+
}]
87+
}
88+
});
89+
90+
it('Creates new submission with PDF', function () {
91+
cy.login('ckwantes', null, 'publicknowledge');
92+
createNewSubmission(submissionData);
93+
});
94+
it('Checks presence of PDF embed viewer at workflow', function () {
595
cy.login('dbarnes', null, 'publicknowledge');
6-
cy.findSubmission('archive', 'Arguments About Arguments');
96+
cy.findSubmission('active', submissionData.title);
797

898
cy.get('#publication-button').click();
999
cy.get('#galleys-button').click();
10100

11101
cy.contains('a', 'PDF');
12102
cy.get('#pdfEmbedViewer').should('exist');
13103
});
104+
it('PDF embed viewer is not affected by metadata editing', function () {
105+
cy.login('dbarnes', null, 'publicknowledge');
106+
cy.findSubmission('active', submissionData.title);
107+
108+
cy.get('#publication-button').click();
109+
cy.get('#galleys-button').click();
110+
cy.wait(3000);
111+
cy.contains('a', 'PDF');
112+
cy.get('#pdfEmbedViewer').should('exist');
113+
114+
cy.get('#titleAbstract-button').click();
115+
cy.get('input[id^="titleAbstract-title-control-en_US"').type(' plus text', {delay: 0});
116+
cy.contains('button', 'Save').click();
117+
cy.wait(3000);
118+
119+
cy.get('#galleys-button').click();
120+
cy.contains('a', 'PDF');
121+
cy.get('#pdfEmbedViewer').should('exist');
122+
});
14123
});

templates/pdfEmbedViewer.tpl

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div id="pdfEmbedViewer" style="display: none;">
1+
<div id="pdfEmbedViewerTemplate" style="display: none;">
22
<iframe
33
src=""
44
width="100%"
@@ -10,36 +10,44 @@
1010
</div>
1111

1212
<script>
13-
function setAndDisplayEmbedViewer(pdfEmbedViewerUrl, galleyTabTbody) {
14-
let trs = galleyTabTbody.querySelectorAll('tr');
15-
let downloadLink = trs[0].querySelector('a.pkp_linkaction_downloadFile');
16-
let embedPdfUrl = downloadLink.getAttribute('href');
17-
18-
$("#pdfEmbedViewer > iframe").attr("src", pdfEmbedViewerUrl + encodeURIComponent(embedPdfUrl));
19-
$(trs[1]).after($("#pdfEmbedViewer"));
20-
$("#pdfEmbedViewer").css("display", "block");
21-
}
22-
23-
$(document).ready(function() {
24-
setTimeout(function() {
25-
let pdfEmbedViewerUrl = "{$pdfJsViewerPluginUrl}/pdf.js/web/viewer.html?file=";
26-
let galleysTabTbodies = document.getElementById('galleys').querySelectorAll('tbody');
13+
function setAndDisplayEmbedViewer() {
14+
let pdfEmbedViewer = document.getElementById('pdfEmbedViewer');
15+
if (pdfEmbedViewer) {
16+
pdfEmbedViewer.remove();
17+
}
2718
28-
if (galleysTabTbodies[1].style.display === 'none') {
29-
setAndDisplayEmbedViewer(pdfEmbedViewerUrl, galleysTabTbodies[0]);
19+
let pdfEmbedViewerUrl = "{$pdfJsViewerPluginUrl}/pdf.js/web/viewer.html?file=";
20+
let trs = document.getElementById('galleys').querySelector('tbody').querySelectorAll('tr');
21+
if (trs.length >= 2) {
22+
let downloadLink = trs[0].querySelector('a.pkp_linkaction_downloadFile');
23+
if (downloadLink) {
24+
let embedPdfUrl = downloadLink.getAttribute('href');
25+
let pdfEmbedViewer = document.getElementById('pdfEmbedViewerTemplate').cloneNode(true);
26+
pdfEmbedViewer.id = 'pdfEmbedViewer';
27+
document.body.appendChild(pdfEmbedViewer);
28+
29+
$("#pdfEmbedViewer > iframe").attr("src", pdfEmbedViewerUrl + encodeURIComponent(embedPdfUrl));
30+
$(trs[1]).after($("#pdfEmbedViewer"));
31+
$("#pdfEmbedViewer").css("display", "block");
3032
}
31-
32-
const secondTbodyObserver = new MutationObserver(function(mutations) {
33-
mutations.forEach(function(mutation) {
34-
if (mutation.attributeName === 'style') {
35-
if (galleysTabTbodies[1].style.display !== 'none') {
36-
$("#pdfEmbedViewer").css("display", "none");
37-
}
38-
}
33+
}
34+
}
35+
36+
function listenToGalleyGridRequests() {
37+
const originalOpen = XMLHttpRequest.prototype.open;
38+
XMLHttpRequest.prototype.open = function(method, url) {
39+
if (url.search('article-galley-grid') >= 0 && (url.search('fetch-grid') >= 0 || url.search('fetch-row') >= 0)) {
40+
this.addEventListener('load', function() {
41+
setTimeout(function() {
42+
setAndDisplayEmbedViewer();
43+
}, 2000);
3944
});
40-
});
41-
42-
secondTbodyObserver.observe(galleysTabTbodies[1], { attributes: true, attributeFilter: ['style'] });
43-
}, 3000);
45+
}
46+
originalOpen.apply(this, arguments);
47+
};
48+
}
49+
50+
$(document).ready(function() {
51+
listenToGalleyGridRequests();
4452
});
4553
</script>

version.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<application>pdfEmbedViewer</application>
1414
<type>plugins.generic</type>
1515
<lazy-load>0</lazy-load>
16-
<release>1.0.0.0</release>
17-
<date>2025-06-16</date>
16+
<release>1.0.1.0</release>
17+
<date>2025-06-23</date>
1818
<class>PdfEmbedViewerPlugin</class>
1919
</version>

0 commit comments

Comments
 (0)