Commit a404e13f authored by Alexandra Rogova's avatar Alexandra Rogova

New model [test]

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