Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
b7269e65
There was a problem fetching the pipeline summary.
Commit
b7269e65
authored
8 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Add value detection in dimensions
parent
73273083
No related branches found
No related tags found
1 merge request
!9
Dimensions middleware
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libs/middlewares/dimensions.js
+34
-25
34 additions, 25 deletions
libs/middlewares/dimensions.js
with
34 additions
and
25 deletions
libs/middlewares/dimensions.js
+
34
−
25
View file @
b7269e65
/**
* Dimensions middleware
*
* EXAMPLE:
* Use it with no parameters to get all the dimensions specified
* app.get('/', dimensions(), function(req, res, next){})
*
* Use it with an array of accepted values
* app.get('/', dimensions(['year', 'location']), function(req, res, next){})
*
* Use it globally
* app.use(dimensions())
*/
* Dimensions middleware
*
* EXAMPLE:
* Use it with no parameters to get all the dimensions specified
* app.get('/', dimensions(), function(req, res, next){})
*
* Use it with an array of accepted values
* app.get('/', dimensions(['year', 'location']), function(req, res, next){})
*
* Use it globally
* app.use(dimensions())
*/
function
intersect
(
a
,
b
)
{
var
t
if
(
b
.
length
>
a
.
length
)
t
=
b
,
b
=
a
,
a
=
t
return
a
.
filter
(
function
(
e
)
{
if
(
b
.
indexOf
(
e
)
!==
-
1
)
return
true
if
(
b
.
indexOf
(
e
)
!==
-
1
)
return
true
})
}
function
dimensions
(
dims
)
{
return
function
(
req
,
res
,
next
)
{
if
(
req
.
query
.
dims
)
{
params
=
req
.
query
.
dims
.
split
(
"
,
"
)
// If the dims array exists and is not empty
if
(
typeof
dims
!==
'
undefined
'
&&
dims
.
length
>
0
)
{
req
.
dims
=
intersect
(
dims
,
params
)
}
else
{
req
.
dims
=
params
}
return
function
(
req
,
res
,
next
)
{
req
.
dims
=
{}
if
(
req
.
query
.
dims
)
{
var
params
=
req
.
query
.
dims
.
split
(
"
,
"
)
var
dimObj
=
{}
for
(
var
i
=
0
;
i
<
params
.
length
;
++
i
)
{
var
kv
=
params
[
i
].
split
(
"
:
"
)
dimObj
[
kv
[
0
]]
=
(
typeof
kv
[
1
]
===
'
undefined
'
)
?
null
:
kv
[
1
]
}
// If the dims array exists and is not empty
if
(
typeof
dims
!==
'
undefined
'
&&
dims
.
length
>
0
)
{
var
intersection
=
intersect
(
dims
,
Object
.
keys
(
dimObj
))
for
(
var
i
=
0
;
i
<
intersection
.
length
;
++
i
)
{
req
.
dims
[
intersection
[
i
]]
=
dimObj
[
intersection
[
i
]]
}
}
else
{
req
.
dims
=
dimObj
}
}
console
.
log
(
req
.
dims
)
next
()
}
console
.
log
(
req
.
dims
)
next
()
}
}
module
.
exports
=
dimensions
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment