81f240f86b16d599cafde436527c5a6a6b87e456 kent Thu Jan 28 20:59:17 2021 -0800 getting rid of a lot of hard coded cdwBrowseFiles where prefixVar should be used. Making it not need a submit button for paging to work. diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c index 8fffdb5..ad19bd7 100644 --- src/hg/lib/tablesTables.c +++ src/hg/lib/tablesTables.c @@ -57,47 +57,49 @@ { if ((i >= offset) && (i < offset+limit)) fieldedTableAdd(table, row, fieldCount, ++id); ++i; } } facetFieldsFromSqlTableFinish(ffList, facetValCmpSelectCountDesc); sqlFreeResult(&sr); *pFfArray = ffArray; *pResultCount = i; return table; } static void showTableFilterInstructionsEtc(struct fieldedTable *table, char *pluralInstructions, struct fieldedTableSegment *largerContext, void (*addFunc)(int), - char *visibleFacetList) + char *visibleFacetList, char *varPrefix) /* Print instructional text, and basic summary info on who passes filter, and a submit * button just in case user needs it */ { /* Print info on matching */ int matchCount = slCount(table->rowList); if (largerContext != NULL) // Need to page? matchCount = largerContext->tableSize; printf("<input class='btn btn-secondary' type='submit' name='submit' id='submit' value='Search'>"); printf("  "); printf("<input class='btn btn-secondary' type='button' id='clearButton' VALUE=\"Clear Search\">"); -jsOnEventById("click", "clearButton", +char jsText[1024]; +safef(jsText, sizeof(jsText), "$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n" - "$('[name=cdwBrowseFiles_page]').val('1');\n" - "$('#submit').click();\n"); + "$('[name=%s_page]').val('1');\n" + "$('#submit').click();\n", varPrefix); +jsOnEventById("click", "clearButton", jsText); printf("<br>"); printf("%d %s found. ", matchCount, pluralInstructions); if (addFunc) addFunc(matchCount); if (!visibleFacetList) { printf("<BR>\n"); printf("You can further filter search results field by field below. "); printf("Wildcard * and ? characters are allowed in text fields. "); printf(">min or <max are allowed in numerical fields.<BR>\n"); } @@ -125,40 +127,40 @@ jsInline(dy->string); dyStringFree(&dy); } #ifdef NOT_CURRENTLY_USED static void printWatermark(char *id, char *watermark) /* Print light text filter prompt as watermark. */ { jsInlineF( "$(function() {\n" " $('#%s').watermark(\"%s\");\n" "});\n", id, watermark); } #endif -static void resetPageNumberOnChange(char *id) +static void resetPageNumberOnChange(char *id, char *varPrefix) /* On change, reset page number to 1. */ { jsInlineF( "$(function() {\n" " $('form').delegate('#%s','change keyup paste',function(e){\n" -" $('[name=cdwBrowseFiles_page]').val('1');\n" +" $('[name=%s_page]').val('1');\n" " });\n" "});\n" -, id); +, id, varPrefix); } static void showTableFilterControlRow(struct fieldedTable *table, struct slName *visibleFields, struct cart *cart, char *varPrefix, int maxLenField, struct hash *suggestHash) /* Assuming we are in table already drow control row. * The suggestHash is keyed by field name. If something is there we'll assume * it's value is slName list of suggestion values */ { /* Include javascript and style we need */ printf("<link rel='stylesheet' href='//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'>\n"); printf("<script src='https://code.jquery.com/ui/1.12.1/jquery-ui.js'></script>\n"); printf("<tr>"); struct slName *el; @@ -174,31 +176,31 @@ int size = fieldedTableMaxColChars(table, fieldIx); if (size > maxLenField) size = maxLenField; /* Print input control getting previous value from cart. Set an id= * so auto-suggest can find this control. */ char *oldVal = cartUsualString(cart, varName, ""); printf("<INPUT TYPE=TEXT NAME=\"%s\" id=\"%s\" SIZE=%d", varName, varName, size+1); if (isEmpty(oldVal)) printf(" placeholder=\" filter \">\n"); else printf(" value=\"%s\">\n", oldVal); /* Write out javascript to reset page number to 1 if filter changes */ - resetPageNumberOnChange(varName); + resetPageNumberOnChange(varName, varPrefix); /* Set up the auto-suggest list for this filter */ if (suggestHash != NULL) { struct slName *suggestList = hashFindVal(suggestHash, field); if (suggestList != NULL) { printSuggestScript(varName, suggestList); } } printf("</td>\n"); } printf("</TR>"); @@ -340,96 +342,97 @@ { if (pageSize < largerContext->tableSize) { int curPage = largerContext->tableOffset/pageSize; int totalPages = (largerContext->tableSize + pageSize - 1)/pageSize; char id[256]; if ((curPage + 1) > 1) { // first page safef(id, sizeof id, "%s_first", varPrefix); printf("<a href='#' id='%s'>⏮</a>", id); jsOnEventByIdF("click", id, "$('[name=%s_page]').val('1');\n" - "$('#submit').click();\n" + "event.target.closest('form').submit();\n" , varPrefix); printf(" "); // prev page safef(id, sizeof id, "%s_prev", varPrefix); printf("<a href='#' id='%s'>⏪</a>", id); jsOnEventByIdF("click", id, "$('[name=%s_page]').val('%d');\n" - "$('#submit').click();\n" + "event.target.closest('form').submit();\n" , varPrefix, (curPage+1)-1); printf(" "); } printf("Displaying page "); char pageVar[64]; safef(pageVar, sizeof(pageVar), "%s_page", varPrefix); cgiMakeIntVar(pageVar, curPage+1, 3); printf(" of %d", totalPages); if ((curPage + 1) < totalPages) { // next page printf(" "); safef(id, sizeof id, "%s_next", varPrefix); printf("<a href='#' id='%s'>⏩</a>", id); jsOnEventByIdF("click", id, "$('[name=%s_page]').val('%d');\n" - "$('#submit').click();\n" + "event.target.closest('form').submit();\n" , varPrefix, (curPage+1)+1); // last page printf(" "); safef(id, sizeof id, "%s_last", varPrefix); printf("<a href='#' id='%s'>⏭</a>", id); jsOnEventByIdF("click", id, "$('[name=%s_page]').val('%d');\n" - "$('#submit').click();\n" + "event.target.closest('form').submit();\n" , varPrefix, totalPages); } } } } void webFilteredFieldedTable(struct cart *cart, struct fieldedTable *table, char *visibleFieldList, char *returnUrl, char *varPrefix, int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext, boolean withFilters, char *pluralInstructions, int pageSize, int facetUsualSize, struct fieldedTableSegment *largerContext, struct hash *suggestHash, struct facetField **ffArray, char *visibleFacetList, void (*addFunc)(int) ) /* 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 (pluralInstructions != NULL) - showTableFilterInstructionsEtc(table, pluralInstructions, largerContext, addFunc, visibleFacetList); + showTableFilterInstructionsEtc(table, pluralInstructions, largerContext, addFunc, + visibleFacetList, varPrefix); 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. struct dyString *facetBar = dyStringNew(1024); char *where = cartUsualString(cart, "cdwFile_filter", ""); boolean gotSelected = FALSE; struct slName *visList = slNameListFromComma(visibleFacetList); @@ -450,84 +453,86 @@ // 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); if (specificallySelected) { char *op = "remove"; htmlDyStringPrintf(facetBar, "<dd class=\"facet\" style='display: inline-block;'>\n"); htmlDyStringPrintf(facetBar, "<input type=checkbox value=%s class=cdwFSCheckBox %s> ", specificallySelected ? "true" : "false", specificallySelected ? "checked" : ""); - htmlDyStringPrintf(facetBar, "<a href='%s|none|&cdwCommand=browseFiles" + htmlDyStringPrintf(facetBar, "<a href='%s" "&browseFiles_facet_op=%s|url|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">", returnUrl, - op, field->fieldName, val->val + op, field->fieldName, val->val, varPrefix ); htmlDyStringPrintf(facetBar, "%s (%d)</a>", val->val, val->selectCount); htmlDyStringPrintf(facetBar, "</dd>\n"); } } slFreeList(&valListCopy); htmlDyStringPrintf(facetBar, "</span></span>\n"); } } if (!isEmpty(where) || gotSelected) { printf("<div>\n"); } if (!isEmpty(where)) { // left column printf("Restricting files to where %s. ", where); printf("  "); printf("<input class='btn btn-secondary' type='button' id='clearRestrictionButton' VALUE=\"Clear Restriction\">"); - jsOnEventById("click", "clearRestrictionButton", - "$('[name=cdwBrowseFiles_page]').val('1');\n" + char jsText[1024]; + safef(jsText, sizeof(jsText), + "$('[name=%s_page]').val('1');\n" "$('[name=clearRestriction]').val('1');\n" - "$('#submit').click();\n"); + "$('#submit').click();\n", varPrefix); + jsOnEventById("click", "clearRestrictionButton", jsText); printf("<br>"); } if (gotSelected) { // reset all facet value selections button char *op = "resetAll"; - htmlPrintf("<a class='btn btn-secondary' href='%s|none|&cdwCommand=browseFiles" + htmlPrintf("<a class='btn btn-secondary' href='%s" "&browseFiles_facet_op=%s|none|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">%s</a>\n", - returnUrl, op, "", "", "Clear All" + returnUrl, op, "", "", varPrefix, "Clear All" ); printf("<dl style='display: inline-block;'>\n"); printf("%s\n", facetBar->string); printf("</dl>\n"); } if (!isEmpty(where) || gotSelected) printf("</div><br>\n"); dyStringFree(&facetBar); } printf("<div class='row'>\n"); // parent container @@ -538,105 +543,105 @@ printf("<div class='col-xs-6 col-sm-4 col-md-4 col-lg-3 col-xl-3'>\n"); struct slName *visList = slNameListFromComma(visibleFacetList); struct slName *vis; for (vis = visList; vis != NULL; vis = vis->next) { int f = fieldedTableMustFindFieldIx(table, vis->name); struct facetField *field = ffArray[f]; htmlPrintf("<div class='card facet-card'><div class='card-body'>\n"); htmlPrintf("<h6 class='card-title'>%s</h6><dl>\n", field->fieldName); struct facetVal *val; if (!field->allSelected) // add reset facet link { char *op = "reset"; - htmlPrintf("<dd><a class='btn btn-secondary' href='%s|none|&cdwCommand=browseFiles" + htmlPrintf("<dd><a class='btn btn-secondary' href='%s" "&browseFiles_facet_op=%s|url|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">%s</a></dd>\n", returnUrl, - op, field->fieldName, "", + op, field->fieldName, "", varPrefix, "Clear" ); } int valuesShown = 0; int valuesNotShown = 0; if (field->showAllValues) // Sort alphabetically if they want all values { slSort(&field->valList, facetValCmp); } for (val = field->valList; val; val=val->next) { boolean specificallySelected = (val->selected && !field->allSelected); if ((val->selectCount > 0 && (field->showAllValues || valuesShown < facetUsualSize)) || specificallySelected) { ++valuesShown; char *op = "add"; if (specificallySelected) op = "remove"; printf("<dd class=\"facet\">\n"); htmlPrintf("<input type=checkbox value=%s class=cdwFSCheckBox %s> ", specificallySelected ? "true" : "false", specificallySelected ? "checked" : ""); - htmlPrintf("<a href='%s|none|&cdwCommand=browseFiles" + htmlPrintf("<a href='%s" "&browseFiles_facet_op=%s|none|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">", returnUrl, - op, field->fieldName, val->val + op, field->fieldName, val->val, varPrefix ); htmlPrintf("%s (%d)</a>", val->val, val->selectCount); printf("</dd>\n"); } else if (val->selectCount > 0) { ++valuesNotShown; } } // show "See More" link when facet has lots of values if (valuesNotShown > 0) { char *op = "showAllValues"; - htmlPrintf("<dd><a href='%s|none|&cdwCommand=browseFiles" + htmlPrintf("<dd><a href='%s" "&browseFiles_facet_op=%s|url|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">See %d More</a></dd>\n", - returnUrl, op, field->fieldName, "", valuesNotShown + returnUrl, op, field->fieldName, "", varPrefix, valuesNotShown ); } // show "See Fewer" link when facet has lots of values if (field->showAllValues && valuesShown >= facetUsualSize) { char *op = "showSomeValues"; - htmlPrintf("<dd><a href='%s|none|&cdwCommand=browseFiles" + htmlPrintf("<dd><a href='%s" "&browseFiles_facet_op=%s|url|" "&browseFiles_facet_fieldName=%s|url|" "&browseFiles_facet_fieldVal=%s|url|" - "&cdwBrowseFiles_page=1' " + "&%s_page=1' " ">%s</a></dd>\n", - returnUrl, op, field->fieldName, "", + returnUrl, op, field->fieldName, "", varPrefix, "See Fewer" ); } htmlPrintf("</div></div>\n"); } printf("</div>\n"); // Clicking a checkbox is actually a click on the following link jsInlineF( "$(function () {\n" " $('.cdwFSCheckBox').click(function() {\n" " this.nextSibling.nextSibling.click();\n" " });\n" "});\n"); }