From c2a14323d547ce8a024246b3f69a1a337c5cc93f Mon Sep 17 00:00:00 2001 From: Touhidur Rahman Date: Thu, 14 Mar 2024 15:25:28 +0600 Subject: [PATCH] pkp/pkp-lib#5885 removed unnecessary fields and controls with field range component enhancement --- classes/components/forms/FieldCheckbox.php | 67 ------------------- classes/components/forms/FieldRangeSlider.php | 66 ++++++++++++++++-- .../forms/context/PKPReviewSetupForm.php | 59 ++++++---------- classes/task/ReviewReminder.php | 17 ++--- js/load.js | 2 - schemas/context.json | 24 ------- 6 files changed, 85 insertions(+), 150 deletions(-) delete mode 100644 classes/components/forms/FieldCheckbox.php diff --git a/classes/components/forms/FieldCheckbox.php b/classes/components/forms/FieldCheckbox.php deleted file mode 100644 index e6db5550789..00000000000 --- a/classes/components/forms/FieldCheckbox.php +++ /dev/null @@ -1,67 +0,0 @@ - $this->viewAsButton, - 'disable' => $this->disable, - 'checkedLabel' => $this->checkedLabel, - 'uncheckedLabel' => $this->uncheckedLabel, - 'options' => $this->options, - ]); - return $config; - } -} diff --git a/classes/components/forms/FieldRangeSlider.php b/classes/components/forms/FieldRangeSlider.php index 4322506017f..b807b888bd9 100644 --- a/classes/components/forms/FieldRangeSlider.php +++ b/classes/components/forms/FieldRangeSlider.php @@ -32,6 +32,13 @@ class FieldRangeSlider extends Field */ public $disable = false; + /** + * Should the range slider be disable if input field value set to NULL on render + * + * @var bool + */ + public $disableOnNull = true; + /** * Range min value * @@ -53,6 +60,13 @@ class FieldRangeSlider extends Field */ public $step = 1; + /** + * Range value on reset + * + * @var int|float|null + */ + public $onResetValue; + /** * Range input size * @@ -81,6 +95,27 @@ class FieldRangeSlider extends Field */ public $valuePositionInUpdateLabel = 'before'; + /** + * Allow the slider range disbale/enable ability + * + * @var bool + */ + public $allowStateToggle = true; + + /** + * Show the label text when range slider is disable + * + * @var string + */ + public $controlLabelOnDisable; + + /** + * Show the label text when range slider is disable + * + * @var string + */ + public $controlLabelOnEnable; + /** * @copydoc Field::getConfig() */ @@ -108,14 +143,31 @@ public function getConfig() $config = parent::getConfig(); + if (!isset($this->controlLabelOnDisable)) { + $this->controlLabelOnDisable = __('common.enable'); + } + + if (!isset($this->controlLabelOnEnable)) { + $this->controlLabelOnEnable = __('common.disable'); + } + + if (!isset($this->onResetValue)) { + $this->onResetValue = $this->value ?? $this->default ?? null; + } + return array_merge($config, [ - 'disable' => $this->disable, - 'options' => $this->options, - 'max' => $this->max, - 'min' => $this->min, - 'size' => $this->size, - 'step' => $this->step, - 'updateLabel' => $this->updateLabel, + 'disable' => $this->disable, + 'disableOnNull' => $this->disableOnNull, + 'options' => $this->options, + 'max' => $this->max, + 'min' => $this->min, + 'size' => $this->size, + 'step' => $this->step, + 'onResetValue' => $this->onResetValue, + 'updateLabel' => $this->updateLabel, + 'allowStateToggle' => $this->allowStateToggle, + 'controlLabelOnDisable' => $this->controlLabelOnDisable, + 'controlLabelOnEnable' => $this->controlLabelOnEnable, ]); } } diff --git a/classes/components/forms/context/PKPReviewSetupForm.php b/classes/components/forms/context/PKPReviewSetupForm.php index e8d02f4b4d0..db7d762e03c 100644 --- a/classes/components/forms/context/PKPReviewSetupForm.php +++ b/classes/components/forms/context/PKPReviewSetupForm.php @@ -16,7 +16,6 @@ namespace PKP\components\forms\context; -use PKP\components\forms\FieldCheckbox; use PKP\components\forms\FieldHTML; use PKP\context\Context; use PKP\components\forms\FieldOptions; @@ -41,6 +40,7 @@ class PKPReviewSetupForm extends FormComponent public const MIN_REMINDER_NOTIFICATION_SEND_IN_DAYS = 1; public const MAX_REMINDER_NOTIFICATION_SEND_IN_DAYS = 14; + public const DEFAULT_REMINDER_NOTIFICATION_SEND_IN_DAYS = 7; /** * Constructor @@ -60,6 +60,9 @@ public function __construct($action, $locales, $context) ->addReminderDisbaleNoticeField($context); } + /** + * Add the default review control fields + */ protected function addDefaultFields(Context $context): static { $this @@ -121,6 +124,9 @@ protected function addDefaultFields(Context $context): static return $this; } + /** + * Add the review reminder control fields + */ protected function addReminderFields(Context $context): static { if (!Config::getVar('general', 'scheduled_tasks')) { @@ -145,16 +151,10 @@ protected function addReminderFields(Context $context): static 'value' => $context->getData('numDaysBeforeReviewResponseReminderDue'), 'min' => static::MIN_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'max' => static::MAX_REMINDER_NOTIFICATION_SEND_IN_DAYS, - 'size' => 'normal', + 'onResetValue' => $context->getData('numDaysBeforeReviewResponseReminderDue') ?? static::DEFAULT_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'updateLabel' => __('manager.setup.reviewOptions.reminders.description.before.days'), - 'groupId' => self::REVIEW_REMINDER_GROUP, - ])) - ->addField(new FieldCheckbox('enableBeforeReviewResponseReminder', [ - 'label' => __('manager.setup.reviewOptions.reminders.disable'), - 'value' => (bool)$context->getData('enableBeforeReviewResponseReminder'), - 'viewAsButton' => true, - 'checkedLabel' => __('manager.setup.reviewOptions.reminders.disable'), - 'uncheckedLabel' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnDisable' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnEnable' => __('manager.setup.reviewOptions.reminders.disable'), 'groupId' => self::REVIEW_REMINDER_GROUP, ])) ->addField(new FieldRangeSlider('numDaysAfterReviewResponseReminderDue', [ @@ -162,16 +162,10 @@ protected function addReminderFields(Context $context): static 'value' => $context->getData('numDaysAfterReviewResponseReminderDue'), 'min' => static::MIN_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'max' => static::MAX_REMINDER_NOTIFICATION_SEND_IN_DAYS, - 'size' => 'normal', + 'onResetValue' => $context->getData('numDaysAfterReviewResponseReminderDue') ?? static::DEFAULT_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'updateLabel' => __('manager.setup.reviewOptions.reminders.description.after.days'), - 'groupId' => self::REVIEW_REMINDER_GROUP, - ])) - ->addField(new FieldCheckbox('enableAfterReviewResponseReminder', [ - 'label' => __('manager.setup.reviewOptions.reminders.disable'), - 'value' => (bool)$context->getData('enableAfterReviewResponseReminder'), - 'viewAsButton' => true, - 'checkedLabel' => __('manager.setup.reviewOptions.reminders.disable'), - 'uncheckedLabel' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnDisable' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnEnable' => __('manager.setup.reviewOptions.reminders.disable'), 'groupId' => self::REVIEW_REMINDER_GROUP, ])) ->addField(new FieldHTML('submissionReviewResponseReminder', [ @@ -183,16 +177,10 @@ protected function addReminderFields(Context $context): static 'value' => $context->getData('numDaysBeforeReviewSubmitReminderDue'), 'min' => static::MIN_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'max' => static::MAX_REMINDER_NOTIFICATION_SEND_IN_DAYS, - 'size' => 'normal', + 'onResetValue' => $context->getData('numDaysBeforeReviewSubmitReminderDue') ?? static::DEFAULT_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'updateLabel' => __('manager.setup.reviewOptions.reminders.description.before.days'), - 'groupId' => self::REVIEW_REMINDER_GROUP, - ])) - ->addField(new FieldCheckbox('enableBeforeReviewSubmitReminder', [ - 'label' => __('manager.setup.reviewOptions.reminders.disable'), - 'value' => (bool)$context->getData('enableBeforeReviewSubmitReminder'), - 'viewAsButton' => true, - 'checkedLabel' => __('manager.setup.reviewOptions.reminders.disable'), - 'uncheckedLabel' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnDisable' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnEnable' => __('manager.setup.reviewOptions.reminders.disable'), 'groupId' => self::REVIEW_REMINDER_GROUP, ])) ->addField(new FieldRangeSlider('numDaysAfterReviewSubmitReminderDue', [ @@ -200,22 +188,19 @@ protected function addReminderFields(Context $context): static 'value' => $context->getData('numDaysAfterReviewSubmitReminderDue'), 'min' => static::MIN_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'max' => static::MAX_REMINDER_NOTIFICATION_SEND_IN_DAYS, - 'size' => 'normal', + 'onResetValue' => $context->getData('numDaysAfterReviewSubmitReminderDue') ?? static::DEFAULT_REMINDER_NOTIFICATION_SEND_IN_DAYS, 'updateLabel' => __('manager.setup.reviewOptions.reminders.description.after.days'), - 'groupId' => self::REVIEW_REMINDER_GROUP, - ])) - ->addField(new FieldCheckbox('enableAfterReviewSubmitReminder', [ - 'label' => __('manager.setup.reviewOptions.reminders.disable'), - 'value' => (bool)$context->getData('enableAfterReviewSubmitReminder'), - 'viewAsButton' => true, - 'checkedLabel' => __('manager.setup.reviewOptions.reminders.disable'), - 'uncheckedLabel' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnDisable' => __('manager.setup.reviewOptions.reminders.enable'), + 'controlLabelOnEnable' => __('manager.setup.reviewOptions.reminders.disable'), 'groupId' => self::REVIEW_REMINDER_GROUP, ])); return $this; } + /** + * Add a html note section instructing how to enable review reminder control fields + */ protected function addReminderDisbaleNoticeField(Context $context): static { if (Config::getVar('general', 'scheduled_tasks')) { diff --git a/classes/task/ReviewReminder.php b/classes/task/ReviewReminder.php index 4e51c3a3de7..fc255fab7d8 100644 --- a/classes/task/ReviewReminder.php +++ b/classes/task/ReviewReminder.php @@ -71,11 +71,6 @@ public function executeActions() unset($context); $context = $contextDao->getById($submission->getData('contextId')); - $enableBeforeReviewResponseReminder = $context->getData('enableBeforeReviewResponseReminder'); - $enableAfterReviewResponseReminder = $context->getData('enableAfterReviewResponseReminder'); - $enableBeforeReviewSubmitReminder = $context->getData('enableBeforeReviewSubmitReminder'); - $enableAfterReviewSubmitReminder = $context->getData('enableAfterReviewSubmitReminder'); - $numDaysBeforeReviewResponseReminderDue = $context->getData('numDaysBeforeReviewResponseReminderDue'); $numDaysAfterReviewResponseReminderDue = $context->getData('numDaysAfterReviewResponseReminderDue'); $numDaysBeforeReviewSubmitReminderDue = $context->getData('numDaysBeforeReviewSubmitReminderDue'); @@ -98,8 +93,7 @@ public function executeActions() if ($reviewAssignment->getDateReminded() === null) { // There has not been any reminder sent yet // need to check should we sent a BEFORE REVIEW REQUEST RESPONSE reminder - if ($enableBeforeReviewResponseReminder && - $numDaysBeforeReviewResponseReminderDue && + if ($numDaysBeforeReviewResponseReminderDue && $dateResponseDue->gt($currentDate) && $dateResponseDue->diffInDays($currentDate) <= $numDaysBeforeReviewResponseReminderDue) { @@ -112,8 +106,7 @@ public function executeActions() $dateReminded = Carbon::parse($reviewAssignment->getDateReminded()); - if ($enableAfterReviewResponseReminder && - $numDaysAfterReviewResponseReminderDue && + if ($numDaysAfterReviewResponseReminderDue && $currentDate->gt($dateResponseDue) && $dateReminded->lt($dateResponseDue) && $currentDate->diffInDays($dateResponseDue) >= $numDaysAfterReviewResponseReminderDue) { @@ -129,8 +122,7 @@ public function executeActions() if ($reviewAssignment->getDateReminded() === null) { // There has not been any reminder sent after responding to REVIEW REQUEST // no REVIEW SUBMIT reminder has been sent - if ($enableBeforeReviewSubmitReminder && - $numDaysBeforeReviewSubmitReminderDue && + if ($numDaysBeforeReviewSubmitReminderDue && $currentDate->lt($dateDue) && $dateDue->diffInDays($currentDate) <= $numDaysBeforeReviewSubmitReminderDue) { @@ -143,8 +135,7 @@ public function executeActions() $dateReminded = Carbon::parse($reviewAssignment->getDateReminded()); - if ($enableAfterReviewSubmitReminder && - $numDaysAfterReviewSubmitReminderDue && + if ($numDaysAfterReviewSubmitReminderDue && $currentDate->gt($dateDue) && $dateReminded->lt($dateDue) && $currentDate->diffInDays($dateDue) >= $numDaysAfterReviewSubmitReminderDue) { diff --git a/js/load.js b/js/load.js index 2330258c5a9..0caa1c076e5 100644 --- a/js/load.js +++ b/js/load.js @@ -77,7 +77,6 @@ import FieldControlledVocab from '@/components/Form/fields/FieldControlledVocab. import FieldHtml from '@/components/Form/fields/FieldHtml.vue'; import FieldMetadataSetting from '@/components/Form/fields/FieldMetadataSetting.vue'; import FieldOptions from '@/components/Form/fields/FieldOptions.vue'; -import FieldCheckbox from '@/components/Form/fields/FieldCheckbox.vue'; import FieldRangeSlider from '@/components/Form/fields/FieldRangeSlider.vue'; import FieldPreparedContent from '@/components/Form/fields/FieldPreparedContent.vue'; import FieldPubId from '@/components/Form/fields/FieldPubId.vue'; @@ -173,7 +172,6 @@ VueRegistry.registerComponent('PkpFieldControlledVocab', FieldControlledVocab); VueRegistry.registerComponent('PkpFieldHtml', FieldHtml); VueRegistry.registerComponent('PkpFieldMetadataSetting', FieldMetadataSetting); VueRegistry.registerComponent('PkpFieldOptions', FieldOptions); -VueRegistry.registerComponent('PkpFieldCheckbox', FieldCheckbox); VueRegistry.registerComponent('PkpFieldRangeSlider', FieldRangeSlider); VueRegistry.registerComponent('PkpFieldPreparedContent', FieldPreparedContent); VueRegistry.registerComponent('PkpFieldPubId', FieldPubId); diff --git a/schemas/context.json b/schemas/context.json index 1deee55c0cc..d89b236af44 100644 --- a/schemas/context.json +++ b/schemas/context.json @@ -539,30 +539,6 @@ "min:0" ] }, - "enableBeforeReviewResponseReminder": { - "type": "boolean", - "validation": [ - "nullable" - ] - }, - "enableAfterReviewResponseReminder": { - "type": "boolean", - "validation": [ - "nullable" - ] - }, - "enableBeforeReviewSubmitReminder": { - "type": "boolean", - "validation": [ - "nullable" - ] - }, - "enableAfterReviewSubmitReminder": { - "type": "boolean", - "validation": [ - "nullable" - ] - }, "numPageLinks": { "type": "integer", "default": 10,