[Groonga-commit] groonga/groonga-admin at 77cbeb1 [master] Export raw column parser

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Dec 31 16:49:02 JST 2014


Kouhei Sutou	2014-12-31 16:49:02 +0900 (Wed, 31 Dec 2014)

  New Revision: 77cbeb1a7762c8f9cda1f949fee3760dfe6edfd2
  https://github.com/groonga/groonga-admin/commit/77cbeb1a7762c8f9cda1f949fee3760dfe6edfd2

  Message:
    Export raw column parser

  Modified files:
    app/scripts/groonga-client/response/column-list.js
    app/scripts/services/schema-loader.js

  Modified: app/scripts/groonga-client/response/column-list.js (+38 -22)
===================================================================
--- app/scripts/groonga-client/response/column-list.js    2014-12-31 16:29:25 +0900 (c6c0079)
+++ app/scripts/groonga-client/response/column-list.js    2014-12-31 16:49:02 +0900 (bd1851c)
@@ -19,29 +19,45 @@
   };
 
   ColumnList.prototype.columns = function() {
+    return this.body().slice(1).map(function(rawColumn) {
+      return this.parseRawColumn(rawColumn);
+    }, this);
+  };
+
+  ColumnList.prototype.parseRawColumn = function(rawColumn) {
     var parameters = this.parameters();
-    return this.body().slice(1).map(function(columnProperties) {
-      var column = {
-        properties: {},
-        rawProperties: columnProperties
-      };
-      parameters.forEach(function(parameter, index) {
-        var name = parameter.name;
-        var value = columnProperties[index];
-        switch (parameter.name) {
-        case 'flags':
-          value = value.split('|');
-          break;
-        case 'source':
-          name = 'sources';
-          break;
-        }
-        column[name] = column.properties[name] = value;
-      });
-      column.isScalar = column.flags.indexOf('COLUMN_SCALAR') != -1;
-      column.isVector = column.flags.indexOf('COLUMN_VECTOR') != -1;
-      column.isIndex  = column.flags.indexOf('COLUMN_INDEX')  != -1;
-      return column;
+    var column = {
+      properties: {},
+      rawProperties: rawColumn
+    };
+    parameters.forEach(function(parameter, index) {
+      var name = parameter.name;
+      var value = rawColumn[index];
+      switch (parameter.name) {
+      case 'type':
+        name = 'sizeType';
+        break;
+      case 'flags':
+        value = value.split('|');
+        break;
+      case 'source':
+        name = 'sources';
+        break;
+      }
+      column[name] = column.properties[name] = value;
     });
+    column.isScalar = column.flags.indexOf('COLUMN_SCALAR') != -1;
+    column.isVector = column.flags.indexOf('COLUMN_VECTOR') != -1;
+    column.isIndex  = column.flags.indexOf('COLUMN_INDEX')  != -1;
+    if (column.isScalar) {
+      column.type = 'scalar';
+    } else if (column.isVector) {
+      column.type = 'vector';
+    } else if (column.isIndex) {
+      column.type = 'index';
+    } else {
+      column.type = 'unknown';
+    }
+    return column;
   };
 })();

  Modified: app/scripts/services/schema-loader.js (+12 -25)
===================================================================
--- app/scripts/services/schema-loader.js    2014-12-31 16:29:25 +0900 (4cfeb73)
+++ app/scripts/services/schema-loader.js    2014-12-31 16:49:02 +0900 (d663a7d)
@@ -93,38 +93,25 @@ angular.module('groongaAdminApp')
         table.columns[column.name] = column;
       }
 
-      function addIDColumn(table) {
-        var properties = {
-          id: table.id,
-          name: '_id',
-          type: 'fix',
-          flags: ['COLUMN_SCALAR', 'PERSISTENT'],
-          domain: table.name,
-          range: 'UInt32',
-          sources: []
-        };
-
-        var rawProperties = angular.copy(properties);
-        rawProperties.source = rawProperties.sources;
-        delete rawProperties.sources;
-        rawProperties.flags = rawProperties.flags.join('|');
-
-        var IDColumn = angular.copy(properties);
-        IDColumn.rawProperties = rawProperties;
-        IDColumn.properties = properties;
-
-        addColumn(table, IDColumn);
-      }
-
       function fetchColumns(table) {
         table.columns = {};
 
-        addIDColumn(table);
-
         return client.execute('column_list', {table: table.name})
           .success(function(response) {
             var columns = response.columns();
 
+            var rawIDColumn = [
+              table.id,                   // id
+              '_id',                      // name
+              table.path,                 // path
+              'fix',                      // type
+              'COLUMN_SCALAR|PERSISTENT', // flags
+              table.name,                 // domain
+              'UInt32',                   // range
+              []                          // source
+            ];
+            columns.unshift(response.parseRawColumn(rawIDColumn));
+
             columns.forEach(function(column) {
               addColumn(table, column);
             });
-------------- next part --------------
HTML����������������������������...
Descargar 



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