Skip to content

Commit

Permalink
3.1 search page flow bugfix (BioKIC#1351)
Browse files Browse the repository at this point in the history
* fix the page flow bugs but confirm existing collection persistance issues

* display which collections are to be queried in harvest params

* solve the collection selection for the new search page

* clean up and subfunctionalize

* slight refactor to improve readability

* add minor aesthetic improvement

* add styling class

* remove collection display in harvest params

* remove translations that are now cruft
  • Loading branch information
Atticus29 committed May 22, 2024
1 parent cd4ec15 commit 17b9844
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
3 changes: 2 additions & 1 deletion collections/harvestparams.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$collManager = new OccurrenceManager();
$searchVar = $collManager->getQueryTermStr();
$SHOULD_INCLUDE_CULTIVATED_AS_DEFAULT = $SHOULD_INCLUDE_CULTIVATED_AS_DEFAULT ?? false;

?>
<!DOCTYPE html>
<html lang="<?php echo $LANG_TAG ?>">
Expand Down Expand Up @@ -72,7 +73,7 @@
}
?>
<div role="main" id="innertext">
<h1 class="page-heading">Search</h1>
<h1 class="page-heading bottom-breathing-room-rel top-breathing-room-rel">Search</h1>
<form name="harvestparams" id="harvestparams" action="list.php" method="post" onsubmit="return checkHarvestParamsForm(this)">
<hr/>
<div>
Expand Down
3 changes: 2 additions & 1 deletion collections/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
if(!preg_match('/^[,\d]+$/',$catId)) $catId = '';
if($catId == '' && isset($DEFAULTCATID)) $catId = $DEFAULTCATID;


$collManager = new OccurrenceManager();
$SHOULD_USE_HARVESTPARAMS = $SHOULD_USE_HARVESTPARAMS ?? false;
//$collManager->reset();
Expand Down Expand Up @@ -90,7 +91,7 @@
?>
</ul>
<?php
$actionPage = $SHOULD_USE_HARVESTPARAMS ? "harvestparams.php" : "./search/index.php";
$actionPage = "harvestparams.php";
if($specArr && $obsArr){
?>
<div id="specobsdiv">
Expand Down
10 changes: 7 additions & 3 deletions collections/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$cntPerPage = array_key_exists('cntperpage', $_REQUEST) ? filter_var($_REQUEST['cntperpage'], FILTER_SANITIZE_NUMBER_INT) : 100;
$pageNumber = array_key_exists('page', $_REQUEST) ? filter_var($_REQUEST['page'], FILTER_SANITIZE_NUMBER_INT) : 1;
$datasetid = array_key_exists('datasetid', $_REQUEST) ? filter_var($_REQUEST['datasetid'], FILTER_SANITIZE_NUMBER_INT) : '';
$comingFrom = array_key_exists('comingFrom', $_REQUEST) ? htmlspecialchars($_REQUEST['comingFrom'], HTML_SPECIAL_CHARS_FLAGS) : '';
$_SESSION['datasetid'] = filter_var($datasetid, FILTER_SANITIZE_NUMBER_INT);

$collManager = new OccurrenceListManager();
Expand All @@ -18,7 +19,6 @@
$occurArr = $collManager->getSpecimenMap($pageNumber, $cntPerPage);
$SHOULD_INCLUDE_CULTIVATED_AS_DEFAULT = $SHOULD_INCLUDE_CULTIVATED_AS_DEFAULT ?? false;
$SHOULD_USE_HARVESTPARAMS = $SHOULD_USE_HARVESTPARAMS ?? false;
$actionPage = $SHOULD_USE_HARVESTPARAMS ? "harvestparams.php" : "./search/index.php";

$_SESSION['citationvar'] = $searchVar;
?>
Expand Down Expand Up @@ -135,8 +135,12 @@ function displayDatasetTools() {
else {
echo '<div class="navpath">';
echo '<a href="../index.php">' . htmlspecialchars($LANG['NAV_HOME'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
echo '<a href="index.php">' . htmlspecialchars($LANG['NAV_COLLECTIONS'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
echo '<a href="' . $actionPage . '">' . htmlspecialchars($LANG['NAV_SEARCH'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
if($comingFrom !== 'search/index.php'){
echo '<a href="index.php">' . htmlspecialchars($LANG['NAV_COLLECTIONS'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
echo '<a href="' . $CLIENT_ROOT . '/collections/harvestparams.php">' . htmlspecialchars($LANG['NAV_SEARCH'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
} else{
echo '<a href="' . $CLIENT_ROOT . '/collections/search/index.php">' . htmlspecialchars($LANG['NAV_SEARCH'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a> &gt;&gt; ';
}
echo '<b>' . $LANG['NAV_SPECIMEN_LIST'] . '</b>';
echo '</div>';
}
Expand Down
2 changes: 1 addition & 1 deletion collections/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
</script>
<script>
let alerts = [{
'alertMsg': '<?php echo $LANG['ALERT_MSG_PREVIOUS_SEARCH_FORM'] ?> <a href="<?php echo $CLIENT_ROOT ?>/collections/harvestparams.php" alt="Traditional Sample Search Form"><?= $LANG['PREVIOUS_SAMPLE_SEARCH']; ?></a>.'
'alertMsg': '<?php echo $LANG['ALERT_MSG_PREVIOUS_SEARCH_FORM'] ?> <a href="<?php echo $CLIENT_ROOT ?>/collections/index.php" alt="Traditional Sample Search Form"><?= $LANG['PREVIOUS_SAMPLE_SEARCH']; ?></a>.'
}];
handleAlerts(alerts, 3000);

Expand Down
42 changes: 40 additions & 2 deletions collections/search/js/searchform.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ function getSearchUrl() {
baseUrl.searchParams.append(key, paramsArr[key]);
});

baseUrl.searchParams.append("comingFrom", "search/index.php");

return baseUrl.href;
}

Expand Down Expand Up @@ -721,6 +723,40 @@ function hideColCheckbox(collid) {
});
}

function uncheckEverything() {
const checkUncheckAllElem = document.getElementById("dballcb");
checkUncheckAllElem.checked = false;
const categoryCollectionsChecked = Array.from(
document.querySelectorAll(`#search-form-colls input[name="cat[]"]:checked`)
);
categoryCollectionsChecked.forEach((individualCollectionChecked) => {
individualCollectionChecked.checked = false;
});

const individualCollectionsChecked = Array.from(
document.querySelectorAll(`#search-form-colls input[name="db[]"]:checked`)
);
individualCollectionsChecked.forEach((individualCollectionChecked) => {
individualCollectionChecked.checked = false;
});
}

function checkTheCollectionsThatShouldBeChecked(queriedCollections) {
queriedCollections.forEach((queriedCollection) => {
let targetElem = document.getElementById("collection-" + queriedCollection);
if (!targetElem) {
// get elements if categories exist
const prefix = "coll-" + queriedCollection + "-";
const candidateTargetElems =
document.querySelectorAll(`[id^="${prefix}"]`) || [];
if (candidateTargetElems.length > 0) {
targetElem = candidateTargetElems[0]; // there should only be one match; get the first one
}
}
targetElem.checked = true;
});
}

function setSearchForm(frm) {
if (sessionStorage.querystr) {
var urlVar = parseUrlVariables(sessionStorage.querystr);
Expand Down Expand Up @@ -823,8 +859,10 @@ function setSearchForm(frm) {
}
}
if (urlVar.db) {
if (frm?.db) {
frm.db.value = urlVar.db;
const queriedCollections = urlVar.db.split(",");
if (queriedCollections.length > 0) {
uncheckEverything();
checkTheCollectionsThatShouldBeChecked(queriedCollections);
}
}
for (var i in urlVar) {
Expand Down

0 comments on commit 17b9844

Please sign in to comment.