First stab at changing favicon based on build or job state
This commit is contained in:
parent
34d4f1624e
commit
acb70dcac7
|
@ -23,4 +23,8 @@ Controller = Ember.Controller.extend GithubUrlPropertievs,
|
|||
gravatarImage(@get('commit.authorEmail'), 40)
|
||||
).property('commit.authorEmail')
|
||||
|
||||
buildStateDidChange: (->
|
||||
@send('faviconStateDidChange', @get('build.state'))
|
||||
).observes('build.state')
|
||||
|
||||
`export default Controller`
|
||||
|
|
|
@ -16,4 +16,8 @@ Controller = Ember.Controller.extend
|
|||
githubCommit(@get('repo.slug'), @get('commit.sha'))
|
||||
).property('repo.slug', 'commit.sha')
|
||||
|
||||
jobStateDidChange: (->
|
||||
@send('faviconStateDidChange', @get('job.state'))
|
||||
).observes('job.state')
|
||||
|
||||
`export default Controller`
|
||||
|
|
36
app/mixins/build-favicon.coffee
Normal file
36
app/mixins/build-favicon.coffee
Normal file
|
@ -0,0 +1,36 @@
|
|||
`import Ember from 'ember'`
|
||||
`import { colorForState } from 'travis/utils/helpers'`
|
||||
`import FaviconManager from 'travis/utils/favicon-manager'`
|
||||
|
||||
Mixin = Ember.Mixin.create
|
||||
actions:
|
||||
faviconStateDidChange: (state) ->
|
||||
if state
|
||||
@setFaviconForState(state)
|
||||
else
|
||||
@setDefault()
|
||||
|
||||
init: ->
|
||||
@faviconManager = new FaviconManager()
|
||||
|
||||
@_super.apply this, arguments
|
||||
|
||||
setFaviconForState: (state) ->
|
||||
color = colorForState(state)
|
||||
|
||||
images = {
|
||||
red: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4z8DwHwAFAAH/VscvDQAAAABJRU5ErkJggg==',
|
||||
yellow: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP4/5ThPwAHrwLktvrIVgAAAABJRU5ErkJggg==',
|
||||
green: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOwv276HwAE7wJLzZ3V0gAAAABJRU5ErkJggg==',
|
||||
gray: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mMoqyj7DwAFMAJkMSbkxgAAAABJRU5ErkJggg=='
|
||||
}
|
||||
|
||||
@setFavicon(images[color])
|
||||
|
||||
setDefault: ->
|
||||
@setFavicon('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAAB3RJTUUH3wIXCgcI1L+jPwAABp9JREFUWMPtVltsVNcVXfvcO2/PjDPjMcYe8AMbiLERxSkgNaC00JpQqWlIlJcgUaW0aqOWVmr/mihKpEaKKvUjEm2jQh8kEUpaqSFJQ9s4OFEMIcHB4DgYv2KwB/DYnhmP53V9596z+zF+zBiPHdpK/emWRrrnnHXXXrP2PWcf4H8cdCvgT9u2rxLgxyHoboBaBMEOACxZZ0IXJL8pTT7W3Hpu9L8qoPONFqfDpT4Dwo8FkWU5rGTOEuOwjCSeanrgUvI/FtB1ckeN1cp/E4Ia5+bCb88g0qFDzjByDgD+O61Yvd8GgEAEsOQBmc3ua9p7fnA5frHc4qV3v1Rts+K0ENQ4o5mIRjRIyTBTDHejCkeVAmetgrJdVigOgmEwIhEN6ZQBEDWQxfLhhbZt6/8tB9r/UGNfVV1xDuCm6bgOXZcgIpQF7POY0CsZmGlG9XedOScYmJzIAABUVcBbagWAfo4kWoqVo6gDgbXlTxKhKZU0oOsyB17WL4Ao9wMAw5BIpw0IQevJX/LcLZXg4j82lwuinwGArpt5CRYMYwkYCUY2LiE1XtLU+XeJftDzTsvaLyxAVZ1PEJENDJjmArmUec8aI/qhjuSACS0s895ewJhG7lkQqSTU53teayy5ybX8Qc9rjVYqK/klQE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IKgDpU0nE+0ZhWlXELAZYEfCyiuylEFKj46h7eDccFb6b+Ew2dwe3P3Jq8bxaTIBkHFUUasmfy4RjOP/U7zETnXcQlhIHxpILHTNyYRCbDt0Hf8vCTYyZh3/3dt97L/vqPQeig9P5nEUd6Gk/XOJz+IZIiHIAkHoWn/z8KBLDN7BiEMFTXwV7oBRWrwuJ0MQ7U91DGWZ+82Co/8iKAl5eU/+NuBY/s+fXT34nfSX8wmTnZUQuDMHMzCyRi8D8hTrkyMDo5YZnULgNlxRwbHXD7cKitIM5QETL3gSr9++EFo4hfLpnmeQsGXzfwdH+1xevLUn+6I2BXin5pyslFxYVwdZtuP1H++Hf2rBokZhs6kVm/gVL3rpU8qIOzMVLaxoeBim/EkBF/rzN54Z7XRWq7/kKvBtzd002JSY+7oU2Gc8Ki/qXyNWRH+49+ufoSqVZsck/DVjrghs2CpCPhBjf8dufVDv87m+B6etEqCMiksxxMM6BcIITM8eDex6LrMT7/5iLfwE4Jt2JlBtnqwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNS0wMi0yM1QxMDowNzowOCswMTowMEwwWcYAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTUtMDItMjNUMTA6MDc6MDgrMDE6MDA9beF6AAAAAElFTkSuQmCC')
|
||||
|
||||
setFavicon: (href) ->
|
||||
@faviconManager.setFavicon(href)
|
||||
|
||||
`export default Mixin`
|
|
@ -15,6 +15,8 @@ Route = TravisRoute.extend
|
|||
deactivate: ->
|
||||
@controllerFor('repo').removeObserver(@get('path'), this, 'contentDidChange')
|
||||
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
contentDidChange: ->
|
||||
path = @get('path')
|
||||
@controllerFor('builds').set('model', @controllerFor('repo').get(path))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
`import TravisRoute from 'travis/routes/basic'`
|
||||
`import config from 'travis/config/environment'`
|
||||
`import BuildFaviconMixin from 'travis/mixins/build-favicon'`
|
||||
|
||||
Route = TravisRoute.extend
|
||||
Route = TravisRoute.extend BuildFaviconMixin,
|
||||
needsAuth: false
|
||||
|
||||
renderTemplate: ->
|
||||
|
|
|
@ -22,6 +22,7 @@ Route = TravisRoute.extend
|
|||
@store.find('build', params.build_id)
|
||||
|
||||
deactivate: ->
|
||||
@_super.apply(this, arguments)
|
||||
@controllerFor('job').set('job', null)
|
||||
@controllerFor('build').set('build', null)
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ Route = TravisRoute.extend
|
|||
deactivate: ->
|
||||
@controllerFor('repos').removeObserver('firstObject', this, 'currentRepoDidChange')
|
||||
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
currentRepoDidChange: ->
|
||||
if repo = @controllerFor('repos').get('firstObject')
|
||||
@controllerFor('repo').set('repo', repo)
|
||||
|
|
|
@ -10,6 +10,7 @@ Route = AbstractBuildsRoute.extend(
|
|||
this.controllerFor('builds').set('isPullRequestsList', true)
|
||||
|
||||
deactivate: ->
|
||||
@_super.apply(this, arguments)
|
||||
this.controllerFor('builds').set('isPullRequestsList', false)
|
||||
)
|
||||
|
||||
|
|
|
@ -16,4 +16,6 @@ Route = TravisRoute.extend
|
|||
@controllerFor('build').set('build', null)
|
||||
@controllerFor('job').set('job', null)
|
||||
|
||||
@_super.apply(this, arguments)
|
||||
|
||||
`export default Route`
|
||||
|
|
38
app/utils/favicon-manager.coffee
Normal file
38
app/utils/favicon-manager.coffee
Normal file
|
@ -0,0 +1,38 @@
|
|||
`import Ember from 'ember'`
|
||||
|
||||
manager = (headTag) ->
|
||||
@headTag = headTag if headTag
|
||||
|
||||
return this
|
||||
|
||||
manager.prototype.getHeadTag = ->
|
||||
@headTag || document.getElementsByTagName('head')[0]
|
||||
|
||||
manager.prototype.setFavicon = (href) ->
|
||||
link = @getLinkTag()
|
||||
|
||||
if !link
|
||||
oldLink = link
|
||||
link = @createLinkTag()
|
||||
head = @getHeadTag()
|
||||
head.appendChild(link)
|
||||
|
||||
link.setAttribute('href', href)
|
||||
|
||||
if oldLink
|
||||
head.removeChild(oldLink)
|
||||
|
||||
manager.prototype.getLinkTag = ->
|
||||
links = document.getElementsByTagName('head')[0].getElementsByTagName('link')
|
||||
if links.length
|
||||
for link in links
|
||||
if link.getAttribute('rel').trim() == 'icon'
|
||||
return link
|
||||
|
||||
manager.prototype.createLinkTag = ->
|
||||
link = document.createElement('link')
|
||||
link.setAttribute('rel', 'icon')
|
||||
link.setAttribute('type', 'image/png')
|
||||
document.getElementsByTagName('head')[0].appendChild(link)
|
||||
|
||||
`export default manager`
|
Loading…
Reference in New Issue
Block a user