Update code for newest ember-model

This commit is contained in:
Piotr Sarnacki 2013-10-18 13:19:25 +02:00
parent b3ce14cc22
commit b5297d7800
5 changed files with 28 additions and 31 deletions

View File

@ -119,14 +119,12 @@ unless window.TravisApplication
loadOrMerge: (type, hash, options) -> loadOrMerge: (type, hash, options) ->
options ||= {} options ||= {}
if !type._idToReference reference = type._getReferenceById(hash.id)
type._idToReference = {}
reference = type._idToReference[hash.id]
if reference && options.skipIfExists if reference && options.skipIfExists
return return
reference = type._referenceForId(hash.id) reference = type._getOrCreateReferenceForId(hash.id)
if reference.record if reference.record
reference.record.merge(hash) reference.record.merge(hash)
else else

View File

@ -9,7 +9,7 @@ Travis.FlashController = Ember.ArrayController.extend
@set('flashes', Ember.A()) @set('flashes', Ember.A())
content: (-> content: (->
@get('unseenBroadcasts').concat(@get('flashes')) @get('unseenBroadcasts').concat(@get('flashes')).filter (o) -> o
).property('unseenBroadcasts.length', 'flashes.length') ).property('unseenBroadcasts.length', 'flashes.length')
unseenBroadcasts: (-> unseenBroadcasts: (->

View File

@ -38,18 +38,19 @@ Array.prototype.diff = (a) ->
@loadedAttributes = [] @loadedAttributes = []
@loadedRelationships = [] @loadedRelationships = []
attributes = this.attributes || [] attributes = this.constructor.getAttributes() || []
relationships = this.relationships || [] relationships = this.constructor.getRelationships() || []
for key in attributes if hash
dataKey = @dataKey(key) for key in attributes
if hash.hasOwnProperty(dataKey) dataKey = @dataKey(key)
@loadedAttributes.pushObject(key) if hash.hasOwnProperty(dataKey)
@loadedAttributes.pushObject(key)
for key in relationships for key in relationships
dataKey = @dataKey(key) dataKey = @dataKey(key)
if hash.hasOwnProperty(dataKey) if hash.hasOwnProperty(dataKey)
@loadedRelationships.pushObject(key) @loadedRelationships.pushObject(key)
incomplete = Ember.EnumerableUtils.intersection(@loadedAttributes, attributes).length != attributes.length || incomplete = Ember.EnumerableUtils.intersection(@loadedAttributes, attributes).length != attributes.length ||
Ember.EnumerableUtils.intersection(@loadedRelationships, relationships).length != relationships.length Ember.EnumerableUtils.intersection(@loadedRelationships, relationships).length != relationships.length
@ -86,10 +87,10 @@ Array.prototype.diff = (a) ->
@loadTheRest(key) @loadTheRest(key)
isAttribute: (name) -> isAttribute: (name) ->
this.attributes.contains(name) this.constructor.getAttributes().contains(name)
isRelationship: (name) -> isRelationship: (name) ->
this.relationships.contains(name) this.constructor.getRelationships().contains(name)
loadTheRest: (key) -> loadTheRest: (key) ->
# for some weird reason key comes changed to a string and for some weird reason it even is called with # for some weird reason key comes changed to a string and for some weird reason it even is called with
@ -145,19 +146,19 @@ Array.prototype.diff = (a) ->
).property() ).property()
isRecordLoaded: (id) -> isRecordLoaded: (id) ->
!!@_referenceForId(id).record reference = @_getReferenceById(id)
reference && reference.record
camelizeKeys: true camelizeKeys: true
# TODO: the functions below will be added to Ember Model, remove them when that # TODO: the functions below will be added to Ember Model, remove them when that
# happens # happens
resetData: -> resetData: ->
@_idToReference = null @_referenceCache = {}
@sideloadedData = null @sideloadedData = {}
@recordCache = null @recordArrays = []
@recordArrays = null @_currentBatchIds = []
@_currentBatchIds = null @_hasManyArrays = []
@_hasManyArrays = null
@_findAllRecordArray = null @_findAllRecordArray = null
unload: (record) -> unload: (record) ->
@ -172,10 +173,8 @@ Array.prototype.diff = (a) ->
delete this.recordCache[key] delete this.recordCache[key]
loadRecordForReference: (reference) -> loadRecordForReference: (reference) ->
record = @create({ _reference: reference }) record = @create({ _reference: reference, id: reference.id })
@recordCache = {} unless @recordCache
@sideloadedData = {} unless @sideloadedData @sideloadedData = {} unless @sideloadedData
@recordCache[reference.id] = record
reference.record = record reference.record = record
record.load(reference.id, @sideloadedData[reference.id]) record.load(reference.id, @sideloadedData[reference.id])
# TODO: find a nicer way to not add record to record arrays twice # TODO: find a nicer way to not add record to record arrays twice

View File

@ -5,7 +5,7 @@
@displaysTabs = (tabs) -> @displaysTabs = (tabs) ->
for name, tab of tabs for name, tab of tabs
equal($("#tab_#{name} a").attr('href'), tab.href, "#{name} tab should link to #{tab.href}") unless tab.hidden equal($("#tab_#{name} a").attr('href'), tab.href, "#{name} tab should link to #{tab.href}") unless tab.hidden
equal($("#tab_#{name}").hasClass('active'), !!tab.active, "#{name} tab should be active") equal($("#tab_#{name}").hasClass('active'), !!tab.active, "#{name} tab should #{'not' unless tab.active} be active")
equal($("#tab_#{name}").hasClass('display-inline'), !tab.hidden, "#{name} tab should has class display-inline") if name in ['build', 'job'] equal($("#tab_#{name}").hasClass('display-inline'), !tab.hidden, "#{name} tab should has class display-inline") if name in ['build', 'job']
@displaysSummaryBuildLink = (link, number) -> @displaysSummaryBuildLink = (link, number) ->

View File

@ -3,9 +3,9 @@ minispade.require 'ext/jquery'
responseTime = 0 responseTime = 0
repos = [ repos = [
{ id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_state: 'passed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core' }, { id: '1', owner: 'travis-ci', name: 'travis-core', slug: 'travis-ci/travis-core', build_ids: [1, 2], last_build_id: 1, last_build_number: 1, last_build_state: 'passed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:00:00Z', last_build_finished_at: '2012-07-02T00:00:30Z', description: 'Description of travis-core', github_language: 'ruby' },
{ id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_state: 'failed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets'}, { id: '2', owner: 'travis-ci', name: 'travis-assets', slug: 'travis-ci/travis-assets', build_ids: [3], last_build_id: 3, last_build_number: 3, last_build_state: 'failed', last_build_duration: 30, last_build_started_at: '2012-07-02T00:01:00Z', last_build_finished_at: '2012-07-01T00:01:30Z', description: 'Description of travis-assets', github_language: 'ruby'},
{ id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_state: null, last_build_duration: null, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: null, description: 'Description of travis-hub'}, { id: '3', owner: 'travis-ci', name: 'travis-hub', slug: 'travis-ci/travis-hub', build_ids: [4], last_build_id: 4, last_build_number: 4, last_build_state: null, last_build_duration: null, last_build_started_at: '2012-07-02T00:02:00Z', last_build_finished_at: null, description: 'Description of travis-hub', github_language: 'ruby' },
] ]
reposByName = (name) -> reposByName = (name) ->