5034a7ae085fbf45e73a2deb4a4afc4ada31350a kent Fri Mar 6 09:53:46 2015 -0800 Adding suggestHash to tables so they can do suggestions. diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c index 114c771..fc3efbf 100644 --- src/hg/lib/tablesTables.c +++ src/hg/lib/tablesTables.c @@ -36,33 +36,57 @@ { /* Print info on matching */ int matchCount = slCount(table->rowList); if (largerContext != NULL) // Need to page? matchCount = largerContext->tableSize; printf(" %d %s found. ", matchCount, itemPlural); cgiMakeButton("submit", "update"); printf("
\n"); printf("First row of table below, above labels, can be used to filter individual fields. "); printf("Wildcard * and ? characters are allowed in text fields. "); printf(">min or <max, is 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 */ +{ +printf("\n"); +} + static void showTableFilterControlRow(struct fieldedTable *table, struct cart *cart, - char *varPrefix, int maxLenField) -/* Assuming we are in table already drow control row */ + 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 */ { printf(""); int i; for (i=0; ifieldCount; ++i) { char *field = table->fields[i]; char varName[256]; safef(varName, sizeof(varName), "%s_f_%s", varPrefix, field); webPrintLinkCellStart(); #ifdef MAKES_TOO_WIDE /* Print out input control. As you can see from all the commented out bits * this part has been a challenge. We'd like to make the input cell fit the * table size, but if we do it with style it makes whole table wider. */ char *oldVal = cartUsualString(cart, varName, ""); @@ -72,49 +96,44 @@ /* Approximate size of input control in characters */ int size = fieldedTableMaxColChars(table, i); if (size > maxLenField) size = maxLenField; #ifdef ACTUALLY_WORKS /* This way does work last I checked and is just a line of code. * Getting an id= property on the input tag though isn't possible this way. */ cartMakeTextVar(cart, varName, "", size + 1); #endif /* Print input control getting previous value from cart. Set an id= * so auto-suggest can find this control. */ char *oldVal = cartUsualString(cart, varName, ""); - printf("", + printf("\n", varName, varName, size+1, oldVal); - - webPrintLinkCellEnd(); - } - -/* Write out javascript to initialize autosuggest */ -printf("\n"); printf(""); } static void showTableSortingLabelRow(struct fieldedTable *table, struct cart *cart, char *varPrefix, char *returnUrl) /* Put up the label row with sorting fields attached. ALso actually sort table. */ { /* Get order var */ char orderVar[256]; safef(orderVar, sizeof(orderVar), "%s_order", varPrefix); char *orderFields = cartUsualString(cart, orderVar, ""); char pageVar[64]; @@ -218,79 +237,79 @@ char pageVar[64]; safef(pageVar, sizeof(pageVar), "%s_page", varPrefix); cgiMakeIntVar(pageVar, curPage+1, 3); printf(" of %d", totalPages); } } } void webFilteredFieldedTable(struct cart *cart, struct fieldedTable *table, char *returnUrl, char *varPrefix, int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext, boolean withFilters, char *itemPlural, - int pageSize, struct fieldedTableSegment *largerContext) + int pageSize, struct fieldedTableSegment *largerContext, struct hash *suggestHash) /* 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) showTableFilterInstructionsEtc(table, itemPlural, largerContext); /* Set up our table within table look. */ webPrintLinkTableStart(); /* Draw optional filters cells ahead of column labels*/ if (withFilters) - showTableFilterControlRow(table, cart, varPrefix, maxLenField); + showTableFilterControlRow(table, cart, varPrefix, maxLenField, suggestHash); showTableSortingLabelRow(table, cart, varPrefix, returnUrl); showTableDataRows(table, pageSize, maxLenField, tagOutputWrappers, wrapperContext); /* Get rid of table within table look */ webPrintLinkTableEnd(); if (largerContext != NULL) showTablePaging(table, cart, varPrefix, largerContext, pageSize); } void webSortableFieldedTable(struct cart *cart, struct fieldedTable *table, char *returnUrl, char *varPrefix, int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext) /* Display all of table including a sortable label row. The tagOutputWrappers * is an optional way to enrich output of specific columns of the table. It is keyed * by column name and has for values functions of type webTableOutputWrapperType. */ { webFilteredFieldedTable(cart, table, returnUrl, varPrefix, maxLenField, tagOutputWrappers, wrapperContext, FALSE, NULL, - slCount(table->rowList), NULL); + slCount(table->rowList), NULL, NULL); } void webFilteredSqlTable(struct cart *cart, struct sqlConnection *conn, char *fields, char *from, char *initialWhere, char *returnUrl, char *varPrefix, int maxFieldWidth, struct hash *tagOutWrappers, void *wrapperContext, - boolean withFilters, char *itemPlural, int pageSize) + boolean withFilters, char *itemPlural, int pageSize, struct hash *suggestHash) /* Given a query to the database in conn that is basically a select query broken into * separate clauses, construct and display an HTML table around results. This HTML table has * column names that will sort the table, and optionally (if withFilters is set) * it will also allow field-by-field wildcard queries on a set of controls it draws above * the labels. * Much of the functionality rests on the call to webFilteredFieldedTable. This function * does the work needed to bring in sections of potentially huge results sets into * the fieldedTable. */ { /* Construct select, from and where clauses in query, keeping an additional copy of where */ struct dyString *query = dyStringNew(0); struct dyString *where = dyStringNew(0); struct slName *field, *fieldList = commaSepToSlNames(fields); boolean gotWhere = FALSE; sqlDyStringPrintf(query, "%s", ""); // TODO check with Galt on how to get reasonable checking back. @@ -378,22 +397,22 @@ struct fieldedTableSegment context = { .tableSize=resultsSize}; if (resultsSize > pageSize) { page = cartUsualInt(cart, pageVar, 0) - 1; if (page < 0) page = 0; int lastPage = (resultsSize-1)/pageSize; if (page > lastPage) page = lastPage; context.tableOffset = page * pageSize; dyStringPrintf(query, " limit %d offset %d", pageSize, context.tableOffset); } struct fieldedTable *table = fieldedTableFromDbQuery(conn, query->string); webFilteredFieldedTable(cart, table, returnUrl, varPrefix, maxFieldWidth, - tagOutWrappers, wrapperContext, withFilters, itemPlural, pageSize, &context); + tagOutWrappers, wrapperContext, withFilters, itemPlural, pageSize, &context, suggestHash); fieldedTableFree(&table); dyStringFree(&query); dyStringFree(&where); }