462b42c25db106915ee8dc8127691ad47684b37d galt Tue Apr 1 15:50:48 2014 -0700 Fixes #12602. Deal with long assembly lists by making a click-able expansion/contraction of long lists in the table. It tries to keep the assembly list to about 40 charachters. diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c index 61b43bc..82239f1 100644 --- src/hg/hgHubConnect/hgHubConnect.c +++ src/hg/hgHubConnect/hgHubConnect.c @@ -57,53 +57,94 @@ static char *removeLastComma(char *string) { if (string != NULL) { int len = strlen(string); if ( string[len - 1] == ',') string[len - 1] = 0; else if (len > 2 && endsWith(string,", ")) string[len - 2] = 0; } return string; } -static void printGenomes(struct trackHub *thub) -/* print supported assembly names from trackHub */ +#define GENLISTWIDTH 40 +static void printGenomeList(struct slName *genomes, int row) +/* print supported assembly names from sl list */ { /* List of associated genomes. */ -struct trackHubGenome *genomes = thub->genomeList; struct dyString *dy = newDyString(100); - +struct dyString *dyShort = newDyString(100); +char *trimmedName = NULL; for(; genomes; genomes = genomes->next) - dyStringPrintf(dy,"%s, ", trackHubSkipHubName(genomes->name)); -ourPrintCell(removeLastComma( dyStringCannibalize(&dy))); + { + trimmedName = trackHubSkipHubName(genomes->name); + dyStringPrintf(dy,"%s, ", trimmedName); + if (dyShort->stringSize == 0 || (dyShort->stringSize+strlen(trimmedName)<=GENLISTWIDTH)) + dyStringPrintf(dyShort,"%s, ", trimmedName); + } +char *genomesString = removeLastComma( dyStringCannibalize(&dy)); +char *genomesShort = removeLastComma( dyStringCannibalize(&dyShort)); +char tempHtml[1024+strlen(genomesString)+strlen(genomesShort)]; +if (strlen(genomesShort) > GENLISTWIDTH) // If even the first element is too long, truncate it. + genomesShort[GENLISTWIDTH] = 0; +if (strlen(genomesShort)==strlen(genomesString)) + { + safef(tempHtml, sizeof tempHtml, "%s", genomesString); } +else + { + safef(tempHtml, sizeof tempHtml, + "[+] %s..." -static void printGenomeList(struct slName *genomes) -/* print supported assembly names from sl list */ + "[-]
%s
" + + , row, row, row, genomesShort + , row, row, row, genomesString); + } +ourPrintCell(tempHtml); +//ourPrintCell(removeLastComma( dyStringCannibalize(&dy))); +} + + +static void printGenomes(struct trackHub *thub, int row) +/* print supported assembly names from trackHub */ { /* List of associated genomes. */ -struct dyString *dy = newDyString(100); - +struct trackHubGenome *genomes = thub->genomeList; +struct slName *list = NULL, *el; for(; genomes; genomes = genomes->next) - dyStringPrintf(dy,"%s, ", trackHubSkipHubName(genomes->name)); -ourPrintCell(removeLastComma( dyStringCannibalize(&dy))); + { + el = slNameNew(genomes->name); + slAddHead(&list, el); + } +slReverse(&list); +printGenomeList(list, row); } + static void hgHubConnectUnlisted(struct hubConnectStatus *hubList, struct hash *publicHash) /* Put up the list of unlisted hubs and other controls for the page. */ /* uses publicHash to distingusih public hubs from unlisted ones */ /* NOTE: Destroys hubList */ { // put out the top of our page printf("
\n" " \n" " \n" "\n", hub->errorMessage); else if (hub->trackHub != NULL) ourPrintCell(hub->trackHub->longLabel); else ourPrintCell(""); if (hub->trackHub != NULL) - printGenomes(hub->trackHub); + printGenomes(hub->trackHub, count); else ourPrintCell(""); ourPrintCell(hub->hubUrl); ourCellStart(); printf( "\n" , hub->id); ourCellEnd(); } printf("
\n" " \n" "trackHub != NULL) ourPrintCell(hub->trackHub->shortLabel); else ourPrintCell(""); if (!isEmpty(hub->errorMessage)) printf("ERROR: %s " "Debug
\n"); printf("
"); } static struct hash *outputPublicTable(struct sqlConnection *conn, char *publicTable) /* Put up the list of public hubs and other controls for the page. */ { struct hash *publicHash = NULL; char query[512]; sqlSafef(query, sizeof(query), "select hubUrl,shortLabel,longLabel,dbList from %s", publicTable); struct sqlResult *sr = sqlGetResult(conn, query); char **row; +int count = 0; boolean gotAnyRows = FALSE; while ((row = sqlNextRow(sr)) != NULL) { + ++count; char *url = row[0], *shortLabel = row[1], *longLabel = row[2], *dbList = row[3]; if (gotAnyRows) webPrintLinkTableNewRow(); else { /* output header */ printf("
\n"); printf(" " " " " " " " " " " " " " @@ -277,31 +320,31 @@ "class=\"hubField\" type=\"button\" value=\"check hub\">" , url); ourCellEnd(); } else errAbort("cannot get id for hub with url %s\n", url); ourPrintCell(shortLabel); if (isEmpty(errorMessage)) ourPrintCell(longLabel); else printf("", errorMessage); - printGenomeList(slNameListFromComma(dbList)); // Leaking a bit of memory + printGenomeList(slNameListFromComma(dbList), count); // Leaking a bit of memory ourPrintCell(url); hashStore(publicHash, url); } sqlFreeResult(&sr); if (gotAnyRows) { printf("
DisplayHub NameDescriptionAssembliesURLERROR: %s " "Debug
\n"); printf("
"); } return publicHash; }