Can now use pipeline as query

This commit is contained in:
didier amyot committed 2015-05-25 12:07:43 -04:00
1 parent 41552040cc
commit e305aa8f2a
16 files changed
+323 -123

No files matched your search

+88 -39
View File
@@ -1,56 +1,105 @@
root = this;
root.controllers.controller('documentCtrl', ['$scope', '$routeParams', '$location', 'util', ($scope, $routeParams, $location, util) ->
$scope.idx = $routeParams.idx
$scope.doc = {}
$scope.idx = Number($routeParams.idx) or 1
$scope.meta = {}
$scope.query = $routeParams.query or ""
$scope.notfound = false
$scope.error = ""
$scope.codeMirrorOptions =
lineWrapping : true
lineNumbers: true
mode: 'text/typescript'
url = "/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }"
if $routeParams.query
url = "#{url}/query/#{$routeParams.query}"
if $routeParams.idx
url = "#{ url }/idx/#{$routeParams.idx - 1}"
else if $routeParams.id
url = "#{ url }/_id/#{$routeParams.id}"
$scope.raw_url = url
util.get(url).then((res) ->
$scope.doc = res.data.document
$scope.meta = res.data.meta
$scope.enlapsed_time = res.data.enlapsed_time
).catch( (res) ->
if res.data.error == "not found"
$scope.notfound = true
root.controllers.controller('documentCtrl', ['$scope', '$routeParams', '$location', 'util', 'documentCtrlUtil', ($scope, $routeParams, $location, util, documentCtrlUtil) ->
$scope.initScopeVariables = ->
$scope.idx = $routeParams.idx
$scope.doc = {}
$scope.idx = Number($routeParams.idx) or 1
$scope.meta = {}
$scope.query = $routeParams.query or $routeParams.pipeline or ""
$scope.notfound = false
$scope.error = ""
$scope.codeMirrorOptions =
lineWrapping : true
lineNumbers: true
mode: 'text/javascript'
$scope.init = ->
$scope.initScopeVariables()
url = documentCtrlUtil.getUrl($routeParams)
$scope.raw_url = url
if $scope.isDocumentFromPipeline()
promise = documentCtrlUtil.getPipeline(url, $scope.idx - 1)
else
promise = util.get(url)
promise.then((res) ->
$scope.doc = res.data.document
$scope.meta = res.data.meta
$scope.total = res.data.meta.count + $scope.idx - 1
$scope.enlapsed_time = res.data.enlapsed_time
).catch((res) ->
$scope.error = res.data.error
)
)
$scope.isDocumentFromPipeline = ->
return $routeParams.pipeline
$scope.search = (query) ->
if query == ""
return ""
$location.path "/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/1/query/#{query}"
$scope.executePipeline = (pipeline) ->
if pipeline == ""
return
$location.path "/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/1/pipeline/#{pipeline}"
$scope.previousDocumentUrl = () ->
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx - 1}"
if $routeParams.query
url = "#{url}/query/#{$routeParams.query}"
return url
return '#' + $location.path().replace(/\/idx\/\d+/, "/idx/#{$scope.idx - 1}")
$scope.nextDocumentUrl = () ->
url = "#/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/idx/#{$scope.idx + 1}"
if $routeParams.query
url = "#{url}/query/#{$routeParams.query}"
return url
return '#' + $location.path().replace(/\/idx\/\d+/, "/idx/#{$scope.idx + 1}")
$scope.hasPreviousDocument = () ->
$scope.idx > 1
$scope.hasNextDocument = ->
$scope.total > 0 and $scope.idx < $scope.total
$scope.init()
])
root = this
root.services.factory('documentCtrlUtil', ['util', (util)->
service =
_cache: {}
getUrl: ($routeParams) ->
url = "/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }"
if $routeParams.query
url = "#{url}/query/#{$routeParams.query}"
else if $routeParams.pipeline
return "#{url}/pipeline/#{$routeParams.pipeline}"
if $routeParams.idx
url = "#{ url }/idx/#{$routeParams.idx - 1}"
else if $routeParams.id
url = "#{ url }/_id/#{$routeParams.id}"
return url
wrapPipelinePromise: (promise, idx) ->
return promise.then (res) ->
ret =
data:
document: res.data.document[idx]
meta:
count: res.data.document.length - idx
enlapsed_time: res.data.enlapsed_time
return promise
getPipeline: (url, idx) ->
if url in _.keys(service._cache)
return service.wrapPipelinePromise(service._cache[url], idx)
service._cache[url] = util.get(url)
return service.getPipeline(url, idx)
return service
]);
+10 -8
View File
@@ -22,13 +22,16 @@ getAxisLabel = (min, stepSize, numberOfBins) ->
root.controllers.controller('keyStatCtrl', ['$scope', '$routeParams', '$location', 'util', ($scope, $routeParams, $location, util) ->
$scope.name = $routeParams.key
$scope.stats = []
$scope.queryObject = $routeParams.query or '{}'
$scope.queryObject = $routeParams.query or $routeParams.pipeline or '{}'
base_url = "/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }/query/#{$scope.queryObject}"
base_url = "/api/#{ $routeParams.server }/#{ $routeParams.database }/#{ $routeParams.collection }"
if $routeParams.pipeline
base_url = "#{base_url}/pipeline/#{$routeParams.pipeline}"
else
base_url = "#{base_url}/query/#{$scope.queryObject}"
stat_url = "#{ base_url }/stats/#{$routeParams.key}"
$scope.alert=alert
$scope.chartConfig =
options:
chart:
@@ -54,8 +57,8 @@ root.controllers.controller('keyStatCtrl', ['$scope', '$routeParams', '$location
return ""
r = $routeParams
$location.path "/#{ r.server }/#{ r.database }/#{ r.collection }/stats/#{ r.key }/query/#{query}"
util.get(stat_url).then((res) ->
for key, val of res.data
$scope.stats.push({name: humanValueOfStatisticalAbreviation[key], value: val })
@@ -68,6 +71,5 @@ root.controllers.controller('keyStatCtrl', ['$scope', '$routeParams', '$location
$scope.chartConfig.series[0].data = res.data.values
$scope.chartConfig.xAxis.categories = getAxisLabel(res.data.min, res.data.step_size, res.data.values.length)
)
])
])
+6 -6
View File
@@ -5,16 +5,16 @@ joinArray = (a, b)->
return a
root.controllers.controller('topBarCtrl', ['$scope', '$location', ($scope, $location) ->
$scope.loading = false
$scope.$on('$routeChangeSuccess', (next, current) ->
$scope.path = _.filter($location.path().split("/"), (s) -> s)
if $scope.path[5] == "query"
if $scope.path[5] in ["query", "pipeline"]
$scope.path = joinArray($scope.path[0...6], $scope.path[7...-1])
$scope.getHistoryUrl = (idx) ->
ret = "#/" + ($scope.path[i] for i in [0...idx]).join("/")
if _.indexOf(["idx", "geojson", "query", "_id", "field", "all", "stats"], $scope.path[idx]) != -1
if _.indexOf(["idx", "geojson", "query", "_id", "field", "all", "stats", "pipeline"], $scope.path[idx]) != -1
return ""
if idx == 0
ret += "servers"
@@ -28,7 +28,7 @@ root.controllers.controller('topBarCtrl', ['$scope', '$location', ($scope, $loca
)
$scope.$on "loading", ()->
$scope.loading = true
$scope.$on "loadingFinished", ()->
$scope.loading = false
])
])