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

Default to XREF if no XREF provided #305

Merged
merged 1 commit into from
Dec 17, 2022
Merged
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
9 changes: 7 additions & 2 deletions module.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

use Cassandra\Set;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Localization\Translation;
Expand Down Expand Up @@ -158,8 +159,12 @@ public function getChartAction(ServerRequestInterface $request): ResponseInterfa
{
$tree = $request->getAttribute('tree');
assert($tree instanceof Tree);

$individual = $this->getIndividual($tree, $request->getQueryParams()['xref']);
if (isset($request->getQueryParams()['xref'])) {
$xref = $request->getQueryParams()['xref'];
} else {
$xref = $tree->getUserPreference(Auth::user(), UserInterface::PREF_TREE_ACCOUNT_XREF);
}
$individual = $this->getIndividual($tree, $tree->significantIndividual(Auth::user(), $xref)->xref());
$userDefaultVars = (new Settings($this))->getSettings();
if (!isset($_REQUEST['reset'])) {
$cookie = new Cookie($tree);
Expand Down
26 changes: 16 additions & 10 deletions resources/javascript/gvexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,25 @@ function changeURLXref(xref) {
}
}
function updateURLParameter(parameter, value, action) {
let url=document.location.href.split("?")[0];
let args=document.location.href.split("?")[1];
let params = new URLSearchParams(args);
if (params.toString().search(parameter) !== -1) {
if (action === "remove") {
params.delete(parameter);
} else if (action === "update") {
params.set(parameter, value);
} else {
return params.get(parameter);
let split = document.location.href.split("?");
let url = split[0];
if (split.length > 1) {
let args = split[1];
let params = new URLSearchParams(args);
if (params.toString().search(parameter) !== -1) {
if (action === "remove") {
params.delete(parameter);
} else if (action === "update") {
params.set(parameter, value);
} else {
return params.get(parameter);
}
}
history.pushState(null, '', url + "?" + params.toString());
} else if (action === "update") {
history.pushState(null, '', url + "?" + parameter + "=" + value);
}
return "";
}

function getURLParameter(parameter) {
Expand Down
9 changes: 6 additions & 3 deletions resources/views/page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace vendor\WebtreesModules\gvexport;

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Tree;


Expand All @@ -25,6 +28,7 @@ use Fisharebest\Webtrees\Tree;

$settings = (new Settings($module))->getSettings();
$nographviz = $settings['graphviz_bin'] == "";
$xref = $individual->xref();
?>

<script type="text/javascript">
Expand All @@ -37,6 +41,7 @@ $nographviz = $settings['graphviz_bin'] == "";

function runPageLoaded() {
if (typeof pageLoaded === 'function' && typeof jQuery === 'function') {
changeURLXref('<?= $xref; ?>');
pageLoaded();
} else {
// If external script loads before inline script, then wait
Expand All @@ -55,7 +60,6 @@ $nographviz = $settings['graphviz_bin'] == "";
newScript.setAttribute("type","text/javascript");
newScript.setAttribute("src","<?= $gvexport_js ?>");
document.head.appendChild(newScript);

</script>
<script src="<?= $module->assetUrl('javascript/viz.js'); ?>"></script>
<script src="<?= $module->assetUrl('javascript/panzoom.min.js'); ?>"></script>
Expand Down Expand Up @@ -92,9 +96,8 @@ $nographviz = $settings['graphviz_bin'] == "";
/* Check if another module (e.g. vesta classic) is adding the XREF to
the name. If so, we want to enable the XREF option for individuals
unless we already have a saved setting */
$individual = $module->getIndividual($tree, $_GET["xref"]);
$startName = $individual->fullName();
$name = str_replace(" (" . $_GET["xref"] . ")", "", $startName);
$name = str_replace(" (" . $xref . ")", "", $startName);
if ($startName != $name && $vars["show_pid"] == "DEFAULT") {
$overridePID = true;
} else {
Expand Down