Example #1
0
exports.register = function() {
  assert.is(settings.getSetting('tempTBool'),
            mockSettings.tempTBool,
            'tempTBool exists before');

  settings.removeSetting(mockSettings.tempTBoolSpec);
  assert.is(settings.getSetting('tempTBool'),
            undefined,
            'tempTBool remove by obj');

  mockSettings.tempTBool = settings.addSetting(mockSettings.tempTBoolSpec);
  assert.is(settings.getSetting('tempTBool'),
            mockSettings.tempTBool,
            'tempTBool re-added 1');

  settings.removeSetting('tempTBool');
  assert.is(settings.getSetting('tempTBool'),
            undefined,
            'tempTBool remove by name');

  mockSettings.tempTBool = settings.addSetting(mockSettings.tempTBoolSpec);
  assert.is(settings.getSetting('tempTBool'),
            mockSettings.tempTBool,
            'tempTBool re-added 2');
};
Example #2
0
 items.forEach(function(item) {
   // Some items are registered using the constructor so we need to check
   // the prototype for the the type of the item
   var type = item.item;
   if (type == null && item.prototype) {
       type = item.prototype.item;
   }
   if (type === 'command') {
     canon.addCommand(item);
   }
   else if (type === 'type') {
     types.addType(item);
   }
   else if (type === 'converter') {
     converters.addConverter(item);
   }
   else if (type === 'setting') {
     settings.addSetting(item);
   }
   else if (type === 'field') {
     fields.addField(item);
   }
   else {
     console.error('Error for: ', item);
     throw new Error('item property not found');
   }
 });
Example #3
0
exports.startup = function() {
  exports.allowSet = settings.addSetting(allowSetSettingSpec);

  canon.addCommand(prefCmdSpec);
  canon.addCommand(prefShowCmdSpec);
  canon.addCommand(prefSetCmdSpec);
  canon.addCommand(prefResetCmdSpec);
};
Example #4
0
exports.startup = function() {
  eagerHelper = settings.addSetting(eagerHelperSettingSpec);
};
Example #5
0
 exports.startup = function() {
   hideIntro = settings.addSetting(hideIntroSettingSpec);
 };
Example #6
0
define(function(require, exports, module) {

  var settings = require('gcli/settings');

  require('gcli/index');

  require('gcli/commands/pref').startup();

  help = require('gcli/commands/help');
  help.startup();

  require('neo4j/commands/intro').startup();
  require('neo4j/commands/cypher').startup();
  require('neo4j/commands/start').startup();
  require('neo4j/commands/match').startup();
  require('neo4j/commands/where').startup();
  require('neo4j/commands/create').startup();
  require('neo4j/commands/relate').startup();
  var canon = require('gcli/canon');

  canon.commandOutputManager.onOutput.add(function(ev) {
    console.log('output has changed');
  });

  help.helpManHtml = require('text!neo4j/commands/help_man.html');
  help.helpListHtml = require('text!neo4j/commands/help_list.html');
  help.helpCss = require('text!neo4j/commands/help.css');

  var helpIntroHtmlSettingSpec = {
    name: 'helpIntroHtml',
    type: 'html',
    description: 'HTML snippet to display as intro to help',
    defaultValue: require('text!neo4j/commands/help_intro.html')
  };
  var helpIntroHtml = settings.addSetting(helpIntroHtmlSettingSpec);

  var cypherHtmlSettingSpec = {
    name: 'cypherHtml',
    type: 'html',
    description: 'HTML snippet to display cypher query result',
    defaultValue: require('text!neo4j/commands/cypher-table.html')
  };

  var cypherHtml =  settings.addSetting(cypherHtmlSettingSpec);

  var cypherUrlSettingSpec = {
    name: 'cypherUrl',
    type: 'string',
    description: 'URL of Cypher REST endpoint',
    defaultValue: '/cypher'
  };
  var cypherUrl = settings.addSetting(cypherUrlSettingSpec);

  var cypherPostTypeSettingSpec = {
    name: 'cypherPostType',
    type: { name: 'selection', data: [ 'text/plain', 'application/json'] },
    description: 'Content type for Cypher query POSTs',
    defaultValue: 'text/plain'
  };
  var cypherPostType = settings.addSetting(cypherPostTypeSettingSpec);

  exports.query = function(cql, context) {
    
    var promise = context.createPromise();

    function onFailure(msg) {
      promise.resolve(msg);
    }

    queryCypher(cql, function(json) {
      promise.resolve(context.createView({
        html: cypherHtml.value,
        data: { "result": json },
        options: { allowEval:true },
        css: require('text!neo4j/commands/cypher_result.css'),
        cssId: 'cypher-result-table'
      }));
    }, onFailure);

    return promise;
  }

  function queryCypher(query, onSuccess, onFailure) {
    var url = cypherUrl.value;

    var req = new XMLHttpRequest();
    req.open('POST', url, true);
    req.setRequestHeader('Accept', 'application/json');
    req.setRequestHeader('Content-type', cypherPostType.value);
    req.onreadystatechange = function(event) {
      if (req.readyState == 4) {
        if (req.status == 400) {
          onFailure(req.responseText);
          return;
        } else if (req.status >= 300 || req.status < 200) {
          onFailure('Error: ' + JSON.stringify(req));
          return;
        }

        var json;
        try {
          json = JSON.parse(req.responseText);
        }
        catch (ex) {
          onFailure('Invalid response: ' + ex + ': ' + req.responseText);
          return;
        }

        if (json.error) {
          onFailure('Error: ' + json.error.message);
          return;
        }

        onSuccess(json);

      }
    }.bind(this);
    if (cypherPostType.value==='application/json') {
      query = '{\"query\":\"'+query+'\" }'
    }
    req.send(query);
  }

});