Advertisement
Guest User

Untitled

a guest
Jun 24th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function() {
  2.     "use strict";
  3.     angular.module("neo4jApp.services").factory("Server", ["$http", "$q", "Settings",
  4.         function($http, $q, Settings) {
  5.             var Server, httpOptions, returnAndUpdate, returnAndUpdateArray, returnAndUpdateObject;
  6.             return httpOptions = {
  7.                 timeout: 1e3 * Settings.maxExecutionTime
  8.             }, returnAndUpdate = function(Type, promise) {
  9.                 var rv;
  10.                 return rv = new Type, promise.success(function(r) {
  11.                     return angular.isArray(rv) ? rv.push.apply(rv, r) : angular.extend(rv, r)
  12.                 }), rv
  13.             }, returnAndUpdateArray = function(promise) {
  14.                 return returnAndUpdate(Array, promise)
  15.             }, returnAndUpdateObject = function(promise) {
  16.                 return returnAndUpdate(Object, promise)
  17.             }, new(Server = function() {
  18.                 function Server() {}
  19.                 return Server.prototype.options = function(path, options) {
  20.                     return null == path && (path = ""), null == options && (options = {}), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), options.method = "OPTIONS", options.url = path, $http(options)
  21.                 }, Server.prototype.head = function(path, options) {
  22.                     return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.head(path, options || httpOptions)
  23.                 }, Server.prototype["delete"] = function(path, data) {
  24.                     return null == path && (path = ""), null == data && (data = null), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http["delete"](path, httpOptions)
  25.                 }, Server.prototype.get = function(path, options) {
  26.                     return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.get(path, options || httpOptions)
  27.                 }, Server.prototype.post = function(path, data) {
  28.                     return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.post(path, data, httpOptions)
  29.                 }, Server.prototype.put = function(path, data) {
  30.                     return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.put(path, data, httpOptions)
  31.                 }, Server.prototype.transaction = function(opts) {
  32.                     var method, path, s, statements, _i, _len;
  33.                     for (opts = angular.extend({
  34.                         path: "",
  35.                         statements: [],
  36.                         method: "post"
  37.                     }, opts), path = opts.path, statements = opts.statements, method = opts.method, path = Settings.endpoint.transaction + path, method = method.toLowerCase(), _i = 0, _len = statements.length; _len > _i; _i++) s = statements[_i], s.resultDataContents = ["row", "graph"], s.includeStats = !0;
  38.                     return "function" == typeof this[method] ? this[method](path, {
  39.                         statements: statements
  40.                     }) : void 0
  41.                 }, Server.prototype.console = function(command, engine) {
  42.                     return null == engine && (engine = "shell"), this.post(Settings.endpoint.console, {
  43.                         command: command,
  44.                         engine: engine
  45.                     })
  46.                 }, Server.prototype.cypher = function(path, data) {
  47.                     return null == path && (path = ""), this.post("" + Settings.endpoint.cypher + path, data)
  48.                 }, Server.prototype.jmx = function(query) {
  49.                     return this.post(Settings.endpoint.jmx, query)
  50.                 }, Server.prototype.labels = function() {
  51.                     return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/labels"))
  52.                 }, Server.prototype.relationships = function() {
  53.                     return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/relationship/types"))
  54.                 }, Server.prototype.propertyKeys = function() {
  55.                     return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/propertykeys"))
  56.                 }, Server.prototype.typeNames = function() {
  57.                     var json = '{'
  58.                             + '"query" : "MATCH n RETURN n.typeName LIMIT 10"'
  59.                             + '}';
  60.                     $http.post("http://localhost:7474/db/data/cypher", json).then(function(response) {
  61.                         var data = response.data;
  62.                         console.log(data);
  63.                         return data;
  64.                     });
  65.                 }, Server.prototype.info = function() {
  66.                     return returnAndUpdateObject(this.get(Settings.endpoint.rest + "/"))
  67.                 }, Server.prototype.status = function(params) {
  68.                     return null == params && (params = ""), this.options("/db/data", {
  69.                         timeout: 1e3 * Settings.heartbeat
  70.                     })
  71.                 }, Server.prototype.log = function(path) {
  72.                     return this.get(path).then(function(r) {
  73.                         return console.log(r)
  74.                     })
  75.                 }, Server.prototype.hasData = function() {
  76.                     var q;
  77.                     return q = $q.defer(), this.cypher("?profile=true", {
  78.                         query: "MATCH (n) RETURN ID(n) LIMIT 1"
  79.                     }).success(function(r) {
  80.                         return q.resolve(1 === r.plan.rows)
  81.                     }).error(q.reject), q.promise
  82.                 }, Server
  83.             }())
  84.         }
  85.     ])
  86. }.call(this),
  87. function() {
  88.     "use strict";
  89.     angular.module("neo4jApp.controllers").config(function($provide, $compileProvider, $filterProvider, $controllerProvider) {
  90.         return $controllerProvider.register("MainCtrl", ["$rootScope", "$window", "Server", "Settings", "motdService",
  91.             function($scope, $window, Server, Settings, motdService) {
  92.                 var license, refresh;
  93.                 return refresh = function() {
  94.                     return $scope.labels = Server.labels(), $scope.relationships = Server.relationships(), $scope.propertyKeys = Server.propertyKeys(), $scope.typeNames = Server.typeNames(), $scope.server = Server.info(), $scope.host = $window.location.host
  95.                 }, $scope.motd = motdService, $scope.neo4j = license = {
  96.                     type: "GPLv3",
  97.                     url: "http://www.gnu.org/licenses/gpl.html",
  98.                     edition: "Enterprise",
  99.                     hasData: Server.hasData()
  100.                 }, $scope.$on("db:changed:labels", refresh), $scope.today = Date.now(), $scope.cmdchar = Settings.cmdchar, $scope.goodBrowser = "Microsoft Internet Explorer" !== navigator.appName && -1 === navigator.userAgent.indexOf("Trident"), Server.jmx(["org.neo4j:instance=kernel#0,name=Configuration", "org.neo4j:instance=kernel#0,name=Kernel", "org.neo4j:instance=kernel#0,name=Store file sizes"]).success(function(response) {
  101.                     var a, r, _i, _len, _results;
  102.                     for ($scope.kernel = {}, _results = [], _i = 0, _len = response.length; _len > _i; _i++) r = response[_i], _results.push(function() {
  103.                         var _j, _len1, _ref, _results1;
  104.                         for (_ref = r.attributes, _results1 = [], _j = 0, _len1 = _ref.length; _len1 > _j; _j++) a = _ref[_j], _results1.push($scope.kernel[a.name] = a.value);
  105.                         return _results1
  106.                     }());
  107.                     return _results
  108.                 }), $scope.$watch("offline", function(serverIsOffline) {
  109.                     return serverIsOffline ? void 0 : refresh()
  110.                 }), $scope.$watch("server", function(val) {
  111.                     return $scope.neo4j.version = val.neo4j_version
  112.                 }, !0), refresh()
  113.             }
  114.         ])
  115.     }).run(["$rootScope", "Editor",
  116.         function() {}
  117.     ])
  118. }.call(this),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement