Skip to content

Commit

Permalink
Merge pull request #470 from danskernesdigitalebibliotek/DDFLSBP-150/…
Browse files Browse the repository at this point in the history
…refactor-threshold-selection

DDFLSBP-150 - Changed the 'threshold_config' textfield into 'expirati…
  • Loading branch information
Dresse authored Nov 15, 2023
2 parents e84bc88 + e7d10ac commit c46257e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion config/sync/dpl_library_agency.general_settings.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
reservation_sms_notifications_disabled: 0
threshold_config: '{ "colorThresholds": { "danger": "0", "warning": "6" } }'
expiration_warning_days_before_config: 6
interest_periods_config: '[
{
"value": "30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function build(): array {
// Config.
'page-size-desktop' => $dashboardSettings->get('page_size_desktop') ?? DplDashboardSettings::PAGE_SIZE_DESKTOP,
'page-size-mobile' => $dashboardSettings->get('page_size_mobile') ?? DplDashboardSettings::PAGE_SIZE_MOBILE,
'threshold-config' => $this->configFactory->get('dpl_library_agency.general_settings')->get('threshold_config') ?? GeneralSettingsForm::THRESHOLD_CONFIG,
'expiration-warning-days-before-config' => $generalSettings->get('expiration_warning_days_before_config') ?? GeneralSettingsForm::EXPIRATION_WARNING_DAYS_BEFORE_CONFIG,
'interest-periods-config' => DplReactAppsController::getInterestPeriods(),
'reservation-detail-allow-remove-ready-reservations-config' => $generalSettings->get('reservation_detail_allow_remove_ready_reservations') ?? GeneralSettingsForm::RESERVATION_DETAIL_ALLOW_REMOVE_READY_RESERVATIONS,
'blacklisted-pickup-branches-config' => DplReactAppsController::buildBranchesListProp($this->branchSettings->getExcludedReservationBranches()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class GeneralSettingsForm extends ConfigFormBase {
// @todo These constants should be defined in a general settings class like we do it in eg dpl_dashboard.
const THRESHOLD_CONFIG = "{ 'colorThresholds': { 'danger': '0', 'warning': '6' } }";
const EXPIRATION_WARNING_DAYS_BEFORE_CONFIG = 6;
const RESERVATION_DETAIL_ALLOW_REMOVE_READY_RESERVATIONS = FALSE;
const INTEREST_PERIODS_CONFIG = '';
const RESERVATION_SMS_NOTIFICATIONS_ENABLED = TRUE;
Expand Down Expand Up @@ -194,17 +194,18 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'#default_value' => $config->get('blocked_patron_e_link_url') ?? self::BLOCKED_PATRON_E_LINK_URL,
];

$form['thresholds'] = [
$form['expiration_warning'] = [
'#type' => 'fieldset',
'#title' => $this->t('Thresholds', [], ['context' => 'Library Agency Configuration']),
'#title' => $this->t('Expiration warning', [], ['context' => 'Library Agency Configuration']),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
];

$form['thresholds']['threshold_config'] = [
'#type' => 'textfield',
'#title' => $this->t('Set thresholds', [], ['context' => 'Library Agency Configuration']),
'#default_value' => $config->get('threshold_config') ?? self::THRESHOLD_CONFIG,
$form['expiration_warning']['expiration_warning_days_before_config'] = [
'#type' => 'number',
'#title' => $this->t('Set expiration warning', [], ['context' => 'Library Agency Configuration']),
'#default_value' => $config->get('expiration_warning_days_before_config') ?? self::EXPIRATION_WARNING_DAYS_BEFORE_CONFIG,
'#description' => $this->t('Insert the number of days before the expiration of the material, when the reminder "Expires soon" should appear.', [], ['context' => 'Library Agency Configuration']),
];

$form['branches'] = [
Expand Down Expand Up @@ -256,7 +257,7 @@ public function validateForm(array &$form, FormStateInterface $form_state): void
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$this->config('dpl_library_agency.general_settings')
->set('threshold_config', $form_state->getValue('threshold_config'))
->set('expiration_warning_days_before_config', $form_state->getValue('expiration_warning_days_before_config'))
->set('reservation_detail_allow_remove_ready_reservations', $form_state->getValue('reservation_detail_allow_remove_ready_reservations'))
->set('interest_periods_config', $form_state->getValue('interest_periods_config'))
->set('reservation_sms_notifications_enabled', $form_state->getValue('reservation_sms_notifications_enabled'))
Expand Down
13 changes: 1 addition & 12 deletions web/modules/custom/dpl_loans/src/Plugin/Block/LoanListBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ public static function create(ContainerInterface $container, array $configuratio
);
}

/**
* Gets threshold config.
*
* @return string
* Returns the threshold config.
*/
public function getThresholdConfig(): string {
$generalSettings = $this->configFactory->get('dpl_library_agency.general_settings');
return $generalSettings->get('threshold_config') ?? GeneralSettingsForm::THRESHOLD_CONFIG;
}

/**
* {@inheritDoc}
*
Expand All @@ -99,7 +88,7 @@ public function build() {
"page-size-mobile" => $loanListSettings->get('page_size_mobile') ?? DplLoansSettings::PAGE_SIZE_MOBILE,

// Config.
"threshold-config" => $this->getThresholdConfig(),
"expiration-warning-days-before-config" => $generalSettings->get('expiration_warning_days_before_config') ?? GeneralSettingsForm::EXPIRATION_WARNING_DAYS_BEFORE_CONFIG,

// Urls.
'ereolen-my-page-url' => dpl_react_apps_format_app_url($generalSettings->get('ereolen_my_page_url'), GeneralSettingsForm::EREOLEN_MY_PAGE_URL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\dpl_library_agency\Form\GeneralSettingsForm;
use Drupal\dpl_react_apps\Controller\DplReactAppsController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\dpl_library_agency\Branch\BranchRepositoryInterface;
Expand Down Expand Up @@ -136,7 +137,7 @@ public function build(): array {
'page-size-mobile' => $menuSettings->get('page_size_mobile'),
'blacklisted-pickup-branches-config' => DplReactAppsController::buildBranchesListProp($this->branchSettings->getExcludedReservationBranches()),
'branches-config' => DplReactAppsController::buildBranchesJsonProp($this->branchRepository->getBranches()),
"threshold-config" => $this->configFactory->get('dpl_library_agency.general_settings')->get('threshold_config'),
"expiration-warning-days-before-config" => $generalSettings->get('expiration_warning_days_before_config') ?? GeneralSettingsForm::EXPIRATION_WARNING_DAYS_BEFORE_CONFIG,
"menu-navigation-data-config" => json_encode($menu, JSON_THROW_ON_ERROR),
'reservation-detail-allow-remove-ready-reservations-config' => $generalSettings->get('reservation_detail_allow_remove_ready_reservations'),
'interest-periods-config' => DplReactAppsController::getInterestPeriods(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function build(): array {
'reservation-details-config' => json_encode([
'allowRemoveReadyReservations' => $allow_remove_ready_reservations,
]),
'threshold-config' => $generalSettings->get('threshold_config') ?? GeneralSettingsForm::THRESHOLD_CONFIG,
'expiration-warning-days-before-config' => $generalSettings->get('expiration_warning_days_before_config') ?? GeneralSettingsForm::EXPIRATION_WARNING_DAYS_BEFORE_CONFIG,

// Texts.
'material-and-author-text' => $this->t('and', [], ['context' => 'Reservation list']),
Expand Down
14 changes: 8 additions & 6 deletions web/profiles/dpl_cms/translations/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -1822,14 +1822,16 @@ msgstr ""
"vises dette link i beskeden til brugeren"

msgctxt "Library Agency Configuration"
msgid "Thresholds"
msgstr "Varsler"
msgid "Expiration warning"
msgstr "Udløbsadvarsel"

msgctxt "Library Agency Configuration"
msgid "Set thresholds"
msgstr ""
"Angivelse af hvor mange dage før udløb bruger skal modtage et varsel "
""
msgid "Set expiration warning"
msgstr "Påmindelse om snarligt udløb"

msgctxt "Library Agency Configuration"
msgid "Insert the number of days before the expiration of the material, when the reminder \"Expires soon\" should appear."
msgstr "Indsæt antallet af dage, før udløb af materialet, hvor påmindelsen \"Udløber snart\" skal dukke op."

msgctxt "Library Agency Configuration"
msgid "Excluded branches"
Expand Down

0 comments on commit c46257e

Please sign in to comment.