Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
1edc8e48
Commit
1edc8e48
authored
Jan 28, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localStorage: ALLDOCs new API and qunit tests
parent
30160fbb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
11 deletions
+93
-11
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+34
-8
test/jiotests.js
test/jiotests.js
+59
-3
No files found.
src/jio.storage/localstorage.js
View file @
1edc8e48
...
...
@@ -320,16 +320,42 @@ jIO.addStorageType('local', function (spec, my) {
* @method allDocs
* @param {object} command The JIO command
*/
that
.
allDocs
=
function
()
{
setTimeout
(
function
()
{
that
.
allDocs
=
function
(
command
)
{
var
i
,
s
,
j
,
file
,
items
=
0
,
all_doc_response
=
{};
all_doc_response
.
rows
=
[];
for
(
i
in
localStorage
)
{
if
(
localStorage
.
hasOwnProperty
(
i
))
{
// filter non-documents
s
=
new
RegExp
(
priv
.
localpath
+
'
\\
/.*$
'
);
if
(
s
.
test
(
i
))
{
items
+=
1
;
j
=
i
.
split
(
'
/
'
).
slice
(
-
1
)[
0
];
file
=
{
value
:
{}
};
file
.
id
=
j
;
file
.
key
=
j
;
if
(
command
.
getOption
(
'
include_docs
'
))
{
file
.
doc
=
JSON
.
parse
(
localStorage
.
getItem
(
i
));
}
all_doc_response
.
rows
.
push
(
file
);
}
}
}
all_doc_response
.
total_rows
=
items
;
if
(
items
>
0
)
{
that
.
success
(
all_doc_response
);
}
else
{
that
.
error
({
"
status
"
:
40
5
,
"
statusText
"
:
"
Method Not Allowe
d
"
,
"
error
"
:
"
method_not_allowe
d
"
,
"
message
"
:
"
Your are not allowed to use this comma
nd
"
,
"
reason
"
:
"
LocalStorage forbids AllDocs command executions
"
"
status
"
:
40
4
,
"
statusText
"
:
"
Not Foun
d
"
,
"
error
"
:
"
not_foun
d
"
,
"
message
"
:
"
No documents fou
nd
"
,
"
reason
"
:
"
No documents found
"
});
}
);
}
};
return
that
;
...
...
test/jiotests.js
View file @
1edc8e48
...
...
@@ -1071,20 +1071,76 @@ test ("Remove", function(){
test
(
"
AllDocs
"
,
function
(){
var
o
=
generateTools
(
this
);
var
o
=
generateTools
(
this
)
,
i
,
m
=
15
;
o
.
jio
=
JIO
.
newJio
({
"
type
"
:
"
local
"
,
"
username
"
:
"
ualldocs
"
,
"
application_name
"
:
"
aalldocs
"
});
o
.
localpath
=
"
jio/localstorage/ualldocs/aalldocs
"
;
// sample data
o
.
titles
=
[
"
Shawshank Redemption
"
,
"
Godfather
"
,
"
Godfather 2
"
,
"
Pulp Fiction
"
,
"
The Good, The Bad and The Ugly
"
,
"
12 Angry Men
"
,
"
The Dark Knight
"
,
"
Schindlers List
"
,
"
Lord of the Rings - Return of the King
"
,
"
Fight Club
"
,
"
Star Wars Episode V
"
,
"
Lord Of the Rings - Fellowship of the Ring
"
,
"
One flew over the Cuckoo's Nest
"
,
"
Inception
"
,
"
Godfellas
"
];
o
.
years
=
[
1994
,
1972
,
1974
,
1994
,
1966
,
1957
,
2008
,
1993
,
2003
,
1999
,
1980
,
2001
,
1975
,
2010
,
1990
];
o
.
director
=
[
"
Frank Darabont
"
,
"
Francis Ford Coppola
"
,
"
Francis Ford Coppola
"
,
"
Quentin Tarantino
"
,
"
Sergio Leone
"
,
"
Sidney Lumet
"
,
"
Christopher Nolan
"
,
"
Steven Spielberg
"
,
"
Peter Jackson
"
,
"
David Fincher
"
,
"
Irvin Kershner
"
,
"
Peter Jackson
"
,
"
Milos Forman
"
,
"
Christopher Nolan
"
,
"
Martin Scorsese
"
]
// set documents
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
fakeDoc
=
{};
o
.
fakeDoc
.
_id
=
"
doc_
"
+
i
;
o
.
fakeDoc
.
title
=
o
.
titles
[
i
];
o
.
fakeDoc
.
year
=
o
.
years
[
i
];
o
.
fakeDoc
.
author
=
o
.
director
[
i
];
localstorage
.
setItem
(
o
.
localpath
+
"
/doc_
"
+
i
,
o
.
fakeDoc
);
}
// response
o
.
allDocsResponse
=
{};
o
.
allDocsResponse
.
rows
=
[];
o
.
allDocsResponse
.
total_rows
=
15
;
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
allDocsResponse
.
rows
.
push
({
"
id
"
:
"
doc_
"
+
i
,
"
key
"
:
"
doc_
"
+
i
,
"
value
"
:
{}
});
};
// alldocs
// error 405 -> method not allowed
o
.
spy
(
o
,
"
status
"
,
405
,
"
Method not allowed
"
);
o
.
spy
(
o
,
"
value
"
,
o
.
allDocsResponse
,
"
All docs
"
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
tick
(
o
);
// include docs
o
.
allDocsResponse
=
{};
o
.
allDocsResponse
.
rows
=
[];
o
.
allDocsResponse
.
total_rows
=
15
;
for
(
i
=
0
;
i
<
m
;
i
+=
1
)
{
o
.
allDocsResponse
.
rows
.
push
({
"
id
"
:
"
doc_
"
+
i
,
"
key
"
:
"
doc_
"
+
i
,
"
value
"
:
{},
"
doc
"
:
localstorage
.
getItem
(
o
.
localpath
+
"
/doc_
"
+
i
)
});
};
// alldocs
o
.
spy
(
o
,
"
value
"
,
o
.
allDocsResponse
,
"
All docs (include docs)
"
);
o
.
jio
.
allDocs
({
"
include_docs
"
:
true
},
o
.
f
);
o
.
tick
(
o
);
o
.
jio
.
stop
();
});
...
...
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