Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
datastore: implementation of auto updating dojo store
using websocket+rest api. master test is now passing, we can detect active to inactive state. also cleanup the tabs from the js. Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>t
- Loading branch information
Pierre Tardy
committed
Dec 4, 2012
1 parent
7006097
commit ca1fe0e
Showing
26 changed files
with
971 additions
and
772 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// This file is part of Buildbot. Buildbot is free software: you can | ||
// redistribute it and/or modify it under the terms of the GNU General Public | ||
// License as published by the Free Software Foundation, version 2. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
// details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program; if not, write to the Free Software Foundation, Inc., 51 | ||
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
// | ||
// Copyright Buildbot Team Members | ||
|
||
/* Generic store serving the list style data APIs of buildbot | ||
Serves as a translation of api between rest+websocket, and dojo's store/query/paging/notification | ||
api described in: | ||
dojo/store/api/Store.js | ||
*/ | ||
define(["dojo/_base/declare", "dojo/_base/lang", | ||
"bb/jsonapi", | ||
"bb/websocket", | ||
"dojo/store/Observable", | ||
"dojo/store/Memory", | ||
"dojo/store/JsonRest", | ||
"dojo/store/Cache", | ||
"dojo/aspect" | ||
|
||
], | ||
function(declare, lang, api, websocket, observable, Memory, JsonRest, Cache, aspect) { | ||
var after = aspect.after; | ||
function createStore(args) { | ||
var memoryStore = new Memory(lang.delegate({},args)); | ||
var restStore = new JsonRest(lang.delegate({sortParam:"sort",target: api.APIv2URL(args.path)+"/"},args)); | ||
var store = observable(new Cache(restStore, memoryStore)); | ||
store._num_listeners = 0; | ||
after(store,"query", function(results) { | ||
/* hook query, in order to register web socket events | ||
if somebody is observing the results */ | ||
after(results,"observe", function(handler) { | ||
store._num_listeners +=1; | ||
if (store._num_listeners === 1) { | ||
store.websocket_listener = websocket.on(args.path, function(event) { | ||
var id = event.message[store.idProperty]; | ||
var o = event.message; | ||
console.log(event); | ||
if (memoryStore.index.hasOwnProperty(id)) { | ||
/* reconstruct object from the cache */ | ||
var no = lang.clone(memoryStore.get(id)); | ||
for (var k in o) { | ||
if (o.hasOwnProperty(k)){ | ||
no[k] = o[k]; | ||
} | ||
} | ||
o = no; | ||
} else if (event.key.length===3 && event.key[2] === "new"){ | ||
/* we dont do store access if this is a new item, | ||
the message is already containing full item, | ||
just cache it. | ||
*/ | ||
memoryStore.put(o); | ||
} else { | ||
o = store.get(id); | ||
} | ||
dojo.when(o, function(o) { | ||
store.notify(o, id); | ||
}); | ||
}); | ||
} | ||
after(handler,"remove", function(x) { | ||
store._num_listeners -=1; | ||
if (store._num_listeners === 0) { | ||
store.websocket_listener.remove(); | ||
} | ||
return x; | ||
}); | ||
return handler; | ||
}); | ||
return results; | ||
}); | ||
return store; | ||
} | ||
var datastore = { | ||
change: createStore({path:["change"],idProperty:"changeid"}), | ||
master: createStore({path:["master"],idProperty:"masterid"}), | ||
buildsets: createStore({path:["buildsets"]}), | ||
builders: createStore({path:["builders"]}) | ||
}; | ||
window.bb.datastore = datastore; /* for console debug */ | ||
return datastore; | ||
} | ||
); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,65 @@ | ||
// This file is part of Buildbot. Buildbot is free software: you can | ||
// redistribute it and/or modify it under the terms of the GNU General Public | ||
// License as published by the Free Software Foundation, version 2. | ||
// | ||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
// details. | ||
// | ||
// You should have received a copy of the GNU General Public License along with | ||
// this program; if not, write to the Free Software Foundation, Inc., 51 | ||
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
// | ||
// Copyright Buildbot Team Members | ||
|
||
|
||
/* utilities, and code related to direct access to the api | ||
deferred based! | ||
*/ | ||
define(["dojo/_base/declare", "dojo/_base/Deferred", "dojo/request/xhr","dojo/json"], | ||
function(declare, Deferred, xhr, json){ | ||
var api_url = dojo.baseUrl + "/../../../../api/"; | ||
var jsonrpc_curid = 0; | ||
return { | ||
createAPIPath: function(a) { | ||
var path=[]; | ||
for (var i = 0;i<a.length; i+=1) { | ||
path.push(a[i]); | ||
} | ||
path = path.join("/"); | ||
console.log(path, a); | ||
return path; | ||
}, | ||
getApiV1: function() { | ||
return xhr(api_url+"v1/"+this.createAPIPath(arguments), | ||
{handleAs:"json"}); | ||
}, | ||
getApiV2: function() { | ||
return xhr(api_url+"v2/"+this.createAPIPath(arguments), | ||
{handleAs:"json"}); | ||
}, | ||
control: function(path, method, args) { | ||
jsonrpc_curid+=1; | ||
return xhr(api_url+"v2/"+this.createAPIPath(path), | ||
{handleAs:"json",method:"POST", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
data:json.stringify({jsonrpc:"2.0", | ||
method:method, | ||
params:args, | ||
id:jsonrpc_curid}) | ||
} | ||
); | ||
} | ||
}; // note the singleton.. | ||
define(["dojo/_base/declare", "dojo/_base/Deferred", "dojo/request/xhr","dojo/json", | ||
"dojo/_base/lang"], | ||
function(declare, Deferred, xhr, json, lang){ | ||
var api_url = dojo.baseUrl + "/../../../../api/"; | ||
var jsonrpc_curid = 0; | ||
return { | ||
createAPIPath: function(a) { | ||
var path=[]; | ||
for (var i = 0;i<a.length; i+=1) { | ||
path.push(a[i]); | ||
} | ||
path = path.join("/"); | ||
return path; | ||
}, | ||
APIv2URL: function(path) { | ||
return api_url+"v2/"+this.createAPIPath(path); | ||
}, | ||
getApiV1: function() { | ||
return xhr(api_url+"v1/"+this.createAPIPath(arguments), | ||
{handleAs:"json"}); | ||
}, | ||
getApiV2: function() { | ||
return xhr(this.APIv2URL(arguments), | ||
{handleAs:"json"}); | ||
}, | ||
get: function(path, args, xhrargs) { | ||
xhrargs = lang.mixin({handleAs:"json"}, xhrargs); | ||
return xhr(this.APIv2URL(path), | ||
xhrargs); | ||
}, | ||
control: function(path, method, args) { | ||
jsonrpc_curid+=1; | ||
return xhr(api_url+"v2/"+this.createAPIPath(path), | ||
{handleAs:"json",method:"POST", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
data:json.stringify({jsonrpc:"2.0", | ||
method:method, | ||
params:args, | ||
id:jsonrpc_curid}) | ||
} | ||
); | ||
} | ||
}; // note the singleton.. | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.