Fossil

Check-in [98e24465]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added showFiles=bool/--show-files option to /json/timeline/ci.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1:98e24465c2f3c9898e894d9286e6a38380272966
User & Date: stephan 2011-09-27 03:25:15
Context
2011-09-27
03:28
Added /json/timeline/ci showFiles to ajax test page. check-in: be700e84 user: stephan tags: json
03:25
Added showFiles=bool/--show-files option to /json/timeline/ci. check-in: 98e24465 user: stephan tags: json
02:09
Changed /json/stat to use brief mode by default due to relatively high runtime cost, replaced 'brief' param with 'full'. Added json_getenv_bool(). check-in: c1914eaa user: stephan tags: json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json_timeline.c.

190
191
192
193
194
195
196


















































197
198
199
200
201
202
203
204
205
206
207
208
209

210
211
212
213
214
215





216
217
218
219
220
221
222
...
230
231
232
233
234
235
236

237

238
239
240
241
242
243
244


245

246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
...
285
286
287
288
289
290
291






292
293
294
295
296
297
298
...
336
337
338
339
340
341
342

343

344
345
346
347
348
349
350
...
423
424
425
426
427
428
429

430

431
432
433
434
435
436
437
    blob_appendf(pSql,"LIMIT %d ",limit);
  }
  if(pPayload){
    cson_object_set(pPayload, "limit",cson_value_new_integer(limit));
  }

}


















































/*
** Implementation of /json/timeline/ci.
**
** Still a few TODOs (like figuring out how to structure
** inheritance info).
*/
static cson_value * json_timeline_ci(){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  cson_value * tmp = NULL;
  cson_value * listV = NULL;
  cson_array * list = NULL;
  int check = 0;

  Stmt q;
  Blob sql = empty_blob;
  if( !g.perm.Read/* && !g.perm.RdTkt && !g.perm.RdWiki*/ ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }





  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);
  json_timeline_setup_sql( "ci", &sql, pay );
#define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \
    g.json.resultCode = (cson_rc.AllocError==check) \
      ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \
    goto error;\
................................................................................
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT "
              " rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"

              " timestampString AS timestampString,"

              " comment AS comment, "
              " user AS user,"
              " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */
              " bgColor AS bgColor," /* why always null? */
              " eventType AS eventType,"
              " tags AS tags," /*FIXME: split this into
                                 a JSON array*/


              " tagId AS tagId"

              " FROM json_timeline"
              " ORDER BY sortId",
              -1);
  db_prepare(&q,blob_buffer(&sql));
  blob_reset(&sql);
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  tmp = listV;
  SET("timeline");
  while( (SQLITE_ROW == db_step(&q) )){
    /* convert each row into a JSON object...*/

    cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt);
    cson_object * row = cson_value_get_object(rowV);
    cson_string const * tagsStr = NULL;
    if(!row){
      json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED,
                 "Could not convert at least one timeline result row to JSON." );
      continue;
................................................................................
    tmp = cson_object_get(row,"isLeaf");
    if(tmp && cson_value_is_integer(tmp)){
      cson_object_set(row,"isLeaf",
                      cson_value_get_integer(tmp)
                      ? cson_value_true()
                      : cson_value_false());
      tmp = NULL;






    }
  }
  db_finalize(&q);
#undef SET
  goto ok;
  error:
  assert( 0 != g.json.resultCode );
................................................................................
  SET("timelineSql");
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"

              " timestampString AS timestampString,"

              " comment AS comment, "
              " user AS user,"
              " eventType AS eventType"
#if 0
              /* can wiki pages have tags? */
              " tags AS tags," /*FIXME: split this into
                                 a JSON array*/
................................................................................
  SET("timelineSql");
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"

              " timestampString AS timestampString,"

              " user AS user,"
              " eventType AS eventType,"
              " comment AS comment,"
              " brief AS briefComment"
              " FROM json_timeline"
              " ORDER BY sortId",
              -1);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













>






>
>
>
>
>







 







>

>





|

>
>

>











>







 







>
>
>
>
>
>







 







>

>







 







>

>







190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
...
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    blob_appendf(pSql,"LIMIT %d ",limit);
  }
  if(pPayload){
    cson_object_set(pPayload, "limit",cson_value_new_integer(limit));
  }

}

