Commit a404e13f authored by Alexandra Rogova's avatar Alexandra Rogova

New model [test]

parent 131452c4
...@@ -3,41 +3,76 @@ ...@@ -3,41 +3,76 @@
(function (window, RSVP, rJS, jIO) { (function (window, RSVP, rJS, jIO) {
"use strict"; "use strict";
rJS(window) rJS(window)
.ready(function(){ .ready(function(){
this.search_storage = jIO.createJIO({ 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", type : "query",
sub_storage:{ sub_storage:{
type : "uuid", type : "uuid",
sub_storage : { sub_storage : {
type: "indexeddb", type: "indexeddb",
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);
}) })
.declareMethod("get", function () { .declareMethod("get", function () {
return this.search_storage.get.apply(this.search_storage, arguments); return this.search_storage.get.apply(this.search_storage, arguments);
}) })
.declareMethod("search", function() { .declareMethod("search", function() {
return this.search_storage.allDocs.apply(this.search_storage, arguments) return this.search_storage.allDocs.apply(this.search_storage, arguments)
}) })
.declareMethod("loaded_doc", function(){ .declareMethod("loaded_doc", function(){
return this.info.put.apply(this.info, arguments); return this.info.put.apply(this.info, arguments);
}) })
.declareMethod("all_loaded_docs", function(){ .declareMethod("all_loaded_docs", function(){
return this.info.allDocs.apply(this.info, arguments); return this.info.allDocs.apply(this.info, arguments);
}); });
}(window, RSVP, rJS, jIO)); }(window, RSVP, rJS, jIO));
\ No newline at end of file
...@@ -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);
}) })
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
var i, var i,
id, id,
promise_list = []; promise_list = [];
for (i = 0; i < result.data.rows.length; i+=1){ for (i = 0; i < result.data.rows.length; i+=1){
id = result.data.rows[i].id; id = result.data.rows[i].id;
promise_list.push(gadget.state.model_gadget.get(id)); promise_list.push(gadget.state.model_gadget.get(id));
......
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