src/hg/instinct/bioInt2/bioIntUI.c 1.1

1.1 2009/03/27 20:15:52 jsanborn
updated code and added UI stubs
Index: src/hg/instinct/bioInt2/bioIntUI.c
===================================================================
RCS file: src/hg/instinct/bioInt2/bioIntUI.c
diff -N src/hg/instinct/bioInt2/bioIntUI.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/hg/instinct/bioInt2/bioIntUI.c	27 Mar 2009 20:15:52 -0000	1.1
@@ -0,0 +1,112 @@
+/* bioIntUI */
+#include "common.h"
+#include "bed.h"
+#include "cart.h"
+#include "linefile.h"
+#include "customTrack.h"
+#include "genoLay.h"
+#include "hash.h"
+#include "hCommon.h"
+#include "hdb.h"
+#include "hPrint.h"
+#include "htmshell.h"
+#include "hui.h"
+#include "trackLayout.h"
+#include "web.h"
+#include "microarray.h"
+#include "ra.h"
+#include "hgStatsLib.h"
+#include "featuresLib.h" 
+#include "json.h"
+#include "bioIntUI.h"
+
+static char const rcsid[] = "$Id$";
+/* ---- Global variables. ---- */
+struct cart *cart;	         /* This holds cgi and other variables between clicks. */
+struct hash *oldVars;	         /* Old cart hash. */
+
+
+void usage()
+/* Explain usage and exit. */
+{
+errAbort(
+  "bioIntUI\n"
+  "usage:\n"
+  "   bioIntUI\n"
+  );
+}
+
+/* get a list of the current analyses */
+void getAnalyses()
+{
+char query[256];
+struct sqlResult *sr = NULL;
+char **row = NULL;
+
+safef(query, sizeof(query),
+      "select * from analyses;");
+
+struct sqlConnection *conn = hAllocConnProfile("localDb", "bioInt");
+sr = sqlGetResult(conn,query);
+struct json *js = newJson();
+struct json *analysis, *analyses = jsonAddContainerList(js, "analyses");
+analysis = analyses;
+while((row = sqlNextRow(sr)))
+{
+	jsonAddString(analysis, "analysisId", row[0]);
+	jsonAddString(analysis, "analysisName", row[3]);
+	analysis = jsonAddContainerToList(&analyses);
+}
+hFreeConn(&conn);
+
+if (js)
+    hPrintf("%s\n", js->print(js));
+}
+
+
+
+void dispatchRoutines()
+/* Look at command variables in cart and figure out which
+ * page to draw. */
+{
+/* retrieve cart variables, handle various modes */
+char *mode = cartOptionalString(cart, bioIntMode);
+if (!mode)
+    errAbort("%s is required.", bioIntMode);
+
+if (sameString(mode, "getAnalyses"))
+    getAnalyses();
+else
+    errAbort("Incorrect mode = %s", mode);
+
+cartRemovePrefix(cart, bioIntPrefix);
+
+}
+
+void hghDoUsualHttp()
+/* Wrap html page dispatcher with code that writes out
+ * HTTP header and write cart back to database. */
+{
+cartWriteCookie(cart, hUserCookie());
+printf("Content-Type:application/x-javascript\r\n\r\n");
+
+/* Dispatch other pages, that actually want to write HTML. */
+cartWarnCatcher(dispatchRoutines, cart, jsonEarlyWarningHandler);
+cartCheckout(&cart);
+}
+
+char *excludeVars[] = {"Submit", "submit", NULL};
+
+int main(int argc, char *argv[])
+/* Process command line. */
+{
+htmlPushEarlyHandlers();
+cgiSpoof(&argc, argv);
+htmlSetStyle(htmlStyleUndecoratedLink);
+
+oldVars = hashNew(12);
+cart = cartForSession(hUserCookie(), excludeVars, oldVars);
+
+hghDoUsualHttp();
+return 0;
+}