Fossil SCM

minor cleanups in the /json/wiki/get and AJAJ code.

stephan 2011-09-22 16:27 json
Commit a9c8a31df50ab273647c8d5f11e5f1837d9247d7
+3 -2
--- ajax/index.html
+++ ajax/index.html
@@ -125,17 +125,18 @@
125125
TheApp.sendRequest();
126126
}
127127
});
128128
129129
TheApp.cgi = new FossilAjaj();
130
- TheApp.timer = {_tstart:0,_tend:0,duration:0,
130
+ TheApp.timer = {
131
+ _tstart:0,_tend:0,duration:0,
131132
start:function(){
132133
this._tstart = (new Date()).getTime();
133134
},
134135
end:function(){
135136
this._tend = (new Date()).getTime();
136
- this.duration = this._tend - this._tstart;
137
+ return this.duration = this._tend - this._tstart;
137138
}
138139
};
139140
var opt = TheApp.cgi.ajaj.options;
140141
opt.beforeSend = function(req,opt) {
141142
TheApp.timer.start();
142143
--- ajax/index.html
+++ ajax/index.html
@@ -125,17 +125,18 @@
125 TheApp.sendRequest();
126 }
127 });
128
129 TheApp.cgi = new FossilAjaj();
130 TheApp.timer = {_tstart:0,_tend:0,duration:0,
 
131 start:function(){
132 this._tstart = (new Date()).getTime();
133 },
134 end:function(){
135 this._tend = (new Date()).getTime();
136 this.duration = this._tend - this._tstart;
137 }
138 };
139 var opt = TheApp.cgi.ajaj.options;
140 opt.beforeSend = function(req,opt) {
141 TheApp.timer.start();
142
--- ajax/index.html
+++ ajax/index.html
@@ -125,17 +125,18 @@
125 TheApp.sendRequest();
126 }
127 });
128
129 TheApp.cgi = new FossilAjaj();
130 TheApp.timer = {
131 _tstart:0,_tend:0,duration:0,
132 start:function(){
133 this._tstart = (new Date()).getTime();
134 },
135 end:function(){
136 this._tend = (new Date()).getTime();
137 return this.duration = this._tend - this._tstart;
138 }
139 };
140 var opt = TheApp.cgi.ajaj.options;
141 opt.beforeSend = function(req,opt) {
142 TheApp.timer.start();
143
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -994,15 +994,15 @@
994994
normalizeAjaxParameters() throws? It can throw if
995995
(de)JSON-izing fails.
996996
*/
997997
var norm = this.normalizeAjaxParameters( WhAjaj.isObject(opt) ? opt : {} );
998998
norm.url = WhAjaj.Connector.sendHelper.normalizeURL(norm);
999
+ if( ! request ) norm.method = 'GET';
9991000
if( WhAjaj.isFunction(norm.beforeSend) )
10001001
{
10011002
norm.beforeSend( request, norm );
10021003
}
1003
- if( ! request ) norm.method = 'GET';
10041004
//alert( WhAjaj.stringify(request)+'\n'+WhAjaj.stringify(norm));
10051005
try { this.sendImpl( request, norm ); }
10061006
catch(e) { ex = e; }
10071007
if(ex) throw ex;
10081008
};
10091009
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -994,15 +994,15 @@
994 normalizeAjaxParameters() throws? It can throw if
995 (de)JSON-izing fails.
996 */
997 var norm = this.normalizeAjaxParameters( WhAjaj.isObject(opt) ? opt : {} );
998 norm.url = WhAjaj.Connector.sendHelper.normalizeURL(norm);
 
999 if( WhAjaj.isFunction(norm.beforeSend) )
1000 {
1001 norm.beforeSend( request, norm );
1002 }
1003 if( ! request ) norm.method = 'GET';
1004 //alert( WhAjaj.stringify(request)+'\n'+WhAjaj.stringify(norm));
1005 try { this.sendImpl( request, norm ); }
1006 catch(e) { ex = e; }
1007 if(ex) throw ex;
1008 };
1009
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -994,15 +994,15 @@
994 normalizeAjaxParameters() throws? It can throw if
995 (de)JSON-izing fails.
996 */
997 var norm = this.normalizeAjaxParameters( WhAjaj.isObject(opt) ? opt : {} );
998 norm.url = WhAjaj.Connector.sendHelper.normalizeURL(norm);
999 if( ! request ) norm.method = 'GET';
1000 if( WhAjaj.isFunction(norm.beforeSend) )
1001 {
1002 norm.beforeSend( request, norm );
1003 }
 
1004 //alert( WhAjaj.stringify(request)+'\n'+WhAjaj.stringify(norm));
1005 try { this.sendImpl( request, norm ); }
1006 catch(e) { ex = e; }
1007 if(ex) throw ex;
1008 };
1009
+12 -8
--- src/json.c
+++ src/json.c
@@ -931,10 +931,21 @@
931931
}
932932
if( modulo ) code = code - (code % modulo);
933933
return code;
934934
}
935935
}
936
+
937
+/*
938
+** Convenience routine which converts a Julian time value into a Unix
939
+** Epoch timestamp. Requires the db, so this cannot be used before the
940
+** repo is opened (will trigger a fatal error in db_xxx()).
941
+*/
942
+static cson_value * json_julian_to_timestamp(double j){
943
+ return cson_value_new_integer((cson_int_t)
944
+ db_int64(0,"SELECT strftime('%%s',%lf)",j)
945
+ );
946
+}
936947
937948
/*
938949
** Creates a new Fossil/JSON response envelope skeleton. It is owned
939950
** by the caller, who must eventually free it using cson_value_free(),
940951
** or add it to a cson container to transfer ownership. Returns NULL
@@ -1567,18 +1578,11 @@
15671578
cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
15681579
/*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
15691580
;
15701581
cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
15711582
cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
1572
- cson_object_set(pay,"timestamp",
1573
- cson_value_new_integer((cson_int_t)
1574
- db_int64(0,
1575
- "SELECT strftime('%%s',%lf)",
1576
- pWiki->rDate
1577
- )
1578
- )
1579
- );
1583
+ cson_object_set(pay,"timestamp", json_julian_to_timestamp(pWiki->rDate));
15801584
cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
15811585
cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
15821586
cson_object_set(pay,"content",cson_value_new_string(zBody,len));
15831587
/*TODO: add 'T' (tag) fields*/
15841588
/*TODO: add the 'A' card (file attachment) entries?*/
15851589
--- src/json.c
+++ src/json.c
@@ -931,10 +931,21 @@
931 }
932 if( modulo ) code = code - (code % modulo);
933 return code;
934 }
935 }
 
 
 
 
 
 
 
 
 
 
 
936
937 /*
938 ** Creates a new Fossil/JSON response envelope skeleton. It is owned
939 ** by the caller, who must eventually free it using cson_value_free(),
940 ** or add it to a cson container to transfer ownership. Returns NULL
@@ -1567,18 +1578,11 @@
1567 cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
1568 /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
1569 ;
1570 cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
1571 cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
1572 cson_object_set(pay,"timestamp",
1573 cson_value_new_integer((cson_int_t)
1574 db_int64(0,
1575 "SELECT strftime('%%s',%lf)",
1576 pWiki->rDate
1577 )
1578 )
1579 );
1580 cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
1581 cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
1582 cson_object_set(pay,"content",cson_value_new_string(zBody,len));
1583 /*TODO: add 'T' (tag) fields*/
1584 /*TODO: add the 'A' card (file attachment) entries?*/
1585
--- src/json.c
+++ src/json.c
@@ -931,10 +931,21 @@
931 }
932 if( modulo ) code = code - (code % modulo);
933 return code;
934 }
935 }
936
937 /*
938 ** Convenience routine which converts a Julian time value into a Unix
939 ** Epoch timestamp. Requires the db, so this cannot be used before the
940 ** repo is opened (will trigger a fatal error in db_xxx()).
941 */
942 static cson_value * json_julian_to_timestamp(double j){
943 return cson_value_new_integer((cson_int_t)
944 db_int64(0,"SELECT strftime('%%s',%lf)",j)
945 );
946 }
947
948 /*
949 ** Creates a new Fossil/JSON response envelope skeleton. It is owned
950 ** by the caller, who must eventually free it using cson_value_free(),
951 ** or add it to a cson container to transfer ownership. Returns NULL
@@ -1567,18 +1578,11 @@
1578 cson_object_set(pay,"version",json_new_string(pWiki->zBaseline))
1579 /*FIXME: pWiki->zBaseline is NULL. How to get the version number?*/
1580 ;
1581 cson_object_set(pay,"rid",cson_value_new_integer((cson_int_t)rid));
1582 cson_object_set(pay,"lastSavedBy",json_new_string(pWiki->zUser));
1583 cson_object_set(pay,"timestamp", json_julian_to_timestamp(pWiki->rDate));
 
 
 
 
 
 
 
1584 cson_object_set(pay,"contentLength",cson_value_new_integer((cson_int_t)len));
1585 cson_object_set(pay,"contentFormat",json_new_string(doParse?"html":"raw"));
1586 cson_object_set(pay,"content",cson_value_new_string(zBody,len));
1587 /*TODO: add 'T' (tag) fields*/
1588 /*TODO: add the 'A' card (file attachment) entries?*/
1589

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button