1
0
Fork 0

Added a more precise information returned from gharial for collections

This commit is contained in:
Michael Hackstein 2014-09-09 12:53:31 +02:00
parent 3a695c15fd
commit 449936b99e
1 changed files with 47 additions and 3 deletions

View File

@ -32,6 +32,7 @@
var FoxxController = require("org/arangodb/foxx").Controller, var FoxxController = require("org/arangodb/foxx").Controller,
controller = new FoxxController(applicationContext), controller = new FoxxController(applicationContext),
cluster = require("org/arangodb/cluster"),
ArangoError = require("org/arangodb").ArangoError, ArangoError = require("org/arangodb").ArangoError,
actions = require("org/arangodb/actions"), actions = require("org/arangodb/actions"),
Model = require("org/arangodb/foxx").Model, Model = require("org/arangodb/foxx").Model,
@ -43,6 +44,41 @@
toId = function(c, k) { toId = function(c, k) {
return c + "/" + k; return c + "/" + k;
}, },
collectionRepresentation = function(collection, showProperties, showCount, showFigures) {
var result = {};
result.id = collection._id;
result.name = collection.name();
result.isSystem = (result.name.charAt(0) === '_');
if (showProperties) {
var properties = collection.properties();
result.doCompact = properties.doCompact;
result.isVolatile = properties.isVolatile;
result.journalSize = properties.journalSize;
result.keyOptions = properties.keyOptions;
result.waitForSync = properties.waitForSync;
if (cluster.isCoordinator()) {
result.shardKeys = properties.shardKeys;
result.numberOfShards = properties.numberOfShards;
}
}
if (showCount) {
result.count = collection.count();
}
if (showFigures) {
var figures = collection.figures();
if (figures) {
result.figures = figures;
}
}
result.status = collection.status();
result.type = collection.type();
return result;
},
buildError = function(err, code) { buildError = function(err, code) {
return { return {
error: true, error: true,
@ -366,9 +402,17 @@
controller.get("/:graph/vertex", function(req, res) { controller.get("/:graph/vertex", function(req, res) {
var name = req.params("graph"); var name = req.params("graph");
var g = Graph._graph(name); var g = Graph._graph(name);
setResponse(res, "collections", _.map(g._vertexCollections(), function(c) { var mapFunc;
if (req.params("collectionObjects")) {
mapFunc = function(c) {
return collectionRepresentation(c, false, false, false);
};
} else {
mapFunc = function(c) {
return c.name(); return c.name();
}).sort(), actions.HTTP_OK); };
}
setResponse(res, "collections", _.map(g._vertexCollections(), mapFunc).sort(), actions.HTTP_OK);
}) })
.pathParam("graph", { .pathParam("graph", {
type: graphName type: graphName