fff97fa89d9b02325b999b0621e676bdf4a1d202 galt Fri Jan 31 16:09:46 2020 -0800 cleanup of tablesTables.c diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c index d0cacd3..42dd8ec 100644 --- src/hg/lib/tablesTables.c +++ src/hg/lib/tablesTables.c @@ -394,126 +394,129 @@ boolean withFilters, char *itemPlural, int pageSize, struct fieldedTableSegment *largerContext, struct hash *suggestHash, struct facetField **ffArray, char *visibleFacetList, void (*addFunc)(int), char *initialWhere) /* Show a fielded table that can be sorted by clicking on column labels and optionally * that includes a row of filter controls above the labels . * The maxLenField is maximum character length of field before truncation with ... * Pass in 0 for no max */ { if (strchr(returnUrl, '?') == NULL) errAbort("Expecting returnUrl to include ? in showFieldedTable\nIt's %s", returnUrl); if (withFilters || visibleFacetList) showTableFilterInstructionsEtc(table, itemPlural, largerContext, addFunc, visibleFacetList); -// show top bar with quick-deselects -if (visibleFacetList) +// Show top bar with quick-deselects for selected facet values +// as well a clear restriction button that cleans out cdwFile_filter cart var. + +boolean haveSelectedValues = FALSE; +// pre-scan to see if we will have any selected values. + { + struct slName *nameList = slNameListFromComma(visibleFacetList); + int f; + for (f = 0; f < table->fieldCount; ++f) + { + struct facetField *field = ffArray[f]; + if (slNameInListUseCase(nameList, field->fieldName)) // i.e. is this field a visible facet? + { + if (!field->allSelected) + { + haveSelectedValues = TRUE; + } + } + } + } +if (visibleFacetList && (!isEmpty(initialWhere) || haveSelectedValues)) { // left column printf("
\n"); if (!isEmpty(initialWhere)) { printf("Restricting files to where %s. ", initialWhere); printf("  "); printf(""); jsOnEventById("click", "clearRestrictionButton", "$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n" "$('[name=cdwBrowseFiles_page]').val('1');\n" "$('[name=clearRestriction]').val('1');\n" "$('#submit').click();\n"); printf("
"); } - htmlPrintf("
\n"); + if (haveSelectedValues) + { + htmlPrintf("
\n"); struct slName *nameList = slNameListFromComma(visibleFacetList); int f; for (f = 0; f < table->fieldCount; ++f) { struct facetField *field = ffArray[f]; if (slNameInListUseCase(nameList, field->fieldName)) // i.e. is this field a visible facet? { - if (!field->allSelected) // something selected TODO is this really the right expression? + if (!field->allSelected) { htmlPrintf("\n"); - htmlPrintf("
\n"); + htmlPrintf("
\n"); htmlPrintf("
%s
\n", field->fieldName); - // why did this newer way not seem to work? or at least to only affect the dds and not the dts? - - // save old way: style='display: inline; float: left;' - struct facetVal *val; - int valuesShown = 0; - int valuesNotShown = 0; // can be used for a click to see-more when there are lots of values - // Sort values alphabetically // Make a copy to not disturb the original order struct facetVal *valListCopy = facetsClone(field->valList); slSort(&valListCopy, facetValCmp); for (val = valListCopy; val; val=val->next) { boolean specificallySelected = (val->selected && !field->allSelected); - // TODO do we want to stop of valuesShown exceeds FacetFieldLimit? Maybe use that or something else or nothing? - if ((val->selectCount > 0 && (field->showAllValues || valuesShown < FacetFieldLimit)) - || specificallySelected) - { - ++valuesShown; - char *op = "add"; if (specificallySelected) - op = "remove"; - if (sameString(op, "remove")) { - printf("
\n"); + char *op = "remove"; + printf("
\n"); htmlPrintf(" ", specificallySelected ? "true" : "false", specificallySelected ? "checked" : ""); htmlPrintf("", cartSessionVarName(), cartSessionId(cart), op, field->fieldName, val->val ); htmlPrintf("%s (%d)", val->val, val->selectCount); printf("
\n"); } } - else if (val->selectCount > 0) - { - ++valuesNotShown; - } - } slFreeList(&valListCopy); htmlPrintf("
\n"); } } } htmlPrintf("
\n"); + } printf("

\n"); } printf("
\n"); // parent container if (visibleFacetList) { // left column printf("
\n"); // reset all facet value selections char *op = "resetAll";