Commit a404e13f authored by Alexandra Rogova's avatar Alexandra Rogova

New model [test]

parent 131452c4
......@@ -5,7 +5,19 @@
rJS(window)
.ready(function(){
this.feeds = jIO.createJIO({
type : "indexeddb",
database : "mynij-v1.2"
});
this.search_storage = jIO.createJIO({
type : "union",
storage_list : []
});
this.sub_storages = [];
/*this.search_storage = jIO.createJIO({
type : "query",
sub_storage:{
type : "uuid",
......@@ -14,14 +26,37 @@
database: "mynij-v1"
}
}
});
});*/
this.info = jIO.createJIO({
type : "indexeddb",
database : "mynij-v1-info"
});
return this.feeds.put("feeds_doc", {});
})
.declareMethod ("add_attachment", function (title, rss){
return this.feeds.putAttachment("feeds_doc", title, new Blob([rss], {type : "text/xml"}))
.push(function (){
this.sub_storages.push({
type : "my_parser",
document_id : "feeds_doc",
attachment_id : title,
parser : "rss",
sub_storage : {
type : "indexeddb",
database : "mynij-v1.2"
}
});
this.search_storage = jIO.createJIO({
type : "union",
storage_list : this.sub_storages
});
});
})
.declareMethod("put", function () {
.declareMethod("put", function () { // deprecated
return this.search_storage.post.apply(this.search_storage, arguments);
})
......
......@@ -21,35 +21,47 @@
})
.declareMethod("read_file_new", function(link){
var gadget = this;
return gadget.get_rss(link)
.push(function(result){
var gadget = this,
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4){
var rss,
title;
rss = result;
rss = xmlhttp.responseText;
title = rss.slice(rss.indexOf("<title>")+7, rss.indexOf("</title>"));
return gadget.is_already_parsed(title)
.push(function(is_parsed){
if (!is_parsed){
return gadget.remove_css(rss)
.push(function(rss_without_css){
return gadget.state.storage.put(rss_without_css);
return gadget.state.storage.add_attachment(title, rss_without_css);
});
}
});
});
})
.declareMethod("get_rss", function(link){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4) return xmlhttp.responseText;
}
}
xmlhttp.open("GET", link, true);
xmlhttp.send();
})
.declareMethod("read_file", function(link) {
.declareMethod("remove_css", function(body){
var regEx = new RegExp('(style="(.*?)"|style=&quot(.*?)&quot)', 'gi');
return body.replace(regEx, "");
})
.declareMethod("is_already_parsed", function(title){
return this.state.storage.all_loaded_docs()
.push(function (result){
var i;
for (i = 0; i<result.data.rows.length; i+=1){
if (result.data.rows[i].id === title) return true;
}
return false;
});
});
/*.declareMethod("read_file", function(link) {
var gadget,
xmlhttp,
cur_text,
......@@ -94,22 +106,6 @@
"body": result
});
});
})
.declareMethod("remove_css", function(body){
var regEx = new RegExp('(style="(.*?)"|style=&quot(.*?)&quot)', 'gi');
return body.replace(regEx, "");
})
.declareMethod("is_already_parsed", function(title){
return this.state.storage.all_loaded_docs()
.push(function (result){
var i;
for (i = 0; i<result.data.rows.length; i+=1){
if (result.data.rows[i].id === title) return true;
}
return false;
});
});
})*/
}(window, RSVP, rJS, jIO));
......@@ -60,7 +60,7 @@
promise_list = [],
i;
for (i = 0; i < gadget.state.to_load.length; i++){
promise_list.push(gadget.state.parser_gadget.read_file("./test-files/" + gadget.state.to_load[i]));
promise_list.push(gadget.state.parser_gadget.read_file_new("./test-files/" + gadget.state.to_load[i]));
}
RSVP.all(promise_list);
})
......
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