Skip to content

Commit c99a373

Browse files
Merge pull request #28 from lepidus/main
Feature/added work type selection (OMP 3.4.0)
2 parents 99eccb8 + 4e61584 commit c99a373

14 files changed

Lines changed: 111 additions & 21 deletions

File tree

classes/api/ThothEndpoint.inc.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ public function register($slimRequest, $response, $args)
5757
$submission = Repo::submission()->get($submissionId);
5858
$params = $slimRequest->getParsedBody();
5959

60-
if (empty($params['imprint'])) {
61-
return $response->withStatus(400)->withJson(['imprint' => [__('plugins.generic.thoth.imprint.required')]]);
60+
$thothImprintId = $params['thothImprintId'];
61+
if (!$thothImprintId) {
62+
return $response->withStatus(400)->withJson(
63+
['thothImprintId' => [__('plugins.generic.thoth.imprint.required')]]
64+
);
6265
}
6366

6467
if (!$submission) {
@@ -94,7 +97,7 @@ public function register($slimRequest, $response, $args)
9497

9598
$disableNotification = $params['disableNotification'] ?? false;
9699
try {
97-
$thothBookId = ThothService::book()->register($publication, $params['imprint']);
100+
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
98101
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
99102
$this->handleNotification($request, $submission, true, $disableNotification);
100103
} catch (QueryException $e) {

classes/components/forms/RegisterForm.inc.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
* publication.
1919
*/
2020

21+
use APP\submission\Submission;
2122
use PKP\components\forms\FieldHTML;
2223
use PKP\components\forms\FieldSelect;
2324
use PKP\components\forms\FormComponent;
25+
use ThothApi\GraphQL\Models\Work as ThothWork;
2426

2527
class RegisterForm extends FormComponent
2628
{
2729
public $id = 'register';
2830

2931
public $method = 'PUT';
3032

31-
public function __construct($action, $imprints, $errors)
33+
public function __construct($action, $imprints, $workType, $errors)
3234
{
3335
$this->action = $action;
3436

@@ -81,13 +83,36 @@ public function __construct($action, $imprints, $errors)
8183
'description' => $msg,
8284
'groupId' => 'default',
8385
]))
84-
->addField(new FieldSelect('imprint', [
86+
->addField(new FieldSelect('thothImprintId', [
8587
'label' => __('plugins.generic.thoth.imprint'),
8688
'options' => $imprintOptions,
8789
'required' => true,
8890
'groupId' => 'default',
8991
'value' => $imprintOptions[0]['value'] ?? null
9092
]));
93+
94+
if ($workType !== Submission::WORK_TYPE_AUTHORED_WORK) {
95+
return;
96+
}
97+
98+
$workTypeOptions = [
99+
[
100+
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
101+
'label' => __('plugins.generic.thoth.workType.monograph')
102+
],
103+
[
104+
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
105+
'label' => __('plugins.generic.thoth.workType.textbook')
106+
],
107+
];
108+
109+
$this->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
110+
'label' => __('plugins.generic.thoth.workType'),
111+
'options' => $workTypeOptions,
112+
'required' => true,
113+
'groupId' => 'default',
114+
'value' => $workTypeOptions[0]['value'] ?? null
115+
]));
91116
}
92117

93118
public function getOptions($list)

classes/components/forms/config/PublishFormConfig.inc.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
use APP\facades\Repo;
18+
use APP\submission\Submission;
19+
use ThothApi\GraphQL\Models\Work as ThothWork;
1820

1921
import('plugins.generic.thoth.classes.facades.ThothService');
2022
import('plugins.generic.thoth.classes.facades.ThothRepository');
@@ -51,12 +53,12 @@ public function addConfig($hookName, $form)
5153
return false;
5254
}
5355

54-
$this->addFields($form, $imprints);
56+
$this->addFields($form, $imprints, $submission->getData('workType'));
5557

5658
return false;
5759
}
5860

