[Groonga-commit] groonga/groonga-admin at a34642c [master] Implement search result show page

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Oct 22 17:27:37 JST 2014


Kouhei Sutou	2014-10-22 17:27:37 +0900 (Wed, 22 Oct 2014)

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

  Message:
    Implement search result show page

  Added files:
    app/scripts/controllers/table-search-controller.js
    app/scripts/groonga-response.js
    app/scripts/groonga-response/select.js
    app/views/tables/search.html
  Modified files:
    app/index.html
    app/scripts/app.js
    app/styles/main.scss

  Modified: app/index.html (+3 -1)
===================================================================
--- app/index.html    2014-10-22 17:07:11 +0900 (bb53fc0)
+++ app/index.html    2014-10-22 17:27:37 +0900 (70ba68f)
@@ -71,9 +71,11 @@
     <!-- endbuild -->
 
         <!-- build:js({.tmp,app}) scripts/scripts.js -->
+        <script src="scripts/groonga-response.js"></script>
+        <script src="scripts/groonga-response/select.js"></script>
         <script src="scripts/app.js"></script>
         <script src="scripts/controllers/main.js"></script>
-        <script src="scripts/controllers/about.js"></script>
+        <script src="scripts/controllers/table-search-controller.js"></script>
         <!-- endbuild -->
 </body>
 </html>

  Modified: app/scripts/app.js (+3 -3)
===================================================================
--- app/scripts/app.js    2014-10-22 17:07:11 +0900 (2c9fdcc)
+++ app/scripts/app.js    2014-10-22 17:27:37 +0900 (c025efb)
@@ -23,9 +23,9 @@ angular
         templateUrl: 'views/main.html',
         controller: 'MainCtrl'
       })
-      .when('/about', {
-        templateUrl: 'views/about.html',
-        controller: 'AboutCtrl'
+      .when('/tables/:table/search', {
+        templateUrl: 'views/tables/search.html',
+        controller: 'TableSearchController'
       })
       .otherwise({
         redirectTo: '/'

  Added: app/scripts/controllers/table-search-controller.js (+37 -0) 100644
===================================================================
--- /dev/null
+++ app/scripts/controllers/table-search-controller.js    2014-10-22 17:27:37 +0900 (fe7811a)
@@ -0,0 +1,37 @@
+'use strict';
+
+/**
+ * @ngdoc function
+ * @name groongaAdminApp.controller:TableSearchController
+ * @description
+ * # TableSearchController
+ * Controller of the groongaAdminApp
+ */
+angular.module('groongaAdminApp')
+  .controller('TableSearchController', function ($scope, $routeParams, $http) {
+    $scope.table = $routeParams.table;
+    $scope.columns = [];
+    $scope.records = [];
+    $scope.message = '';
+    $scope.elapsedTimeInMilliseconds = 0;
+    $scope.nTotalRecords = 0;
+
+    var parameters = {
+      table: $scope.table,
+      callback: 'JSON_CALLBACK'
+    };
+    $http.jsonp('/d/select.json', {params: parameters})
+      .success(function(data) {
+        var response = new window.GroongaResponse.Select(data);
+        $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();
+      });
+  });

  Added: app/scripts/groonga-response.js (+4 -0) 100644
===================================================================
--- /dev/null
+++ app/scripts/groonga-response.js    2014-10-22 17:27:37 +0900 (8638b2b)
@@ -0,0 +1,4 @@
+'use strict';
+
+window.GroongaResponse = {
+};

  Added: app/scripts/groonga-response/select.js (+55 -0) 100644
===================================================================
--- /dev/null
+++ app/scripts/groonga-response/select.js    2014-10-22 17:27:37 +0900 (8d3cfd9)
@@ -0,0 +1,55 @@
+'use strict';
+
+(function() {
+  function Select(rawData) {
+    this._rawData = rawData;
+  }
+  window.GroongaResponse.Select = Select;
+
+  Select.prototype.header = function() {
+    return this._rawData[0];
+  };
+
+  Select.prototype.status = function() {
+    return this.header()[0];
+  };
+
+  Select.prototype.isSuccess = function() {
+    return this.status() === 0;
+  };
+
+  Select.prototype.startTime = function() {
+    var startTime = new Date();
+    startTime.setTime(this.header()[1]);
+    return startTime;
+  };
+
+  Select.prototype.elapsedTime = function() {
+    return this.header()[2];
+  };
+
+  Select.prototype.errorMessage = function() {
+    return this.header()[3];
+  };
+
+  Select.prototype.body = function() {
+    return this._rawData[1];
+  };
+
+  Select.prototype.nTotalRecords = function() {
+    return this.body()[0][0][0];
+  };
+
+  Select.prototype.columns = function() {
+    return this.body()[0][1].map(function(rawDefinition) {
+      return {
+        name: rawDefinition[0],
+        type: rawDefinition[1]
+      };
+    });
+  };
+
+  Select.prototype.records = function() {
+    return this.body()[0].slice(2);
+  };
+})();

  Modified: app/styles/main.scss (+8 -0)
===================================================================
--- app/styles/main.scss    2014-10-22 17:07:11 +0900 (8cac086)
+++ app/styles/main.scss    2014-10-22 17:27:37 +0900 (31f8372)
@@ -68,6 +68,14 @@ body {
   }
 }
 
+table.search-result {
+  @extend .table;
+  @extend .table-striped;
+  @extend .table-bordered;
+  @extend .table-hover;
+  @extend .table-condensed;
+}
+
 /* Responsive: Portrait tablets and up */
 @media screen and (min-width: 768px) {
   /* Remove the padding we set earlier */

  Added: app/views/tables/search.html (+30 -0) 100644
===================================================================
--- /dev/null
+++ app/views/tables/search.html    2014-10-22 17:27:37 +0900 (773fb91)
@@ -0,0 +1,30 @@
+<div ng-controller="TableSearchController">
+  <h1>Search</h1>
+  <div class="container">
+    <p class="error-message">{{message}}</p>
+    <p class="statistics">
+      <span id="elapsed-time">{{elapsedTimeInMilliseconds | number : 3}}ms</span>
+      <span id="n-total-records">({{nTotalRecords}})</span>
+    </p>
+  </div>
+  <div class="container">
+    <div class="table-responsive">
+      <table class="search-result">
+        <thead>
+          <tr>
+            <th ng-repeat="column in columns track by $index">
+              {{column.name}}
+            </th>
+          </tr>
+        </thead>
+        <tbody>
+          <tr ng-repeat="record in records track by $index">
+            <td ng-repeat="row in record track by $index">
+              {{row}}
+            </td>
+          </tr>
+        </tbody>
+      </table>
+    </div>
+  </div>
+</div>
-------------- next part --------------
HTML����������������������������...
Download 



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