a4c8987ac13d72f85a7c3adde3f867456a85516f
chmalee
  Thu Sep 26 15:52:46 2024 -0700
Save newly created hubs to file table, return hubs when loading the page

diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c
index f7ea546..60d961a 100644
--- src/hg/hgHubConnect/trackHubWizard.c
+++ src/hg/hgHubConnect/trackHubWizard.c
@@ -12,31 +12,31 @@
 #include "trashDir.h"
 #include "hgHubConnect.h"
 #include "jsHelper.h"
 #include "web.h"
 #include "wikiLink.h"
 #include "customTrack.h"
 #include "userdata.h"
 #include "jsonWrite.h"
 #include "cartJson.h"
 #include "hubSpace.h"
 #include "hubConnect.h"
 
 void removeOneFile(char *userName, char *cgiFileName)
 /* Remove one single file for userName */
 {
-char *fileName = prefixUserFile(userName, cgiFileName);
+char *fileName = prefixUserFile(userName, cgiEncodeFull(cgiFileName));
 if (fileExists(fileName))
     {
     fprintf(stderr, "deleting file: '%s'\n", fileName);
     removeFileForUser(fileName, userName);
     fflush(stderr);
     }
 }
 
 void doRemoveFile(struct cartJson *cj, struct hash *paramHash)
 /* Process the request to remove a file */
 {
 char *userName = getUserName();
 if (userName)
     {
     struct jsonElement *deleteJson = hashFindVal(paramHash, "fileNameList");
@@ -99,61 +99,74 @@
     char *path = prefixUserFile(userName, name);
     if (isDirectory(path))
         {
         // can't make a hub that already exists!
         fprintf(stdout, "Status: 400 Bad Request\n\n");
         fprintf(stdout, "Hub already exists, select hub from dropdown or try a different name");
         fflush(stdout);
         exit(1);
         }
     else
         {
         // good we can make a new directory and stuff a hub.txt in it
         // the directory needs to be 777, so ignore umask for now
         writeHubText(path, userName, name, db);
         // TODO: add a row to the hubspace table for the hub.txt
+        //addHubTxtToTable(userName, path, name, db);
         // return json to fill out the table
         jsonWriteString(cj->jw, "hubName", name);
         jsonWriteString(cj->jw, "db", db);
+        time_t now = time(NULL);
+        jsonWriteString(cj->jw, "creationTime", sqlUnixTimeToDate(&now, FALSE));
         }
     }
 }
 
 static void outFilesForUser()
 /* List out the currently stored files for the user and their sizes */
 {
 char *userName = getUserName();
 struct jsonWrite *jw = jsonWriteNew(); // the JSON to return for the client javascript
 jsonWriteObjectStart(jw, NULL);
 if (userName)
     {
     // the url for this user:
     jsonWriteString(jw, "userUrl", webDataDir(userName));
     jsonWriteListStart(jw, "fileList");
     struct hubSpace *file, *fileList = listFilesForUser(userName);
     for (file = fileList; file != NULL; file = file->next)
         {
         jsonWriteObjectStart(jw, NULL);
         jsonWriteString(jw, "fileName", file->fileName);
         jsonWriteNumber(jw, "fileSize", file->fileSize);
         jsonWriteString(jw, "fileType", file->fileType);
-        jsonWriteString(jw, "hub", "temp");
+        jsonWriteString(jw, "hub", "");
         jsonWriteString(jw, "genome", file->db);
         jsonWriteString(jw, "createTime", file->creationTime);
         jsonWriteObjectEnd(jw);
         }
     jsonWriteListEnd(jw);
+    jsonWriteListStart(jw, "hubList");
+    struct userHubs *hub, *hubList = listHubsForUser(userName);
+    for (hub = hubList; hub != NULL; hub = hub->next)
+        {
+        jsonWriteObjectStart(jw, NULL);
+        jsonWriteString(jw, "hubName", hub->hubName);
+        jsonWriteString(jw, "genome", hub->genome);
+        jsonWriteObjectEnd(jw);
+        }
+    jsonWriteListEnd(jw);
     }
 jsonWriteObjectEnd(jw);
 jsInlineF("var userFiles = %s;\n", dyStringCannibalize(&jw->dy));
 jsonWriteFree(&jw);
 }
 
 void doTrackHubWizard()
 /* Offer an upload form so users can upload all their hub files */
 {
 jsIncludeFile("utils.js", NULL);
 jsIncludeFile("ajax.js", NULL);
 jsIncludeFile("lodash.3.10.0.compat.min.js", NULL);
 jsIncludeFile("cart.js", NULL);
 jsIncludeFile("tus.js", NULL);
 jsIncludeFile("hgMyData.js", NULL);