59-
private function addFields($form, $imprints)
61+
private function addFields($form, $imprints, $workType)
6062
{
6163
$imprintOptions = [];
6264
foreach ($imprints as $imprint) {
@@ -74,14 +76,38 @@ private function addFields($form, $imprints)
7476
'value' => false,
7577
'groupId' => 'default',
7678
]))
77-
->addField(new \PKP\components\forms\FieldSelect('imprint', [
79+
->addField(new \PKP\components\forms\FieldSelect('thothImprintId', [
7880
'label' => __('plugins.generic.thoth.imprint'),
7981
'options' => $imprintOptions,
8082
'required' => true,
8183
'showWhen' => 'registerConfirmation',
8284
'groupId' => 'default',
8385
'value' => $imprintOptions[0]['value'] ?? null
8486
]));
87+
88+
if ($workType !== Submission::WORK_TYPE_AUTHORED_WORK) {
89+
return;
90+
}
91+
92+
$workTypeOptions = [
93+
[
94+
'value' => ThothWork::WORK_TYPE_MONOGRAPH,
95+
'label' => __('plugins.generic.thoth.workType.monograph')
96+
],
97+
[
98+
'value' => ThothWork::WORK_TYPE_TEXTBOOK,
99+
'label' => __('plugins.generic.thoth.workType.textbook')
100+
],
101+
];
102+
103+
$form->addField(new \PKP\components\forms\FieldSelect('thothWorkType', [
104+
'label' => __('plugins.generic.thoth.workType'),
105+
'options' => $workTypeOptions,
106+
'required' => true,
107+
'showWhen' => 'registerConfirmation',
108+
'groupId' => 'default',
109+
'value' => $workTypeOptions[0]['value'] ?? null
110+
]));
85111
}
86112

87113
private function showErrors($form, $errors)

classes/factories/ThothBookFactory.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public function createFromPublication($publication)
2727
$request = Application::get()->getRequest();
2828
$submission = Repo::submission()->get($publication->getData('submissionId'));
2929
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
30+
$thothWorkType = $request->getUserVar('thothWorkType');
3031

3132
return new ThothWork([
32-
'workType' => $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
33+
'workType' => $thothWorkType ?? $this->getWorkTypeBySubmissionWorkType($submission->getData('workType')),
3334
'workStatus' => empty($publication->getData('datePublished'))
3435
? ThothWork::WORK_STATUS_FORTHCOMING
3536
: ThothWork::WORK_STATUS_ACTIVE,

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function validate($hookName, $args)
3333
return;
3434
}
3535

36-
$imprint = $request->getUserVar('imprint');
37-
if (empty($imprint)) {
38-
$errors['imprint'] = [__('plugins.generic.thoth.imprint.required')];
36+
$thothImprintId = $request->getUserVar('thothImprintId');
37+
if (empty($thothImprintId)) {
38+
$errors['thothImprintId'] = [__('plugins.generic.thoth.imprint.required')];
3939
}
4040
}
4141

@@ -54,10 +54,10 @@ public function registerThothBook($hookName, $args)
5454
return false;
5555
}
5656

57-
$imprint = $request->getUserVar('imprint');
57+
$thothImprintId = $request->getUserVar('thothImprintId');
5858
$thothNotification = new ThothNotification();
5959
try {
60-
$thothBookId = ThothService::book()->register($publication, $imprint);
60+
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
6161
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
6262
$thothNotification->notifySuccess($request, $submission);
6363
} catch (QueryException $e) {

classes/services/ThothBookService.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public function validate($publication)
7878

7979
if ($landingPage = $thothBook->getLandingPage()) {
8080
$retrievedThothBook = $this->repository->find($landingPage);
81-
if ($retrievedThothBook !== null) {
81+
if (
82+
$retrievedThothBook !== null
83+
&& $retrievedThothBook->getLandingPage() === $landingPage
84+
) {
8285
$errors[] = __(
8386
'plugins.generic.thoth.validation.landingPageExists',
8487
['landingPage' => $landingPage]

controllers/modal/RegisterHandler.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function register($args, $request)
8787
);
8888

8989
$imprints = [];
90-
90+
$workType = $this->submission->getData('workType');
9191
try {
9292
$errors = ThothService::book()->validate($this->publication);
9393

@@ -101,7 +101,7 @@ public function register($args, $request)
101101
}
102102

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

106106
$settingsData = [
107107
'components' => [

js/ui/components/ListPanel/ThothListPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pkp.Vue.component('thoth-list-panel', {
307307
'X-Http-Method-Override': 'PUT',
308308
},
309309
data: {
310-
imprint: this.selectedImprint,
310+
thothImprintId: this.selectedImprint,
311311
disableNotification: true
312312
},
313313
success: (response) => this.updateItem(response),

locale/en/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "Your site administrator must set a secret in the config file ('api_key_s
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Thoth credentials not configured."
3333

34+
msgid "plugins.generic.thoth.workType"
35+
msgstr "Work Type"
36+
37+
msgid "plugins.generic.thoth.workType.monograph"
38+
msgstr "Monograph"
39+
40+
msgid "plugins.generic.thoth.workType.textbook"
41+
msgstr "Textbook"
42+
3443
msgid "plugins.generic.thoth.thothBook"
3544
msgstr "Thoth Book: "
3645

locale/es/locale.po

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ msgstr "El administrador de su sitio debe establecer un secreto en el archivo de
3131
msgid "plugins.generic.thoth.credentialsMissing"
3232
msgstr "Credenciales de Thoth no configuradas."
3333

34+
msgid "plugins.generic.thoth.workType"
35+
msgstr "Tipo de Trabajo"
36+
37+
msgid "plugins.generic.thoth.workType.monograph"
38+
msgstr "Monografía"
39+
40+
msgid "plugins.generic.thoth.workType.textbook"
41+
msgstr "Libro de Texto"
42+
3443
msgid "plugins.generic.thoth.thothBook"
3544
msgstr "Libro de Thoth: "
3645

0 commit comments

Comments
 (0)