[Groonga-commit] groonga/groonga-admin at 2af9608 [master] Create function for each doe block

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Nov 4 14:53:04 JST 2014


Kouhei Sutou	2014-11-04 14:53:04 +0900 (Tue, 04 Nov 2014)

  New Revision: 2af96088cb1063bb53d8af32997001efe7ec855b
  https://github.com/groonga/groonga-admin/commit/2af96088cb1063bb53d8af32997001efe7ec855b

  Message:
    Create function for each doe block

  Modified files:
    app/scripts/controllers/table-search-controller.js

  Modified: app/scripts/controllers/table-search-controller.js (+79 -65)
===================================================================
--- app/scripts/controllers/table-search-controller.js    2014-11-04 14:46:16 +0900 (767b4d7)
+++ app/scripts/controllers/table-search-controller.js    2014-11-04 14:53:04 +0900 (607973c)
@@ -9,20 +9,27 @@
  */
 angular.module('groongaAdminApp')
   .controller('TableSearchController', function ($scope, $routeParams, $location, $http) {
-    $scope.table = $routeParams.table;
-    $scope.style = 'table';
-    $scope.rawData = [];
-    $scope.columns = [];
-    $scope.records = [];
-    $scope.indexedColumns = [];
-    $scope.outputColumns = [];
-    $scope.commandLine = '';
-    $scope.message = '';
-    $scope.elapsedTimeInMilliseconds = 0;
-    $scope.nTotalRecords = 0;
-    $scope.parameters = angular.copy($location.search());
+    var client = new GroongaClient($http);
+
+    function initialize() {
+      $scope.table = $routeParams.table;
+      $scope.style = 'table';
+      $scope.rawData = [];
+      $scope.columns = [];
+      $scope.records = [];
+      $scope.indexedColumns = [];
+      $scope.outputColumns = [];
+      $scope.commandLine = '';
+      $scope.message = '';
+      $scope.elapsedTimeInMilliseconds = 0;
+      $scope.nTotalRecords = 0;
+      $scope.parameters = angular.copy($location.search());
 
-    $scope.search = function() {
+      $scope.search = search;
+      $scope.clear  = clear;
+    }
+
+    function search() {
       var matchColumns = $scope.indexedColumns
           .filter(function(indexedColumn) {
             return indexedColumn.inUse;
@@ -46,17 +53,17 @@ angular.module('groongaAdminApp')
                                         'output_columns': outputColumns
                                       });
       $location.search(parameters);
-    };
+    }
 
-    $scope.clear = function() {
+    function clear() {
       $location.search({});
-    };
+    }
 
-    var client = new GroongaClient($http);
-    client.execute('table_list')
-      .success(function(response) {
-        response.tables().forEach(function(table) {
-          client.execute('column_list', {table: table.name})
+    function fillOptions() {
+      client.execute('table_list')
+        .success(function(response) {
+          response.tables().forEach(function(table) {
+            client.execute('column_list', {table: table.name})
             .success(function(response) {
               response.columns().forEach(function(column) {
                 if (!column.isIndex) {
@@ -76,54 +83,61 @@ angular.module('groongaAdminApp')
                 });
               });
             });
+          });
         });
-      });
 
-    client.execute('column_list', {table: $scope.table})
-      .success(function(response) {
-        var outputColumns = $scope.parameters.output_columns;
-        console.log(response.columns());
-        response.columns().forEach(function(column) {
-          if (column.isIndex) {
-            return;
-          }
-          var inUse = true;
-          if (outputColumns) {
-            inUse = outputColumns.indexOf(column.name) !== -1;
-          }
-          $scope.outputColumns.push({name: column.name, inUse: inUse});
+      client.execute('column_list', {table: $scope.table})
+        .success(function(response) {
+          var outputColumns = $scope.parameters.output_columns;
+          console.log(response.columns());
+          response.columns().forEach(function(column) {
+            if (column.isIndex) {
+              return;
+            }
+            var inUse = true;
+            if (outputColumns) {
+              inUse = outputColumns.indexOf(column.name) !== -1;
+            }
+            $scope.outputColumns.push({name: column.name, inUse: inUse});
+          });
         });
-      });
+    }
 
-    var parameters = {
-      table: $scope.table
-    };
-    angular.forEach($scope.parameters, function(value, key) {
-      if (key in parameters) {
-        return;
-      }
-      parameters[key] = value;
-    });
-    var request = client.execute('select', parameters);
-    request.success(function(response) {
-      $scope.rawData = response.rawData();
-      $scope.commandLine = request.commandLine();
-      $scope.elapsedTimeInMilliseconds = response.elapsedTime() * 1000;
-      if (!response.isSuccess()) {
-        $scope.message =
-          'Failed to call "select" command: ' + response.errorMessage();
-        $scope.nTotalRecords = 0;
-        return;
-      }
-      $scope.nTotalRecords = response.nTotalRecords();
-      $scope.columns = response.columns();
-      $scope.records = response.records().map(function(record) {
-        return record.map(function(value, index) {
-          return {
-            value: value,
-            column: $scope.columns[index]
-          };
+    function select() {
+      var parameters = {
+        table: $scope.table
+      };
+      angular.forEach($scope.parameters, function(value, key) {
+        if (key in parameters) {
+          return;
+        }
+        parameters[key] = value;
+      });
+      var request = client.execute('select', parameters);
+      request.success(function(response) {
+        $scope.rawData = response.rawData();
+        $scope.commandLine = request.commandLine();
+        $scope.elapsedTimeInMilliseconds = response.elapsedTime() * 1000;
+        if (!response.isSuccess()) {
+          $scope.message =
+            'Failed to call "select" command: ' + response.errorMessage();
+          $scope.nTotalRecords = 0;
+          return;
+        }
+        $scope.nTotalRecords = response.nTotalRecords();
+        $scope.columns = response.columns();
+        $scope.records = response.records().map(function(record) {
+          return record.map(function(value, index) {
+            return {
+              value: value,
+              column: $scope.columns[index]
+            };
+          });
         });
       });
-    });
+    }
+
+    initialize();
+    fillOptions();
+    select();
   });
-------------- next part --------------
HTML����������������������������...
下載 



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