[Groonga-commit] groonga/gcs [ember] Remove Domains class

Back to archive index

Yoji SHIDARA null+****@clear*****
Thu Sep 27 17:58:00 JST 2012


Yoji SHIDARA	2012-09-27 17:58:00 +0900 (Thu, 27 Sep 2012)

  New Revision: c1d8aa57e2a16c345b5be74c31b554b7a5bc450b
  https://github.com/groonga/gcs/commit/c1d8aa57e2a16c345b5be74c31b554b7a5bc450b

  Log:
    Remove Domains class

  Modified files:
    public/js/gcs.js
    views/index.jade

  Modified: public/js/gcs.js (+25 -39)
===================================================================
--- public/js/gcs.js    2012-09-26 18:02:34 +0900 (2a4b609)
+++ public/js/gcs.js    2012-09-27 17:58:00 +0900 (07c2baa)
@@ -43,59 +43,42 @@ App.Domain = Ember.Object.extend({
   }
 });
 
-App.Domains = Ember.Object.extend({
-  all: [],
+App.Domain.reopenClass({
   host: location.host,
-  configurationEndpoint: function() {
-    return 'http://' + this.get('host') + '/';
-  }.property('host'),
-  fetch: function() {
+  get configurationEndpoint() {
+    return 'http://' + this.host + '/';
+  },
+  findAll: function() {
+    var domains = Ember.ArrayProxy.create({content: Ember.A()});
     var self = this;
     $.ajax({
       type: 'GET',
-      url:  self.get('configurationEndpoint'),
+      url:  self.configurationEndpoint,
       data: {
         Version: '2011-02-01',
         Action:  'DescribeDomains'
       },
       dataType: 'xml',
       success: function(data) {
-        var domains = [];
         var domainStatusMembers = $(data).find('DomainStatusList > member');
         domainStatusMembers.each(function(index) {
-            var domainElement = $(this);
-            var name = domainElement.find('DomainName').text();
-            var endpoint = domainElement.find('SearchService > Endpoint').text();
-            var domain = App.Domain.create({
-              name: name,
-              endpoint: endpoint,
-              configurationEndpoint: self.get('configurationEndpoint')
-            });
-            domain.fetchFields();
-            domains.push(domain);
+          var domainElement = $(this);
+          var name = domainElement.find('DomainName').text();
+          var endpoint = domainElement.find('SearchService > Endpoint').text();
+          var domain = App.Domain.create({
+            name: name,
+            endpoint: endpoint,
+            configurationEndpoint: self.configurationEndpoint
           });
-        var timer = setInterval(function() {
-          if (domains.length == domainStatusMembers.size()) {
-            // Now all DescribeIndexFields requests are done
-            clearInterval(timer);
-            self.set('all', domains);
-          }
-        }, 100);
+          domain.fetchFields();
+          domains.pushObject(domain);
+        });
       }
     });
-  },
-  first: function() {
-    if (this.all.length > 0) {
-      return this.all[0];
-    } else {
-      return null;
-    }
-  }.property('all')
+    return domains;
+  }
 });
 
-App.domains = App.Domains.create();
-App.domains.fetch();
-
 App.SearchController = Ember.ArrayController.extend({
   query: null,
   perPage: 5,
@@ -220,8 +203,10 @@ App.SearchFormView = Ember.View.extend({
   }
 });
 
+App.domains = App.Domain.findAll();
+
 App.IndexController = Ember.ArrayController.extend({
-  contentBinding: 'App.domains.all'
+  contentBinding: 'App.domains'
 });
 
 App.IndexView = Ember.View.extend({
@@ -236,7 +221,7 @@ App.Router = Ember.Router.extend({
     },
     index: Ember.Route.extend({
       route: '/',
-      connectOutlets: function(router) {
+      connectOutlets: function(router, context) {
         router.get('applicationController').connectOutlet('index');
       }
     }),
@@ -260,6 +245,7 @@ App.Router = Ember.Router.extend({
           domainName: context.domain.name
         };
       }
-    })
+    }),
+    loading: Em.State.extend({})
   })
 });

  Modified: views/index.jade (+2 -2)
===================================================================
--- views/index.jade    2012-09-26 18:02:34 +0900 (71635cd)
+++ views/index.jade    2012-09-27 17:58:00 +0900 (ef75456)
@@ -23,7 +23,7 @@ html
             .well(style="padding: 10px 0 10px 0;")
               ul.nav.nav-list
                 li.nav-header Domains
-                {{#each App.domains.all}}
+                {{#each App.domains}}
                 li <a href {{action showSearch this}}>{{name}}</a>
                 {{/each}}
           .span10
@@ -35,7 +35,7 @@ html
         tbody
           tr
             th Configuration Endpoint
-            td {{App.domains.configurationEndpoint}}
+            td {{App.Domain.configurationEndpoint}}
 
     script(data-template-name="search", type="text/x-handlebars")
       h1 Search domain '{{domain.name}}'
-------------- next part --------------
HTML����������������������������...
Descargar 



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