Commit d20872b3 authored by Ujvari Gergely's avatar Ujvari Gergely

Remove clause parser

parent 64a3b4f1
......@@ -42,8 +42,8 @@ class Displayer
streamfilter
.setPastDataNone()
.setMatchPolicyIncludeAny()
.addClausesParse('references:^' + $scope.annotation.id)
.addClausesParse('id:=' + $scope.annotation.id)
.addClause('references', 'first_of', $scope.annotation.id, true)
.addClause('id', 'equals', $scope.annotation.id, true)
.getFilter()
$scope.change_annotation_content = (id, new_annotation) =>
......
class ClauseParser
filter_fields : ['references', 'text', 'user', 'uri', 'id', 'tags', 'created', 'updated']
operators: [
'#<=', '#>=', '#<', '#>', '#=',
'=>', '>=', '<=', '=<', '>', '<',
'[', '=~', '^', '{',
'='
]
operator_mapping:
'=': 'equals'
'>': 'gt'
'<': 'lt'
'=>': 'ge'
'>=': 'ge'
'=<': 'le'
'<=': 'le'
'[' : 'one_of'
'=~' : 'matches'
'^' : 'first_of'
'{' : 'match_of' # one_of but not exact search
'#=' : 'lene'
'#>' : 'leng'
'#>=' : 'lenge'
'#<' : 'lenl'
'#<=' : 'lenle'
insensitive_operator : 'i'
parse_clauses: (clauses) ->
bads = []
structure = []
unless clauses
return
clauses = clauses.split ' '
for clause in clauses
#Here comes the long and boring validation checking
clause = clause.trim()
if clause.length < 1 then continue
parts = clause.split /:(.+)/
unless parts.length > 1
bads.push [clause, 'Filter clause is not well separated']
continue
unless parts[0] in @filter_fields
bads.push [clause, 'Unknown filter field']
continue
field = parts[0]
if parts[1][0] is @insensitive_operator
sensitive = false
rest = parts[1][1..]
else
sensitive = true
rest = parts[1]
operator_found = false
for operator in @operators
if (rest.indexOf operator) is 0
oper = @operator_mapping[operator]
if operator is '[' or operator is '{'
value = rest[operator.length..].split ','
else
value = rest[operator.length..]
operator_found = true
if field is 'user'
value = 'acct:' + value + '@' + window.location.hostname
break
unless operator_found
bads.push [clause, 'Unknown operator']
continue
structure.push
'field' : '/' + field
'operator': oper
'value' : value
'case_sensitive': sensitive
[structure, bads]
class StreamFilter
strategies: ['include_any', 'include_all', 'exclude_any', 'exclude_all']
past_modes: ['none','hits','time']
......@@ -166,29 +85,13 @@ class StreamFilter
@filter.clauses.push clause
this
addClause: (field, operator, value, case_sensitive = false, es_query_string = false) ->
addClause: (field, operator, value, case_sensitive = false, options = {}) ->
@filter.clauses.push
field: field
operator: operator
value: value
case_sensitive: case_sensitive
es_query_string: es_query_string
this
setClausesParse: (clauses_to_parse, error_checking = false) ->
res = @parser.parse_clauses clauses_to_parse
if res[1].length
console.log "Errors while parsing clause:"
console.log res[1]
if res? and (not error_checking) or (error_checking and res[1]?.length is 0)
@filter.clauses = res[0]
this
addClausesParse: (clauses_to_parse, error_checking = false) ->
res = @parser.parse_clauses clauses_to_parse
if res? and (not error_checking) or (error_checking and res[1]?.length is 0)
for clause in res[0]
@filter.clauses.push clause
options: options
this
resetFilter: ->
......@@ -202,5 +105,4 @@ class StreamFilter
angular.module('h.streamfilter',['bootstrap'])
.service('clauseparser', ClauseParser)
.service('streamfilter', StreamFilter)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment