From 41552040cc7736e856f7d384e2cd2ad2cf19ff1b Mon Sep 17 00:00:00 2001 From: didier amyot Date: Fri, 10 Apr 2015 08:16:46 -0700 Subject: [PATCH] added objectid timestamp to the user interface the logic is done on the client. --- client/coffee/directives/value.coffee | 19 +++++++++++++------ client/coffee/services.coffee | 14 +++++++++++--- client/partials/directives/value.html | 8 +++++--- params.yml | 19 ++++++++++++++++++- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/client/coffee/directives/value.coffee b/client/coffee/directives/value.coffee index 2d8046f..9a3cd3d 100644 --- a/client/coffee/directives/value.coffee +++ b/client/coffee/directives/value.coffee @@ -1,6 +1,6 @@ directive = () -> - directive = + directive = templateUrl: "/partials/directives/value.html" replace: true, transclude: false, @@ -10,13 +10,13 @@ directive = () -> docId: "=" key: "=" expended: "=" - controller:["$scope", "$routeParams", ($scope, $routeParams) -> + controller:["$scope", "$routeParams", "util", ($scope, $routeParams, util) -> $scope.isSmallString = (str)-> if not _.isString(str) return false rgx = str.match(/\n/g) or [] return str.length < 1000 and rgx.length < 20 - + $scope.isSmallObject = (obj) -> return $scope.isSmallString(JSON.stringify(obj, null, 4)) @@ -28,15 +28,22 @@ directive = () -> rp = $routeParams s = $scope return "#/#{rp.server}/#{rp.database}/#{rp.collection}/_id/#{s.docId}/field/#{s.key}" - + $scope.isObjectId = (val) -> + objectIdRegexp = /^[01234567890abcdef]{24}$/ + return _.isString(val) and objectIdRegexp.test(val) + + $scope.getDateFromObjectId = (objectId) -> + util.parseObjectId(objectId).date.toISOString() + $scope.valueLength = if _.isObject($scope.value) then _.keys($scope.value).length else $scope.value.length - $scope.isString = _.isString($scope.value) + $scope.isObjectId = $scope.isObjectId($scope.value) + $scope.isString = not $scope.isObjectId and _.isString($scope.value) $scope.isNumber = _.isNumber($scope.value) $scope.isObject = _.isObject($scope.value) $scope.isArray = _.isArray($scope.value) $scope.isBoolean = _.isBoolean($scope.value) ] return directive - + directives.directive( "vulValue", [directive]) diff --git a/client/coffee/services.coffee b/client/coffee/services.coffee index 2bddd3c..edd9642 100644 --- a/client/coffee/services.coffee +++ b/client/coffee/services.coffee @@ -1,14 +1,22 @@ root = this root.services.factory('util', ['$http', '$rootScope', ($http, $rootScope)-> - service = + service = get: (params...) -> $rootScope.$broadcast("loading") return $http.get(params...). finally( () -> $rootScope.$broadcast("loadingFinished") ) - + parseObjectId: (objectIdAsString) -> + if objectIdAsString.length != 24 + throw new Error("object id string must be of length 24") + ret = + date: new Date(parseInt(objectIdAsString.substr(0, 8), 16) * 1000) + machine: parseInt(objectIdAsString.substr(8, 14), 16) + process: parseInt(objectIdAsString.substr(14, 18), 16) + counter: parseInt(objectIdAsString.substr(18, 24), 16) + return service -]); \ No newline at end of file +]); diff --git a/client/partials/directives/value.html b/client/partials/directives/value.html index e2058a3..f0eb2e5 100644 --- a/client/partials/directives/value.html +++ b/client/partials/directives/value.html @@ -1,11 +1,13 @@ + +
 {{value}}  [ {{getDateFromObjectId(value)}} ]
+
 {{value}} 
- +
 {{ getSmallPrefix(value) }} 
-
{{value | number | replaceAllCommasBySpaces}} @@ -20,4 +22,4 @@
true
false
-
\ No newline at end of file + diff --git a/params.yml b/params.yml index d30ed43..25da353 100644 --- a/params.yml +++ b/params.yml @@ -21,4 +21,21 @@ MongoServers: - name: vulture example - url: mongodb://vulture:vulture_example@ds047800.mongolab.com:47800/vulture_example \ No newline at end of file + url: mongodb://vulture:vulture_example@ds047800.mongolab.com:47800/vulture_example + + - + name: mioau + url: localhost:9999 + + + - + name: kilink + url: 192.168.82.105:27017 + + - + name: brandindex demo + url: vdev-bix.paix.yougov.local + + - + name: brandindex prod + url: vbixmgo.paix.yougov.local