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, + "<span id=Short%d " + "onclick=\"javascript:" + "document.getElementById('Short%d').style.display='none';" + "document.getElementById('Full%d').style.display='inline';" + "return false;\">[+] %s...</span>" -static void printGenomeList(struct slName *genomes) -/* print supported assembly names from sl list */ + "<span id=Full%d " + "style=\"display:none\" " + "onclick=\"javascript:" + "document.getElementById('Full%d').style.display='none';" + "document.getElementById('Short%d').style.display='inline';" + "return false;\">[-]<br>%s</span>" + + , 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("<div id=\"unlistedHubs\" class=\"hubList\"> \n" "<table id=\"unlistedHubsTable\"> \n" "<thead><tr> \n" "<th colspan=\"6\" id=\"addHubBar\"><label for=\"hubUrl\">URL:</label> \n" "<input name=\"hubText\" id=\"hubUrl\" class=\"hubField\"" "type=\"text\" size=\"65\"> \n" "<input name=\"hubAddButton\"" "onClick=\"hubText.value=$.trim(hubText.value);if(validateUrl($('#hubUrl').val())) { document.addHubForm.elements['hubUrl'].value=hubText.value;" @@ -184,62 +225,64 @@ if (hub->trackHub != NULL) ourPrintCell(hub->trackHub->shortLabel); else ourPrintCell(""); if (!isEmpty(hub->errorMessage)) printf("<TD><span class=\"hubError\">ERROR: %s </span>" "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>\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( "<input name=\"hubDisconnectButton\"" "onClick=\"document.disconnectHubForm.elements['hubId'].value='%d';" "document.disconnectHubForm.submit();return true;\" " "class=\"hubField\" type=\"button\" value=\"X\">\n" , hub->id); ourCellEnd(); } printf("</TR></tbody></TABLE>\n"); printf("</div>"); } 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("<div id=\"publicHubs\" class=\"hubList\"> \n"); printf("<table id=\"publicHubsTable\"> " "<thead><tr> " "<th>Display</th> " "<th>Hub Name</th> " "<th>Description</th> " "<th>Assemblies</th> " "<th>URL</th> " @@ -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("<TD><span class=\"hubError\">ERROR: %s </span>" "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug</a></TD>", 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("</TR></tbody></TABLE>\n"); printf("</div>"); } return publicHash; }