Commit 4f5d5b13 authored by Alexandra Rogova's avatar Alexandra Rogova

new model start

parent 387a207a
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function (window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.ready(function(){
var gadget = this;
this.my_indexes = [];
var index_storage = jIO.createJIO({
type :"indexeddb",
database :"my_indexes"
});
return index_storage.allDocs()
.push(function(result){
var i,
promise_list = [];
for (i=0; i<result.length; i+=1){ //CHECK THIS
promise_list.push(index_storage.get(result[i].id));
}
return RSVP.all(promise_list);
})
.push(function(result){
var i,
promise_list = [];
for (i=0; i<result.length; i+=1){
promise_list.push(gadget._load_index(result[i]));
}
return RSVP.all(promise_list);
});
})
.declareMethod("_load_index", function(to_load){ /*!!! DOES NOT WORK CHECK WHAT index_storage.get(index_id) RETURNS !!!*/
/*var raw_index,
index,
index_storage,
gadget = this;*/
/*index_storage = jIO.createJIO({
type :"indexeddb",
database :"my_indexes"
});*/
/*return index_storage.get(index_id)
.push(function(result){*/
var raw_index,
index,
key,
doc;
index = elasticlunr(function () {
this.use(elasticlunr.fr);
this.addField('title');
this.addField('body');
this.addField('link');
this.setRef('id'); //id = index.x."/a/b" where index = index name, x = substorage id, "/a/b" = item id in x
});
raw_index = JSON.parse(to_load);
for (key in raw_index.documentStore.docs){
doc = {
"id" : raw_index.documentStore.docs[key].id,
"title" : raw_index.documentStore.docs[key].title,
"body" : raw_index.documentStore.docs[key].body,
"link" : raw_index.documentStore.docs[key].link
};
index.addDoc(doc);
}
this.my_indexes.push({
name : "" , // get name,
index : index
});
//});
})
.declareMethod("add_rss", function(index_name, link){
//WIP needs proxy
})
.declareMethod("remove_rss", function(index_name, something){
//WIP needs working brain
})
.declareMethod("_get_index", function(index_name){
var i;
for (i=0; i<this.my_indexes; i+=1){
if (this.my_indexes[i].name === index_name) return this.my_indexes[i];
}
return null;
})
.declareMethod("search", function(index_name, key){
return this._get_index(index_name)
.push(function(result){
if (result === null) return [];
else return result.search(key);
});
})
.declareMethod("my_indexes", function(){
index_storage = jIO.createJIO({
type :"indexeddb",
database :"my_indexes"
});
return index_storage.allDocs()
.push(function(result){
var i,
promise_list = [];
for (i = 0; i<result.data.rows.length; i+=1){
promise_list.push(index_storage.get(result.data.rows[i].id));
}
return promise_list;
})
.push(function(result){
var i,
info = [];
for (i=0; i< result.data.rows.length; i+=1){ //CHECK
info.push(result.data.rows[i]);
}
return info;
});
})
.declareMethod("download_index", function(index_id){
var gadget = this;
return this.getDeclaredGadget("server")
.push(function(server){
return server.get(index_id);
})
.push(function(result){
return gadget._load_index(result);
});
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function (window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.delcareMethod("get_all_available_indexes", function(){
var all_indexes = jIO.createJIO({
type : "indexeddb",
database : "all_indexes"
});
return all_indexes.allDocs()
.push(function(result){
var i,
promise_list = [];
for (i = 0; i<result.data.rows.length; i+=1){
promise_list.push(all_indexes.get(result.data.rows[i].id));
}
return promise_list;
})
.push(function(result){
var i,
info = [];
for (i=0; i< result.data.rows.length; i+=1){ //CHECK
info.push(result.data.rows[i]);
}
return info;
});
})
.declareMethod("get", function(index_id){
var all_indexes = jIO.createJIO({
type : "indexeddb",
database : "all_indexes"
});
return all_indexes.get(index_id);
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
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