diff --git a/assets/scripts/app/store.coffee b/assets/scripts/app/store.coffee index c49a25f7..5274e969 100644 --- a/assets/scripts/app/store.coffee +++ b/assets/scripts/app/store.coffee @@ -8,6 +8,10 @@ Travis.Store = DS.Store.extend revision: 4 adapter: Travis.RestAdapter.create() + init: -> + @_super.apply this, arguments + @_loadedData = {} + load: (type, id, hash) -> result = @_super.apply this, arguments @@ -75,18 +79,30 @@ Travis.Store = DS.Store.extend # attached. I don't want to use store.sideload here as it will not use merge, # if we need sideload becasue we have side records with other events it needs to # be revised - if type == Travis.Build && json.repository - result = @loadIncomplete(Travis.Repo, json.repository) + if type == Travis.Build && (json.repository || json.repo) + result = @loadIncomplete(Travis.Repo, json.repository || json.repo) @loadIncomplete(type, json[root]) + addLoadedData: (type, clientId, hash) -> + id = hash.id + @_loadedData[type.toString()] ||= {} + loadedData = (@_loadedData[type][clientId] ||= []) + for key of hash + loadedData.pushObject key unless loadedData.contains(key) + + isDataLoadedFor: (type, clientId, key) -> + if recordsData = @_loadedData[type.toString()] + if data = recordsData[clientId] + data.contains(key) + loadIncomplete: (type, hash) -> result = @merge(type, hash) if result && result.clientId + @addLoadedData(type, result.clientId, hash) record = @findByClientId(type, result.clientId) unless record.get('complete') - record.set 'incomplete', true - record.loadedAttributes = Object.keys hash + record.loadedAsIncomplete() @_updateAssociations(type, type.singularName(), hash) diff --git a/assets/scripts/lib/travis/model.coffee b/assets/scripts/lib/travis/model.coffee index 02d4a607..d39e19da 100644 --- a/assets/scripts/lib/travis/model.coffee +++ b/assets/scripts/lib/travis/model.coffee @@ -23,7 +23,9 @@ this isAttributeLoaded: (name) -> - @loadedAttributes.contains(name) + if meta = Ember.get(this.constructor, 'attributes').get(name) + name = meta.key(this.constructor) + @get('store').isDataLoadedFor(this.constructor, @get('clientId'), name) isComplete: (-> if @get 'incomplete' @@ -43,6 +45,9 @@ select: -> @constructor.select(@get('id')) + loadedAsIncomplete: () -> + @set 'incomplete', true + @Travis.Model.reopenClass find: -> if arguments.length == 0 @@ -77,15 +82,4 @@ Travis.app.store.adapter.pluralize(@singularName()) isAttribute: (name) -> - unless @attributesSaved - @_saveAttributes() - @cachedAttributes.contains(name) - - _saveAttributes: -> - @attributesSaved = true - - cachedAttributes = [] - @eachComputedProperty (name, meta) -> - cachedAttributes.pushObject name if meta.isAttribute - - @cachedAttributes = cachedAttributes + Ember.get(this, 'attributes').has(name) diff --git a/assets/scripts/spec/unit/incomplete_spec.coffee b/assets/scripts/spec/unit/incomplete_spec.coffee index 053e78b0..f2229009 100644 --- a/assets/scripts/spec/unit/incomplete_spec.coffee +++ b/assets/scripts/spec/unit/incomplete_spec.coffee @@ -1,6 +1,7 @@ Travis.Foo = Travis.Model.extend name: DS.attr('string') description: DS.attr('string') + lastName: DS.attr('string') record = null store = null @@ -22,6 +23,7 @@ describe 'Travis.Model', -> attrs = { id: 1 name: 'foo' + last_name: 'foobar' } record = store.loadIncomplete(Travis.Foo, attrs) @@ -51,6 +53,25 @@ describe 'Travis.Model', -> store.loadIncomplete(Travis.Foo, id: 1) expect( record.get('incomplete') ).toBeFalsy() + it 'does not load data on non attribute', -> + record.get('foobarbaz') + waits 50 + runs -> + expect( record.get('incomplete') ).toBeTruthy() + + it 'works with camel case values', -> + expect( record.get('lastName') ).toEqual 'foobar' + waits 50 + runs -> + expect( record.get('complete') ).toBeFalsy() + + it 'adds takes into account additional data loaded as incomplete', -> + record = store.loadIncomplete(Travis.Foo, { id: 1, description: 'baz' }) + expect( record.get('description') ).toEqual 'baz' + waits 50 + runs -> + expect( record.get('complete') ).toBeFalsy() + describe 'with complete record', -> beforeEach -> id = 5 diff --git a/public/scripts/app.js b/public/scripts/app.js index 95571f2f..f861c3b1 100644 --- a/public/scripts/app.js +++ b/public/scripts/app.js @@ -30501,4 +30501,4 @@ var _require=function(){function c(a,c){document.addEventListener?a.addEventList ++g&&setTimeout(c,0)})}}(); (function(){!window.WebSocket&&window.MozWebSocket&&(window.WebSocket=window.MozWebSocket);if(window.WebSocket)Pusher.Transport=window.WebSocket,Pusher.TransportType="native";var c=(document.location.protocol=="http:"?Pusher.cdn_http:Pusher.cdn_https)+Pusher.VERSION,a=[];window.JSON||a.push(c+"/json2"+Pusher.dependency_suffix+".js");if(!window.WebSocket)window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,a.push(c+"/flashfallback"+Pusher.dependency_suffix+".js");var b=function(){return window.WebSocket?function(){Pusher.ready()}: function(){window.WebSocket?(Pusher.Transport=window.WebSocket,Pusher.TransportType="flash",window.WEB_SOCKET_SWF_LOCATION=c+"/WebSocketMain.swf",WebSocket.__addTask(function(){Pusher.ready()}),WebSocket.__initialize()):(Pusher.Transport=null,Pusher.TransportType="none",Pusher.ready())}}(),e=function(a){var b=function(){document.body?a():setTimeout(b,0)};b()},g=function(){e(b)};a.length>0?_require(a,g):g()})(); -;minispade.register('app', "(function() {(function() {\nminispade.require('auth');\nminispade.require('controllers');\nminispade.require('helpers');\nminispade.require('models');\nminispade.require('pusher');\nminispade.require('routes');\nminispade.require('slider');\nminispade.require('store');\nminispade.require('tailing');\nminispade.require('templates');\nminispade.require('views');\nminispade.require('config/locales');\nminispade.require('data/sponsors');\n\n Travis.reopen({\n App: Em.Application.extend({\n autoinit: false,\n currentUserBinding: 'auth.user',\n authStateBinding: 'auth.state',\n init: function() {\n this._super.apply(this, arguments);\n this.store = Travis.Store.create();\n this.store.loadMany(Travis.Sponsor, Travis.SPONSORS);\n this.slider = new Travis.Slider();\n this.pusher = new Travis.Pusher(Travis.config.pusher_key);\n this.tailing = new Travis.Tailing();\n return this.set('auth', Travis.Auth.create({\n app: this,\n endpoint: Travis.config.api_endpoint\n }));\n },\n storeAfterSignInPath: function(path) {\n return this.get('auth').storeAfterSignInPath(path);\n },\n autoSignIn: function(path) {\n return this.get('auth').autoSignIn(path);\n },\n signIn: function() {\n return this.get('auth').signIn();\n },\n signOut: function() {\n this.get('auth').signOut();\n return this.get('router').send('afterSignOut');\n },\n receive: function() {\n return this.store.receive.apply(this.store, arguments);\n },\n toggleSidebar: function() {\n var element;\n $('body').toggleClass('maximized');\n element = $('');\n $('#top .profile').append(element);\n Em.run.later((function() {\n return element.remove();\n }), 10);\n element = $('');\n $('#repo').append(element);\n return Em.run.later((function() {\n return element.remove();\n }), 10);\n }\n })\n });\n\n}).call(this);\n\n})();\n//@ sourceURL=app");minispade.register('auth', "(function() {(function() {\n\n this.Travis.Auth = Ember.Object.extend({\n iframe: $('