Skip to content

Commit

Permalink
Merge pull request #1813 from bozana/10821
Browse files Browse the repository at this point in the history
pkp/pkp-lib#10821 Migrate pubid plugin to vue3, Use pkp-button for Apply Number in URN plugin, disable for empty value, Fix anyPubIdExists, pubIdExists, checkDuplicate
  • Loading branch information
bozana authored Jan 20, 2025
2 parents 209e65d + f98ab13 commit bfe2b39
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion classes/monograph/ChapterDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function pubIdExists(string $pubIdType, string $pubId, int $excludePubObj
return DB::table('submission_chapter_settings AS scs')
->join('submission_chapters AS sc', 'scs.chapter_id', '=', 'sc.chapter_id')
->join('publications AS p', 'sc.publication_id', '=', 'p.publication_id')
->join('submissions AS s', 'p.submission_id', '=', 's.submisison_id')
->join('submissions AS s', 'p.submission_id', '=', 's.submission_id')
->where('scs.setting_name', '=', "pub-id::{$pubIdType}")
->where('scs.setting_value', '=', $pubId)
->where('sc.chapter_id', '<>', $excludePubObjectId)
Expand Down
20 changes: 9 additions & 11 deletions classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,17 @@ public function getDAOs()
/**
* @copydoc PKPPubIdPlugin::checkDuplicate()
*/
public function checkDuplicate($pubId, $pubObjectType, $excludeId, int $contextId)
public function checkDuplicate($pubId, $pubObject, int $contextId)
{
/** @var ChapterDAO */
$chapterDao = DAORegistry::getDAO('ChapterDAO');
foreach ($this->getPubObjectTypes() as $type => $fqcn) {
if ($type === 'Chapter') {
$excludeTypeId = $type === $pubObjectType ? $excludeId : null;
if ($chapterDao->pubIdExists($this->getPubIdType(), $pubId, $excludeTypeId, $contextId)) {
return false;
}
$allowedPubObjectTypes = $this->getPubObjectTypes();
if ($pubObject instanceof $allowedPubObjectTypes['Chapter']) {
/** @var ChapterDAO */
$chapterDao = DAORegistry::getDAO('ChapterDAO');
if ($chapterDao->pubIdExists($this->getPubIdType(), $pubId, $pubObject->getId(), $contextId)) {
return false;
}
return true;
}

return parent::checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId);
return parent::checkDuplicate($pubId, $pubObject, $contextId);
}
}
3 changes: 2 additions & 1 deletion classes/press/PressDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/press/PressDAO.php
*
Expand Down Expand Up @@ -106,7 +107,7 @@ public function anyPubIdExists(
$forSameType = false
) {
$pubObjectDaos = [
Application::ASSOC_TYPE_SUBMISSION => Repo::submission()->dao,
Application::ASSOC_TYPE_PUBLICATION => Repo::publication()->dao,
Application::ASSOC_TYPE_CHAPTER => DAORegistry::getDAO('ChapterDAO'),
Application::ASSOC_TYPE_REPRESENTATION => Application::getRepresentationDAO(),
Application::ASSOC_TYPE_SUBMISSION_FILE => Repo::submissionFile()->dao,
Expand Down
2 changes: 2 additions & 0 deletions classes/publicationFormat/PublicationFormatDAO.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/publicationFormat/PublicationFormatDAO.php
*
Expand Down Expand Up @@ -493,6 +494,7 @@ public function pubIdExists(string $pubIdType, string $pubId, int $excludePubObj
->join('publications AS p', 'p.publication_id', '=', 'pf.publication_id')
->join('submissions AS s', 's.submission_id', '=', 'p.submission_id')
->where('pft.setting_name', '=', "pub-id::{$pubIdType}")
->where('pft.setting_value', '=', $pubId)
->where('pf.publication_format_id', '<>', $excludePubObjectId)
->where('s.context_id', '=', $contextId)
->count() > 0;
Expand Down
21 changes: 10 additions & 11 deletions plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function validatePublicationUrn(string $hookName, array $args): void
if (strpos($props['pub-id::other::urn'], $urnPrefix) !== 0) {
$urnErrors[] = __('plugins.pubIds.urn.editor.missingPrefix', ['urnPrefix' => $urnPrefix]);
}
if (!$this->checkDuplicate($props['pub-id::other::urn'], 'Publication', $submission->getId(), $contextId)) {
if (!$this->checkDuplicate($props['pub-id::other::urn'], $publication, $contextId)) {
$urnErrors[] = $this->getNotUniqueErrorMsg();
}
if (!empty($urnErrors)) {
Expand Down Expand Up @@ -319,10 +319,6 @@ public function addPublicationFormFields(string $hookName, FormComponent $form):

$appyCheckNumber = $this->getSetting($form->submissionContext->getId(), 'urnCheckNo');

if ($appyCheckNumber) {
// Load the checkNumber.js file that is required for URN fields
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));
}
// If a pattern exists, use a DOI-like field to generate the URN
if ($pattern) {
$fieldData = [
Expand Down Expand Up @@ -467,12 +463,20 @@ public function loadUrnFieldComponent(string $hookName, array $args): void
$templateMgr = $args[0];
$template = $args[1];

if ($template !== 'workflow/workflow.tpl') {
if ($template !== 'dashboard/editors.tpl') {
return;
}

$context = Application::get()->getRequest()->getContext();
$suffixType = $this->getSetting($context->getId(), 'urnSuffix');

$appyCheckNumber = $this->getSetting($context->getId(), 'urnCheckNo');

if ($appyCheckNumber) {
// Load the checkNumber.js file that is required for URN fields
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));
}

if ($suffixType === 'default' || $suffixType === 'pattern') {
$templateMgr->addJavaScript(
'field-pub-id-urn-component',
Expand All @@ -498,11 +502,6 @@ public function loadUrnFieldComponent(string $hookName, array $args): void
.pkpFormField--urn__input {
display: inline-block;
}
.pkpFormField--urn__button {
margin-left: 0.25rem;
height: 2.5rem; // Match input height
}
',
[
'contexts' => 'backend',
Expand Down
8 changes: 4 additions & 4 deletions plugins/pubIds/urn/js/FieldPubIdUrn.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* @brief A Vue.js component for URN field, that is used for pattern suffixes and that considers check number.
*/

pkp.Vue.component('field-pub-id-urn', {
pkp.registry.registerComponent('FieldPubIdUrn', {
name: 'FieldPubIdUrn',
extends: pkp.Vue.component('field-pub-id'),
extends: pkp.registry.getComponent('PkpFieldPubId'),
props: {
applyCheckNumber: {
type: Boolean,
Expand All @@ -22,10 +22,10 @@ pkp.Vue.component('field-pub-id-urn', {
},
methods: {
generateId() {
var id = pkp.Vue.component('field-pub-id').options.methods['generateId'].apply(this);
var id = pkp.registry.getComponent('PkpFieldPubId').methods['generateId'].apply(this);
return this.applyCheckNumber
? id + $.pkp.plugins.generic.urn.getCheckNumber(id, this.prefix)
: id;
}
},
});
})
110 changes: 55 additions & 55 deletions plugins/pubIds/urn/js/FieldTextUrn.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,76 @@
*
* @brief A Vue.js component for URN text form field, that is used for custom suffixes, and that considers adding a check number.
*/
var template = pkp.Vue.compile('<div class="pkpFormField pkpFormField--text pkpFormField--urn" :class="classes">' +
' <form-field-label' +
' :controlId="controlId"' +
' :label="label"' +
' :localeLabel="localeLabel"' +
' :isRequired="isRequired"' +
' :requiredLabel="__(\'common.required\')"' +
' :multilingualLabel="multilingualLabel"' +
' />' +
' <div' +
' v-if="isPrimaryLocale && description"' +
' class="pkpFormField__description"' +
' v-html="description"' +
' :id="describedByDescriptionId"' +
' />' +
' <div class="pkpFormField__control" :class="controlClasses">' +
' <input' +
' class="pkpFormField__input pkpFormField--text__input pkpFormField--urn__input"' +
' ref="input"' +
' v-model="currentValue"' +
' :type="inputType"' +
' :id="controlId"' +
' :name="localizedName"' +
' :aria-describedby="describedByIds"' +
' :aria-invalid="!!errors.length"' +
' :required="isRequired"' +
' :style="inputStyles"' +
' />' +
' <button' +
' v-if="applyCheckNumber"' +
' class="pkpButton pkpFormField--urn__button"' +
' @click.prevent="addCheckNumber"' +
' >' +
' {{ addCheckNumberLabel }}' +
' </button>' +
' <field-error' +
' v-if="errors.length"' +
' :id="describedByErrorId"' +
' :messages="errors"' +
' />' +
' </div>' +
' </div>' +
' </div>');

pkp.Vue.component('field-text-urn', {
pkp.registry.registerComponent('FieldTextUrn', {
name: 'FieldTextUrn',
extends: pkp.Vue.component('field-text'),
extends: pkp.registry.getComponent('PkpFieldText'),
template:
'<div class="pkpFormField pkpFormField--text pkpFormField--urn" :class="classes">' +
' <form-field-label' +
' :controlId="controlId"' +
' :label="label"' +
' :localeLabel="localeLabel"' +
' :isRequired="isRequired"' +
' :requiredLabel="t(\'common.required\')"' +
' :multilingualLabel="multilingualLabel"' +
' />' +
' <div' +
' v-if="isPrimaryLocale && description"' +
' class="pkpFormField__description"' +
' v-html="description"' +
' :id="describedByDescriptionId"' +
' />' +
' <div class="pkpFormField__control" :class="controlClasses">' +
' <input' +
' class="pkpFormField__input pkpFormField--text__input pkpFormField--urn__input"' +
' ref="input"' +
' v-model="currentValue"' +
' :type="inputType"' +
' :id="controlId"' +
' :name="localizedName"' +
' :aria-describedby="describedByIds"' +
' :aria-invalid="!!errors.length"' +
' :required="isRequired"' +
' :style="inputStyles"' +
' />' +
' <pkp-button' +
' v-if="applyCheckNumber"' +
' @click.prevent="addCheckNumber"' +
' :disabled="currentValue.length === 0"' +
' >' +
' {{ addCheckNumberLabel }}' +
' </pkp-button>' +
' <field-error' +
' v-if="errors.length"' +
' :id="describedByErrorId"' +
' :messages="errors"' +
' />' +
' </div>' +
' </div>',
props: {
addCheckNumberLabel: {
type: String,
required: true
required: true,
},
urnPrefix: {
type: String,
required: true
required: true,
},
applyCheckNumber: {
type: Boolean,
required: true
}
required: true,
},
},
methods: {
/**
* Add a check number to the end of the URN
*/
addCheckNumber() {
this.currentValue += $.pkp.plugins.generic.urn.getCheckNumber(this.currentValue, this.urnPrefix);
}
this.currentValue += $.pkp.plugins.generic.urn.getCheckNumber(
this.currentValue || '',
this.urnPrefix,
);
},
},
render: function(h) {
return template.render.call(this, h);
}
});
});

0 comments on commit bfe2b39

Please sign in to comment.