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
fb0ce479
Commit
fb0ce479
authored
May 29, 2019
by
Alexandra Rogova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getting all attachments ok
parent
7576610c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
160 additions
and
66 deletions
+160
-66
gadget_model.js
gadget_model.js
+17
-15
gadget_parser.js
gadget_parser.js
+0
-47
jio.my_parser_storage.js
jio.my_parser_storage.js
+123
-0
search.js
search.js
+20
-4
No files found.
gadget_model.js
View file @
fb0ce479
...
@@ -5,16 +5,12 @@
...
@@ -5,16 +5,12 @@
rJS
(
window
)
rJS
(
window
)
.
ready
(
function
(){
.
ready
(
function
(){
this
.
feeds
=
jIO
.
createJIO
({
this
.
feeds
=
jIO
.
createJIO
({
type
:
"
indexeddb
"
,
type
:
"
indexeddb
"
,
database
:
"
mynij-v1.2
"
database
:
"
mynij-v1.2
"
});
});
this
.
search_storage
=
jIO
.
createJIO
({
type
:
"
union
"
,
storage_list
:
[]
});
this
.
sub_storages
=
[];
this
.
sub_storages
=
[];
this
.
info
=
jIO
.
createJIO
({
this
.
info
=
jIO
.
createJIO
({
...
@@ -24,7 +20,7 @@
...
@@ -24,7 +20,7 @@
return
this
.
feeds
.
put
(
"
feeds_doc
"
,
{});
return
this
.
feeds
.
put
(
"
feeds_doc
"
,
{});
})
})
.
declareMethod
(
"
add_attachment
"
,
function
(
title
,
rss
){
.
declareMethod
(
"
add_attachment
"
,
function
(
title
,
rss
){
var
gadget
=
this
;
var
gadget
=
this
;
return
this
.
feeds
.
putAttachment
(
"
feeds_doc
"
,
title
,
new
Blob
([
rss
],
{
type
:
"
text/xml
"
}))
return
this
.
feeds
.
putAttachment
(
"
feeds_doc
"
,
title
,
new
Blob
([
rss
],
{
type
:
"
text/xml
"
}))
...
@@ -38,21 +34,27 @@
...
@@ -38,21 +34,27 @@
type
:
"
indexeddb
"
,
type
:
"
indexeddb
"
,
database
:
"
mynij-v1.2
"
database
:
"
mynij-v1.2
"
}
}
}
};
gadget
.
sub_storages
.
push
(
new_sub_storage
);
var
tmp
=
jIO
.
createJIO
(
new_sub_storage
);
gadget
.
search_storage
=
jIO
.
createJIO
({
gadget
.
sub_storages
.
push
(
tmp
);
type
:
"
union
"
,
storage_list
:
gadget
.
sub_storages
});
});
});
})
})
.
declareMethod
(
"
allDocs
"
,
function
(){
var
promise_list
=
[],
i
;
for
(
i
=
0
;
i
<
this
.
sub_storages
.
length
;
i
+=
1
){
promise_list
.
push
(
this
.
sub_storages
[
i
].
allDocs
());
}
return
RSVP
.
all
(
promise_list
);
})
.
declareMethod
(
"
get
"
,
function
()
{
.
declareMethod
(
"
get
"
,
function
(
id_storage
,
id_item
)
{
return
this
.
s
earch_storage
.
get
.
apply
(
this
.
search_storage
,
arguments
);
return
this
.
s
ub_storages
[
id_storage
].
get
(
id_item
);
})
})
.
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
(){
...
...
gadget_parser.js
View file @
fb0ce479
...
@@ -56,51 +56,4 @@
...
@@ -56,51 +56,4 @@
});
});
});
});
/*.declareMethod("read_file", function(link) {
var gadget,
xmlhttp,
cur_text,
promise_list = [],
feed_title;
gadget = this;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4) {
cur_text = xmlhttp.responseText,
feed_title = cur_text.slice(cur_text.indexOf("<title>")+7, cur_text.indexOf("</title>"));
return gadget.is_already_parsed(feed_title)
.push (function (resultat){
if (!resultat){
promise_list.push(gadget.state.storage.loaded_doc(feed_title, {"loaded" : "true"}));
cur_text = cur_text.slice(cur_text.indexOf("<item>"), cur_text.length - 1);
while (cur_text.indexOf("<item>") > -1) {
promise_list.push(gadget.parse(cur_text));
cur_text = cur_text.slice(cur_text.indexOf("</item>") + 6, cur_text.length - 1);
}
RSVP.all(promise_list);
}
});
}
};
xmlhttp.open("GET", link, true);
xmlhttp.send();
})
.declareMethod("parse", function(local_cur_text) {
var title_start = local_cur_text.indexOf("<title>") + 7,
title_end = local_cur_text.indexOf("</title>"),
link_start = local_cur_text.indexOf("<link>") + 6,
link_end = local_cur_text.indexOf("</link>"),
body_start = local_cur_text.indexOf("<description>"),
body_end = local_cur_text.indexOf("</description>") + 14;
return this.remove_css(local_cur_text.slice(body_start, body_end))
.push (function(result){
return gadget.state.storage.put({
"title": local_cur_text.slice(title_start, title_end),
"link": local_cur_text.slice(link_start, link_end),
"body": result
});
});
})*/
}(
window
,
RSVP
,
rJS
,
jIO
));
}(
window
,
RSVP
,
rJS
,
jIO
));
jio.my_parser_storage.js
0 → 100644
View file @
fb0ce479
(
function
(
jIO
,
DOMParser
,
Node
)
{
"
use strict
"
;
/////////////////////////////////////////////////////////////
// RSS Parser
/////////////////////////////////////////////////////////////
function
RSSParser
(
txt
)
{
this
.
_dom_parser
=
new
DOMParser
().
parseFromString
(
txt
,
'
text/xml
'
);
}
RSSParser
.
prototype
.
parseElement
=
function
(
element
)
{
var
tag_element
,
i
,
j
,
attribute
,
result
=
{};
for
(
i
=
element
.
childNodes
.
length
-
1
;
i
>=
0
;
i
-=
1
)
{
tag_element
=
element
.
childNodes
[
i
];
if
((
tag_element
.
nodeType
===
Node
.
ELEMENT_NODE
)
&&
(
tag_element
.
tagName
!==
'
item
'
))
{
result
[
tag_element
.
tagName
]
=
tag_element
.
textContent
;
for
(
j
=
tag_element
.
attributes
.
length
-
1
;
j
>=
0
;
j
-=
1
)
{
attribute
=
tag_element
.
attributes
[
j
];
if
(
attribute
.
value
)
{
result
[
tag_element
.
tagName
+
'
_
'
+
attribute
.
name
]
=
attribute
.
value
;
}
}
}
}
return
result
;
};
RSSParser
.
prototype
.
getDocumentList
=
function
(
include
,
id
)
{
var
result_list
,
item_list
=
this
.
_dom_parser
.
querySelectorAll
(
"
rss > channel > item
"
),
i
;
//console.log(item_list);
if
((
id
===
'
/0
'
)
||
(
id
===
undefined
))
{
result_list
=
[{
id
:
'
/0
'
,
value
:
{}
}];
if
(
include
)
{
result_list
[
0
].
doc
=
this
.
parseElement
(
this
.
_dom_parser
.
querySelector
(
"
rss > channel
"
)
);
}
}
else
{
result_list
=
[];
}
for
(
i
=
0
;
i
<
item_list
.
length
;
i
+=
1
)
{
if
((
id
===
'
/0/
'
+
i
)
||
(
id
===
undefined
))
{
result_list
.
push
({
id
:
'
/0/
'
+
i
,
value
:
{}
});
if
(
include
)
{
result_list
[
result_list
.
length
-
1
].
doc
=
this
.
parseElement
(
item_list
[
i
]);
}
}
}
return
result_list
;
};
/////////////////////////////////////////////////////////////
// Helpers
/////////////////////////////////////////////////////////////
function
getParser
(
storage
)
{
return
storage
.
_sub_storage
.
getAttachment
(
storage
.
_document_id
,
storage
.
_attachment_id
,
{
format
:
'
text
'
})
.
push
(
function
(
txt
)
{
return
new
RSSParser
(
txt
);
});
}
/////////////////////////////////////////////////////////////
// Storage
/////////////////////////////////////////////////////////////
function
MyParserStorage
(
spec
)
{
this
.
_attachment_id
=
spec
.
attachment_id
;
this
.
_document_id
=
spec
.
document_id
;
this
.
_parser_name
=
spec
.
parser
;
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
}
MyParserStorage
.
prototype
.
hasCapacity
=
function
(
capacity
)
{
return
(
capacity
===
"
list
"
)
||
(
capacity
===
'
include
'
);
};
MyParserStorage
.
prototype
.
buildQuery
=
function
(
options
)
{
if
(
options
===
undefined
)
{
options
=
{};
}
return
getParser
(
this
)
.
push
(
function
(
parser
)
{
return
parser
.
getDocumentList
((
options
.
include_docs
||
false
));
});
};
MyParserStorage
.
prototype
.
get
=
function
(
id
)
{
return
getParser
(
this
)
.
push
(
function
(
parser
)
{
var
result_list
=
parser
.
getDocumentList
(
true
,
id
);
//console.log(result_list);
if
(
result_list
.
length
)
{
return
result_list
[
0
].
doc
;
}
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find parsed document:
"
+
id
,
404
);
});
};
MyParserStorage
.
prototype
.
put
=
function
(
id
,
metadata
){
return
this
.
_sub_storage
.
put
(
id
,
metadata
);
};
MyParserStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
){
return
this
.
_sub_storage
.
putAttachment
(
id
,
name
,
blob
);
};
jIO
.
addStorage
(
'
my_parser
'
,
MyParserStorage
);
}(
jIO
,
DOMParser
,
Node
));
\ No newline at end of file
search.js
View file @
fb0ce479
...
@@ -66,10 +66,26 @@
...
@@ -66,10 +66,26 @@
})
})
.
declareMethod
(
"
search
"
,
function
(
key
){
.
declareMethod
(
"
search
"
,
function
(
key
){
return
this
.
state
.
model_gadget
.
search
()
var
gadget
=
this
;
.
push
(
function
(
result
){
return
gadget
.
state
.
model_gadget
.
allDocs
()
console
.
log
(
result
);
.
push
(
function
(
result
){
})
var
i
,
j
,
promise_list
=
[];
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
){
for
(
j
=
1
;
j
<
result
[
i
].
data
.
rows
.
length
;
j
+=
1
){
promise_list
.
push
(
gadget
.
state
.
model_gadget
.
get
(
i
,
result
[
i
].
data
.
rows
[
j
].
id
));
}
}
console
.
log
(
promise_list
.
length
);
return
RSVP
.
all
(
promise_list
);
}).
push
(
function
(
result
){
console
.
log
(
"
result :
"
);
console
.
log
(
result
);
});
/*var options = { query:'title:"% mai %"'};
return gadget.state.model_gadget.search(options)
.push(function(result){
console.log("result : "); console.log(result);
});*/
/*var gadget = this,
/*var gadget = this,
options;
options;
...
...
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