Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Mynij
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alexandra Rogova
Mynij
Commits
143031ba
Commit
143031ba
authored
Jun 05, 2019
by
Alexandra Rogova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new database model, server client separation
parent
4f5d5b13
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
82 additions
and
311 deletions
+82
-311
gadget_model.js
gadget_model.js
+1
-0
gadget_parser.js
gadget_parser.js
+12
-45
gadget_result.js
gadget_result.js
+0
-2
new_gadget_model.js
new_gadget_model.js
+0
-136
search.html
search.html
+6
-22
search.js
search.js
+63
-67
server_model_gadget.html
server_model_gadget.html
+0
-0
server_model_gadget.js
server_model_gadget.js
+0
-39
No files found.
gadget_model.js
View file @
143031ba
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
.
ready
(
function
(){
.
ready
(
function
(){
this
.
index
=
elasticlunr
(
function
()
{
this
.
index
=
elasticlunr
(
function
()
{
this
.
use
(
elasticlunr
.
fr
);
this
.
use
(
elasticlunr
.
fr
);
this
.
addField
(
'
title
'
);
this
.
addField
(
'
title
'
);
...
...
gadget_parser.js
View file @
143031ba
...
@@ -4,59 +4,26 @@
...
@@ -4,59 +4,26 @@
"
use strict
"
;
"
use strict
"
;
rJS
(
window
)
rJS
(
window
)
.
declareAcquiredMethod
(
"
get_model
"
,
"
get_model
"
)
.
declareMethod
(
"
parse
"
,
function
(
file_link
){
.
declareMethod
(
"
read_file_new
"
,
function
(
link
){
var
gadget
=
this
,
var
gadget
=
this
,
storage
;
return
gadget
.
get_model
()
.
push
(
function
(
result
){
storage
=
result
;
})
.
push
(
function
(){
var
xmlhttp
=
new
XMLHttpRequest
();
xmlhttp
.
onreadystatechange
=
function
()
{
if
(
xmlhttp
.
status
==
200
&&
xmlhttp
.
readyState
==
4
){
var
rss
,
title
;
title
;
rss
=
xmlhttp
.
responseText
;
return
new
RSVP
.
Queue
().
push
(
function
(){
return
jIO
.
util
.
ajax
({
url
:
file_link
});
})
.
push
(
function
(
file
){
var
rss
;
rss
=
file
.
currentTarget
.
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_loaded
(
title
)
return
gadget
.
remove_css
(
rss
);
.
push
(
function
(
is_loaded
){
if
(
!
is_loaded
){
return
gadget
.
remove_css
(
rss
)
.
push
(
function
(
rss_without_css
){
return
storage
.
add_attachment
(
title
,
rss_without_css
);
})
})
.
push
(
function
(){
.
push
(
function
(
rss_without_css
){
return
storage
.
loaded_doc
(
title
,
{
"
loaded
"
:
"
true
"
});
return
{
title
:
title
,
content
:
rss_without_css
};
});
}
});
}
};
xmlhttp
.
open
(
"
GET
"
,
link
,
true
);
xmlhttp
.
send
();
});
});
})
})
.
declareMethod
(
"
remove_css
"
,
function
(
body
){
.
declareMethod
(
"
remove_css
"
,
function
(
body
){
var
regEx
=
new
RegExp
(
'
(style="(.*?)"|style="(.*?)")
'
,
'
gi
'
);
var
regEx
=
new
RegExp
(
'
(style="(.*?)"|style="(.*?)")
'
,
'
gi
'
);
return
body
.
replace
(
regEx
,
""
);
return
body
.
replace
(
regEx
,
""
);
})
.
declareMethod
(
"
is_already_loaded
"
,
function
(
title
){
return
this
.
get_model
()
.
push
(
function
(
storage
){
return
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
));
gadget_result.js
View file @
143031ba
...
@@ -39,7 +39,6 @@
...
@@ -39,7 +39,6 @@
}
else
{
}
else
{
return
this
.
cut_description
(
item
.
body
,
key
)
return
this
.
cut_description
(
item
.
body
,
key
)
.
push
(
function
(
result
){
.
push
(
function
(
result
){
console
.
log
(
result
);
var
array
=
[...
result
.
matchAll
(
key
)],
var
array
=
[...
result
.
matchAll
(
key
)],
i
;
i
;
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
){
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
){
...
@@ -55,7 +54,6 @@
...
@@ -55,7 +54,6 @@
.
declareMethod
(
"
clear
"
,
function
(){
.
declareMethod
(
"
clear
"
,
function
(){
var
list
=
document
.
getElementById
(
"
list
"
);
var
list
=
document
.
getElementById
(
"
list
"
);
console
.
log
(
list
);
while
(
list
.
firstChild
)
{
while
(
list
.
firstChild
)
{
list
.
removeChild
(
list
.
firstChild
);
list
.
removeChild
(
list
.
firstChild
);
}
}
...
...
new_gadget_model.js
deleted
100644 → 0
View file @
4f5d5b13
/*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
search.html
View file @
143031ba
...
@@ -17,34 +17,18 @@
...
@@ -17,34 +17,18 @@
<form
id =
"search_bar"
>
<form
id =
"search_bar"
>
<input
type=
"search"
required
>
<input
type=
"search"
required
>
</form>
</form>
<nav
id=
"navbar"
>
<ul>
<li
id=
"options"
><a>
Mes index
</a></li>
<li><a
class=
"active"
>
Scolaire
</a></li>
<li><a>
Index 1
</a></li>
<li><a>
Index 2
</a></li>
<li><a>
Index 3
</a></li>
<li><a>
Index 4
</a></li>
<li><a>
Index 5
</a></li>
<li><a>
Index 6
</a></li>
<li><a>
Index 7
</a></li>
<li><a>
Index 8
</a></li>
<li><a>
Index 9
</a></li>
<li><a>
Index 10
</a></li>
</ul>
</nav>
<dialog
id=
"myDialog"
>
This is an open dialog window
</dialog>
<div
data-gadget-url=
"gadget_result.html"
<div
data-gadget-url=
"gadget_result.html"
data-gadget-scope=
"result"
data-gadget-scope=
"result"
data-gadget-sandbox=
"public"
>
data-gadget-sandbox=
"public"
>
<div
data-gadget-url=
"gadget_model.html"
data-gadget-scope=
"model"
data-gadget-sandbox=
"public"
>
<div
data-gadget-url=
"gadget_parser.html"
<div
data-gadget-url=
"gadget_parser.html"
data-gadget-scope=
"parser"
data-gadget-scope=
"parser"
data-gadget-sandbox=
"public"
>
data-gadget-sandbox=
"public"
>
<div
data-gadget-url=
"gadget_server_model.html"
data-gadget-scope=
"server_model"
data-gadget-sandbox=
"public"
>
<div
data-gadget-url=
"gadget_client_model.html"
data-gadget-scope=
"client_model"
data-gadget-sandbox=
"public"
>
</div>
</div>
</body>
</body>
</html>
</html>
search.js
View file @
143031ba
(
function
(
window
,
document
,
rJS
,
RSVP
)
{
(
function
(
window
,
document
,
rJS
,
RSVP
)
{
var
gadget
;
var
gadget
;
var
preventDefault
=
function
(
e
)
{
e
=
e
||
window
.
event
;
if
(
e
.
preventDefault
)
e
.
preventDefault
();
e
.
returnValue
=
false
;
};
rJS
(
window
)
rJS
(
window
)
.
allowPublicAcquisition
(
"
get_server_model
"
,
function
(){
return
this
.
state
.
server_model_gadget
;
})
.
setState
({
.
setState
({
model_gadget
:
null
,
server_model_gadget
:
null
,
client_model_gadget
:
null
,
parser_gadget
:
null
,
parser_gadget
:
null
,
result_gadget
:
null
,
result_gadget
:
null
,
to_load
:
[
to_load
:
[
...
@@ -31,15 +30,20 @@
...
@@ -31,15 +30,20 @@
})
})
.
ready
(
function
(){
.
ready
(
function
(){
var
model_gadget
,
var
server_model_gadget
,
client_model_gadget
,
result_gadget
,
result_gadget
,
gadget
;
console
.
log
(
"
ready !
"
);
gadget
=
this
;
gadget
=
this
;
return
gadget
.
getDeclaredGadget
(
"
model
"
)
.
push
(
function
(
model
){
return
gadget
.
getDeclaredGadget
(
"
server_model
"
)
model_gadget
=
model
;
.
push
(
function
(
server_model
){
server_model_gadget
=
server_model
;
})
.
push
(
function
(){
return
gadget
.
getDeclaredGadget
(
"
client_model
"
);
})
.
push
(
function
(
client_model
){
client_model_gadget
=
client_model
;
})
})
.
push
(
function
(){
.
push
(
function
(){
return
gadget
.
getDeclaredGadget
(
"
result
"
);
return
gadget
.
getDeclaredGadget
(
"
result
"
);
...
@@ -52,44 +56,61 @@
...
@@ -52,44 +56,61 @@
})
})
.
push
(
function
(
result
){
.
push
(
function
(
result
){
return
gadget
.
changeState
({
return
gadget
.
changeState
({
model_gadget
:
model_gadget
,
server_model_gadget
:
server_model_gadget
,
client_model_gadget
:
client_model_gadget
,
parser_gadget
:
result
,
parser_gadget
:
result
,
result_gadget
:
result_gadget
result_gadget
:
result_gadget
});
});
});
})
})
.
onStateChange
(
function
(
modification_dict
){
var
gadget
=
this
;
return
gadget
.
state
.
server_model_gadget
.
loaded
()
.
push
(
function
(
loaded
){
if
(
!
loaded
){
return
gadget
.
state
.
server_model_gadget
.
add_doc
(
"
scolaire
"
)
.
push
(
function
(){
.
push
(
function
(){
return
gadget
.
set_on_click_options
(
);
return
gadget
.
state
.
server_model_gadget
.
add_index
(
"
scolaire
"
);
})
})
.
push
(
function
(){
.
push
(
function
(){
document
.
addEventListener
(
"
keydown
"
,
function
(
event
){
var
promise_list
=
[],
if
(
event
.
key
===
"
Escape
"
&&
document
.
getElementById
(
"
myDialog
"
).
open
){
i
;
document
.
getElementById
(
"
myDialog
"
).
close
();
for
(
i
=
0
;
i
<
gadget
.
state
.
to_load
.
length
;
i
++
){
return
gadget
.
enableScroll
(
);
promise_list
.
push
(
gadget
.
state
.
parser_gadget
.
parse
(
"
./test-files/
"
+
gadget
.
state
.
to_load
[
i
])
);
}
}
},
true
);
return
RSVP
.
all
(
promise_list
);
});
})
})
.
push
(
function
(
parsed_file_items
){
.
onStateChange
(
function
(
modification_dict
){
var
i
,
var
gadget
=
this
,
promise_list
=
[],
promise_list
=
[],
i
;
queue
=
new
RSVP
.
Queue
(),
for
(
i
=
0
;
i
<
gadget
.
state
.
to_load
.
length
;
i
++
){
add_to_feed
;
promise_list
.
push
(
gadget
.
state
.
parser_gadget
.
read_file_new
(
"
./test-files/
"
+
gadget
.
state
.
to_load
[
i
]));
add_to_feed
=
function
(
doc_name
,
feed
){
queue
.
push
(
function
(){
return
gadget
.
state
.
server_model_gadget
.
add_feed_to_doc
(
doc_name
,
feed
);
});
};
for
(
i
=
0
;
i
<
parsed_file_items
.
length
;
i
+=
1
){
add_to_feed
(
"
scolaire
"
,
{
title
:
parsed_file_items
[
i
].
title
,
content
:
parsed_file_items
[
i
].
content
});
}
}
promise_list
.
push
(
gadget
.
state
.
model_gadget
.
load_index
());
return
queue
;
RSVP
.
all
(
promise_list
);
})
})
.
push
(
function
(){
.
allowPublicAcquisition
(
"
get_model
"
,
function
(){
return
gadget
.
state
.
server_model_gadget
.
add_doc_to_index
(
"
scolaire
"
,
"
scolaire
"
);
return
this
.
getDeclaredGadget
(
"
model
"
);
})
.
push
(
function
(){
return
gadget
.
state
.
client_model_gadget
.
download_new_index
(
"
scolaire
"
);
});
}
});
})
})
.
declareMethod
(
"
search
"
,
function
(
key
){
.
declareMethod
(
"
search
"
,
function
(
key
){
var
gadget
=
this
;
var
gadget
=
this
;
return
gadget
.
state
.
result_gadget
.
clear
()
return
gadget
.
state
.
result_gadget
.
clear
()
.
push
(
function
(){
.
push
(
function
(){
return
gadget
.
state
.
model_gadget
.
search
(
key
);
return
gadget
.
state
.
client_model_gadget
.
search_in_index
(
"
scolaire
"
,
key
);
})
})
.
push
(
function
(
result
){
.
push
(
function
(
result
){
if
(
result
.
length
===
0
)
{
if
(
result
.
length
===
0
)
{
...
@@ -109,31 +130,6 @@
...
@@ -109,31 +130,6 @@
.
onEvent
(
"
submit
"
,
function
(
event
){
.
onEvent
(
"
submit
"
,
function
(
event
){
this
.
search
(
event
.
target
.
elements
[
0
].
value
);
this
.
search
(
event
.
target
.
elements
[
0
].
value
);
})
.
declareMethod
(
"
set_on_click_options
"
,
function
(){
var
options
=
document
.
getElementById
(
"
options
"
),
gadget
=
this
;
options
.
onclick
=
function
(){
document
.
getElementById
(
"
myDialog
"
).
showModal
();
return
gadget
.
disableScroll
();
};
})
.
declareMethod
(
"
disableScroll
"
,
function
(){
if
(
window
.
addEventListener
)
window
.
addEventListener
(
'
DOMMouseScroll
'
,
preventDefault
,
false
);
document
.
addEventListener
(
'
wheel
'
,
preventDefault
,
{
passive
:
false
});
// Disable scrolling in Chrome
window
.
onwheel
=
preventDefault
;
// modern standard
window
.
onmousewheel
=
document
.
onmousewheel
=
preventDefault
;
// older browsers, IE
window
.
ontouchmove
=
preventDefault
;
// mobile
})
.
declareMethod
(
"
enableScroll
"
,
function
(){
if
(
window
.
removeEventListener
)
window
.
removeEventListener
(
'
DOMMouseScroll
'
,
preventDefault
,
false
);
document
.
removeEventListener
(
'
wheel
'
,
preventDefault
,
{
passive
:
false
});
// Enable scrolling in Chrome
window
.
onmousewheel
=
document
.
onmousewheel
=
null
;
window
.
onwheel
=
null
;
window
.
ontouchmove
=
null
;
});
});
}(
window
,
document
,
rJS
,
RSVP
));
}(
window
,
document
,
rJS
,
RSVP
));
server_model_gadget.html
deleted
100644 → 0
View file @
4f5d5b13
server_model_gadget.js
deleted
100644 → 0
View file @
4f5d5b13
/*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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment