Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options for charts blocks #4796

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 67 additions & 14 deletions app/Module/ChartsBlockModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,18 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
$title = $module->chartTitle($individual);
$chart_url = $module->chartUrl($individual, [
'ajax' => true,
'generations' => 3,
'layout' => PedigreeChartModule::STYLE_RIGHT,
'generations' => $this->getBlockSetting($block_id, 'pedigree_generations', '3'),
'layout' => $this->getBlockSetting(
$block_id,
'pedigree_style',
PedigreeChartModule::DEFAULT_STYLE
),
'style' => $this->getBlockSetting(
$block_id,
'pedigree_style',
PedigreeChartModule::DEFAULT_STYLE
),
// Note: some modules use 'layout', others 'style'
]);
$content = view('modules/charts/chart', [
'block_id' => $block_id,
Expand All @@ -132,7 +142,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
$title = $module->chartTitle($individual);
$chart_url = $module->chartUrl($individual, [
'ajax' => true,
'generations' => 2,
'generations' => $this->getBlockSetting($block_id, 'descendants_generations', '2'),
'chart_style' => DescendancyChartModule::CHART_STYLE_TREE,
]);
$content = view('modules/charts/chart', [
Expand All @@ -153,7 +163,7 @@ public function getBlock(Tree $tree, int $block_id, string $context, array $conf
$title = $module->chartTitle($individual);
$chart_url = $module->chartUrl($individual, [
'ajax' => true,
'generations' => 2,
'generations' => $this->getBlockSetting($block_id, 'hourglass_generations', '2'),
]);
$content = view('modules/charts/chart', [
'block_id' => $block_id,
Expand Down Expand Up @@ -231,9 +241,17 @@ public function saveBlockConfiguration(ServerRequestInterface $request, int $blo
{
$type = Validator::parsedBody($request)->string('type');
$xref = Validator::parsedBody($request)->isXref()->string('xref');
$pedigree_generations = Validator::parsedBody($request)->integer('pedigree_generations');
$pedigree_style = Validator::parsedBody($request)->string('pedigree_style');
$descendants_generations = Validator::parsedBody($request)->integer('descendants_generations');
$hourglass_generations = Validator::parsedBody($request)->integer('hourglass_generations');

$this->setBlockSetting($block_id, 'type', $type);
$this->setBlockSetting($block_id, 'pid', $xref);
$this->setBlockSetting($block_id, 'pedigree_generations', (string) $pedigree_generations);
$this->setBlockSetting($block_id, 'pedigree_style', $pedigree_style);
$this->setBlockSetting($block_id, 'descendants_generations', (string) $descendants_generations);
$this->setBlockSetting($block_id, 'hourglass_generations', (string) $hourglass_generations);
}

/**
Expand All @@ -253,21 +271,56 @@ public function editBlockConfiguration(Tree $tree, int $block_id): string
$type = $this->getBlockSetting($block_id, 'type', 'pedigree');
$xref = $this->getBlockSetting($block_id, 'pid', $default_xref);

$charts = [
'pedigree' => I18N::translate('Pedigree'),
'descendants' => I18N::translate('Descendants'),
'hourglass' => I18N::translate('Hourglass chart'),
'treenav' => I18N::translate('Interactive tree'),
];
$charts = [];
// Only add charts that are available
$pedigreeModule = $this->module_service->findByInterface(PedigreeChartModule::class)->first();
if ($pedigreeModule instanceof PedigreeChartModule) {
$charts['pedigree'] = I18N::translate('Pedigree');
$pedigree_max_generations = $pedigreeModule::MAXIMUM_GENERATIONS;
$pedigree_min_generations = $pedigreeModule::MINIMUM_GENERATIONS;
$pedigree_styles = $pedigreeModule->styles(I18N::direction());
}
$descendantsModule = $this->module_service->findByInterface(DescendancyChartModule::class)->first();
if ($descendantsModule instanceof DescendancyChartModule) {
$charts['descendants'] = I18N::translate('Descendants');
$descendants_max_generations = $descendantsModule::MAXIMUM_GENERATIONS;
$descendants_min_generations = $descendantsModule::MINIMUM_GENERATIONS;
}
$hourglassModule = $this->module_service->findByInterface(HourglassChartModule::class)->first();
if ($hourglassModule instanceof HourglassChartModule) {
$charts['hourglass'] = I18N::translate('Hourglass chart');
$hourglass_max_generations = $hourglassModule::MAXIMUM_GENERATIONS;
$hourglass_min_generations = $hourglassModule::MINIMUM_GENERATIONS;
}
$treeModule = $this->module_service->findByInterface(InteractiveTreeModule::class)->first();
if ($treeModule instanceof InteractiveTreeModule) {
$charts['treenav'] = I18N::translate('Interactive tree');
}
uasort($charts, I18N::comparator());

$pedigree_generations = $this->getBlockSetting($block_id, 'pedigree_generations', '3');
$pedigree_style = $this->getBlockSetting($block_id, 'pedigree_style', $pedigreeModule::DEFAULT_STYLE);
$descendants_generations = $this->getBlockSetting($block_id, 'descendants_generations', '2');
$hourglass_generations = $this->getBlockSetting($block_id, 'hourglass_generations', '2');

$individual = Registry::individualFactory()->make($xref, $tree);

return view('modules/charts/config', [
'charts' => $charts,
'individual' => $individual,
'tree' => $tree,
'type' => $type,
'charts' => $charts,
'individual' => $individual,
'tree' => $tree,
'type' => $type,
'pedigree_generations' => $pedigree_generations ?? null,
'pedigree_max_generations' => $pedigree_max_generations ?? null,
'pedigree_min_generations' => $pedigree_min_generations ?? null,
'pedigree_style' => $pedigree_style ?? null,
'pedigree_styles' => $pedigree_styles ?? null,
'descendants_generations' => $descendants_generations ?? null,
'descendants_max_generations' => $descendants_max_generations ?? null,
'descendants_min_generations' => $descendants_min_generations ?? null,
'hourglass_generations' => $hourglass_generations ?? null,
'hourglass_max_generations' => $hourglass_max_generations ?? null,
'hourglass_min_generations' => $hourglass_min_generations ?? null,
]);
}
}
4 changes: 2 additions & 2 deletions app/Module/DescendancyChartModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class DescendancyChartModule extends AbstractModule implements ModuleChartInterf
];

// Limits
protected const MINIMUM_GENERATIONS = 2;
protected const MAXIMUM_GENERATIONS = 10;
public const MINIMUM_GENERATIONS = 2;
public const MAXIMUM_GENERATIONS = 10;

private ChartService $chart_service;

Expand Down
4 changes: 2 additions & 2 deletions app/Module/HourglassChartModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class HourglassChartModule extends AbstractModule implements ModuleChartInterfac
];

// Limits
protected const MINIMUM_GENERATIONS = 2;
protected const MAXIMUM_GENERATIONS = 10;
public const MINIMUM_GENERATIONS = 2;
public const MAXIMUM_GENERATIONS = 10;

/**
* Initialization.
Expand Down
6 changes: 3 additions & 3 deletions app/Module/PedigreeChartModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class PedigreeChartModule extends AbstractModule implements ModuleChartInterface
];

// Limits
protected const MINIMUM_GENERATIONS = 2;
protected const MAXIMUM_GENERATIONS = 12;
public const MINIMUM_GENERATIONS = 2;
public const MAXIMUM_GENERATIONS = 12;

// For RTL languages
protected const MIRROR_STYLE = [
Expand Down Expand Up @@ -356,7 +356,7 @@ protected function individualLink(Individual $individual, string $style, int $ge
*
* @return array<string>
*/
protected function styles(string $direction): array
public function styles(string $direction): array
{
// On right-to-left pages, the CSS will mirror the chart, so we need to mirror the label.
if ($direction === 'rtl') {
Expand Down
79 changes: 78 additions & 1 deletion resources/views/modules/charts/config.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ use Fisharebest\Webtrees\Tree;

/**
* @var array<string,string> $charts
* @var Individual|null $individual
* @var Individual $individual
* @var int $pedigree_generations
* @var int $pedigree_max_generations
* @var int $pedigree_min_generations
* @var string $pedigree_style
* @var array<string,string> $pedigree_styles
* @var int $descendants_generations
* @var int $descendants_max_generations
* @var int $descendants_min_generations
* @var int $hourglass_generations
* @var int $hourglass_max_generations
* @var int $hourglass_min_generations
* @var Tree $tree
* @var string $type
*/
Expand All @@ -34,3 +45,69 @@ use Fisharebest\Webtrees\Tree;
<?= view('components/select-individual', ['name' => 'xref', 'individual' => $individual, 'tree' => $tree]) ?>
</div>
</div>

<div id="options-pedigree"<?= $type !== 'pedigree' ? ' style="display: none"' : '' ?>>
<div class="row mb-3">
<label class="col-sm-3 col-form-label wt-page-options-label" for="pedigree_generations">
<?= I18N::translate('Generations') ?>
</label>
<div class="col-sm-9 wt-page-options-value">
<?= view('components/select-number', ['name' => 'pedigree_generations', 'selected' => $pedigree_generations, 'options' => range($pedigree_min_generations, $pedigree_max_generations)]) ?>
</div>
</div>

<div class="row mb-3">
<label class="col-sm-3 col-form-label wt-page-options-label" for="style">
<?= I18N::translate('Layout') ?>
</label>
<div class="col-sm-9 wt-page-options-value">
<?= view('components/radios-inline', ['name' => 'pedigree_style', 'options' => $pedigree_styles, 'selected' => $pedigree_style]) ?>
</div>
</div>
</div>

<div id="options-descendants"<?= $type !== 'descendants' ? ' style="display: none"' : '' ?>>
<div class="row mb-3">
<label class="col-sm-3 col-form-label wt-page-options-label" for="descendants_generations">
<?= I18N::translate('Generations') ?>
</label>
<div class="col-sm-9 wt-page-options-value">
<?= view('components/select-number', ['name' => 'descendants_generations', 'selected' => $descendants_generations, 'options' => range($descendants_min_generations, $descendants_max_generations)]) ?>
</div>
</div>
</div>

<div id="options-hourglass"<?= $type !== 'hourglass' ? ' style="display: none"' : '' ?>>
<div class="row mb-3">
<label class="col-sm-3 col-form-label wt-page-options-label" for="hourglass_generations">
<?= I18N::translate('Generations') ?>
</label>
<div class="col-sm-9 wt-page-options-value">
<?= view('components/select-number', ['name' => 'hourglass_generations', 'selected' => $hourglass_generations, 'options' => range($hourglass_min_generations, $hourglass_max_generations)]) ?>
</div>
</div>
</div>

<script type="text/javascript">
const typeEl = document.getElementById('type');
typeEl.addEventListener('change', () => {
const selectedOption = typeEl.options[typeEl.selectedIndex].value;
if (selectedOption === 'pedigree') {
document.getElementById('options-pedigree').style.removeProperty('display');
document.getElementById('options-descendants').style.display = 'none';
document.getElementById('options-hourglass').style.display = 'none';
} else if (selectedOption === 'descendants') {
document.getElementById('options-pedigree').style.display = 'none';
document.getElementById('options-descendants').style.removeProperty('display');
document.getElementById('options-hourglass').style.display = 'none';
} else if (selectedOption === 'hourglass') {
document.getElementById('options-pedigree').style.display = 'none';
document.getElementById('options-descendants').style.display = 'none';
document.getElementById('options-hourglass').style.removeProperty('display');
} else {
document.getElementById('options-pedigree').style.display = 'none';
document.getElementById('options-descendants').style.display = 'none';
document.getElementById('options-hourglass').style.display = 'none';
}
});
</script>