From c1498a0c82ab7b600f87ed9e8d7eeeea3603fc6a Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 16 Sep 2012 14:40:16 +0200 Subject: [PATCH] add sync to the profile (callback still does not work) --- assets/javascripts/app/models/user.coffee | 18 ++++++++++++++++++ .../app/templates/profile/tabs/hooks.hbs | 3 +++ assets/stylesheets/profile.sass | 3 +++ public/javascripts/application.js | 2 +- public/stylesheets/application.css | 4 ++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/app/models/user.coffee b/assets/javascripts/app/models/user.coffee index dd83b2d7..51aa0a94 100644 --- a/assets/javascripts/app/models/user.coffee +++ b/assets/javascripts/app/models/user.coffee @@ -11,6 +11,10 @@ require 'travis/model' syncedAt: DS.attr('string') repoCount: DS.attr('number') + init: -> + @poll() if @get('isSyncing') + @._super() + urlGithub: (-> "http://github.com/#{@get('login')}" ).property() @@ -27,3 +31,17 @@ require 'travis/model' [this].concat Travis.Account.filter().toArray() ).property() + sync: -> + $.post('/api/profile/sync') + @set('isSyncing', true) + @poll() + + poll: -> + $.get('/api/profile', ((data) -> + if data.user.is_syncing + Ember.run.later(this, this.poll.bind(this), 3000) + else if this.get('isSyncing') + # TODO this doesn't seem to work properly + Travis.app.store.load(Travis.User, data.user) + Travis.app.store.loadMany(Travis.Account, data.accounts) + ).bind(this)) diff --git a/assets/javascripts/app/templates/profile/tabs/hooks.hbs b/assets/javascripts/app/templates/profile/tabs/hooks.hbs index 9887bffc..c8520f46 100644 --- a/assets/javascripts/app/templates/profile/tabs/hooks.hbs +++ b/assets/javascripts/app/templates/profile/tabs/hooks.hbs @@ -10,6 +10,9 @@ {{else}}

Last synchronized from GitHub: {{formatTime user.syncedAt}} +