Commit a404e13f authored by Alexandra Rogova's avatar Alexandra Rogova

New model [test]

parent 131452c4
...@@ -5,7 +5,19 @@ ...@@ -5,7 +5,19 @@
rJS(window) rJS(window)
.ready(function(){ .ready(function(){
this.feeds = jIO.createJIO({
type : "indexeddb",
database : "mynij-v1.2"
});
this.search_storage = jIO.createJIO({ this.search_storage = jIO.createJIO({
type : "union",
storage_list : []
});
this.sub_storages = [];
/*this.search_storage = jIO.createJIO({
type : "query", type : "query",
sub_storage:{ sub_storage:{
type : "uuid", type : "uuid",
...@@ -14,14 +26,37 @@ ...@@ -14,14 +26,37 @@
database: "mynij-v1" database: "mynij-v1"
} }
} }
}); });*/
this.info = jIO.createJIO({ this.info = jIO.createJIO({
type : "indexeddb", type : "indexeddb",
database : "mynij-v1-info" 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); return this.search_storage.post.apply(this.search_storage, arguments);
}) })
......
...@@ -21,35 +21,47 @@ ...@@ -21,35 +21,47 @@
}) })
.declareMethod("read_file_new", function(link){ .declareMethod("read_file_new", function(link){
var gadget = this; var gadget = this,
return gadget.get_rss(link) xmlhttp = new XMLHttpRequest();
.push(function(result){
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4){
var rss, var rss,
title; title;
rss = result; rss = xmlhttp.responseText;
title = rss.slice(rss.indexOf("<title>")+7, rss.indexOf("</title>")); title = rss.slice(rss.indexOf("<title>")+7, rss.indexOf("</title>"));
return gadget.is_already_parsed(title) return gadget.is_already_parsed(title)
.push(function(is_parsed){ .push(function(is_parsed){
if (!is_parsed){ if (!is_parsed){
return gadget.remove_css(rss) return gadget.remove_css(rss)
.push(function(rss_without_css){ .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.open("GET", link, true);
xmlhttp.send(); 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, var gadget,
xmlhttp, xmlhttp,
cur_text, cur_text,
...@@ -94,22 +106,6 @@ ...@@ -94,22 +106,6 @@
"body": result "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)); }(window, RSVP, rJS, jIO));
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
promise_list = [], promise_list = [],
i; i;
for (i = 0; i < gadget.state.to_load.length; 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); 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