Skip to content

Commit

Permalink
pkp#4787 reactive update of suggestion list in add reviewer modal
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Dec 2, 2024
1 parent 60b1612 commit ae77089
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
19 changes: 18 additions & 1 deletion classes/components/listPanels/PKPSelectReviewerListPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 5 additions & 7 deletions controllers/grid/users/reviewer/form/CreateReviewerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions js/controllers/grid/users/reviewer/AdvancedReviewerSearchHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);


//
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit ae77089

Please sign in to comment.