cf924d2aa402c655a84131bbcb689bfc3d5307aa
angie
  Fri Nov 20 16:21:13 2015 -0800
Data Integrator UI for adding related SQL tables and fields for SQL-based
tracks using all.joiner.  This is only the UI -- the implementation will be
in a subsequent commit.  Main changes:
- cartJson interface between hgIntegrator.c and hgIntegratorModel.js:
- new command getRelatedTables
- the getFields command used to expect a simple comma-sep list of tracks.
Now it expects a list of ';'-sep track blobs, each of which may include
multiple comma-sep tables (track plus related tables).
- UI state interface between hgIntegrator.jsx and hgIntegratorModel.js:
- fieldSelect now supports multiple tables per track
- js/react/hgIntegrator/hgIntegrator.jsx: new subsections of 'Choose fields...'
dialog (FieldSelect) for adding related tables and showing their available
fields w/checkboxes; corresponding new UI state and events.
- js/model/hgIntegrator/hgIntegratorModel.js:
- new handlers for UI events and cartJson data for related tables/fields
- hgIntegrator.c: new code to return information about what tables (if any)
are related to each selected track, and what fields are in selected related
tables.

Other changes:
- hgIntegratorModel.js:
- split monolithic handleCartVar into separate handlers
- add new 'hgi_uiChoices' cart var to remember things that may not pertain
to the current query, such as a user's related tables/fields selections
for a table that is not included in the current query.
- convert between hgi_querySpec and internal UI state representation
(querySpecUpdateUiChoices, toQuerySpecJS)
- cart.js: added uiChoices convenience functions, stringifying of cartSet val
- cartJson interface between hgIntegrator.c and hgIntegratorModel.js:
- new command getQueryState: bundle querySpec and uiChoices from the cart
since they need to be processed together
- UI state interface between hgIntegrator.jsx and hgIntegratorModel.js:
- split UI state's querySpec object into separate dataSources and
outFileOptions objects (no point in bundling those in the UI)

Thanks to Kate and Matt for helpful suggestions about the UI.

refs #15544

diff --git src/hg/lib/hAnno.c src/hg/lib/hAnno.c
index ae45ed9..b4d2953 100644
--- src/hg/lib/hAnno.c
+++ src/hg/lib/hAnno.c
@@ -94,49 +94,53 @@
         continue;
     char *sqlType = field->type;
     // hg19.wgEncodeOpenChromSynthGm12878Pk.pValue has sql type "float unsigned",
     // and I'd rather pretend it's just a float than work unsigned floats into autoSql.
     if (sameString(sqlType, "float unsigned"))
 	sqlType = "float";
     char *asType = asTypeNameFromSqlType(sqlType);
     if (asType == NULL)
 	errAbort("No asTypeInfo for sql type '%s'!", field->type);
     dyStringPrintf(dy, "    %s %s;\t\"\"\n", asType, field->field);
     }
 dyStringAppend(dy, "    )\n");
 return asParseText(dy->string);
 }
 
-static struct asObject *getAutoSqlForTable(char *db, char *table, struct trackDb *tdb,
+struct asObject *hAnnoGetAutoSqlForDbTable(char *db, char *table, struct trackDb *tdb,
                                            boolean skipBin)
 /* Get autoSql for db.dbTable from tdb and/or db.tableDescriptions;
  * if it doesn't match columns, make one up from db.table sql fields.
  * Some subtleties are lost in translation from .as to .sql, that's why
  * we try tdb & db.tableDescriptions first.  But ultimately we need to return
  * an asObj whose columns match all fields of the table. */
 {
 struct sqlConnection *conn = hAllocConn(db);
 struct sqlFieldInfo *fieldList = sqlFieldInfoGet(conn, table);
 struct asObject *asObj = NULL;
 if (tdb != NULL)
     asObj = asForTdb(conn, tdb);
+if (asObj == NULL)
+    asObj = asFromTableDescriptions(conn, table);
 hFreeConn(&conn);
 if (columnsMatch(asObj, fieldList))
     return asObj;
 else
+    {
     return asObjectFromFields(table, fieldList, skipBin);
     }
+}
 
 static char *getBigDataFileName(char *db, struct trackDb *tdb, char *selTable, char *chrom)
 /* Get fileName from bigBed/bigWig/BAM/VCF database table, or bigDataUrl from custom track. */
 {
 char *bigDataUrl = trackDbSetting(tdb, "bigDataUrl");
 if (isNotEmpty(bigDataUrl))
     {
     return bigDataUrl;
     }
 else
     {
     struct sqlConnection *conn = hAllocConn(db);
     char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, selTable, chrom);
     hFreeConn(&conn);
     return fileOrUrl;
@@ -209,31 +213,31 @@
 else if (sameString("knownGene", tdb->track))
     {
     struct sqlConnection *conn = hAllocConn(dataDb);
     if (sqlTableExists(conn, "knownGene") && sqlTableExists(conn, "kgXref"))
         streamer = annoStreamDbKnownGeneNew(dataDb, assembly, maxOutRows);
     hFreeConn(&conn);
     }
 else if (trackHubDatabase(db))
     errAbort("Unrecognized type '%s' for hub track '%s'", tdb->type, tdb->track);
 if (streamer == NULL)
     {
     char maybeSplitTable[HDB_MAX_TABLE_STRING];
     if (!hFindSplitTable(dataDb, chrom, dbTable, maybeSplitTable, NULL))
         errAbort("hAnnoStreamerFromTrackDb: can't find table (or split table) for '%s.%s'",
                  dataDb, dbTable);
-    struct asObject *asObj = getAutoSqlForTable(dataDb, maybeSplitTable, tdb, TRUE);
+    struct asObject *asObj = hAnnoGetAutoSqlForDbTable(dataDb, maybeSplitTable, tdb, TRUE);
     streamer = annoStreamDbNew(dataDb, maybeSplitTable, assembly, asObj, maxOutRows);
     }
 return streamer;
 }
 
 struct annoGrator *hAnnoGratorFromBigFileUrl(char *fileOrUrl, struct annoAssembly *assembly,
                                              int maxOutRows, enum annoGratorOverlap overlapRule)
 /* Determine what kind of big data file/url we have and make streamer & grator for it. */
 {
 struct annoStreamer *streamer = NULL;
 struct annoGrator *grator = NULL;
 char *type = customTrackTypeFromBigFile(fileOrUrl);
 if (sameString(type, "bigBed") || sameString("bigGenePred", type))
     streamer = annoStreamBigBedNew(fileOrUrl, assembly, maxOutRows);
 else if (sameString(type, "vcfTabix"))
@@ -356,20 +360,20 @@
     {
     // If none of the above, it must be a database table; deduce autoSql from sql fields.
     char *dataDb = db, *dbTable = tdb->table;
     if (isCustomTrack(tdb->track))
         {
         dbTable = trackDbSetting(tdb, "dbTableName");
         if (dbTable)
             dataDb = CUSTOM_TRASH;
         else
             return NULL;
         }
     char maybeSplitTable[HDB_MAX_TABLE_STRING];
     if (!hFindSplitTable(dataDb, chrom, dbTable, maybeSplitTable, NULL))
         errAbort("hAnnoGetAutoSqlForTdb: can't find table (or split table) for '%s.%s'",
                  dataDb, dbTable);
-    asObj = getAutoSqlForTable(dataDb, maybeSplitTable, tdb, TRUE);
+    asObj = hAnnoGetAutoSqlForDbTable(dataDb, maybeSplitTable, tdb, TRUE);
     }
 return asObj;
 }