static cson_value * json_timeline_get_changed_files(int rid){
  cson_value * rowsV = NULL;
  cson_array * rows = NULL;
  Stmt q;
  db_prepare(&q, 
#if 0
             "SELECT (mlink.pid==0) AS isNew,"
             "       (mlink.fid==0) AS isDel,"
             "       filename.name AS name"
             " FROM mlink, filename"
             " WHERE mid=%d"
             " AND pid!=fid"
             " AND filename.fnid=mlink.fnid"
             " ORDER BY 3 /*sort*/",
#else
           "SELECT (pid==0) AS isnew,"
           "       (fid==0) AS isdel,"
           "       (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
           "       (SELECT uuid FROM blob WHERE rid=fid),"
           "       (SELECT uuid FROM blob WHERE rid=pid)"
           "  FROM mlink"
           " WHERE mid=%d AND pid!=fid"
           " ORDER BY 3 /*sort*/",
#endif
             rid
             );
  while( (SQLITE_ROW == db_step(&q)) ){
    cson_value * rowV = cson_value_new_object();
    cson_object * row = cson_value_get_object(rowV);
    int const isNew = db_column_int(&q,0);
    int const isDel = db_column_int(&q,1);
    if(!rowsV){
      rowsV = cson_value_new_array();
      rows = cson_value_get_array(rowsV);
    }
    cson_object_set(row, "name", json_new_string(db_column_text(&q,2)));
    cson_object_set(row, "uuid", json_new_string(db_column_text(&q,3)));
    cson_object_set(row, "prevUuid", json_new_string(db_column_text(&q,4)));
    cson_object_set(row, "state",
                    json_new_string(isNew
                                    ? "added"
                                    : (isDel
                                       ? "removed"
                                       : "modified")));
    cson_array_append( rows, rowV );
  }
  db_finalize(&q);
  return rowsV;
}
/*
** Implementation of /json/timeline/ci.
**
** Still a few TODOs (like figuring out how to structure
** inheritance info).
*/
static cson_value * json_timeline_ci(){
  cson_value * payV = NULL;
  cson_object * pay = NULL;
  cson_value * tmp = NULL;
  cson_value * listV = NULL;
  cson_array * list = NULL;
  int check = 0;
  int showFiles = 0;
  Stmt q;
  Blob sql = empty_blob;
  if( !g.perm.Read/* && !g.perm.RdTkt && !g.perm.RdWiki*/ ){
    g.json.resultCode = FSL_JSON_E_DENIED;
    return NULL;
  }
  if( g.isHTTP ){
    showFiles = json_getenv_bool("showFiles",0);
  }else{
    showFiles = 0!=find_option("show-files", "f",0);
  }
  payV = cson_value_new_object();
  pay = cson_value_get_object(payV);
  json_timeline_setup_sql( "ci", &sql, pay );
#define SET(K) if(0!=(check=cson_object_set(pay,K,tmp))){ \
    g.json.resultCode = (cson_rc.AllocError==check) \
      ? FSL_JSON_E_ALLOC : FSL_JSON_E_UNKNOWN; \
    goto error;\
................................................................................
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT "
              " rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"
#if 0
              " timestampString AS timestampString,"
#endif
              " comment AS comment, "
              " user AS user,"
              " isLeaf AS isLeaf," /*FIXME: convert to JSON bool */
              " bgColor AS bgColor," /* why always null? */
              " eventType AS eventType,"
              " tags AS tags" /*FIXME: split this into
                                 a JSON array*/
#if 0
              /*tagId is always null?*/
              " tagId AS tagId"
#endif
              " FROM json_timeline"
              " ORDER BY sortId",
              -1);
  db_prepare(&q,blob_buffer(&sql));
  blob_reset(&sql);
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  tmp = listV;
  SET("timeline");
  while( (SQLITE_ROW == db_step(&q) )){
    /* convert each row into a JSON object...*/
    int const rid = db_column_int(&q,0);
    cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt);
    cson_object * row = cson_value_get_object(rowV);
    cson_string const * tagsStr = NULL;
    if(!row){
      json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED,
                 "Could not convert at least one timeline result row to JSON." );
      continue;
................................................................................
    tmp = cson_object_get(row,"isLeaf");
    if(tmp && cson_value_is_integer(tmp)){
      cson_object_set(row,"isLeaf",
                      cson_value_get_integer(tmp)
                      ? cson_value_true()
                      : cson_value_false());
      tmp = NULL;
    }
    if( showFiles ){
      cson_value * flist = json_timeline_get_changed_files(rid);
      if(flist){
        cson_object_set(row,"files",flist);
      }
    }
  }
  db_finalize(&q);
#undef SET
  goto ok;
  error:
  assert( 0 != g.json.resultCode );
................................................................................
  SET("timelineSql");
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"
#if 0
              " timestampString AS timestampString,"
#endif
              " comment AS comment, "
              " user AS user,"
              " eventType AS eventType"
#if 0
              /* can wiki pages have tags? */
              " tags AS tags," /*FIXME: split this into
                                 a JSON array*/
................................................................................
  SET("timelineSql");
#endif

  blob_reset(&sql);
  blob_append(&sql, "SELECT rid AS rid,"
              " uuid AS uuid,"
              " mtime AS timestamp,"
#if 0
              " timestampString AS timestampString,"
#endif
              " user AS user,"
              " eventType AS eventType,"
              " comment AS comment,"
              " brief AS briefComment"
              " FROM json_timeline"
              " ORDER BY sortId",
              -1);