Skip to content

Commit

Permalink
Some minor adjustments for config panel
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Nov 25, 2023
1 parent a7282e4 commit 2681acb
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 29 deletions.
45 changes: 30 additions & 15 deletions resources/views/modules/pedigree-chart/config.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the package magicsunday/webtrees-pedigree-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
*/

declare(strict_types=1);

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
Expand All @@ -9,29 +16,37 @@ use MagicSunday\Webtrees\PedigreeChart\Configuration;

/**
* @var Configuration $configuration
* @var string $moduleName
* @var string $title
* @var string $moduleName
* @var string $title
* @var string $description
*/

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ModulesAllPage::class) => I18N::translate('Modules'), $title]]) ?>

<h1><?= $title ?></h1>
<p><?= $description ?></p>

<form method="post">
<?= view($moduleName.'::modules/pedigree-chart/form/generations', ['configuration' => $configuration]) ?>

<?= view($moduleName.'::modules/pedigree-chart/form/orientation', ['configuration' => $configuration]) ?>

<button type="submit" class="btn btn-primary">
<?= I18N::translate('save') ?>
</button>

<a href="<?= route(ControlPanel::class) ?>" class="btn btn-secondary">
<?= view('icons/cancel') ?>
<?= I18N::translate('cancel') ?>
</a>
<div class="mb-3">
<?= view($moduleName.'::modules/pedigree-chart/form/generations', ['configuration' => $configuration]) ?>
</div>
<div class="mb-3">
<?= view($moduleName.'::modules/pedigree-chart/form/orientation', ['configuration' => $configuration]) ?>
</div>

<div class="row mb-3">
<div class="offset-sm-3 col-sm-9">
<button type="submit" class="btn btn-primary">
<?= I18N::translate('save') ?>
</button>

<a href="<?= route(ControlPanel::class) ?>" class="btn btn-secondary">
<?= view('icons/cancel') ?>
<?= I18N::translate('cancel') ?>
</a>
</div>
</div>

<?= csrf_field() ?>
</form>
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the package magicsunday/webtrees-pedigree-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
*/

declare(strict_types=1);

use Fisharebest\Webtrees\I18N;
Expand All @@ -8,7 +15,6 @@ use MagicSunday\Webtrees\PedigreeChart\Configuration;
/**
* @var Configuration $configuration
*/

?>

<div class="form-group row">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* This file is part of the package magicsunday/webtrees-pedigree-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
*/

declare(strict_types=1);

use Fisharebest\Webtrees\I18N;
Expand All @@ -8,7 +15,6 @@ use MagicSunday\Webtrees\PedigreeChart\Configuration;
/**
* @var Configuration $configuration
*/

?>

<div class="form-group row">
Expand Down
1 change: 0 additions & 1 deletion resources/views/modules/pedigree-chart/page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ use MagicSunday\Webtrees\PedigreeChart\Configuration;
</div>

<?= view($moduleName.'::modules/pedigree-chart/form/generations', ['configuration' => $configuration]) ?>

<?= view($moduleName.'::modules/pedigree-chart/form/orientation', ['configuration' => $configuration]) ?>

<div class="collapse" id="showMoreOptions">
Expand Down
27 changes: 21 additions & 6 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ public function getGenerations(): int
} else {
$validator = Validator::queryParams($this->request);
}

return $validator
->isBetween(self::MIN_GENERATIONS, self::MAX_GENERATIONS)
->integer('generations', (int) $this->module->getPreference('default_generations',
(string) self::DEFAULT_GENERATIONS));
->integer(
'generations',
(int) $this->module->getPreference(
'default_generations',
(string) self::DEFAULT_GENERATIONS
)
);
}

/**
Expand Down Expand Up @@ -147,9 +153,18 @@ public function getLayout(): string
}

return $validator
->isInArray([self::LAYOUT_BOTTOMTOP, self::LAYOUT_LEFTRIGHT, self::LAYOUT_RIGHTLEFT,
self::LAYOUT_TOPBOTTOM])
->string('layout', $this->module->getPreference('default_tree_layout',
self::DEFAULT_TREE_LAYOUT));
->isInArray([
self::LAYOUT_BOTTOMTOP,
self::LAYOUT_LEFTRIGHT,
self::LAYOUT_RIGHTLEFT,
self::LAYOUT_TOPBOTTOM,
])
->string(
'layout',
$this->module->getPreference(
'default_tree_layout',
self::DEFAULT_TREE_LAYOUT
)
);
}
}
17 changes: 12 additions & 5 deletions src/Traits/ModuleConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of the package magicsunday/webtrees-pedigree-chart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
* LICENSE file distributed with this source code.
*/

declare(strict_types=1);
Expand All @@ -13,7 +13,6 @@

use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Validator;
use MagicSunday\Webtrees\PedigreeChart\Configuration;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -30,6 +29,8 @@ trait ModuleConfigTrait
use \Fisharebest\Webtrees\Module\ModuleConfigTrait;

/**
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function getAdminAction(ServerRequestInterface $request): ResponseInterface
Expand All @@ -41,7 +42,8 @@ public function getAdminAction(ServerRequestInterface $request): ResponseInterfa
[
'configuration' => new Configuration($request, $this),
'moduleName' => $this->name(),
'title' => self::title(),
'title' => $this->title(),
'description' => $this->description(),
]
);
}
Expand All @@ -58,8 +60,13 @@ public function postAdminAction(ServerRequestInterface $request): ResponseInterf
$this->setPreference('default_generations', (string) $configuration->getGenerations());
$this->setPreference('default_tree_layout', $configuration->getLayout());

FlashMessages::addMessage(I18N::translate('The preferences for the module “%s” have been updated.',
$this->title()), 'success');
FlashMessages::addMessage(
I18N::translate(
'The preferences for the module “%s” have been updated.',
$this->title()
),
'success'
);

return redirect($this->getConfigLink());
}
Expand Down

0 comments on commit 2681acb

Please sign in to comment.