cd0b41f1116bd93328ab34e9eceaa5f9afa8b825 chmalee Thu Feb 6 13:36:29 2025 -0800 Lots of changes to hub space UI after code review and QA feedback. 1) Make the table interface more like a file explorer where you view the 'root' directory by default and then can click into 'folders'. Also adds a breadcrumb nav so you can go backwards. 2) Fix bug in delete command to remove directories correctly. 3) cgiEncode the parentDir of incoming requests to prevent moving files to weird locations diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c index a21592ef726..500677e76f4 100644 --- src/hg/hgHubConnect/trackHubWizard.c +++ src/hg/hgHubConnect/trackHubWizard.c @@ -91,99 +91,107 @@ char *db = jsonStringField(fileObj, "genome"); char *fullPath = jsonStringField(fileObj, "fullPath"); removeOneFile(userName, fileName, fullPath, db, fileType); // write out the fullPath so the DataTable can remove the correct row: jsonWriteString(cj->jw, NULL, fullPath); } jsonWriteListEnd(cj->jw); } } void doMoveFile(struct cartJson *cj, struct hash *paramHash) /* Move a file to a new hub */ { } -static void outFilesForUser() -/* List out the currently stored files for the user and their sizes */ +static void outUiDataForUser(struct jsonWrite *jw) +/* List out the currently stored files for the user as well as other data + * needed to create the hubSpace table */ { char *userName = getUserName(); -struct jsonWrite *jw = jsonWriteNew(); // the JSON to return for the client javascript -jsonWriteObjectStart(jw, NULL); +jsonWriteObjectStart(jw, "userFiles"); 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); cgiDecodeFull(file->fileName, file->fileName, strlen(file->fileName)); jsonWriteString(jw, "fileName", file->fileName); jsonWriteNumber(jw, "fileSize", file->fileSize); jsonWriteString(jw, "fileType", file->fileType); jsonWriteString(jw, "parentDir", file->parentDir); jsonWriteString(jw, "genome", file->db); jsonWriteString(jw, "lastModified", file->lastModified); jsonWriteString(jw, "uploadTime", file->creationTime); jsonWriteString(jw, "fullPath", stripDataDir(file->location, userName)); jsonWriteString(jw, "md5sum", file->md5sum); jsonWriteObjectEnd(jw); } jsonWriteListEnd(jw); } -jsonWriteObjectEnd(jw); -jsInlineF("var isLoggedIn = %s\n", getUserName() ? "true" : "false"); -jsInlineF("var userFiles = %s;\n", dyStringCannibalize(&jw->dy)); -jsInlineF("var hubNameDefault = \"%s\";\n", defaultHubNameForUser(getUserName())); +jsonWriteBoolean(jw, "isLoggedIn", getUserName() ? TRUE : FALSE); +jsonWriteString(jw, "hubNameDefault", defaultHubNameForUser(getUserName())); // if the user is not logged, the 0 for the quota is ignored -jsInlineF("var userQuota = %llu\n", getUserName() ? checkUserQuota(getUserName()) : 0); -jsInlineF("var maxQuota = %llu\n", getUserName() ? getMaxUserQuota(getUserName()) : HUB_SPACE_DEFAULT_QUOTA); -jsonWriteFree(&jw); +jsonWriteNumber(jw, "userQuota", getUserName() ? checkUserQuota(getUserName()) : 0); +jsonWriteNumber(jw, "maxQuota", getUserName() ? getMaxUserQuota(getUserName()) : HUB_SPACE_DEFAULT_QUOTA); +jsonWriteObjectEnd(jw); +} + +void getHubSpaceUIState(struct cartJson *cj, struct hash *paramHash) +/* Get all the data we need to make a users hubSpace UI table. The cartJson library + * deals with printing the json */ +{ +outUiDataForUser(cj->jw); } void doTrackHubWizard(char *database) /* 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); puts("\n"); puts("\n"); puts(""); puts("\n"); puts(""); puts("\n"); puts(""); puts(""); puts(""); jsIncludeFile("hgMyData.js", NULL); // the skeleton HTML: webIncludeFile("inc/hgMyData.html"); webIncludeResourceFile("hgMyData.css"); -// get the current files stored for this user -outFilesForUser(); +// get the current files and vars stored for this user +struct jsonWrite *jw = jsonWriteNew(); +outUiDataForUser(jw); +jsInlineF("\nvar uiData = {%s}\n", jw->dy->string); +jsonWriteFree(&jw); jsInlineF("\nvar cartDb=\"%s %s\";\n", trackHubSkipHubName(hGenome(database)), database); jsInlineF("\nvar tusdEndpoint=\"%s\";\n", cfgOptionDefault("hubSpaceTusdEndpoint", NULL)); jsInline("$(document).ready(function() {\nhubCreate.init();\n})"); puts(""); } void revokeApiKey(struct cartJson *cj, struct hash *paramHash) /* Remove any api keys for the user */ { char *userName = getUserName(); struct sqlConnection *conn = hConnectCentral(); struct dyString *query = sqlDyStringCreate("delete from %s where userName='%s'", HUBSPACE_AUTH_TABLE, userName); sqlUpdate(conn, dyStringCannibalize(&query)); hDisconnectCentral(&conn); jsonWriteString(cj->jw, "revoke", "true");