many improvements!
This commit is contained in:
1 parent
da7cacb57e
commit
dda4e0b6ae
13 files changed
+245
-31
No files matched your search
@@ -1,24 +1,112 @@
|
||||
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 = () ->
|
||||
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', '$http', ($scope, $routeParams, $http) ->
|
||||
$scope.idx = $routeParams.idx
|
||||
$scope.doc = {}
|
||||
$scope.idx = Number($routeParams.idx)
|
||||
$scope.meta = {}
|
||||
$http.get("/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$routeParams.idx - 1}").then((res) ->
|
||||
$scope.newQuery = $routeParams.query or ""
|
||||
|
||||
url = "/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }"
|
||||
if $routeParams.query
|
||||
url = "#{url}/query/#{$routeParams.query}"
|
||||
url = "#{ url }/idx/#{$routeParams.idx - 1}"
|
||||
|
||||
$http.get(url).then((res) ->
|
||||
$scope.doc = res.data.document
|
||||
$scope.meta = res.data.meta
|
||||
)
|
||||
|
||||
$scope.parseQueryToJSON = (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 == ""
|
||||
return ""
|
||||
return "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/1/query/#{query}"
|
||||
|
||||
$scope.previousDocumentUrl = () ->
|
||||
"#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}"
|
||||
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}"
|
||||
if $routeParams.query
|
||||
url = "/query/#{$routeParams.query}"
|
||||
return url
|
||||
|
||||
$scope.nextDocumentUrl = () ->
|
||||
"#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx + 1}"
|
||||
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx + 1}"
|
||||
if $routeParams.query
|
||||
url = "/query/#{$routeParams.query}"
|
||||
return url
|
||||
|
||||
$scope.hasPreviousDocument = () ->
|
||||
$scope.idx > 1
|
||||
])
|
||||
|
||||
|
||||
])
|
||||
@@ -0,0 +1,40 @@
|
||||
root = this;
|
||||
|
||||
|
||||
root.controllers.controller('geojsonmapCtrl', ['$scope', '$routeParams', '$http', ($scope, $routeParams, $http) ->
|
||||
$scope.geojson = {}
|
||||
$scope.geojsonData = {}
|
||||
$scope.idx = Number($routeParams.idx)
|
||||
$scope.center = # experimental point around Québec
|
||||
lat: 46.1227
|
||||
lng: -72.6169
|
||||
zoom: 7
|
||||
|
||||
|
||||
$http.get("/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$routeParams.idx - 1}").then((res) ->
|
||||
$scope.geojson = res.data.document[$routeParams.key]
|
||||
if not $scope.geojson.properties
|
||||
$scope.geojson.properties = {}
|
||||
$scope.geojson.properties["_vulture_url_link"] = ""
|
||||
$scope.meta = res.data.meta
|
||||
$scope.geojsonData =
|
||||
data: $scope.geojson
|
||||
style: undefined
|
||||
resetStyleOnMouseout: true
|
||||
)
|
||||
|
||||
$scope.previousDocumentUrl = () ->
|
||||
"#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}/geojson/#{$routeParams.key}"
|
||||
|
||||
$scope.nextDocumentUrl = () ->
|
||||
"#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx + 1}/geojson/#{$routeParams.key}"
|
||||
|
||||
$scope.hasPreviousDocument = () ->
|
||||
$scope.idx > 1
|
||||
|
||||
$scope.$on "leafletDirectiveMap.geojsonClick", (ev, featureSelected, leafletEvent) ->
|
||||
a = 90
|
||||
b = 89
|
||||
|
||||
])
|
||||
|
||||
@@ -3,9 +3,11 @@ root = this;
|
||||
root.controllers.controller('topBarCtrl', ['$scope', '$location', ($scope, $location) ->
|
||||
$scope.$on('$routeChangeSuccess', (next, current) ->
|
||||
$scope.path = _.filter($location.path().split("/"), (s) -> s)
|
||||
if $scope.path[5] == "query"
|
||||
$scope.path = $scope.path[0...-1]
|
||||
$scope.getHistoryUrl = (idx) ->
|
||||
ret = "#/" + ($scope.path[i] for i in [0...idx]).join("/")
|
||||
if $scope.path[idx] == "idx"
|
||||
if _.indexOf(["idx", "geojson"], $scope.path[idx]) != -1
|
||||
return ""
|
||||
if idx == 0
|
||||
ret += "servers"
|
||||
@@ -13,6 +15,8 @@ root.controllers.controller('topBarCtrl', ['$scope', '$location', ($scope, $loca
|
||||
ret += "/databases"
|
||||
else if idx == 2
|
||||
ret += "/collections"
|
||||
else if idx == 4
|
||||
ret += "/#{ $scope.path[4] }"
|
||||
return ret
|
||||
)
|
||||
])
|
||||
Reference in new issue
Block a user