- Timestamp:
- 12/04/12 16:29:49 (12 years ago)
- Location:
- Dev/branches/rest-dojo-ui/server
- Files:
-
- 2 added
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
Dev/branches/rest-dojo-ui/server/couchdb-admin/config/config.js
r414 r415 2 2 'dojo/_base/json', 3 3 'dojo/_base/lang', 4 'dojo/Deferred',5 'dojo/request',6 4 'dojox/lang/functional', 7 './docs' 8 ],function(json,lang,Deferred,request,func,docs){ 9 var dbUrl = "http://localhost:5984/"; 5 './util/async', 6 './util/db', 7 './data/design-docs' 8 ],function(json,lang,func,async,db,docs){ 10 9 11 10 function serializeFunctions(value) { … … 23 22 } 24 23 25 function req(method,path,body) { 26 var args = { 27 contentType: 'application/json', 28 handleAs: 'json', 29 data: json.toJson(body || {}) 30 }; 31 return request[method](dbUrl+path,args); 32 } 33 34 function asyncSeq(functions) { 35 var d = new Deferred(); 36 (function stepper(fs,arg) { 37 if ( fs.length > 0 ) { 38 try { 39 var f = fs.shift(); 40 var ret = f(arg); 41 if ( ret && ret.then ) { 42 ret.then(function(ret){ 43 stepper(fs,ret); 44 }); 45 } else { 46 stepper(fs,ret); 47 } 48 } catch(err) { 49 d.reject(err); 50 } 51 } else { 52 d.resolve(); 53 } 54 })(functions); 55 return d.promise; 56 } 57 58 function asyncFor(list,callback,ctx) { 59 var d = new Deferred(); 60 (function stepper(list,idx){ 61 if ( list.length > 0 ) { 62 var el = list.shift(); 63 var ret = callback.call(ctx,el,idx); 64 if ( ret && ret.then ) { 65 ret.then(function(){ 66 stepper(list,idx+1); 67 }); 68 } else { 69 stepper(list,idx+1); 70 } 71 } else { 72 d.resolve(); 73 } 74 })(list,0); 75 return d.promise; 76 } 77 78 asyncSeq([ 24 async.seq([ 79 25 function(){ 80 console.log("Configuring CouchDB for RFT:");26 console.log("Configuring CouchDB for QED:"); 81 27 }, 82 28 function(){ 83 29 console.log("Checking CouchDB version"); 84 return req('get','')30 return db.req('get','') 85 31 .then(function(res){ 86 32 if (res.version !== "1.2.0" ) { … … 92 38 },function(){ 93 39 console.log("Checking database 'qed'"); 94 return req('get','qed')40 return db.req('get','qed') 95 41 .then(function(res){ 96 42 if (res.error) { 97 43 console.log("Creating database 'qed'"); 98 return req('put','/qed');44 return db.req('put','/qed'); 99 45 } else { 100 46 console.log("Database 'qed' found."); … … 102 48 },function(res){ 103 49 console.log("Creating database 'qed'"); 104 return req('put','/qed');50 return db.req('put','/qed'); 105 51 }); 106 52 },function(){ … … 108 54 },function(docs){ 109 55 console.log("Putting documents in database."); 110 return async For(func.keys(docs),function(docUrl){56 return async.forEach(func.keys(docs),function(docUrl){ 111 57 var doc = docs[docUrl]; 112 58 var configAction = doc.__configAction; … … 117 63 case "update": 118 64 console.log(docUrl+" updating."); 119 return req('get',docUrl)65 return db.req('get',docUrl) 120 66 .then(function(oldDoc){ 121 67 lang.mixin(oldDoc,doc); 122 return req('put',docUrl,oldDoc);68 return db.req('put',docUrl,oldDoc); 123 69 },function(){ 124 return req('put',docUrl,doc);70 return db.req('put',docUrl,doc); 125 71 }); 126 72 case "replace": 127 73 default: 128 74 console.log(docUrl+" replacing."); 129 return req('get',docUrl)75 return db.req('get',docUrl) 130 76 .then(function(oldDoc){ 131 77 doc['_rev'] = oldDoc['_rev']; 132 return req('put',docUrl,doc);78 return db.req('put',docUrl,doc); 133 79 },function(){ 134 return req('put',docUrl,doc);80 return db.req('put',docUrl,doc); 135 81 }); 136 82 }
Note: See TracChangeset
for help on using the changeset viewer.