46be8ee0e162296c4a15954f967797e389f88b0e braney Thu Aug 18 16:07:51 2011 -0700 add a note about the data not being QA'ed by UCSC #3260 diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c index a8a5656..ffce0cf 100644 --- src/hg/hgHubConnect/hgHubConnect.c +++ src/hg/hgHubConnect/hgHubConnect.c @@ -1,448 +1,450 @@ /* hgHubConnect - the CGI web-based program to select track data hubs to connect with. */ #include "common.h" #include "hash.h" #include "linefile.h" #include "errabort.h" #include "errCatch.h" #include "hCommon.h" #include "dystring.h" #include "jksql.h" #include "cheapcgi.h" #include "htmshell.h" #include "hdb.h" #include "hui.h" #include "cart.h" #include "dbDb.h" #include "web.h" #include "trackHub.h" #include "hubConnect.h" #include "dystring.h" #include "hPrint.h" #include "jsHelper.h" #include "obscure.h" #define hgHub "hgHub_" /* prefix for all control variables */ #define hgHubDo hgHub "do_" /* prefix for all commands */ #define hgHubDoClear hgHubDo "clear" #define hgHubDoDisconnect hgHubDo "disconnect" #define hgHubDoReset hgHubDo "reset" struct cart *cart; /* The user's ui state. */ struct hash *oldVars = NULL; static char *destUrl = "../cgi-bin/hgTracks"; static char *pageTitle = "Import Tracks from Data Hubs"; char *database = NULL; char *organism = NULL; static void ourCellStart() { puts(""); } static void ourCellEnd() { puts(""); } static void ourPrintCell(char *str) { ourCellStart(); puts(str); ourCellEnd(); } static void hgHubConnectUnlisted() /* Put up the list of unlisted hubs and other controls for the page. */ { // put out the top of our page printf("
" " " " " " " " "); // count up the number of unlisted hubs we currently have int count = 0; struct hubConnectStatus *hub, *hubList = hubConnectStatusListFromCartAll(cart); for(hub = hubList; hub; hub = hub->next) { if (isHubUnlisted(hub)) count++; } if (count == 0) { // nothing to see here printf( "" "
" " " "" "
No Track Hubs for this genome assembly
"); printf("
"); return; } // time to output the big table. First the header printf( " " "Display " "Hub Name " "Description " "URL " "Disconnect " "\n"); // start first row printf(""); count = 0; for(hub = hubList; hub; hub = hub->next) { /* if the hub is public, then don't list it here */ if (!isHubUnlisted(hub)) continue; if (count) webPrintLinkTableNewRow(); // ends last row and starts a new one count++; // if there's an error message, we don't let people select it if (isEmpty(hub->errorMessage)) { ourCellStart(); char hubName[32]; safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id); cartMakeCheckBox(cart, hubName, FALSE); ourCellEnd(); } else { // give people a chance to clear the error ourCellStart(); printf( "" , hub->hubUrl); ourCellEnd(); } ourPrintCell(hub->shortLabel); if (isEmpty(hub->errorMessage)) ourPrintCell(hub->longLabel); else printf("ERROR: %s" "Debug", hub->errorMessage); ourPrintCell(hub->hubUrl); ourCellStart(); printf( "" , hub->id); ourCellEnd(); } printf("\n"); printf(""); } static void makeGenomePrint() /* print out the name of the current database etc. */ { getDbAndGenome(cart, &database, &organism, oldVars); printf("
\n"); printf("genome: %s    assembly: %s ", organism, hFreezeDate(database)); printf("
\n"); } void hgHubConnectPublic() /* Put up the list of public hubs and other controls for the page. */ { struct sqlConnection *conn = hConnectCentral(); char query[512]; safef(query, sizeof(query), "select hubUrl,shortLabel,longLabel,dbList from %s", hubPublicTableName); 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 (nameInCommaList(database, dbList)) { if (gotAnyRows) webPrintLinkTableNewRow(); else { /* output header */ printf("
\n"); printf(" " " " " " " " " " " " "\n"); // start first row printf(""); gotAnyRows = TRUE; } 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(); } else if (!isEmpty(errorMessage)) { // give user a chance to clear the error ourCellStart(); printf( "" , url); ourCellEnd(); } else errAbort("cannot get id for hub with url %s\n", url); ourPrintCell(shortLabel); if (isEmpty(errorMessage)) ourPrintCell(longLabel); else printf("", errorMessage); ourPrintCell(url); } } sqlFreeResult(&sr); if (gotAnyRows) { printf("
DisplayHub NameDescriptionURL
ERROR: %s
\n"); } else { printf("
\n"); printf("No Public Track Hubs for this genome assembly
"); } printf("
"); hDisconnectCentral(&conn); } static void tryHubOpen(unsigned id) /* try to open hub, leaks trackHub structure */ { /* try opening this again to reset error */ struct errCatch *errCatch = errCatchNew(); struct trackHub *tHub; if (errCatchStart(errCatch)) tHub = trackHubFromId(id); errCatchEnd(errCatch); if (errCatch->gotError) hubSetErrorMessage( errCatch->message->string, id); else hubSetErrorMessage(NULL, id); errCatchFree(&errCatch); tHub = NULL; } static void doResetHub(struct cart *theCart) { char *url = cartOptionalString(cart, hgHubDataText); if (url != NULL) { unsigned id = hubResetError(url); tryHubOpen(id); } else errAbort("must specify url in %s\n", hgHubDataText); } static void doClearHub(struct cart *theCart) { char *url = cartOptionalString(cart, hgHubDataText); printf("
clearing hub %s\n",url);
 if (url != NULL)
     hubClearStatus(url);
 else
     errAbort("must specify url in %s\n", hgHubDataText);
 printf("
Completed\n");
 }
 
 static void doDisconnectHub(struct cart *theCart)
 {
 char *id = cartOptionalString(cart, "hubId");
 
 if (id != NULL)
     {
     char buffer[1024];
     safef(buffer, sizeof buffer, "hgHubConnect.hub.%s", id);
     cartRemove(cart, buffer);
     }
 
 cartRemove(theCart, "hubId");
 }
 
 void doMiddle(struct cart *theCart)
 /* Write header and body of html page. */
 {
 boolean gotDisconnect = FALSE;
 
 cart = theCart;
 setUdcCacheDir();
 
 if (cartVarExists(cart, hgHubDoClear))
     {
     doClearHub(cart);
     cartWebEnd();
     return;
     }
 
 if (cartVarExists(cart, hgHubDoDisconnect))
     {
     gotDisconnect = TRUE;
     doDisconnectHub(cart);
     }
 
 if (cartVarExists(cart, hgHubDoReset))
     {
     doResetHub(cart);
     }
 
 cartWebStart(cart, NULL, "%s", pageTitle);
 jsIncludeFile("jquery.js", NULL);
 jsIncludeFile("utils.js", NULL);
 jsIncludeFile("jquery-ui.js", NULL);
 
 webIncludeResourceFile("jquery-ui.css");
 
 jsIncludeFile("ajax.js", NULL);
 jsIncludeFile("hgHubConnect.js", NULL);
 webIncludeResourceFile("hgHubConnect.css");
 
 printf("
\n"); printf( "

Track data hubs are collections of tracks from outside of UCSC that " "can be imported into the Genome Browser. To import a public hub check " "the box in the list below. " "After import the hub will show up as a group of tracks with its own blue " "bar and label underneath the main browser graphic, and in the " "configure page. For more information, see the " "" "User's Guide.

\n" + "

NOTE: Because Track Hubs are created and maintained by external sources," + " UCSC cannot be held responsible for their content.

" ); printf("
\n"); // figure out and print out genome name makeGenomePrint(); // check to see if we have any new hubs unsigned newId = hubCheckForNew(database, cart); if (newId) tryHubOpen(newId); // here's a little form for the add new hub button printf("
\n", "../cgi-bin/hgHubConnect"); cgiMakeHiddenVar("hubUrl", ""); cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); puts("
"); // this the form for the disconnect hub button printf("
\n", "../cgi-bin/hgHubConnect"); cgiMakeHiddenVar("hubId", ""); cgiMakeHiddenVar(hgHubDoDisconnect, "on"); cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); puts("
"); // this the form for the reset hub button printf("
\n", "../cgi-bin/hgHubConnect"); cgiMakeHiddenVar("hubUrl", ""); cgiMakeHiddenVar(hgHubDoReset, "on"); cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); puts("
"); // ... and now the main form if (cartVarExists(cart, hgHubConnectCgiDestUrl)) destUrl = cartOptionalString(cart, hgHubConnectCgiDestUrl); printf("
\n", destUrl); cartSaveSession(cart); // we have two tabs for the public and unlisted hubs printf("
" " "); hgHubConnectPublic(); hgHubConnectUnlisted(); printf("
"); printf("
"); cgiMakeButton("Submit", "Load Selected Hubs"); printf("Contact genome@soe.ucsc.edu to add a public hub.\n"); printf("
"); if ((newId != 0) || gotDisconnect) // make MyHubs the default tab { printf("\n"); } cgiMakeHiddenVar(hgHubConnectRemakeTrackHub, "on"); printf("
\n"); puts(""); cartWebEnd(); } char *excludeVars[] = {"Submit", "submit", "hc_one_url", hgHubDoReset, hgHubDoClear, hgHubDoDisconnect, hgHubDataText, hgHubConnectRemakeTrackHub, NULL}; int main(int argc, char *argv[]) /* Process command line. */ { oldVars = hashNew(10); cgiSpoof(&argc, argv); cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars); return 0; }