[Groonga-commit] groonga/gcs [ember] Use computed properties to extract from data

Back to archive index

Yoji SHIDARA null+****@clear*****
Tue Sep 25 15:44:38 JST 2012


Yoji SHIDARA	2012-09-25 15:44:38 +0900 (Tue, 25 Sep 2012)

  New Revision: 02cde1c1dce9d2921db02eb4f9dc40696b79ea25
  https://github.com/groonga/gcs/commit/02cde1c1dce9d2921db02eb4f9dc40696b79ea25

  Log:
    Use computed properties to extract from data

  Modified files:
    public/js/gcs.js

  Modified: public/js/gcs.js (+33 -22)
===================================================================
--- public/js/gcs.js    2012-09-25 15:23:52 +0900 (04c71be)
+++ public/js/gcs.js    2012-09-25 15:44:38 +0900 (59e1d1c)
@@ -23,16 +23,44 @@ App.SearchController = Ember.ArrayController.extend({
   query: null,
   perPage: 5,
   start: 0,
-  numHits: null,
-  numReceived: null,
-  resultsAvailable: null,
-  searched: false,
+  data: null,
   numStart: function() {
     return this.get('start') + 1;
   }.property('start'),
   numEnd: function() {
     return this.get('start') + this.get('numReceived');
   }.property('numReceived', 'start'),
+  searched: function() {
+    return !!this.data;
+  }.property('data'),
+  resultsAvailable: function() {
+    return this.data && this.data.hits.found > 0;
+  }.property('data'),
+  numHits: function() {
+    return this.data ? this.data.hits.found : 0;
+  }.property('data'),
+  numReceived: function() {
+    return this.data ? this.data.hits.hit.length : 0;
+  }.property('data'),
+  content: function() {
+    var data = this.get('data');
+    if (!data) {
+      return [];
+    }
+    var numStart = this.get('numStart');
+    var content = data.hits.hit.map(function(hit, index) {
+      var pairs = [];
+      jQuery.each(hit.data, function(columnName, value) {
+        pairs.push({columnName: columnName, value: value});
+      });
+      return {
+        index: numStart + index,
+        id: hit.id,
+        data: pairs
+      };
+    });
+    return content;
+  }.property('data'),
   urlForRawRequest: function() {
     var domain = App.currentDomain;
     var searchEndpoint = 'http://' + domain.endpoint + '/2011-02-01/search';
@@ -56,9 +84,7 @@ App.SearchController = Ember.ArrayController.extend({
     var domain = App.currentDomain;
     var searchEndpoint = 'http://' + domain.endpoint + '/2011-02-01/search';
 
-    var perPage = this.get('perPage');
     var params = this.get('paramsForRequest');
-    var start = this.get('start');
     var self = this;
     $.ajax({
       type: 'GET',
@@ -66,22 +92,7 @@ App.SearchController = Ember.ArrayController.extend({
       data: params,
       dataType: 'jsonp',
       success: function(data) {
-        self.set('searched', true);
-        self.set('resultsAvailable', data.hits.found > 0);
-        self.set('numHits', data.hits.found);
-        self.set('numReceived', data.hits.hit.length);
-        var content = data.hits.hit.map(function(hit, index) {
-          var pairs = [];
-          jQuery.each(hit.data, function(columnName, value) {
-            pairs.push({columnName: columnName, value: value});
-          });
-          return {
-            index: start + index + 1,
-            id: hit.id,
-            data: pairs
-          };
-        });
-        self.set('content', content);
+        self.set('data', data);
       }
     });
   }
-------------- next part --------------
HTML����������������������������...
Download 



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