4c396a03784396605a6d9e2d698a7a999ab65d24 braney Wed Nov 30 20:04:14 2011 -0800 fix problems with status field in hubStatus not reflecting the actual state of the hubPublic table. We're no longer using the status field (#5965) diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c index b67b64f..55fc759 100644 --- src/hg/hgHubConnect/hgHubConnect.c +++ src/hg/hgHubConnect/hgHubConnect.c @@ -72,58 +72,61 @@ { if (hub == NULL) return; struct trackHub *thub = hub->trackHub; if (thub != NULL) { /* List of associated genomes. */ struct trackHubGenome *genomes = thub->genomeList; for(; genomes; genomes = genomes->next) hashStore(hash, genomes->name); } } -static void hgHubConnectUnlisted(struct hubConnectStatus *hubList) +static void hgHubConnectUnlisted(struct hubConnectStatus *hubList, + struct hash *publicHash) /* Put up the list of unlisted hubs and other controls for the page. */ +/* adds hubUrls to publicHash */ /* NOTE: Destroys hubList */ { // put out the top of our page printf("<div id=\"unlistedHubs\" class=\"hubList\"> " "<table id=\"unlistedHubsTable\"> " "<thead><tr> " "<th colspan=\"5\" id=\"addHubBar\"><label for \"hubUrl\">URL:</label> " "<input name=\"hubText\" id=\"hubUrl\" class=\"hubField\"" "type=\"text\" size=\"65\"> " "<input name=\"hubAddButton\"" "onClick=\"document.addHubForm.elements['hubUrl'].value=hubText.value;" "document.addHubForm.submit();return true;\" " "class=\"hubField\" type=\"button\" value=\"Add Hub\">" "</th> " "</tr> "); // count up the number of unlisted hubs we currently have int unlistedHubCount = 0; struct hubConnectStatus *unlistedHubList = NULL; struct hubConnectStatus *hub, *nextHub; struct hash *assHash = newHash(5); for(hub = hubList; hub; hub = nextHub) { nextHub = hub->next; - if (isHubUnlisted(hub) ) + // if url is not in publicHash, it's unlisted */ + if (!((publicHash != NULL) && hashLookup(publicHash, hub->hubUrl))) { addGenomesToHash(hub, assHash); unlistedHubCount++; slAddHead(&unlistedHubList, hub); } } hubList = NULL; // hubList no longer valid struct hashCookie cookie = hashFirst(assHash); struct dyString *dy = newDyString(100); struct hashEl *hel; int numAssemblies = 0; while ((hel = hashNext(&cookie)) != NULL) { @@ -206,62 +209,66 @@ ourCellStart(); printf( "<input name=\"hubDisconnectButton\"" "onClick=\"document.disconnectHubForm.elements['hubId'].value='%d';" "document.disconnectHubForm.submit();return true;\" " "class=\"hubField\" type=\"button\" value=\"X\">" , hub->id); ourCellEnd(); } printf("</TR></tbody></TABLE>\n"); printf("</div>"); } -static boolean outputPublicTable(struct sqlConnection *conn, char *publicTable) +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]; safef(query, sizeof(query), "select hubUrl,shortLabel,longLabel,dbList from %s", publicTable); struct sqlResult *sr = sqlGetResult(conn, query); char **row; boolean gotAnyRows = FALSE; while ((row = sqlNextRow(sr)) != NULL) { 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> " "</tr></thead>\n"); // start first row printf("<tbody> <tr>"); gotAnyRows = TRUE; + + // allocate the hash to store hubUrl's + publicHash = newHash(5); } char *errorMessage = NULL; // get an id for this hub unsigned id = hubFindOrAddUrlInStatusTable(database, cart, url, &errorMessage); if ((id != 0) && isEmpty(errorMessage)) { ourCellStart(); char hubName[32]; safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, id); cartMakeCheckBox(cart, hubName, FALSE); ourCellEnd(); } @@ -278,55 +285,60 @@ 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); ourPrintCell(removeLastComma(dbList)); ourPrintCell(url); + hashStore(publicHash, url); } sqlFreeResult(&sr); if (gotAnyRows) { printf("</TR></tbody></TABLE>\n"); printf("</div>"); } -return gotAnyRows; +return publicHash; } -void hgHubConnectPublic() +struct hash *hgHubConnectPublic() /* Put up the list of public hubs and other controls for the page. */ { +struct hash *retHash = NULL; struct sqlConnection *conn = hConnectCentral(); char *publicTable = cfgOptionEnvDefault("HGDB_HUB_PUBLIC_TABLE", "hubPublicTableName", defaultHubPublicTableName); -if (!(sqlTableExists(conn, publicTable) && outputPublicTable(conn, publicTable) )) +if (!(sqlTableExists(conn, publicTable) && + (retHash = outputPublicTable(conn, publicTable)) != NULL )) { printf("<div id=\"publicHubs\" class=\"hubList\"> \n"); printf("No Public Track Hubs for this genome assembly<BR>"); printf("</div>"); } hDisconnectCentral(&conn); + +return retHash; } static void tryHubOpen(unsigned id) /* try to open hub, leaks trackHub structure */ { /* try opening this again to reset error */ struct sqlConnection *conn = hConnectCentral(); struct errCatch *errCatch = errCatchNew(); struct hubConnectStatus *hub = NULL; if (errCatchStart(errCatch)) hub = hubConnectStatusForId(conn, id); errCatchEnd(errCatch); if (errCatch->gotError) hubUpdateStatus( errCatch->message->string, NULL); else @@ -489,32 +501,32 @@ puts("</FORM>"); // ... and now the main form if (cartVarExists(cart, hgHubConnectCgiDestUrl)) destUrl = cartOptionalString(cart, hgHubConnectCgiDestUrl); printf("<FORM ACTION=\"%s\" METHOD=\"POST\" NAME=\"mainForm\">\n", destUrl); cartSaveSession(cart); // we have two tabs for the public and unlisted hubs printf("<div id=\"tabs\">" "<ul> <li><a href=\"#publicHubs\">Public Hubs</a></li>" "<li><a href=\"#unlistedHubs\">My Hubs</a></li> " "</ul> "); -hgHubConnectPublic(); -hgHubConnectUnlisted(hubList); +struct hash *publicHash = hgHubConnectPublic(); +hgHubConnectUnlisted(hubList, publicHash); printf("</div>"); printf("<div class=\"tabFooter\">"); cgiMakeButton("Submit", "Load Selected Hubs"); char *emailAddress = cfgOptionDefault("hub.emailAddress","genome@soe.ucsc.edu"); printf("<span class=\"small\">" "Contact <A HREF=\"mailto:%s\">%s</A> to add a public hub." "</span>\n", emailAddress,emailAddress); printf("</div>"); cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); printf("</div>\n"); puts("</FORM>");