From ae7708954f577396ca17c2a58085e7317e442f7b Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Thu, 28 Nov 2024 17:57:16 +0600 Subject: [PATCH] pkp/pkp-lib#4787 reactive update of suggestion list in add reviewer modal --- .../listPanels/PKPSelectReviewerListPanel.php | 19 ++++++++++- .../form/AdvancedSearchReviewerForm.php | 34 ++++++++++++++++--- .../reviewer/form/CreateReviewerForm.php | 12 +++---- .../form/EnrollExistingReviewerForm.php | 3 +- .../reviewer/AdvancedReviewerSearchHandler.js | 28 +++++++-------- 5 files changed, 69 insertions(+), 27 deletions(-) diff --git a/classes/components/listPanels/PKPSelectReviewerListPanel.php b/classes/components/listPanels/PKPSelectReviewerListPanel.php index bf8065b5f11..c83777488b1 100644 --- a/classes/components/listPanels/PKPSelectReviewerListPanel.php +++ b/classes/components/listPanels/PKPSelectReviewerListPanel.php @@ -163,11 +163,12 @@ public function getConfig() $config['selectReviewerLabel'] = __('editor.submission.selectReviewer'); $config['warnOnAssignmentLabel'] = __('reviewer.list.warnOnAssign'); $config['warnOnAssignmentUnlockLabel'] = __('reviewer.list.warnOnAssignUnlock'); - $config['submission'] = $this->submission; + // $config['submission'] = $this->submission; if ($context->getData('reviewerSuggestionEnabled')) { $config['suggestionTitle'] = __('editor.submission.findAndSelectReviewerFromSuggestions'); $config['suggestions'] = $this->getReviewerSuggestions(); + $config['reviewerSuggestionsApiUrl'] = $this->getReviewerSuggestionsApiUrl(); } return $config; @@ -216,6 +217,22 @@ protected function _getCollector(): Collector ->limit($this->count); } + /** + * Get the API url prefix of reviewer sugeestion's operation + */ + protected function getReviewerSuggestionsApiUrl(): string + { + $request = Application::get()->getRequest(); + $context = $request->getContext(); + + return $request->getDispatcher()->url( + $request, + Application::ROUTE_API, + $context->getPath(), + "submissions/{$this->submission->getId()}/reviewers/suggestions" + ); + } + /** * Get the reviewer suggestions submission */ diff --git a/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php b/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php index e67bb139ad0..ac125808a7d 100644 --- a/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php +++ b/controllers/grid/users/reviewer/form/AdvancedSearchReviewerForm.php @@ -17,17 +17,17 @@ namespace PKP\controllers\grid\users\reviewer\form; use APP\core\Application; -use PKP\submission\reviewer\suggestion\ReviewerSuggestion; - use APP\facades\Repo; use APP\submission\Submission; use APP\template\TemplateManager; +use Carbon\Carbon; use Illuminate\Support\Facades\Mail; use PKP\controllers\grid\users\reviewer\PKPReviewerGridHandler; use PKP\core\PKPApplication; use PKP\db\DAORegistry; use PKP\emailTemplate\EmailTemplate; use PKP\facades\Locale; +use PKP\form\validation\FormValidator; use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxAction; use PKP\mail\mailables\ReviewRequest; @@ -37,6 +37,7 @@ use PKP\submission\reviewAssignment\ReviewAssignment; use PKP\submission\reviewRound\ReviewRound; use PKP\submission\reviewRound\ReviewRoundDAO; +use PKP\submission\reviewer\suggestion\ReviewerSuggestion; class AdvancedSearchReviewerForm extends ReviewerForm { @@ -54,7 +55,7 @@ public function __construct($submission, $reviewRound, $reviewerSuggestion = nul $this->setTemplate('controllers/grid/users/reviewer/form/advancedSearchReviewerForm.tpl'); - $this->addCheck(new \PKP\form\validation\FormValidator($this, 'reviewerId', 'required', 'editor.review.mustSelect')); + $this->addCheck(new FormValidator($this, 'reviewerId', 'required', 'editor.review.mustSelect')); } /** @@ -87,7 +88,10 @@ public function initData() $mailable = $this->getMailable(); $templates = Repo::emailTemplate()->getCollector($context->getId()) - ->filterByKeys([ReviewRequest::getEmailTemplateKey(), ReviewRequestSubsequent::getEmailTemplateKey()]) + ->filterByKeys([ + ReviewRequest::getEmailTemplateKey(), + ReviewRequestSubsequent::getEmailTemplateKey() + ]) ->getMany() ->mapWithKeys(function (EmailTemplate $item, int $key) use ($mailable) { return [$item->getData('key') => Mail::compileParams($item->getLocalizedData('body'), $mailable->viewData)]; @@ -275,6 +279,28 @@ public function fetch($request, $template = null, $display = false) return parent::fetch($request, $template, $display); } + /** + * @copydoc Form::execute() + */ + public function execute(...$functionArgs) + { + /** @var \PKP\submission\reviewAssignment\ReviewAssignment $reviewAssignment */ + $reviewAssignment = parent::execute(...$functionArgs); + $reviewerId = $reviewAssignment->getData('reviewerId'); + + if ($this->reviewerSuggestion?->existingReviewerRole + && $this->reviewerSuggestion->existingUser->getId() == $reviewerId) { + + $this->reviewerSuggestion->markAsApprove( + Carbon::now(), + $reviewerId, + Application::get()->getRequest()->getUser()->getId() + ); + } + + return $reviewAssignment; + } + protected function getEmailTemplates(): array { $subsequentTemplate = Repo::emailTemplate()->getByKey( diff --git a/controllers/grid/users/reviewer/form/CreateReviewerForm.php b/controllers/grid/users/reviewer/form/CreateReviewerForm.php index 87222fae342..50499a30895 100644 --- a/controllers/grid/users/reviewer/form/CreateReviewerForm.php +++ b/controllers/grid/users/reviewer/form/CreateReviewerForm.php @@ -199,13 +199,11 @@ public function execute(...$functionArgs) } } - if ($this->getData('reviewerSuggestionId')) { - $this->reviewerSuggestion->markAsApprove( - Carbon::now(), - $reviewerId, - $request->getUser()->getId() - ); - } + $this->reviewerSuggestion?->markAsApprove( + Carbon::now(), + $reviewerId, + $request->getUser()->getId() + ); return parent::execute(...$functionArgs); } diff --git a/controllers/grid/users/reviewer/form/EnrollExistingReviewerForm.php b/controllers/grid/users/reviewer/form/EnrollExistingReviewerForm.php index 970071bf74a..4ffdbd7967b 100644 --- a/controllers/grid/users/reviewer/form/EnrollExistingReviewerForm.php +++ b/controllers/grid/users/reviewer/form/EnrollExistingReviewerForm.php @@ -105,6 +105,8 @@ public function readInputData() */ public function execute(...$functionArgs) { + $request = Application::get()->getRequest(); + // Assign a reviewer user group to an existing non-reviewer $userId = (int) $this->getData('userId'); @@ -122,7 +124,6 @@ public function execute(...$functionArgs) if ($this->reviewerSuggestion?->existingUser && $this->reviewerSuggestion->existingUser->getId() == $userId) { - $request = Application::get()->getRequest(); $this->reviewerSuggestion->markAsApprove( Carbon::now(), $userId, diff --git a/js/controllers/grid/users/reviewer/AdvancedReviewerSearchHandler.js b/js/controllers/grid/users/reviewer/AdvancedReviewerSearchHandler.js index d2a4fe9774e..4086ebe5d39 100644 --- a/js/controllers/grid/users/reviewer/AdvancedReviewerSearchHandler.js +++ b/js/controllers/grid/users/reviewer/AdvancedReviewerSearchHandler.js @@ -16,9 +16,7 @@ (function($) { /** @type {Object} */ - $.pkp.controllers.grid.users.reviewer = - $.pkp.controllers.grid.users.reviewer || {}; - + $.pkp.controllers.grid.users.reviewer = $.pkp.controllers.grid.users.reviewer || {}; /** * @constructor @@ -28,31 +26,34 @@ * @param {jQueryObject} $container the wrapped page element. * @param {Object} options handler options. */ - $.pkp.controllers.grid.users.reviewer.AdvancedReviewerSearchHandler = - function($container, options) { + $.pkp.controllers.grid.users.reviewer.AdvancedReviewerSearchHandler = function($container, options) { this.parent($container, options); $container.find('.button').button(); - - pkp.eventBus.$on( - 'selected:reviewer', - (reviewer) => this.handleReviewerAssign_($container, options, reviewer) - ); + let self = this; + + pkp.eventBus.$on('selected:reviewer', function (reviewer) { + self.handleReviewerAssign_($container, options, reviewer) + }); $('#regularReviewerForm').hide(); this.bind('refreshForm', this.handleRefresh_); + // TODO : Not Working as intended to if ($container.find('input#reviewerId').val()) { + this.initializeTinyMCE(); this.handleReviewerAssign_($container, options, { id: $container.find('input#reviewerId').val(), fullName: 'some name', }); } }; + $.pkp.classes.Helper.inherits( - $.pkp.controllers.grid.users.reviewer.AdvancedReviewerSearchHandler, - $.pkp.classes.Handler); + $.pkp.controllers.grid.users.reviewer.AdvancedReviewerSearchHandler, + $.pkp.classes.Handler + ); // @@ -97,9 +98,8 @@ // Multiple available templates $templateOption = $('#reviewerFormFooter select[name="template"]'); - this.initializeTinyMCE(); editor = tinyMCE.EditorManager.get($textarea.attr('id')); - + console.log(editor); templateKey = ''; if (options.lastRoundReviewerIds.includes(reviewer.id)) {