Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function() {
- "use strict";
- angular.module("neo4jApp.services").factory("Server", ["$http", "$q", "Settings",
- function($http, $q, Settings) {
- var Server, httpOptions, returnAndUpdate, returnAndUpdateArray, returnAndUpdateObject;
- return httpOptions = {
- timeout: 1e3 * Settings.maxExecutionTime
- }, returnAndUpdate = function(Type, promise) {
- var rv;
- return rv = new Type, promise.success(function(r) {
- return angular.isArray(rv) ? rv.push.apply(rv, r) : angular.extend(rv, r)
- }), rv
- }, returnAndUpdateArray = function(promise) {
- return returnAndUpdate(Array, promise)
- }, returnAndUpdateObject = function(promise) {
- return returnAndUpdate(Object, promise)
- }, new(Server = function() {
- function Server() {}
- return Server.prototype.options = function(path, options) {
- return null == path && (path = ""), null == options && (options = {}), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), options.method = "OPTIONS", options.url = path, $http(options)
- }, Server.prototype.head = function(path, options) {
- return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.head(path, options || httpOptions)
- }, Server.prototype["delete"] = function(path, data) {
- return null == path && (path = ""), null == data && (data = null), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http["delete"](path, httpOptions)
- }, Server.prototype.get = function(path, options) {
- return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.get(path, options || httpOptions)
- }, Server.prototype.post = function(path, data) {
- return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.post(path, data, httpOptions)
- }, Server.prototype.put = function(path, data) {
- return null == path && (path = ""), 0 !== path.indexOf(Settings.host) && (path = Settings.host + path), $http.put(path, data, httpOptions)
- }, Server.prototype.transaction = function(opts) {
- var method, path, s, statements, _i, _len;
- for (opts = angular.extend({
- path: "",
- statements: [],
- method: "post"
- }, 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;
- return "function" == typeof this[method] ? this[method](path, {
- statements: statements
- }) : void 0
- }, Server.prototype.console = function(command, engine) {
- return null == engine && (engine = "shell"), this.post(Settings.endpoint.console, {
- command: command,
- engine: engine
- })
- }, Server.prototype.cypher = function(path, data) {
- return null == path && (path = ""), this.post("" + Settings.endpoint.cypher + path, data)
- }, Server.prototype.jmx = function(query) {
- return this.post(Settings.endpoint.jmx, query)
- }, Server.prototype.labels = function() {
- return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/labels"))
- }, Server.prototype.relationships = function() {
- return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/relationship/types"))
- }, Server.prototype.propertyKeys = function() {
- return returnAndUpdateArray(this.get(Settings.endpoint.rest + "/propertykeys"))
- }, Server.prototype.typeNames = function() {
- var json = '{'
- + '"query" : "MATCH n RETURN n.typeName LIMIT 10"'
- + '}';
- $http.post("http://localhost:7474/db/data/cypher", json).then(function(response) {
- var data = response.data;
- console.log(data);
- return data;
- });
- }, Server.prototype.info = function() {
- return returnAndUpdateObject(this.get(Settings.endpoint.rest + "/"))
- }, Server.prototype.status = function(params) {
- return null == params && (params = ""), this.options("/db/data", {
- timeout: 1e3 * Settings.heartbeat
- })
- }, Server.prototype.log = function(path) {
- return this.get(path).then(function(r) {
- return console.log(r)
- })
- }, Server.prototype.hasData = function() {
- var q;
- return q = $q.defer(), this.cypher("?profile=true", {
- query: "MATCH (n) RETURN ID(n) LIMIT 1"
- }).success(function(r) {
- return q.resolve(1 === r.plan.rows)
- }).error(q.reject), q.promise
- }, Server
- }())
- }
- ])
- }.call(this),
- function() {
- "use strict";
- angular.module("neo4jApp.controllers").config(function($provide, $compileProvider, $filterProvider, $controllerProvider) {
- return $controllerProvider.register("MainCtrl", ["$rootScope", "$window", "Server", "Settings", "motdService",
- function($scope, $window, Server, Settings, motdService) {
- var license, refresh;
- return refresh = function() {
- 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
- }, $scope.motd = motdService, $scope.neo4j = license = {
- type: "GPLv3",
- url: "http://www.gnu.org/licenses/gpl.html",
- edition: "Enterprise",
- hasData: Server.hasData()
- }, $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) {
- var a, r, _i, _len, _results;
- for ($scope.kernel = {}, _results = [], _i = 0, _len = response.length; _len > _i; _i++) r = response[_i], _results.push(function() {
- var _j, _len1, _ref, _results1;
- for (_ref = r.attributes, _results1 = [], _j = 0, _len1 = _ref.length; _len1 > _j; _j++) a = _ref[_j], _results1.push($scope.kernel[a.name] = a.value);
- return _results1
- }());
- return _results
- }), $scope.$watch("offline", function(serverIsOffline) {
- return serverIsOffline ? void 0 : refresh()
- }), $scope.$watch("server", function(val) {
- return $scope.neo4j.version = val.neo4j_version
- }, !0), refresh()
- }
- ])
- }).run(["$rootScope", "Editor",
- function() {}
- ])
- }.call(this),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement