Skip to content

Commit

Permalink
Merge pull request #27 from lepidus/stable-3_3_0
Browse files Browse the repository at this point in the history
Feature/added work type selection (OMP 3.3.0)
  • Loading branch information
thiagolepidus authored Feb 20, 2025
2 parents df5bd1d + c99ab95 commit 18e8526
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 24 deletions.
11 changes: 7 additions & 4 deletions classes/api/ThothEndpoint.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ public function register($slimRequest, $response, $args)
$submission = $handler->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION);
$params = $slimRequest->getParsedBody();

if (empty($params['imprint'])) {
return $response->withStatus(400)->withJson(['imprint' => [__('plugins.generic.thoth.imprint.required')]]);
$thothImprintId = $params['thothImprintId'];
if (!$thothImprintId) {
return $response->withStatus(400)->withJson(
['thothImprintId' => [__('plugins.generic.thoth.imprint.required')]]
);
}

if (!$submission) {
Expand Down Expand Up @@ -86,9 +89,9 @@ public function register($slimRequest, $response, $args)

AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_APP_SUBMISSION);

$disableNotification = $params['disableNotification'];
$disableNotification = $params['disableNotification'] ?? false;
try {
$thothBookId = ThothService::book()->register($publication, $params['imprint']);
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
$this->handleNotification($request, $submission, true, $disableNotification);
} catch (QueryException $e) {
Expand Down
24 changes: 22 additions & 2 deletions classes/components/forms/RegisterForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
use PKP\components\forms\FieldHTML;
use PKP\components\forms\FieldSelect;
use PKP\components\forms\FormComponent;
use ThothApi\GraphQL\Models\Work as ThothWork;

class RegisterForm extends FormComponent
{
public $id = 'register';

public $method = 'PUT';

public function __construct($action, $imprints, $errors)
public function __construct($action, $imprints, $workType, $errors)
{
$this->action = $action;

Expand Down Expand Up @@ -80,13 +81,32 @@ public function __construct($action, $imprints, $errors)
'description' => $msg,
'groupId' => 'default',
]))
->addField(new FieldSelect('imprint', [
->addField(new FieldSelect('thothImprintId', [
'label' => __('plugins.generic.thoth.imprint'),
'options' => $imprintOptions,
'required' => true,
'groupId' => 'default',
'value' => $imprintOptions[0]['value'] ?? null
]));

$workTypeOptions = [
[
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
'label' => __('plugins.generic.thoth.workType.monograph')
],
[
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
'label' => __('plugins.generic.thoth.workType.textbook')
],
];

$this->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
'label' => __('plugins.generic.thoth.workType'),
'options' => $workTypeOptions,
'required' => true,
'groupId' => 'default',
'value' => $workTypeOptions[0]['value'] ?? null
]));
}

public function getOptions($list)
Expand Down
32 changes: 29 additions & 3 deletions classes/components/forms/config/PublishFormConfig.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @brief Thoth config for publish form
*/

use ThothApi\GraphQL\Models\Work as ThothWork;

import('plugins.generic.thoth.classes.facades.ThothService');
import('plugins.generic.thoth.classes.facades.ThothRepo');

Expand Down Expand Up @@ -48,12 +50,12 @@ public function addConfig($hookName, $form)
return false;
}

$this->addFields($form, $imprints);
$this->addFields($form, $imprints, $submission->getData('workType'));

return false;
}

private function addFields($form, $imprints)
private function addFields($form, $imprints, $workType)
{
$imprintOptions = [];
foreach ($imprints as $imprint) {
Expand All @@ -71,14 +73,38 @@ private function addFields($form, $imprints)
'value' => false,
'groupId' => 'default',
]))
->addField(new \PKP\components\forms\FieldSelect('imprint', [
->addField(new \PKP\components\forms\FieldSelect('thothImprintId', [
'label' => __('plugins.generic.thoth.imprint'),
'options' => $imprintOptions,
'required' => true,
'showWhen' => 'registerConfirmation',
'groupId' => 'default',
'value' => $imprintOptions[0]['value'] ?? null
]));

if ($workType !== WORK_TYPE_AUTHORED_WORK) {
return;
}

$workTypeOptions = [
[
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
'label' => __('plugins.generic.thoth.workType.monograph')
],
[
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
'label' => __('plugins.generic.thoth.workType.textbook')
],
];

$form->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
'label' => __('plugins.generic.thoth.workType'),
'options' => $workTypeOptions,
'required' => true,
'showWhen' => 'registerConfirmation',
'groupId' => 'default',
'value' => $workTypeOptions[0]['value'] ?? null
]));
}

private function showErrors($form, $errors)
Expand Down
7 changes: 5 additions & 2 deletions classes/factories/ThothBookFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ public function createFromPublication($publication)
$request = Application::get()->getRequest();
$submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId'));
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
$thothWorkType = $request->getUserVar('thothWorkType');

return new ThothWork([
'workType' => $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
'workStatus' => ThothWork::WORK_STATUS_ACTIVE,
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
'workStatus' => empty($publication->getData('datePublished'))
? ThothWork::WORK_STATUS_FORTHCOMING
: ThothWork::WORK_STATUS_ACTIVE,
'fullTitle' => $publication->getLocalizedFullTitle(),
'title' => $publication->getLocalizedTitle(),
'subtitle' => $publication->getLocalizedData('subtitle'),
Expand Down
4 changes: 3 additions & 1 deletion classes/factories/ThothChapterFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function createFromChapter($chapter)

return new ThothWork([
'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER,
'workStatus' => ThothWork::WORK_STATUS_ACTIVE,
'workStatus' => (empty($chapter->getDatePublished()) && empty($publication->getData('datePublished')))
? ThothWork::WORK_STATUS_FORTHCOMING
: ThothWork::WORK_STATUS_ACTIVE,
'fullTitle' => $chapter->getLocalizedFullTitle(),
'title' => $chapter->getLocalizedTitle(),
'subtitle' => $chapter->getLocalizedData('subtitle'),
Expand Down
10 changes: 5 additions & 5 deletions classes/listeners/PublicationPublishListener.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function validate($hookName, $args)
return;
}

$imprint = $request->getUserVar('imprint');
if (empty($imprint)) {
$errors['imprint'] = [__('plugins.generic.thoth.imprint.required')];
$thothImprintId = $request->getUserVar('thothImprintId');
if (empty($thothImprintId)) {
$errors['thothImprintId'] = [__('plugins.generic.thoth.imprint.required')];
}
}

Expand All @@ -50,10 +50,10 @@ public function registerThothBook($hookName, $args)
return false;
}

$imprint = $request->getUserVar('imprint');
$thothImprintId = $request->getUserVar('thothImprintId');
$thothNotification = new ThothNotification();
try {
$thothBookId = ThothService::book()->register($publication, $imprint);
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
$thothNotification->notifySuccess($request, $submission);
} catch (QueryException $e) {
Expand Down
5 changes: 4 additions & 1 deletion classes/services/ThothBookService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public function validate($publication)

if ($landingPage = $thothBook->getLandingPage()) {
$retrievedThothBook = $this->repository->find($landingPage);
if ($retrievedThothBook !== null) {
if (
$retrievedThothBook !== null
&& $retrievedThothBook->getLandingPage() === $landingPage
) {
$errors[] = __(
'plugins.generic.thoth.validation.landingPageExists',
['landingPage' => $landingPage]
Expand Down
4 changes: 2 additions & 2 deletions controllers/modal/RegisterHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function register($args, $request)
);

$imprints = [];

$workType = $this->submission->getData('workType');
try {
$errors = ThothService::book()->validate($this->publication);

Expand All @@ -97,7 +97,7 @@ public function register($args, $request)
}

$plugin->import('classes.components.forms.RegisterForm');
$registerForm = new RegisterForm($publicationApiUrl, $imprints, $errors);
$registerForm = new RegisterForm($publicationApiUrl, $imprints, $workType, $errors);

$settingsData = [
'components' => [
Expand Down
2 changes: 1 addition & 1 deletion js/ui/components/ListPanel/ThothListPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pkp.Vue.component('thoth-list-panel', {
'X-Http-Method-Override': 'PUT',
},
data: {
imprint: this.selectedImprint,
thothImprintId: this.selectedImprint,
disableNotification: true
},
success: (response) => this.updateItem(response),
Expand Down
9 changes: 9 additions & 0 deletions locale/en_US/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ msgstr "Your site administrator must set a secret in the config file ('api_key_s
msgid "plugins.generic.thoth.credentialsMissing"
msgstr "Thoth credentials not configured."

msgid "plugins.generic.thoth.workType"
msgstr "Work Type"

msgid "plugins.generic.thoth.workType.monograph"
msgstr "Monograph"

msgid "plugins.generic.thoth.workType.textbook"
msgstr "Textbook"

msgid "plugins.generic.thoth.thothBook"
msgstr "Thoth Book: "

Expand Down
9 changes: 9 additions & 0 deletions locale/es_ES/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ msgstr "El administrador de su sitio debe establecer un secreto en el archivo de
msgid "plugins.generic.thoth.credentialsMissing"
msgstr "Credenciales de Thoth no configuradas."

msgid "plugins.generic.thoth.workType"
msgstr "Tipo de Trabajo"

msgid "plugins.generic.thoth.workType.monograph"
msgstr "Monografía"

msgid "plugins.generic.thoth.workType.textbook"
msgstr "Libro de Texto"

msgid "plugins.generic.thoth.thothBook"
msgstr "Libro de Thoth: "

Expand Down
9 changes: 9 additions & 0 deletions locale/pt_BR/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ msgstr "O administrador do seu site deve definir um segredo no arquivo de config
msgid "plugins.generic.thoth.credentialsMissing"
msgstr "Credenciais do Thoth não configuradas."

msgid "plugins.generic.thoth.workType"
msgstr "Tipo de Trabalho"

msgid "plugins.generic.thoth.workType.monograph"
msgstr "Monografia"

msgid "plugins.generic.thoth.workType.textbook"
msgstr "Livro de Texto"

msgid "plugins.generic.thoth.thothBook"
msgstr "Livro Thoth: "

Expand Down
4 changes: 3 additions & 1 deletion tests/classes/services/ThothBookServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ public function testLandingPageExistsBookValidationFails()
->getMock();
$mockRepository->expects($this->once())
->method('find')
->will($this->returnValue(new ThothWork()));
->will($this->returnValue(new ThothWork([
'landingPage' => 'http://www.publicknowledge.omp/index.php/publicknowledge/catalog/book/14'
])));

$mockPublication = $this->getMockBuilder(Publication::class)->getMock();

Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<version>
<application>thoth</application>
<type>plugins.generic</type>
<release>0.1.6.0</release>
<date>2025-02-18</date>
<release>0.1.7.0</release>
<date>2025-02-20</date>
<lazy-load>1</lazy-load>
<class>ThothPlugin</class>
</version>

0 comments on commit 18e8526

Please sign in to comment.