84769302d77939430b003999bd6397ecc64207b5
galt
Fri Feb 7 15:33:28 2020 -0800
CIRM cdwWebBrowse: Placing the Clear-All-Facets button in a more logical location. Now only visble if some facets have been chosen.
diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c
index dab9121..77e170c 100644
--- src/hg/lib/tablesTables.c
+++ src/hg/lib/tablesTables.c
@@ -1,836 +1,841 @@
/* tablesTables - this module deals with two types of tables SQL tables in a database,
* and fieldedTable objects in memory. It has routines to do sortable, filterable web
* displays on tables. */
#include "common.h"
#include "hash.h"
#include "obscure.h"
#include "linefile.h"
#include "jksql.h"
#include "jsHelper.h"
#include "sqlSanity.h"
#include "fieldedTable.h"
#include "cheapcgi.h"
#include "htmshell.h"
#include "web.h"
#include "cart.h"
#include "facetField.h"
#include "tablesTables.h"
struct fieldedTable *fieldedTableFromDbQuery(struct sqlConnection *conn, char *query)
/* Return fieldedTable from a database query */
{
struct sqlResult *sr = sqlGetResult(conn, query);
char **fields;
int fieldCount = sqlResultFieldArray(sr, &fields);
struct fieldedTable *table = fieldedTableNew(query, fields, fieldCount);
char **row;
int i = 0;
while ((row = sqlNextRow(sr)) != NULL)
fieldedTableAdd(table, row, fieldCount, ++i);
sqlFreeResult(&sr);
return table;
}
struct fieldedTable *fieldedTableAndCountsFromDbQuery(struct sqlConnection *conn, char *query, int limit, int offset,
char *selectedFields, struct facetField ***pFfArray, int *pResultCount)
/* Return fieldedTable from a database query and also fetch use and select counts */
{
struct sqlResult *sr = sqlGetResult(conn, query);
char **fields;
int fieldCount = sqlResultFieldArray(sr, &fields);
struct facetField **ffArray;
AllocArray(ffArray, fieldCount);
struct fieldedTable *table = fieldedTableNew(query, fields, fieldCount);
struct facetField *ffList = facetFieldsFromSqlTableInit(fields, fieldCount, selectedFields, ffArray);
char **row;
int i = 0;
int id = 0;
char *nullVal = "n/a";
/* Scan through result saving it in list. */
while ((row = sqlNextRow(sr)) != NULL)
{
if (perRowFacetFields(fieldCount, row, nullVal, ffArray))
{
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 *itemPlural, struct fieldedTableSegment *largerContext, void (*addFunc)(int),
char *visibleFacetList)
/* 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("");
printf("  ");
printf("");
jsOnEventById("click", "clearButton",
"$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n"
"$('[name=cdwBrowseFiles_page]').val('1');\n"
"$('#submit').click();\n");
printf("
");
printf("%d %s found. ", matchCount, itemPlural);
if (addFunc)
addFunc(matchCount);
if (!visibleFacetList)
{
printf("
\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.
\n");
}
}
static void printSuggestScript(char *id, struct slName *suggestList)
/* Print out a little javascript to wrap auto-suggester around control with given ID */
{
struct dyString *dy = dyStringNew(256);
dyStringPrintf(dy,"$(document).ready(function() {\n");
dyStringPrintf(dy," $('#%s').autocomplete({\n", id);
dyStringPrintf(dy," delay: 100,\n");
dyStringPrintf(dy," minLength: 0,\n");
dyStringPrintf(dy," source: [");
char *separator = "";
struct slName *suggest;
for (suggest = suggestList; suggest != NULL; suggest = suggest->next)
{
dyStringPrintf(dy,"%s\"%s\"", separator, suggest->name);
separator = ",";
}
dyStringPrintf(dy,"]\n");
dyStringPrintf(dy," });\n");
dyStringPrintf(dy,"});\n");
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)
/* 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"
" });\n"
"});\n"
, id);
}
static void showTableFilterControlRow(struct fieldedTable *table, 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("\n");
printf("\n");
int i;
printf("