Commit 720d75aa authored by Ivan Tyagov's avatar Ivan Tyagov

Merge branch 'GadgetCatalog'

parents 8650bed5 18958049
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -552,6 +552,89 @@ var RenderJs = (function () { ...@@ -552,6 +552,89 @@ var RenderJs = (function () {
}; };
}()), }()),
GadgetCatalog : (function () {
/*
* Gadget catalog provides API to get list of gadgets from a repository
*/
var cache_id = "setGadgetIndexUrlList";
function updateGadgetIndexFromURL(url) {
// split to base and document url
var url_list = url.split('/'),
document_url = url_list[url_list.length-1];
url_list.splice($.inArray(document_url, url_list), 1);
var base_url = url_list.join('/'),
web_dav = jIO.newJio({
"type": "dav",
"username": "",
"password": "",
"url": base_url});
web_dav.get(document_url,
function (err, response) {
RenderJs.Cache.set(url, response);
});
};
return {
updateGadgetIndex: function () {
/*
* Update gadget index from all configured remote repositories.
*/
$.each(RenderJs.GadgetCatalog.getGadgetIndexUrlList(),
function(index, value) {
updateGadgetIndexFromURL(value);
});
},
setGadgetIndexUrlList: function (url_list) {
/*
* Set list of Gadget Index repositories.
*/
// store in Cache (html5 storage)
RenderJs.Cache.set(cache_id, url_list)
},
getGadgetIndexUrlList: function () {
/*
* Get list of Gadget Index repositories.
*/
// get from Cache (html5 storage)
return RenderJs.Cache.get(cache_id, undefined)
},
getGadgetListThatProvide: function (service) {
/*
* Return list of all gadgets that providen a given service.
* Read this list from data structure created in HTML5 local
* storage by updateGadgetIndexFromURL
*/
// XXX: get from Cache stored index and itterate over it
// to find matching ones
var gadget_list = new Array();
$.each(RenderJs.GadgetCatalog.getGadgetIndexUrlList(),
function(index, url) {
// get repos from cache
var cached_repo = RenderJs.Cache.get(url);
$.each(cached_repo['gadget_list'],
function(index, gadget) {
if (jQuery.inArray(service, gadget["service_list"]) > -1) {
// gadget provides a service, add to list
gadget_list.push(gadget);
}
}
)
});
return gadget_list;
},
registerServiceList: function (gadget, service_list) {
/*
* Register a service provided by a gadget.
*/
},
};
}()),
InteractionGadget : (function () { InteractionGadget : (function () {
/* /*
* Basic gadget interaction gadget implementation. * Basic gadget interaction gadget implementation.
......
...@@ -3,11 +3,14 @@ require.config({ ...@@ -3,11 +3,14 @@ require.config({
paths: { paths: {
jquery: "lib/jquery/jquery", jquery: "lib/jquery/jquery",
"jquery.json": "lib/json/jquery.json.min", "jquery.json": "lib/json/jquery.json.min",
"davstorage": "lib/jio/davstorage",
"md5": "lib/jio/md5",
"jio": "lib/jio/jio",
renderjs: "renderjs" renderjs: "renderjs"
}, },
shim: { shim: {
"jquery.json": [ "jquery" ], "jquery.json": [ "jquery" ],
renderjs: [ "jquery", "jquery.json" ] renderjs: [ "jquery", "jquery.json", "md5", "jio", "davstorage"]
} }
}); });
......
{
"gadget_list":[ {"title": "HTML WYSIWYG",
"description": "A simple HTML editor",
"url": "http://example.com/html-editor.html",
"service_list": ["edit_html", "view_html"]},
{"title": "SVG WYSIWYG",
"description": "A simple SVG editor",
"url": "http://example.com/svg-editor.html",
"service_list": ["edit_svg", "view_svg"]}
]
}
\ No newline at end of file
...@@ -24,6 +24,14 @@ function parseJSONAndUpdateNameSpace(result) { ...@@ -24,6 +24,14 @@ function parseJSONAndUpdateNameSpace(result) {
last_name=result['last_name']; last_name=result['last_name'];
} }
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function setupRenderJSTest(){ function setupRenderJSTest(){
/* /*
* Main RenderJS test entry point * Main RenderJS test entry point
...@@ -164,5 +172,46 @@ function setupRenderJSTest(){ ...@@ -164,5 +172,46 @@ function setupRenderJSTest(){
}); });
}); });
module("GadgetCatalog");
test('GadgetCatalog', function () {
cleanUp();
// allow test to be run alone (i.e. url contains arguments)
var base_url = window.location.protocol + "//" + window.location.hostname + window.location.pathname;
// generate random argument to test always with new cache id
var url_list = new Array(base_url + '/gadget_index/gadget_index.json?t='+makeid());
RenderJs.GadgetCatalog.setGadgetIndexUrlList(url_list)
deepEqual(url_list, RenderJs.GadgetCatalog.getGadgetIndexUrlList());
RenderJs.GadgetCatalog.updateGadgetIndex();
stop();
// XXX: until we have a way to know that update which runs asynchronously is over
// we use hard coded timeouts.
setTimeout(function(){
start();
cached = RenderJs.Cache.get(url_list[0]);
equal("HTML WYSIWYG", cached["gadget_list"][0]["title"]);
deepEqual(["edit_html", "view_html"], cached["gadget_list"][0]["service_list"]);
// check that we can find gadgets that provide some service_list
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("view_html");
equal("HTML WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_html", "view_html"], gadget_list[0]["service_list"]);
gadget_list = RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_svg");
equal("SVG WYSIWYG", gadget_list[0]["title"]);
deepEqual(["edit_svg", "view_svg"], gadget_list[0]["service_list"]);
// no such service is provided by gadget repos
equal(0, RenderJs.GadgetCatalog.getGadgetListThatProvide("edit_html1"));
}, 1000)
});
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment