Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Aurélien Vermylen
jio
Commits
63be634c
Commit
63be634c
authored
Nov 06, 2017
by
Aurélien Vermylen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rehaul back: list by user again...
parent
ff174e12
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
148 deletions
+137
-148
dist/jio-v3.23.1.js
dist/jio-v3.23.1.js
+37
-38
dist/jio-v3.23.1.min.js
dist/jio-v3.23.1.min.js
+5
-5
src/jio.js
src/jio.js
+2
-2
src/jio.storage/automaticapistorage.js
src/jio.storage/automaticapistorage.js
+35
-36
test/jio.storage/automaticapistorage.tests.js
test/jio.storage/automaticapistorage.tests.js
+58
-67
No files found.
dist/jio-v3.23.1.js
View file @
63be634c
...
...
@@ -7605,8 +7605,8 @@ return new Parser;
i
,
value
,
result_list
;
if
(
obj
===
undefined
)
{
return
undefined
;
if
(
obj
===
undefined
||
obj
===
null
)
{
return
'
null
'
;
}
if
(
obj
.
constructor
===
Object
)
{
key_list
=
Object
.
keys
(
obj
).
sort
();
...
...
@@ -14496,12 +14496,12 @@ return new Parser;
var
result
=
[],
type
=
endpoint
.
split
(
'
/
'
)[
1
],
promises
,
dev
=
filters
.
device
||
'
all
'
,
usr
=
filters
.
user
||
'
all
'
,
isId
=
checkEndpointAsId
(
endpoint
),
device
_dict
=
{},
user
_dict
=
{},
i
;
// Remove '
device
' filter which should not be put in Automatic request.
delete
filters
.
device
;
// Remove '
user
' filter which should not be put in Automatic request.
delete
filters
.
user
;
// Check endpoint validity.
if
(
!
checkEndpoint
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Wrong Automatic API query. (usually
'
+
...
...
@@ -14515,7 +14515,7 @@ return new Parser;
// Promise chain to handle multi-part response ("_metadata"->"next" parts).
function
treatNext
(
returned
)
{
var
data
,
device
_id
,
user
_id
,
next
;
// If the returned value was an error, return it (-> quite nasty design
// to have to return errors, but this is in order for all RSVP.all() to
...
...
@@ -14524,7 +14524,7 @@ return new Parser;
return
returned
;
}
data
=
returned
[
0
];
device_id
=
device
_dict
[
returned
[
1
]];
user_id
=
user
_dict
[
returned
[
1
]];
data
=
[
data
];
if
(
!
isId
)
{
if
(
data
[
0
].
_metadata
===
undefined
)
{
...
...
@@ -14539,16 +14539,16 @@ return new Parser;
path
=
URI
(
dat
.
url
).
path
();
temp
=
{
'
automatic_path
'
:
path
,
'
reference
'
:
'
/
'
+
device
_id
+
path
,
'
id
'
:
'
/
'
+
device
_id
+
path
,
'
reference
'
:
'
/
'
+
user
_id
+
path
,
'
id
'
:
'
/
'
+
user
_id
+
path
,
'
type
'
:
type
,
'
start_date
'
:
dat
.
started_at
||
null
,
'
stop_date
'
:
dat
.
ended_at
||
null
,
'
automatic_
device
'
:
device
_id
'
automatic_
user
'
:
user
_id
};
result
.
push
(
temp
);
return
jio
.
_cache
.
put
(
'
/
'
+
device
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
device
_id
+
path
,
'
data
'
,
return
jio
.
_cache
.
put
(
'
/
'
+
user
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
user
_id
+
path
,
'
data
'
,
new
Blob
([
JSON
.
stringify
(
dat
)],
{
type
:
'
text/plain
'
}));
});
...
...
@@ -14581,21 +14581,20 @@ return new Parser;
return
new
RSVP
.
Queue
().
push
(
function
()
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
'
device
'
,
''
]}),
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
''
]}),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
}
//'xhrFields': {withCredentials: true}
});
}).
push
(
function
(
resp
dev
)
{
var
temp
=
JSON
.
parse
(
resp
dev
.
target
.
responseText
);
if
(
temp
.
results
.
length
===
0
)
{
}).
push
(
function
(
resp
usr
)
{
var
temp
=
JSON
.
parse
(
resp
usr
.
target
.
responseText
);
if
(
temp
.
id
===
undefined
)
{
return
new
jIO
.
util
.
jIOError
(
'
No device associated to this account yet.
'
,
2
00
'
Could not find user information
'
,
4
00
);
}
device_dict
[
token
]
=
temp
.
results
[
0
]
.
id
;
if
(
dev
===
'
all
'
||
dev
===
device
_dict
[
token
])
{
user_dict
[
token
]
=
temp
.
id
;
if
(
usr
===
'
all
'
||
usr
===
user
_dict
[
token
])
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
URI
(
automatic_template
.
expand
({
endpoint
:
...
...
@@ -14621,7 +14620,7 @@ return new Parser;
return
RSVP
.
all
(
promises
);
}).
push
(
function
(
trueOrErrorArray
)
{
// If we queried an id, return results should be length 1
if
(
isId
&&
(
dev
!==
'
all
'
))
{
if
(
isId
&&
(
usr
!==
'
all
'
))
{
if
(
result
.
length
===
1
)
{
return
result
[
0
];
}
...
...
@@ -14631,7 +14630,7 @@ return new Parser;
}
// Result is empty, so we throw the correct token error.
i
=
jio
.
_access_tokens
.
map
(
function
(
token
)
{
if
(
device_dict
[
token
]
===
dev
)
{
if
(
user_dict
[
token
]
===
usr
)
{
return
true
;
}
return
false
;
...
...
@@ -14641,8 +14640,8 @@ return new Parser;
throw
trueOrErrorArray
[
i
];
}
// If we didn't find the error in the promise returns, we don't have
// a token for
device dev
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
device:
'
+
dev
,
400
);
// a token for
user usr
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
user:
'
+
usr
,
400
);
}
// Otherwise return results and errors and let caller handle.
return
result
;
...
...
@@ -14673,8 +14672,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
get
=
function
(
id
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14687,13 +14686,13 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
(
res
)
{
return
res
;
},
function
()
{
return
_queryAutomaticAPI
(
endpoint
,
{
'
device
'
:
dev
},
self
)
return
_queryAutomaticAPI
(
endpoint
,
{
'
user
'
:
usr
},
self
)
.
push
(
function
(
res
)
{
return
res
;
},
function
(
err
)
{
...
...
@@ -14726,8 +14725,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14740,7 +14739,7 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
()
{
...
...
@@ -14770,8 +14769,8 @@ return new Parser;
AutomaticAPIStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -14784,7 +14783,7 @@ return new Parser;
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
{
data
:
null
};
...
...
@@ -14804,9 +14803,9 @@ return new Parser;
key_list
,
automatic_filters
=
{},
simplequery_type_value
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
device
'
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
user
'
,
'
vehicle
'
],
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
device
'
,
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
user
'
,
'
vehicle
'
],
intercept_accepted_operators
=
[[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
=
'
],
[
'
=
'
]],
...
...
dist/jio-v3.23.1.min.js
View file @
63be634c
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/jio.js
View file @
63be634c
...
...
@@ -129,8 +129,8 @@
i
,
value
,
result_list
;
if
(
obj
===
undefined
)
{
return
undefined
;
if
(
obj
===
undefined
||
obj
===
null
)
{
return
'
null
'
;
}
if
(
obj
.
constructor
===
Object
)
{
key_list
=
Object
.
keys
(
obj
).
sort
();
...
...
src/jio.storage/automaticapistorage.js
View file @
63be634c
...
...
@@ -54,12 +54,12 @@
var
result
=
[],
type
=
endpoint
.
split
(
'
/
'
)[
1
],
promises
,
dev
=
filters
.
device
||
'
all
'
,
usr
=
filters
.
user
||
'
all
'
,
isId
=
checkEndpointAsId
(
endpoint
),
device
_dict
=
{},
user
_dict
=
{},
i
;
// Remove '
device
' filter which should not be put in Automatic request.
delete
filters
.
device
;
// Remove '
user
' filter which should not be put in Automatic request.
delete
filters
.
user
;
// Check endpoint validity.
if
(
!
checkEndpoint
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Wrong Automatic API query. (usually
'
+
...
...
@@ -73,7 +73,7 @@
// Promise chain to handle multi-part response ("_metadata"->"next" parts).
function
treatNext
(
returned
)
{
var
data
,
device
_id
,
user
_id
,
next
;
// If the returned value was an error, return it (-> quite nasty design
// to have to return errors, but this is in order for all RSVP.all() to
...
...
@@ -82,7 +82,7 @@
return
returned
;
}
data
=
returned
[
0
];
device_id
=
device
_dict
[
returned
[
1
]];
user_id
=
user
_dict
[
returned
[
1
]];
data
=
[
data
];
if
(
!
isId
)
{
if
(
data
[
0
].
_metadata
===
undefined
)
{
...
...
@@ -97,16 +97,16 @@
path
=
URI
(
dat
.
url
).
path
();
temp
=
{
'
automatic_path
'
:
path
,
'
reference
'
:
'
/
'
+
device
_id
+
path
,
'
id
'
:
'
/
'
+
device
_id
+
path
,
'
reference
'
:
'
/
'
+
user
_id
+
path
,
'
id
'
:
'
/
'
+
user
_id
+
path
,
'
type
'
:
type
,
'
start_date
'
:
dat
.
started_at
||
null
,
'
stop_date
'
:
dat
.
ended_at
||
null
,
'
automatic_
device
'
:
device
_id
'
automatic_
user
'
:
user
_id
};
result
.
push
(
temp
);
return
jio
.
_cache
.
put
(
'
/
'
+
device
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
device
_id
+
path
,
'
data
'
,
return
jio
.
_cache
.
put
(
'
/
'
+
user
_id
+
path
,
temp
).
push
(
function
()
{
return
jio
.
_cache
.
putAttachment
(
'
/
'
+
user
_id
+
path
,
'
data
'
,
new
Blob
([
JSON
.
stringify
(
dat
)],
{
type
:
'
text/plain
'
}));
});
...
...
@@ -139,21 +139,20 @@
return
new
RSVP
.
Queue
().
push
(
function
()
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
'
device
'
,
''
]}),
'
url
'
:
automatic_template
.
expand
({
endpoint
:
[
'
user
'
,
'
me
'
,
''
]}),
'
headers
'
:
{
'
Authorization
'
:
'
Bearer
'
+
token
}
//'xhrFields': {withCredentials: true}
});
}).
push
(
function
(
resp
dev
)
{
var
temp
=
JSON
.
parse
(
resp
dev
.
target
.
responseText
);
if
(
temp
.
results
.
length
===
0
)
{
}).
push
(
function
(
resp
usr
)
{
var
temp
=
JSON
.
parse
(
resp
usr
.
target
.
responseText
);
if
(
temp
.
id
===
undefined
)
{
return
new
jIO
.
util
.
jIOError
(
'
No device associated to this account yet.
'
,
2
00
'
Could not find user information
'
,
4
00
);
}
device_dict
[
token
]
=
temp
.
results
[
0
]
.
id
;
if
(
dev
===
'
all
'
||
dev
===
device
_dict
[
token
])
{
user_dict
[
token
]
=
temp
.
id
;
if
(
usr
===
'
all
'
||
usr
===
user
_dict
[
token
])
{
return
jIO
.
util
.
ajax
({
'
type
'
:
'
GET
'
,
'
url
'
:
URI
(
automatic_template
.
expand
({
endpoint
:
...
...
@@ -179,7 +178,7 @@
return
RSVP
.
all
(
promises
);
}).
push
(
function
(
trueOrErrorArray
)
{
// If we queried an id, return results should be length 1
if
(
isId
&&
(
dev
!==
'
all
'
))
{
if
(
isId
&&
(
usr
!==
'
all
'
))
{
if
(
result
.
length
===
1
)
{
return
result
[
0
];
}
...
...
@@ -189,7 +188,7 @@
}
// Result is empty, so we throw the correct token error.
i
=
jio
.
_access_tokens
.
map
(
function
(
token
)
{
if
(
device_dict
[
token
]
===
dev
)
{
if
(
user_dict
[
token
]
===
usr
)
{
return
true
;
}
return
false
;
...
...
@@ -199,8 +198,8 @@
throw
trueOrErrorArray
[
i
];
}
// If we didn't find the error in the promise returns, we don't have
// a token for
device dev
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
device:
'
+
dev
,
400
);
// a token for
user usr
.
throw
new
jIO
.
util
.
jIOError
(
'
No valid token for
user:
'
+
usr
,
400
);
}
// Otherwise return results and errors and let caller handle.
return
result
;
...
...
@@ -231,8 +230,8 @@
AutomaticAPIStorage
.
prototype
.
get
=
function
(
id
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -245,13 +244,13 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
(
res
)
{
return
res
;
},
function
()
{
return
_queryAutomaticAPI
(
endpoint
,
{
'
device
'
:
dev
},
self
)
return
_queryAutomaticAPI
(
endpoint
,
{
'
user
'
:
usr
},
self
)
.
push
(
function
(
res
)
{
return
res
;
},
function
(
err
)
{
...
...
@@ -284,8 +283,8 @@
AutomaticAPIStorage
.
prototype
.
getAttachment
=
function
(
id
,
name
,
options
)
{
var
self
=
this
,
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -298,7 +297,7 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
this
.
_cache
.
get
(
id
).
push
(
function
()
{
...
...
@@ -328,8 +327,8 @@
AutomaticAPIStorage
.
prototype
.
allAttachments
=
function
(
id
)
{
var
endpoint
=
id
.
split
(
'
/
'
),
dev
;
dev
=
endpoint
.
splice
(
1
,
1
)[
0
];
usr
;
usr
=
endpoint
.
splice
(
1
,
1
)[
0
];
endpoint
=
endpoint
.
join
(
'
/
'
);
if
(
id
.
indexOf
(
'
/
'
)
!==
0
)
{
throw
new
jIO
.
util
.
jIOError
(
'
id
'
+
id
+
...
...
@@ -342,7 +341,7 @@
if
(
!
checkEndpointAsId
(
endpoint
))
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
if
(
dev
===
'
all
'
)
{
if
(
usr
===
'
all
'
)
{
throw
new
jIO
.
util
.
jIOError
(
'
Invalid id.
'
,
400
);
}
return
{
data
:
null
};
...
...
@@ -362,9 +361,9 @@
key_list
,
automatic_filters
=
{},
simplequery_type_value
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
device
'
,
intercept_keys
=
[
'
start_date
'
,
'
stop_date
'
,
'
user
'
,
'
vehicle
'
],
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
device
'
,
intercept_keys_automatic_name
=
[
'
started_at
'
,
'
ended_at
'
,
'
user
'
,
'
vehicle
'
],
intercept_accepted_operators
=
[[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
>
'
,
'
>=
'
,
'
<
'
,
'
<=
'
],
[
'
=
'
],
[
'
=
'
]],
...
...
test/jio.storage/automaticapistorage.tests.js
View file @
63be634c
This diff is collapsed.
Click to expand it.
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