Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
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
Douglas
jio
Commits
07163a47
Commit
07163a47
authored
Mar 25, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
local storage post generates uuid if id is not provided
parent
79fd7311
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
15 deletions
+34
-15
src/jio.storage/localstorage.js
src/jio.storage/localstorage.js
+26
-13
test/jiotests.js
test/jiotests.js
+8
-2
No files found.
src/jio.storage/localstorage.js
View file @
07163a47
...
@@ -41,6 +41,26 @@ jIO.addStorageType('local', function (spec, my) {
...
@@ -41,6 +41,26 @@ jIO.addStorageType('local', function (spec, my) {
priv
.
application_name
;
priv
.
application_name
;
// ==================== Tools ====================
// ==================== Tools ====================
/**
* Generate a new uuid
* @method generateUuid
* @return {string} The new uuid
*/
priv
.
generateUuid
=
function
()
{
var
S4
=
function
()
{
/* 65536 */
var
i
,
string
=
Math
.
floor
(
Math
.
random
()
*
0x10000
).
toString
(
16
);
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
string
=
'
0
'
+
string
;
}
return
string
;
};
return
S4
()
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
"
-
"
+
S4
()
+
S4
()
+
S4
();
};
/**
/**
* Update [doc] the document object and remove [doc] keys
* Update [doc] the document object and remove [doc] keys
* which are not in [new_doc]. It only changes [doc] keys not starting
* which are not in [new_doc]. It only changes [doc] keys not starting
...
@@ -108,25 +128,18 @@ jIO.addStorageType('local', function (spec, my) {
...
@@ -108,25 +128,18 @@ jIO.addStorageType('local', function (spec, my) {
*/
*/
that
.
post
=
function
(
command
)
{
that
.
post
=
function
(
command
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
var
doc
=
command
.
getDocId
();
var
doc
,
doc_id
=
command
.
getDocId
();
if
(
!
(
typeof
doc
===
"
string
"
&&
doc
!==
""
))
{
if
(
!
doc_id
)
{
that
.
error
({
doc_id
=
priv
.
generateUuid
();
"
status
"
:
405
,
"
statusText
"
:
"
Method Not Allowed
"
,
"
error
"
:
"
method_not_allowed
"
,
"
message
"
:
"
Cannot create document which id is undefined
"
,
"
reason
"
:
"
Document id is undefined
"
});
return
;
}
}
doc
=
localstorage
.
getItem
(
priv
.
localpath
+
"
/
"
+
doc
);
doc
=
localstorage
.
getItem
(
priv
.
localpath
+
"
/
"
+
doc
_id
);
if
(
doc
===
null
)
{
if
(
doc
===
null
)
{
// the document does not exist
// the document does not exist
localstorage
.
setItem
(
priv
.
localpath
+
"
/
"
+
command
.
getDocId
()
,
localstorage
.
setItem
(
priv
.
localpath
+
"
/
"
+
doc_id
,
command
.
cloneDoc
());
command
.
cloneDoc
());
that
.
success
({
that
.
success
({
"
ok
"
:
true
,
"
ok
"
:
true
,
"
id
"
:
command
.
getDocId
()
"
id
"
:
doc_id
});
});
}
else
{
}
else
{
// the document already exists
// the document already exists
...
...
test/jiotests.js
View file @
07163a47
...
@@ -768,8 +768,14 @@ test ("Post", function(){
...
@@ -768,8 +768,14 @@ test ("Post", function(){
});
});
// post without id
// post without id
o
.
spy
(
o
,
"
status
"
,
405
,
"
Post without id
"
);
o
.
spy
(
o
,
"
jobstatus
"
,
"
done
"
,
"
Post without id
"
);
o
.
jio
.
post
({},
o
.
f
);
o
.
jio
.
post
({},
function
(
err
,
response
)
{
var
uuid
;
o
.
f
(
err
,
response
);
uuid
=
(
err
||
response
).
id
;
ok
(
isUuid
(
uuid
),
"
Uuid should look like
"
+
"
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx :
"
+
uuid
);
});
o
.
tick
(
o
);
o
.
tick
(
o
);
// post non empty document
// post non empty document
...
...
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