Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
fe765144
Commit
fe765144
authored
Jun 01, 2012
by
Tristan Cavelier
Committed by
Sebastien Robin
Jun 07, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding Indexed storage + qunit tests.
parent
10a18668
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
932 additions
and
163 deletions
+932
-163
OfficeJS/lib/jio/jio.js
OfficeJS/lib/jio/jio.js
+18
-23
OfficeJS/lib/jio/jio.min.js
OfficeJS/lib/jio/jio.min.js
+2
-2
OfficeJS/lib/jio/jio.storage.js
OfficeJS/lib/jio/jio.storage.js
+454
-110
OfficeJS/lib/jio/jio.storage.min.js
OfficeJS/lib/jio/jio.storage.min.js
+2
-2
OfficeJS/src/jio.storage.js
OfficeJS/src/jio.storage.js
+326
-26
OfficeJS/test/jiotests.js
OfficeJS/test/jiotests.js
+130
-0
No files found.
OfficeJS/lib/jio/jio.js
View file @
fe765144
/*! JIO - v0.1.0 - 2012-0
5-29
/*! JIO - v0.1.0 - 2012-0
6-01
* Copyright (c) 2012 Nexedi; Licensed */
* Copyright (c) 2012 Nexedi; Licensed */
var
JIO
=
var
JIO
=
(
function
()
{
var
jio_loader_function
=
function
(
localOrCookieStorage
,
$
)
{
(
function
()
{
var
jio_loader_function
=
function
(
localOrCookieStorage
,
$
)
{
...
@@ -169,13 +168,6 @@ var JIO =
...
@@ -169,13 +168,6 @@ var JIO =
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Tools
// Tools
extend
=
function
(
o1
,
o2
)
{
var
key
;
for
(
key
in
o2
)
{
o1
[
key
]
=
o2
[
key
];
}
return
o1
;
},
// end Tools
// end Tools
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
...
@@ -229,7 +221,7 @@ var JIO =
...
@@ -229,7 +221,7 @@ var JIO =
newJob
=
function
(
spec
,
my
)
{
newJob
=
function
(
spec
,
my
)
{
// Job constructor
// Job constructor
var
job
=
extend
(
{},
spec
);
var
job
=
$
.
extend
(
true
,
{},
spec
);
job
[
'
id
'
]
=
0
;
job
[
'
id
'
]
=
0
;
job
[
'
status
'
]
=
'
initial
'
;
job
[
'
status
'
]
=
'
initial
'
;
job
[
'
date
'
]
=
Date
.
now
();
job
[
'
date
'
]
=
Date
.
now
();
...
@@ -441,8 +433,8 @@ var JIO =
...
@@ -441,8 +433,8 @@ var JIO =
// options.job = the job object containing at least {id:..}.
// options.job = the job object containing at least {id:..}.
// options.where = remove values where options.where(job) === true
// options.where = remove values where options.where(job) === true
var
settings
=
extend
({
where
:
function
(
job
)
{
return
true
;}},
var
settings
=
$
.
extend
({
where
:
function
(
job
)
{
return
true
;}},
options
),
andwhere
,
found
=
false
,
k
=
'
key
'
;
options
),
andwhere
,
found
=
false
,
k
=
'
key
'
;
//// modify the job list
//// modify the job list
if
(
settings
.
job
)
{
if
(
settings
.
job
)
{
...
@@ -556,7 +548,7 @@ var JIO =
...
@@ -556,7 +548,7 @@ var JIO =
// It is a callback function called just before user callback.
// It is a callback function called just before user callback.
// It is called to manage job_object according to the ended job.
// It is called to manage job_object according to the ended job.
var
job
=
extend
(
{},
endedjob
);
// copy
var
job
=
$
.
extend
(
true
,
{},
endedjob
);
// copy
// This job is supposed terminated, we can remove it from queue.
// This job is supposed terminated, we can remove it from queue.
that
.
removeJob
({
'
job
'
:
job
});
that
.
removeJob
({
'
job
'
:
job
});
...
@@ -800,7 +792,7 @@ var JIO =
...
@@ -800,7 +792,7 @@ var JIO =
//// Getters Setters
//// Getters Setters
that
.
cloneJob
=
function
()
{
that
.
cloneJob
=
function
()
{
return
extend
(
{},
priv
.
job
);
return
$
.
extend
(
true
,
{},
priv
.
job
);
};
};
that
.
getUserName
=
function
()
{
that
.
getUserName
=
function
()
{
return
priv
.
job
.
userName
||
''
;
return
priv
.
job
.
userName
||
''
;
...
@@ -817,6 +809,9 @@ var JIO =
...
@@ -817,6 +809,9 @@ var JIO =
that
.
getStorageLocation
=
function
()
{
that
.
getStorageLocation
=
function
()
{
return
priv
.
job
.
storage
.
location
||
''
;
return
priv
.
job
.
storage
.
location
||
''
;
};
};
that
.
getSecondStorage
=
function
()
{
return
priv
.
job
.
storage
.
storage
||
{};
};
that
.
getStorageArray
=
function
()
{
that
.
getStorageArray
=
function
()
{
return
priv
.
job
.
storage
.
storageArray
||
[];
return
priv
.
job
.
storage
.
storageArray
||
[];
};
};
...
@@ -827,7 +822,7 @@ var JIO =
...
@@ -827,7 +822,7 @@ var JIO =
return
priv
.
job
.
fileContent
||
''
;
return
priv
.
job
.
fileContent
||
''
;
};
};
that
.
cloneOptionObject
=
function
()
{
that
.
cloneOptionObject
=
function
()
{
return
extend
(
{},
priv
.
job
.
options
);
return
$
.
extend
(
true
,
{},
priv
.
job
.
options
);
};
};
that
.
getMaxTries
=
function
()
{
that
.
getMaxTries
=
function
()
{
return
priv
.
job
.
maxtries
;
return
priv
.
job
.
maxtries
;
...
@@ -1146,7 +1141,7 @@ var JIO =
...
@@ -1146,7 +1141,7 @@ var JIO =
// } else { } // Error
// } else { } // Error
// }});
// }});
var
settings
=
extend
(
{
var
settings
=
$
.
extend
(
true
,
{
'
userName
'
:
priv
.
storage
.
userName
,
'
userName
'
:
priv
.
storage
.
userName
,
'
storage
'
:
priv
.
storage
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
applicant
'
:
priv
.
applicant
,
...
@@ -1179,7 +1174,7 @@ var JIO =
...
@@ -1179,7 +1174,7 @@ var JIO =
// } else { } // Error
// } else { } // Error
// }});
// }});
var
settings
=
extend
(
{
var
settings
=
$
.
extend
(
true
,
{
'
storage
'
:
priv
.
storage
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
applicant
'
:
priv
.
applicant
,
'
fileContent
'
:
''
,
'
fileContent
'
:
''
,
...
@@ -1217,7 +1212,7 @@ var JIO =
...
@@ -1217,7 +1212,7 @@ var JIO =
// fileName:'string',fileContent:'string',
// fileName:'string',fileContent:'string',
// creationDate:123,lastModified:456 }
// creationDate:123,lastModified:456 }
var
settings
=
extend
(
{
var
settings
=
$
.
extend
(
true
,
{
'
storage
'
:
priv
.
storage
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
applicant
'
:
priv
.
applicant
,
'
method
'
:
'
loadDocument
'
,
'
method
'
:
'
loadDocument
'
,
...
@@ -1251,7 +1246,7 @@ var JIO =
...
@@ -1251,7 +1246,7 @@ var JIO =
// result.return_value is an Array that contains documents objects.
// result.return_value is an Array that contains documents objects.
var
settings
=
extend
(
{
var
settings
=
$
.
extend
(
true
,
{
'
storage
'
:
priv
.
storage
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
applicant
'
:
priv
.
applicant
,
'
method
'
:
'
getDocumentList
'
,
'
method
'
:
'
getDocumentList
'
,
...
@@ -1281,7 +1276,7 @@ var JIO =
...
@@ -1281,7 +1276,7 @@ var JIO =
// } else { } // Not Removed
// } else { } // Not Removed
// }});
// }});
var
settings
=
extend
(
{
var
settings
=
$
.
extend
(
true
,
{
'
storage
'
:
priv
.
storage
,
'
storage
'
:
priv
.
storage
,
'
applicant
'
:
priv
.
applicant
,
'
applicant
'
:
priv
.
applicant
,
'
method
'
:
'
removeDocument
'
,
'
method
'
:
'
removeDocument
'
,
...
@@ -1296,7 +1291,7 @@ var JIO =
...
@@ -1296,7 +1291,7 @@ var JIO =
//// end Methods
//// end Methods
//// Initialize
//// Initialize
var
settings
=
extend
(
{
'
use_local_storage
'
:
true
},
spec
.
options
);
var
settings
=
$
.
extend
(
true
,
{
'
use_local_storage
'
:
true
},
spec
.
options
);
// objectify storage and applicant
// objectify storage and applicant
if
(
typeof
spec
.
storage
===
'
string
'
)
{
if
(
typeof
spec
.
storage
===
'
string
'
)
{
...
@@ -1349,7 +1344,7 @@ var JIO =
...
@@ -1349,7 +1344,7 @@ var JIO =
// applicant: the applicant object or json string
// applicant: the applicant object or json string
// options.useLocalStorage: if true, save job queue on localStorage.
// options.useLocalStorage: if true, save job queue on localStorage.
var
settings
=
extend
(
{
'
use_local_storage
'
:
true
},
options
);
var
settings
=
$
.
extend
(
true
,
{
'
use_local_storage
'
:
true
},
options
);
return
newJioConstructor
({
storage
:
storage
,
return
newJioConstructor
({
storage
:
storage
,
applicant
:
applicant
,
applicant
:
applicant
,
...
@@ -1380,7 +1375,7 @@ var JIO =
...
@@ -1380,7 +1375,7 @@ var JIO =
};
};
that
.
getConstObject
=
function
()
{
that
.
getConstObject
=
function
()
{
// Returns a copy of the constants
// Returns a copy of the constants
return
extend
(
{},
jio_const_obj
);
return
$
.
extend
(
true
,
{},
jio_const_obj
);
};
};
return
that
;
return
that
;
};
};
...
...
OfficeJS/lib/jio/jio.min.js
View file @
fe765144
This diff is collapsed.
Click to expand it.
OfficeJS/lib/jio/jio.storage.js
View file @
fe765144
This diff is collapsed.
Click to expand it.
OfficeJS/lib/jio/jio.storage.min.js
View file @
fe765144
This diff is collapsed.
Click to expand it.
OfficeJS/src/jio.storage.js
View file @
fe765144
This diff is collapsed.
Click to expand it.
OfficeJS/test/jiotests.js
View file @
fe765144
...
@@ -871,6 +871,136 @@ test ('Remove document', function () {
...
@@ -871,6 +871,136 @@ test ('Remove document', function () {
mytest
(
'
DummyStorageAllOK,3tries: remove document.
'
,
'
done
'
);
mytest
(
'
DummyStorageAllOK,3tries: remove document.
'
,
'
done
'
);
o
.
jio
.
stop
();
o
.
jio
.
stop
();
});
});
module
(
'
Jio IndexedStorage
'
);
test
(
'
Check name availability
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
(),
t
=
this
,
mytest
=
function
(
message
,
value
)
{
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
value
,
message
);};
t
.
spy
(
o
,
'
f
'
);
o
.
jio
.
checkNameAvailability
({
userName
:
'
MrIndexedCheck
'
,
callback
:
o
.
f
,
maxtries
:
3
});
clock
.
tick
(
100000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
};
o
.
jio
=
JIO
.
createNew
({
type
:
'
indexed
'
,
storage
:{
type
:
'
dummyall3tries
'
,
userName
:
'
indexedcheck
'
}},
{
ID
:
'
jiotests
'
});
mytest
(
'
dummy ok : name must be available
'
,
true
);
o
.
jio
.
stop
();
});
test
(
'
Document load
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
indexed
'
,
storage
:{
type
:
'
dummyall3tries
'
,
userName
:
'
indexedload
'
}},
{
ID
:
'
jiotests
'
});
// loading must take long time with dummyall3tries
o
.
f
=
function
()
{};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
memo
'
,
maxtries
:
3
,
callback
:
o
.
f
,
options
:{
metadata_only
:
true
}});
clock
.
tick
(
500
);
ok
(
!
o
.
f
.
calledOnce
,
'
Callback must not be called
'
);
// wait long time too retreive list
clock
.
tick
(
100000
);
// now we can test if the document metadata are loaded faster.
o
.
doc
=
{
fileName
:
'
memo
'
,
lastModified
:
25000
,
creationDate
:
20000
};
o
.
f2
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
o
.
doc
,
'
Document metadata retrieved
'
);
};
this
.
spy
(
o
,
'
f2
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
memo
'
,
maxtries
:
3
,
callback
:
o
.
f2
,
options
:{
metadata_only
:
true
}});
clock
.
tick
(
500
);
if
(
!
o
.
f2
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
// test a simple document loading
o
.
doc2
=
{
fileName
:
'
file
'
,
lastModified
:
17000
,
creationDate
:
11000
,
fileContent
:
'
content2
'
};
o
.
f3
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,
o
.
doc2
,
'
Simple document loading
'
);
};
this
.
spy
(
o
,
'
f3
'
);
o
.
jio
.
loadDocument
({
fileName
:
'
file
'
,
maxtries
:
3
,
callback
:
o
.
f3
});
clock
.
tick
(
100000
);
if
(
!
o
.
f3
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
test
(
'
Document save
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
indexed
'
,
storage
:{
type
:
'
dummyall3tries
'
,
userName
:
'
indexedsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
document save
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
({
fileName
:
'
file
'
,
maxtries
:
3
,
callback
:
o
.
f
});
clock
.
tick
(
100000
);
if
(
!
o
.
f
.
calledOnce
){
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
test
(
'
Get document list
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
indexed
'
,
storage
:{
type
:
'
dummyall3tries
'
,
userName
:
'
indexedgetlist
'
}},
{
ID
:
'
jiotests
'
});
o
.
doc1
=
{
fileName
:
'
file
'
,
lastModified
:
15000
,
creationDate
:
10000
};
o
.
doc2
=
{
fileName
:
'
memo
'
,
lastModified
:
25000
,
creationDate
:
20000
};
// getting list must take long time with dummyall3tries
o
.
f
=
function
()
{};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
getDocumentList
({
maxtries
:
3
,
callback
:
o
.
f
});
clock
.
tick
(
500
);
ok
(
!
o
.
f
.
calledOnce
,
'
Callback must not be called
'
);
// wail long time too retreive list
clock
.
tick
(
100000
);
// now we can test if the document list is loaded faster
o
.
f2
=
function
(
result
)
{
deepEqual
(
result
.
return_value
,[
o
.
doc1
,
o
.
doc2
],
'
get document list
'
);
};
this
.
spy
(
o
,
'
f2
'
);
o
.
jio
.
getDocumentList
({
maxtries
:
3
,
callback
:
o
.
f2
});
clock
.
tick
(
500
);
if
(
!
o
.
f2
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
});
test
(
'
Remove document
'
,
function
()
{
var
o
=
{},
clock
=
this
.
sandbox
.
useFakeTimers
();
o
.
jio
=
JIO
.
createNew
({
type
:
'
indexed
'
,
storage
:{
type
:
'
dummyall3tries
'
,
userName
:
'
indexedsave
'
}},
{
ID
:
'
jiotests
'
});
o
.
f
=
function
(
result
)
{
deepEqual
(
result
.
status
,
'
done
'
,
'
document remove
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
removeDocument
({
fileName
:
'
file
'
,
maxtries
:
3
,
callback
:
o
.
f
});
clock
.
tick
(
100000
);
if
(
!
o
.
f
.
calledOnce
){
ok
(
false
,
'
no response / too much results
'
);
}
o
.
jio
.
stop
();
});
// end require
// end require
};
// end thisfun
};
// end thisfun
...
...
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