the search bar is now a directive
This commit is contained in:
1 parent
342c8855b6
commit
14ce42475e
4 files changed
+11
-106
No files matched your search
@@ -1,73 +1,12 @@
|
|||||||
root = this;
|
root = this;
|
||||||
|
|
||||||
mongoJsToMongoJSON = (queryString) ->
|
|
||||||
ObjectId = (id) ->
|
|
||||||
return {"$oid": id}
|
|
||||||
|
|
||||||
DBRef = (name, id) ->
|
|
||||||
return {"$ref": name, "$id": id}
|
|
||||||
|
|
||||||
Timestamp = (t, i) ->
|
|
||||||
return {"t": t, "i": i}
|
|
||||||
NumberLong = (number) ->
|
|
||||||
return { "$numberLong": String(number)}
|
|
||||||
MaxKey = { "$maxKey": 1 }
|
|
||||||
MinKey = { "$minKey": 1 }
|
|
||||||
|
|
||||||
query = ""
|
|
||||||
eval("query = " + queryString)
|
|
||||||
fixQuery = (query) ->
|
|
||||||
if _.isArray(query)
|
|
||||||
for v, i in query
|
|
||||||
query[i] = fixQuery(v)
|
|
||||||
return query
|
|
||||||
if _.isRegExp(query)
|
|
||||||
options = ""
|
|
||||||
for k, option of {multiline: "m", global: "g", ignoreCase: "i"}
|
|
||||||
if query[k]
|
|
||||||
options += option
|
|
||||||
return { "$regex": query.source, "$options": options }
|
|
||||||
if _.isDate(query)
|
|
||||||
return { "$date": query.getTime()}
|
|
||||||
if query == undefined
|
|
||||||
return { "$undefined": true }
|
|
||||||
if _.isObject(query)
|
|
||||||
for k, v of query
|
|
||||||
query[k] = fixQuery(v)
|
|
||||||
return query
|
|
||||||
return query
|
|
||||||
|
|
||||||
return fixQuery(query)
|
|
||||||
|
|
||||||
testmongoJsToMongoJSON = () ->
|
root.controllers.controller('documentCtrl', ['$scope', '$routeParams', '$location', 'util', ($scope, $routeParams, $location, util) ->
|
||||||
assertEqual = (a, b) ->
|
|
||||||
if not _.isEqual(a, b)
|
|
||||||
console.log("error! ", a, " != ", b)
|
|
||||||
s = """{a: 89}"""
|
|
||||||
assertEqual(mongoJsToMongoJSON(s), {a : 89})
|
|
||||||
s = """{a: [1,3,{reg: /allo/gim}]}"""
|
|
||||||
assertEqual(mongoJsToMongoJSON(s), {a: [1,3, {reg: { "$regex":"allo", "$options": "mgi" }}]})
|
|
||||||
s = """{a: [
|
|
||||||
1,
|
|
||||||
3,
|
|
||||||
{reg:
|
|
||||||
[/allo/gim,
|
|
||||||
new Date("2014-05-08T21:52:24.320Z")
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}"""
|
|
||||||
assertEqual(mongoJsToMongoJSON(s), {a: [1,3, {reg: [{ "$regex":"allo", "$options": "mgi" }, {"$date": 1399585944320}]}]})
|
|
||||||
|
|
||||||
|
|
||||||
testmongoJsToMongoJSON()
|
|
||||||
|
|
||||||
root.controllers.controller('documentCtrl', ['$scope', '$routeParams', 'util', ($scope, $routeParams, util) ->
|
|
||||||
$scope.idx = $routeParams.idx
|
$scope.idx = $routeParams.idx
|
||||||
$scope.doc = {}
|
$scope.doc = {}
|
||||||
$scope.idx = Number($routeParams.idx) or 1
|
$scope.idx = Number($routeParams.idx) or 1
|
||||||
$scope.meta = {}
|
$scope.meta = {}
|
||||||
$scope.newQuery = $routeParams.query or ""
|
$scope.query = $routeParams.query or ""
|
||||||
$scope.notfound = false
|
$scope.notfound = false
|
||||||
$scope.error = ""
|
$scope.error = ""
|
||||||
$scope.codeMirrorOptions =
|
$scope.codeMirrorOptions =
|
||||||
@@ -93,20 +32,10 @@ root.controllers.controller('documentCtrl', ['$scope', '$routeParams', 'util', (
|
|||||||
$scope.error = res.data.error
|
$scope.error = res.data.error
|
||||||
)
|
)
|
||||||
|
|
||||||
$scope.parseQueryToJSON = (query) ->
|
$scope.search = (query) ->
|
||||||
try
|
|
||||||
ret = JSON.stringify(mongoJsToMongoJSON(query))
|
|
||||||
$scope.error = ""
|
|
||||||
return ret
|
|
||||||
catch error
|
|
||||||
$scope.error
|
|
||||||
return ""
|
|
||||||
|
|
||||||
$scope.getQueryPath = ()->
|
|
||||||
query = $scope.parseQueryToJSON($scope.newQuery)
|
|
||||||
if query == ""
|
if query == ""
|
||||||
return ""
|
return ""
|
||||||
return "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/1/query/#{query}"
|
$location.path "/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/1/query/#{query}"
|
||||||
|
|
||||||
$scope.previousDocumentUrl = () ->
|
$scope.previousDocumentUrl = () ->
|
||||||
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}"
|
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ root.controllers.controller('topBarCtrl', ['$scope', '$location', ($scope, $loca
|
|||||||
$scope.path = joinArray($scope.path[0...6], $scope.path[7...-1])
|
$scope.path = joinArray($scope.path[0...6], $scope.path[7...-1])
|
||||||
$scope.getHistoryUrl = (idx) ->
|
$scope.getHistoryUrl = (idx) ->
|
||||||
ret = "#/" + ($scope.path[i] for i in [0...idx]).join("/")
|
ret = "#/" + ($scope.path[i] for i in [0...idx]).join("/")
|
||||||
if _.indexOf(["idx", "geojson", "query", "_id", "field", "all"], $scope.path[idx]) != -1
|
if _.indexOf(["idx", "geojson", "query", "_id", "field", "all", "stats"], $scope.path[idx]) != -1
|
||||||
return ""
|
return ""
|
||||||
if idx == 0
|
if idx == 0
|
||||||
ret += "servers"
|
ret += "servers"
|
||||||
|
|||||||
@@ -68,10 +68,11 @@ directive = () ->
|
|||||||
transclude: false,
|
transclude: false,
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope:
|
scope:
|
||||||
query: "="
|
query: "@"
|
||||||
callback: "="
|
callback: "="
|
||||||
controller:["$scope", "$routeParams", ($scope, $routeParams) ->
|
controller:["$scope", "$routeParams", ($scope, $routeParams) ->
|
||||||
$scope.bigInput = false
|
$scope.bigInput = false
|
||||||
|
$scope.newQuery = $scope.query or ""
|
||||||
$scope.codeMirrorOptions =
|
$scope.codeMirrorOptions =
|
||||||
lineWrapping : true
|
lineWrapping : true
|
||||||
lineNumbers: true
|
lineNumbers: true
|
||||||
@@ -94,7 +95,9 @@ directive = () ->
|
|||||||
$scope.callCallback = () ->
|
$scope.callCallback = () ->
|
||||||
query = $scope.parseQueryToJSON($scope.newQuery)
|
query = $scope.parseQueryToJSON($scope.newQuery)
|
||||||
if query != ""
|
if query != ""
|
||||||
$scope.$eval($scope.callback, query)
|
f = () ->
|
||||||
|
$scope.callback(query)
|
||||||
|
$scope.$eval(f)
|
||||||
]
|
]
|
||||||
return directive
|
return directive
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,5 @@
|
|||||||
<div class="row">
|
|
||||||
<div class="large-9 columns">
|
|
||||||
<input type="text" ng-model="newQuery" style="font-family: monospace;font-size: 1.2em;">
|
|
||||||
</div>
|
|
||||||
<div class="large-3 columns right">
|
|
||||||
<ul class="button-group">
|
|
||||||
<li>
|
|
||||||
<a class="button tiny" ng-href="{{ getQueryPath() }}" ng-class="{disabled: getQueryPath()=='' }">
|
|
||||||
Query <i class="fa fa-thumbs-o-down" style="color:red;" ng-show="getQueryPath()=='' && newQuery != ''"></i>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="button tiny" ng-click="newQuery=''" ng-class="{disabled: newQuery=='' }">Clear</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a class="button tiny" ng-click="bigInput = !bigInput" >
|
|
||||||
<i class="fa fa-pencil-square-o" ng-show="!bigInput"></i>
|
|
||||||
<i class="fa fa-minus-square-o" ng-show="bigInput"></i>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row" ng-show="bigInput">
|
<vul-search-bar query="{{ query }}" callback="search"></vul-search-bar>
|
||||||
<div class="large-12 columns">
|
|
||||||
<ui-codemirror ng-model="newQuery" ui-codemirror="codeMirrorOptions" ></ui-codemirror>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="large-12 columns" style="text-align: center;">
|
<div class="large-12 columns" style="text-align: center;">
|
||||||
|
|||||||
Reference in new issue
Block a user