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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 67 additions & 14 deletions app/Module/ChartsBlockModule.php
Expand Up @@ -112,8 +112,18 @@
$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'

Check warning on line 126 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L115-L126

Added lines #L115 - L126 were not covered by tests
]);
$content = view('modules/charts/chart', [
'block_id' => $block_id,
Expand All @@ -132,7 +142,7 @@
$title = $module->chartTitle($individual);
$chart_url = $module->chartUrl($individual, [
'ajax' => true,
'generations' => 2,
'generations' => $this->getBlockSetting($block_id, 'descendants_generations', '2'),

Check warning on line 145 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L145

Added line #L145 was not covered by tests
'chart_style' => DescendancyChartModule::CHART_STYLE_TREE,
]);
$content = view('modules/charts/chart', [
Expand All @@ -153,7 +163,7 @@
$title = $module->chartTitle($individual);
$chart_url = $module->chartUrl($individual, [
'ajax' => true,
'generations' => 2,
'generations' => $this->getBlockSetting($block_id, 'hourglass_generations', '2'),

Check warning on line 166 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L166

Added line #L166 was not covered by tests
]);
$content = view('modules/charts/chart', [
'block_id' => $block_id,
Expand Down Expand Up @@ -231,9 +241,17 @@
{
$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');

Check warning on line 247 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L244-L247

Added lines #L244 - L247 were not covered by tests

$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);

Check warning on line 254 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L251-L254

Added lines #L251 - L254 were not covered by tests
}

/**
Expand All @@ -253,21 +271,56 @@
$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 = [];

Check warning on line 274 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L274

Added line #L274 was not covered by tests
// 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());

Check warning on line 281 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L276-L281

Added lines #L276 - L281 were not covered by tests
}
$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;

Check warning on line 287 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L283-L287

Added lines #L283 - L287 were not covered by tests
}
$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;

Check warning on line 293 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L289-L293

Added lines #L289 - L293 were not covered by tests
}
$treeModule = $this->module_service->findByInterface(InteractiveTreeModule::class)->first();
if ($treeModule instanceof InteractiveTreeModule) {
$charts['treenav'] = I18N::translate('Interactive tree');

Check warning on line 297 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L295-L297

Added lines #L295 - L297 were not covered by tests
}
uasort($charts, I18N::comparator());

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

Check failure on line 302 in app/Module/ChartsBlockModule.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Cannot access constant DEFAULT_STYLE on Fisharebest\Webtrees\Module\PedigreeChartModule|null.
$descendants_generations = $this->getBlockSetting($block_id, 'descendants_generations', '2');
$hourglass_generations = $this->getBlockSetting($block_id, 'hourglass_generations', '2');

Check warning on line 304 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L301-L304

Added lines #L301 - L304 were not covered by tests

$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,

Check failure on line 313 in app/Module/ChartsBlockModule.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Variable $pedigree_generations on left side of ?? always exists and is not nullable.
'pedigree_max_generations' => $pedigree_max_generations ?? null,
'pedigree_min_generations' => $pedigree_min_generations ?? null,
'pedigree_style' => $pedigree_style ?? null,

Check failure on line 316 in app/Module/ChartsBlockModule.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Variable $pedigree_style on left side of ?? always exists and is not nullable.
'pedigree_styles' => $pedigree_styles ?? null,
'descendants_generations' => $descendants_generations ?? null,

Check failure on line 318 in app/Module/ChartsBlockModule.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Variable $descendants_generations on left side of ?? always exists and is not nullable.
'descendants_max_generations' => $descendants_max_generations ?? null,
'descendants_min_generations' => $descendants_min_generations ?? null,
'hourglass_generations' => $hourglass_generations ?? null,

Check failure on line 321 in app/Module/ChartsBlockModule.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.3)

Variable $hourglass_generations on left side of ?? always exists and is not nullable.
'hourglass_max_generations' => $hourglass_max_generations ?? null,
'hourglass_min_generations' => $hourglass_min_generations ?? null,

Check warning on line 323 in app/Module/ChartsBlockModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/ChartsBlockModule.php#L309-L323

Added lines #L309 - L323 were not covered by tests
]);
}
}
4 changes: 2 additions & 2 deletions app/Module/DescendancyChartModule.php
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
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
Expand Up @@ -58,8 +58,8 @@
];

// 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 @@
*
* @return array<string>
*/
protected function styles(string $direction): array
public function styles(string $direction): array

Check warning on line 359 in app/Module/PedigreeChartModule.php

View check run for this annotation

Codecov / codecov/patch

app/Module/PedigreeChartModule.php#L359

Added line #L359 was not covered by tests
{
// 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
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>