[Groonga-commit] groonga/gcs-console [master] Implement DefineIndexField operation

Back to archive index

Yoji SHIDARA null+****@clear*****
Tue Nov 6 16:53:37 JST 2012


Yoji SHIDARA	2012-11-06 16:53:37 +0900 (Tue, 06 Nov 2012)

  New Revision: 544edabc6134760de6a90e2450aa7f0f71d3a9ad
  https://github.com/groonga/gcs-console/commit/544edabc6134760de6a90e2450aa7f0f71d3a9ad

  Log:
    Implement DefineIndexField operation

  Modified files:
    app.js
    routes/index.js
    test/index-fields.test.js
    views/domain-index-fields.jade

  Modified: app.js (+1 -0)
===================================================================
--- app.js    2012-11-06 16:48:02 +0900 (fb3506a)
+++ app.js    2012-11-06 16:53:37 +0900 (e2adfe2)
@@ -45,6 +45,7 @@ function setupApplication(app) {
   app.get('/domain/:name/index_fields', auth, routes.domainIndexFields);
   app.get('/domain_create', auth, routes.domainCreate);
   app.post('/domain_create', auth, routes.domainCreatePost);
+  app.post('/domain/:name/index_fields', auth, routes.domainCreateIndexField);
   app.delete('/domain/:name', auth, routes.domainDelete);
 }
 

  Modified: routes/index.js (+36 -8)
===================================================================
--- routes/index.js    2012-11-06 16:48:02 +0900 (ad82ca0)
+++ routes/index.js    2012-11-06 16:53:37 +0900 (33ea839)
@@ -42,6 +42,16 @@ function convertToArray(data) {
   }
 }
 
+function errorToRender(error) {
+  var errorToRender = null;
+  try {
+    errorToRender = new Error(error.Body.Response.Errors.Error.Message);
+  } catch(e) {
+    errorToRender = e;
+  }
+  return errorToRender;
+}
+
 exports.domain = function(req, res) {
   withDomain(req, res, function(req, res) {
     res.render('domain-show', {
@@ -162,18 +172,11 @@ exports.domainCreatePost = function(req, res) {
         return;
       }
 
-      var errorToRender = null;
-      try {
-        errorToRender = new Error(error.Body.Response.Errors.Error.Message)
-      } catch(e) {
-        errorToRender = e;
-      };
-
       res.render('domain-create', {
         action: "domain_create",
         domain: null,
         creatingDomainName: domainName,
-        error: errorToRender
+        error: errorToRender(error)
       });
       return;
     }
@@ -198,3 +201,28 @@ exports.domainDelete = function(req, res) {
     res.redirect('/');
   });
 };
+
+exports.domainCreateIndexField = function(req, res) {
+  withDomain(req, res, function(req, res) {
+    req.cloudsearch.DefineIndexField({
+      DomainName: req.domain.DomainName,
+      IndexField: {
+        IndexFieldName: req.body.name,
+        IndexFieldType: req.body.type
+      }
+    }, function(error, data) {
+      if (error) {
+        res.status(500);
+        res.render('domain-index-fields', {
+          error: errorToRender(error),
+          action: 'domain_index_fields',
+          domain: req.domain,
+          indexFields: req.indexFields
+        });
+        return;
+      }
+      req.flash('info', 'IndexField successfully created');
+      res.redirect('/domain/' + req.domain.DomainName);
+    });
+  });
+};

  Modified: test/index-fields.test.js (+8 -1)
===================================================================
--- test/index-fields.test.js    2012-11-06 16:48:02 +0900 (fa74e65)
+++ test/index-fields.test.js    2012-11-06 16:53:37 +0900 (dc4daf9)
@@ -11,7 +11,7 @@ suite('dashboard', function() {
     target.teardown()
   });
 
-  test('Create domain and navigate to index fields tab', function(done) {
+  test('Create domain and add an index field', function(done) {
     var browser = new Browser();
     browser
       .visit(target.rootURL)
@@ -28,6 +28,13 @@ suite('dashboard', function() {
       .then(function() {
         assert.equal(browser.location.pathname, "/domain/test/index_fields");
       })
+      .then(function() {
+        browser.fill('name', 'test');
+        return browser.pressButton('Create')
+      })
+      .then(function() {
+        assert.equal(browser.text(".alert"), "IndexField successfully created");
+      })
       .then(done, done);
   });
 });

  Modified: views/domain-index-fields.jade (+18 -0)
===================================================================
--- views/domain-index-fields.jade    2012-11-06 16:48:02 +0900 (ff93ffb)
+++ views/domain-index-fields.jade    2012-11-06 16:53:37 +0900 (92aa138)
@@ -22,3 +22,21 @@ block domain-content
           default
             td
             td
+
+  .well
+    form(action="/domain/"+domain.DomainName+"/index_fields", method="POST").form-horizontal
+      legend Create an index field
+      .control-group
+        label.control-label Name
+        .controls
+          input(type="text", name="name")
+      .control-group
+        label.control-label Type
+        .controls
+          select(type="text", name="type")
+            option(value="text") text
+            option(value="literal") literal
+            option(value="uint") uint
+      .control-group
+        .controls
+          button.btn(type="submit").btn-primary Create
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index