Skip to content

Commit

Permalink
Merge pull request #28 from lepidus/main
Browse files Browse the repository at this point in the history
Feature/added work type selection (OMP 3.4.0)
  • Loading branch information
thiagolepidus authored Feb 20, 2025
2 parents 99eccb8 + 4e61584 commit c99a373
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 21 deletions.
9 changes: 6 additions & 3 deletions classes/api/ThothEndpoint.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ public function register($slimRequest, $response, $args)
$submission = Repo::submission()->get($submissionId);
$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 @@ -94,7 +97,7 @@ public function register($slimRequest, $response, $args)

$disableNotification = $params['disableNotification'] ?? false;
try {
$thothBookId = ThothService::book()->register($publication, $params['imprint']);
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
$this->handleNotification($request, $submission, true, $disableNotification);
} catch (QueryException $e) {
Expand Down
29 changes: 27 additions & 2 deletions classes/components/forms/RegisterForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
* publication.
*/

use APP\submission\Submission;
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 @@ -81,13 +83,36 @@ 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
]));

if ($workType !== Submission::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')
],
];

$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 @@ -15,6 +15,8 @@
*/

use APP\facades\Repo;
use APP\submission\Submission;
use ThothApi\GraphQL\Models\Work as ThothWork;

import('plugins.generic.thoth.classes.facades.ThothService');
import('plugins.generic.thoth.classes.facades.ThothRepository');
Expand Down Expand Up @@ -51,12 +53,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 @@ -74,14 +76,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 !== Submission::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
3 changes: 2 additions & 1 deletion classes/factories/ThothBookFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function createFromPublication($publication)
$request = Application::get()->getRequest();
$submission = Repo::submission()->get($publication->getData('submissionId'));
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
$thothWorkType = $request->getUserVar('thothWorkType');

return new ThothWork([
'workType' => $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
'workStatus' => empty($publication->getData('datePublished'))
? ThothWork::WORK_STATUS_FORTHCOMING
: ThothWork::WORK_STATUS_ACTIVE,
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 @@ -33,9 +33,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 @@ -54,10 +54,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);
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
$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 @@ -78,7 +78,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 @@ -87,7 +87,7 @@ public function register($args, $request)
);

$imprints = [];

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

Expand All @@ -101,7 +101,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 @@ -307,7 +307,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/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/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
3 changes: 3 additions & 0 deletions tests/classes/factories/ThothBookFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ private function setUpMockEnvironment()
->andReturn('https://omp.publicknowledgeproject.org/index.php/press/catalog/book/3')
->getMock()
)
->shouldReceive('getUserVar')
->with('thothWorkType')
->andReturn(null)
->getMock();
Registry::set('request', $mockRequest);

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 @@ -122,7 +122,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(\APP\publication\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.2.4.0</release>
<date>2025-02-18</date>
<release>0.2.5.0</release>
<date>2025-02-20</date>
<lazy-load>1</lazy-load>
<class>ThothPlugin</class>
</version>

0 comments on commit c99a373

Please sign in to comment.