Fossil SCM
added /json/report/get.
Commit
e21b391dcd355a91c1c636d90b91eb7a5c78da96
Parent
8c4a23aee42c162…
2 files changed
+3
+37
-1
+3
| --- ajax/index.html | ||
| +++ ajax/index.html | ||
| @@ -261,10 +261,13 @@ | ||
| 261 | 261 | <input type='button' value='query' |
| 262 | 262 | onclick='TheApp.cgi.sendCommand("/json/query?format=o","SELECT * from user")' /> |
| 263 | 263 | |
| 264 | 264 | <input type='button' value='report list' |
| 265 | 265 | onclick='TheApp.cgi.sendCommand("/json/report/list")' /> |
| 266 | +<input type='button' value='report get' | |
| 267 | + onclick='TheApp.cgi.sendCommand("/json/report/get",2)' /> | |
| 268 | + | |
| 266 | 269 | <input type='button' value='report run' |
| 267 | 270 | onclick='TheApp.cgi.sendCommand("/json/report/run",{"report":2,"format":"o"})' /> |
| 268 | 271 | |
| 269 | 272 | <!-- not yet ready... |
| 270 | 273 | <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' /> |
| 271 | 274 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -261,10 +261,13 @@ | |
| 261 | <input type='button' value='query' |
| 262 | onclick='TheApp.cgi.sendCommand("/json/query?format=o","SELECT * from user")' /> |
| 263 | |
| 264 | <input type='button' value='report list' |
| 265 | onclick='TheApp.cgi.sendCommand("/json/report/list")' /> |
| 266 | <input type='button' value='report run' |
| 267 | onclick='TheApp.cgi.sendCommand("/json/report/run",{"report":2,"format":"o"})' /> |
| 268 | |
| 269 | <!-- not yet ready... |
| 270 | <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' /> |
| 271 |
| --- ajax/index.html | |
| +++ ajax/index.html | |
| @@ -261,10 +261,13 @@ | |
| 261 | <input type='button' value='query' |
| 262 | onclick='TheApp.cgi.sendCommand("/json/query?format=o","SELECT * from user")' /> |
| 263 | |
| 264 | <input type='button' value='report list' |
| 265 | onclick='TheApp.cgi.sendCommand("/json/report/list")' /> |
| 266 | <input type='button' value='report get' |
| 267 | onclick='TheApp.cgi.sendCommand("/json/report/get",2)' /> |
| 268 | |
| 269 | <input type='button' value='report run' |
| 270 | onclick='TheApp.cgi.sendCommand("/json/report/run",{"report":2,"format":"o"})' /> |
| 271 | |
| 272 | <!-- not yet ready... |
| 273 | <input type='button' value='artifact/XYZ' onclick='TheApp.cgi.sendCommand("/json/artifact?uuid=json")' /> |
| 274 |
+37
-1
| --- src/json_report.c | ||
| +++ src/json_report.c | ||
| @@ -64,10 +64,13 @@ | ||
| 64 | 64 | ** |
| 65 | 65 | ** Returns >0 (the report number) on success . |
| 66 | 66 | */ |
| 67 | 67 | static int json_report_get_number(int argPos){ |
| 68 | 68 | int nReport = json_find_option_int("report",NULL,"r",-1); |
| 69 | + if( (nReport<=0) && cson_value_is_integer(g.json.reqPayload.v)){ | |
| 70 | + nReport = cson_value_get_integer(g.json.reqPayload.v); | |
| 71 | + } | |
| 69 | 72 | if( (nReport <= 0) && (argPos>0) ){ |
| 70 | 73 | char const * arg = json_command_arg(argPos); |
| 71 | 74 | if(arg && fossil_isdigit(*arg)) { |
| 72 | 75 | nReport = atoi(arg); |
| 73 | 76 | } |
| @@ -78,11 +81,44 @@ | ||
| 78 | 81 | static cson_value * json_report_create(){ |
| 79 | 82 | return NULL; |
| 80 | 83 | } |
| 81 | 84 | |
| 82 | 85 | static cson_value * json_report_get(){ |
| 83 | - return NULL; | |
| 86 | + int nReport; | |
| 87 | + Stmt q = empty_Stmt; | |
| 88 | + cson_value * pay = NULL; | |
| 89 | + | |
| 90 | + if(!g.perm.TktFmt){ | |
| 91 | + json_set_err(FSL_JSON_E_DENIED, | |
| 92 | + "Requires 't' privileges."); | |
| 93 | + return NULL; | |
| 94 | + } | |
| 95 | + nReport = json_report_get_number(3); | |
| 96 | + if(nReport <=0){ | |
| 97 | + json_set_err(FSL_JSON_E_MISSING_ARGS, | |
| 98 | + "Missing or invalid 'number' (-n) parameter."); | |
| 99 | + return NULL; | |
| 100 | + } | |
| 101 | + | |
| 102 | + db_prepare(&q,"SELECT rn AS rn," | |
| 103 | + " owner AS owner," | |
| 104 | + " title AS title," | |
| 105 | + " strftime('%%s',mtime) as mtime," | |
| 106 | + " cols as columns," | |
| 107 | + " sqlcode as sqlCode" | |
| 108 | + " FROM reportfmt" | |
| 109 | + " WHERE rn=%d", | |
| 110 | + nReport); | |
| 111 | + if( SQLITE_ROW != db_step(&q) ){ | |
| 112 | + db_finalize(&q); | |
| 113 | + json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND, | |
| 114 | + "Report #%d not found.", nReport); | |
| 115 | + return NULL; | |
| 116 | + } | |
| 117 | + pay = cson_sqlite3_row_to_object(q.pStmt); | |
| 118 | + db_finalize(&q); | |
| 119 | + return pay; | |
| 84 | 120 | } |
| 85 | 121 | |
| 86 | 122 | /* |
| 87 | 123 | ** Impl of /json/report/list. |
| 88 | 124 | */ |
| 89 | 125 |
| --- src/json_report.c | |
| +++ src/json_report.c | |
| @@ -64,10 +64,13 @@ | |
| 64 | ** |
| 65 | ** Returns >0 (the report number) on success . |
| 66 | */ |
| 67 | static int json_report_get_number(int argPos){ |
| 68 | int nReport = json_find_option_int("report",NULL,"r",-1); |
| 69 | if( (nReport <= 0) && (argPos>0) ){ |
| 70 | char const * arg = json_command_arg(argPos); |
| 71 | if(arg && fossil_isdigit(*arg)) { |
| 72 | nReport = atoi(arg); |
| 73 | } |
| @@ -78,11 +81,44 @@ | |
| 78 | static cson_value * json_report_create(){ |
| 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | static cson_value * json_report_get(){ |
| 83 | return NULL; |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | ** Impl of /json/report/list. |
| 88 | */ |
| 89 |
| --- src/json_report.c | |
| +++ src/json_report.c | |
| @@ -64,10 +64,13 @@ | |
| 64 | ** |
| 65 | ** Returns >0 (the report number) on success . |
| 66 | */ |
| 67 | static int json_report_get_number(int argPos){ |
| 68 | int nReport = json_find_option_int("report",NULL,"r",-1); |
| 69 | if( (nReport<=0) && cson_value_is_integer(g.json.reqPayload.v)){ |
| 70 | nReport = cson_value_get_integer(g.json.reqPayload.v); |
| 71 | } |
| 72 | if( (nReport <= 0) && (argPos>0) ){ |
| 73 | char const * arg = json_command_arg(argPos); |
| 74 | if(arg && fossil_isdigit(*arg)) { |
| 75 | nReport = atoi(arg); |
| 76 | } |
| @@ -78,11 +81,44 @@ | |
| 81 | static cson_value * json_report_create(){ |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | static cson_value * json_report_get(){ |
| 86 | int nReport; |
| 87 | Stmt q = empty_Stmt; |
| 88 | cson_value * pay = NULL; |
| 89 | |
| 90 | if(!g.perm.TktFmt){ |
| 91 | json_set_err(FSL_JSON_E_DENIED, |
| 92 | "Requires 't' privileges."); |
| 93 | return NULL; |
| 94 | } |
| 95 | nReport = json_report_get_number(3); |
| 96 | if(nReport <=0){ |
| 97 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 98 | "Missing or invalid 'number' (-n) parameter."); |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | db_prepare(&q,"SELECT rn AS rn," |
| 103 | " owner AS owner," |
| 104 | " title AS title," |
| 105 | " strftime('%%s',mtime) as mtime," |
| 106 | " cols as columns," |
| 107 | " sqlcode as sqlCode" |
| 108 | " FROM reportfmt" |
| 109 | " WHERE rn=%d", |
| 110 | nReport); |
| 111 | if( SQLITE_ROW != db_step(&q) ){ |
| 112 | db_finalize(&q); |
| 113 | json_set_err(FSL_JSON_E_RESOURCE_NOT_FOUND, |
| 114 | "Report #%d not found.", nReport); |
| 115 | return NULL; |
| 116 | } |
| 117 | pay = cson_sqlite3_row_to_object(q.pStmt); |
| 118 | db_finalize(&q); |
| 119 | return pay; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | ** Impl of /json/report/list. |
| 124 | */ |
| 125 |