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
a9ae8a4c
Commit
a9ae8a4c
authored
May 31, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: complexquery.js
parent
d45aeb6f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
44 deletions
+61
-44
src/queries/complexquery.js
src/queries/complexquery.js
+28
-7
src/queries/query.js
src/queries/query.js
+33
-4
src/queries/simplequery.js
src/queries/simplequery.js
+0
-33
No files found.
src/queries/complexquery.js
View file @
a9ae8a4c
...
...
@@ -10,17 +10,38 @@ var ComplexQuery = newClass(Query, function (spec) {
*/
this
.
operator
=
spec
.
operator
||
"
AND
"
;
this
.
query_list
=
todo
;
this
.
query_list
=
spec
.
query_list
||
[]
;
/**
* Filter the item list only if all the sub queries match this item according
* to the logical operator.
* See {{#crossLink "Query/exec:method"}}{{/crossLink}}
*/
this
.
exec
=
function
(
item_list
,
option
)
{
// XXX
this
.
match
=
function
()
{
todo
};
// XXX
this
.
toString
=
function
()
{
var
str_list
=
[
"
(
"
];
this
.
query_list
.
forEach
(
function
(
query
)
{
str_list
.
push
(
query
.
toString
());
str_list
.
push
(
this
.
operator
);
});
str_list
.
pop
();
// remove last operator
str_list
.
push
(
"
)
"
);
retrun
str_list
.
join
(
"
"
);
};
// XXX
this
.
serialized
=
function
()
{
var
s
=
{
"
type
"
:
"
complex
"
,
"
operator
"
:
this
.
operator
,
"
query_list
"
:
[]
};
this
.
query_list
.
forEach
(
function
(
query
)
{
s
.
query_list
.
push
(
query
.
serialized
());
});
return
s
;
};
// XXX
this
[
"
AND
"
]
=
function
(
item
,
wildcard_character
)
{
var
i
;
...
...
src/queries/query.js
View file @
a9ae8a4c
...
...
@@ -5,9 +5,18 @@
* @class Query
* @constructor
*/
var
Query
=
newClass
(
function
()
{
var
Query
=
newClass
(
function
(
spec
)
{
/**
* Creates a new item list with matching item only
* The wildcard character used to extend comparison action
*
* @property wildcard_character
* @type String
*/
this
.
wildcard_character
=
spec
.
wildcard_character
||
"
%
"
;
/**
* Filter the item list with matching item only
*
* @method exec
* @param {Array} item_list The list of object
...
...
@@ -18,9 +27,29 @@ var Query = newClass(function() {
* and "ascending" or "descending"
* @param {Array} [option.limit=undefined] Couple of integer, first is an
* index and second is the length.
* @return {Array} The new item list
*/
this
.
exec
=
function
(
item_list
,
option
)
{};
this
.
exec
=
function
(
item_list
,
option
)
{
var
i
;
for
(
i
=
0
;
i
<
item_list
.
length
;)
{
if
(
!
this
.
match
(
item
,
option
.
wildcard_character
))
{
item_list
.
splice
(
i
,
1
);
}
else
{
i
+=
1
;
}
}
if
(
option
.
sort_on
)
{
Query
.
sortOn
(
option
.
sort_on
,
item_list
);
}
if
(
option
.
limit
)
{
new_item_list
=
item_list
.
slice
(
option
.
limit
[
0
],
option
.
limit
[
1
]
+
option
.
limit
[
0
]
+
1
);
}
if
(
option
.
select_list
)
{
Query
.
filterListSelect
(
option
.
select_list
,
item_list
);
}
};
/**
* Test if an item matches this query
...
...
src/queries/simplequery.js
View file @
a9ae8a4c
...
...
@@ -34,39 +34,6 @@ var SimpleQuery = newClass(Query, function (spec) {
*/
this
.
value
=
spec
.
value
;
/**
* The wildcard character used to extend comparison action
*
* @property wildcard_character
* @type String
*/
this
.
wildcard_character
=
spec
.
wildcard_character
||
"
%
"
;
/**
* #crossLink "Query/exec:method"
*/
this
.
exec
=
function
(
item_list
,
option
)
{
var
new_item_list
=
[];
item_list
.
forEach
(
function
(
item
)
{
if
(
!
this
.
match
(
item
,
option
.
wildcard_character
))
{
new_item_list
.
push
(
item
);
}
});
if
(
option
.
sort_on
)
{
Query
.
sortOn
(
option
.
sort_on
,
new_item_list
);
}
if
(
option
.
limit
)
{
new_item_list
=
new_item_list
.
slice
(
option
.
limit
[
0
],
option
.
limit
[
1
]
+
option
.
limit
[
0
]
+
1
);
}
if
(
option
.
select_list
)
{
Query
.
filterListSelect
(
option
.
select_list
,
new_item_list
);
}
return
new_item_list
;
};
/**
* #crossLink "Query/match:method"
*/
...
...
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