Commit d89b0fc9 authored by Alexandra Rogova's avatar Alexandra Rogova

first commit

parent 2646f9aa
......@@ -45,6 +45,19 @@ input{
padding: 0 20px;
}
input[type="button"]{
width: 8em;
height: 2em;
position: relative;
border-radius: 3px;
}
input[type="button"]:hover{
cursor: pointer;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
transition:all 200ms ease-out;
}
::-webkit-scrollbar {
display: none;
}
......@@ -97,3 +110,11 @@ input{
padding-bottom:0.2%;
}
.showbox {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 5%;
}
flexsearch @ 38e457cb
Subproject commit 38e457cb1b48abad1f91dc3332bc528e3e97cb76
jio @ b08e246c
Subproject commit b08e246c91d99293f685c85e990174f204964ca4
msgpack-lite @ 5b71d82c
Subproject commit 5b71d82cad4b96289a466a6403d2faaa3e254167
renderjs @ c04e9c65
Subproject commit c04e9c65bc354f3ea43ce55afaa427f56fd9bae4
<!doctype html>
<html>
<head>
<title>Model Gadget</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="./elasticlunr/elasticlunr.js"></script>
<script src="./lunr-languages/lunr.stemmer.support.js"></script>
<script src="./lunr-languages/lunr.fr.js"></script>
<script src="gadget_client_model.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function (window, document, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.declareAcquiredMethod("get_server_model", "get_server_model")
.setState({
my_docs : null,
my_indexes : null,
indexes : null
})
.ready(function(){
var my_docs = jIO.createJIO({
type : "indexeddb",
database : "mynij.my_docs"
}),
my_indexes = jIO.createJIO({
type : "indexeddb",
database : "mynij.my_indexes"
});
this.changeState({
my_docs : my_docs,
my_indexes : my_indexes,
indexes : []
});
})
.onStateChange(function (modification_dict){
if (this.state.indexes.length === 0) return this._load_my_indexes();
})
.declareMethod("search_in_index", function(index_name, key){
if (this.state.indexes.length === 0) return null;
return this.get_right_index(index_name)
.push(function(result_index){
if (result_index === null) return null;
return result_index.search(key);
});
})
.declareMethod("get_right_index", function(index_name){
var i;
for (i=0; i<this.state.indexes.length; i+=1){
if (this.state.indexes[i].name === index_name) return this.state.indexes[i].index;
}
return null;
})
.declareMethod("search_in_all", function(key){
// TODO later
})
.declareMethod("_load_my_indexes", function(){
var gadget = this,
index_names;
return gadget.state.my_indexes.allDocs()
.push(function(index_ids){
var i,
promise_list = [];
index_names = index_ids;
for (i=0; i<index_ids.data.rows.length; i+=1){
promise_list.push(gadget.state.my_indexes.get(index_ids.data.rows[i].id));
}
return RSVP.all(promise_list);
})
.push(function(indexes){
var i,
promise_list = [];
for (i=0; i<indexes.length; i+=1){
promise_list.push(gadget._build_index(index_names.data.rows[i].id, indexes[i]));
}
return RSVP.all(promise_list);
});
})
.declareMethod("download_new_index", function(index_name){
var gadget = this,
server,
index_received;
return gadget.get_server_model()
.push(function(server_model){
server = server_model;
})
.push(function(){
return server.get_index(index_name);
})
.push(function(index_result){
index_received = index_result;
var promise_list = [];
promise_list.push(gadget._download_all_index_docs(index_result.docs, server));
promise_list.push(gadget._download_actual_index(index_name, index_received.index));
return RSVP.all(promise_list);
});
})
.declareMethod("_download_all_index_docs", function(doc_list, server){
var i,
gadget = this,
promise_list = [],
doc_info;
for (i=0; i<doc_list.length; i+=1){
promise_list.push(server.get_doc(doc_list[i]));
}
return new RSVP.Queue()
.push(function(){
return RSVP.all(promise_list);
})
.push(function(doc_info){
var i,
promise_list = [];
for (i=0; i<doc_info.length; i+=1){
promise_list.push(gadget.state.my_docs.put(doc_list[i], {links : doc_info[i]}));
promise_list.push(gadget._download_doc_attachments(doc_list[i], doc_info[i], server));
}
return RSVP.all(promise_list);
});
})
.declareMethod("_download_doc_attachments", function(doc_name, attachment_list, server){
var i,
gadget = this,
promise_list = [];
for (i=0; i<attachment_list.links.length; i+=1){
promise_list.push(server.get_attachment(doc_name, attachment_list.links[i], {"format": "text"}));
}
return new RSVP.Queue()
.push(function(){
return RSVP.all(promise_list);
})
.push(function(attachments){
var i,
promise_list = [];
for (i=0; i<attachments.length; i+=1){
promise_list.push(gadget.state.my_docs.putAttachment(doc_name, attachment_list.links[i], new Blob([attachments[i], {type : "text/xml"}])));
}
return RSVP.all(promise_list);
});
})
.declareMethod("_download_actual_index", function(index_name, index){
this.state.indexes.push({name : index_name, index : index});
return this.state.my_indexes.put(index_name, JSON.stringify(index));
})
.declareMethod("_build_index", function(index_name, index){
var raw_index,
new_index,
key,
doc;
new_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 = doc name, "/a/b" = item id in x
});
raw_index = JSON.parse(index);
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
};
new_index.addDoc(doc);
}
this.state.indexes.push({name: index_name, index : new_index});
});
}(window, document, RSVP, rJS, jIO));
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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