Last active
October 14, 2017 06:21
-
-
Save workmanw/60efa60e191fa9026774 to your computer and use it in GitHub Desktop.
Sites and Flights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
flights: null, | |
sortedFlights: Ember.computed.sort('flights', '_flightSort'), | |
_flightSort: ['executeAt'], | |
sortOrder: Ember.computed.alias('_flightSort.firstObject'), | |
isAsc: Ember.computed.equal('sortOrder', 'executeAt'), | |
isDesc: Ember.computed.equal('sortOrder', 'executeAt:desc'), | |
actions: { | |
asc() { | |
this.set('_flightSort', ['executeAt']); | |
}, | |
desc() { | |
this.set('_flightSort', ['executeAt:desc']); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
sites: null, | |
sortedSites: Ember.computed.sort('sites', '_siteSort'), | |
_siteSort: ['name'] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Helper.helper(function ([d]) { | |
return d ? d.toGMTString() : ''; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
name: 'fixture', | |
after: 'ember-data', | |
initialize: initialize | |
} | |
export function initialize(application) { | |
let store = application.lookup('service:store'); | |
store.pushPayload({ | |
data: [{ | |
id: '1', | |
type: 'site', | |
attributes: { | |
name: 'Atlanta' | |
}, | |
relationships: { | |
flights: { | |
data: [ | |
{ id: '10', type: 'flight' }, | |
{ id: '11', type: 'flight' }, | |
{ id: '14', type: 'flight' } | |
] | |
} | |
} | |
}, { | |
id: '2', | |
type: 'site', | |
attributes: { | |
name: 'Chicago' | |
}, | |
relationships: { | |
flights: { | |
data: [ | |
{ id: '12', type: 'flight' }, | |
{ id: '13', type: 'flight' } | |
] | |
} | |
} | |
}], | |
included: [{ | |
id: '10', | |
type: 'flight', | |
attributes: { | |
'name': 'DL 2341', | |
'execute-at': '2015-10-26T08:00Z' | |
} | |
}, { | |
id: '11', | |
type: 'flight', | |
attributes: { | |
'name': 'AA 435', | |
'execute-at': '2015-10-25T13:30Z' | |
} | |
}, { | |
id: '12', | |
type: 'flight', | |
attributes: { | |
'name': 'UA 113', | |
'execute-at': '2015-10-24T22:45Z' | |
} | |
}, { | |
id: '13', | |
type: 'flight', | |
attributes: { | |
'name': 'US 953', | |
'execute-at': '2015-10-25T14:00Z' | |
} | |
}, { | |
id: '14', | |
type: 'flight', | |
attributes: { | |
'name': 'AS 763', | |
'execute-at': '2015-10-28T12:20Z' | |
} | |
}] | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
executeAt: DS.attr('date'), | |
site: DS.belongsTo('site') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
flights: DS.hasMany('flight') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import config from './config/environment'; | |
var Router = Ember.Router.extend({ | |
location: config.locationType | |
}); | |
Router.map(function() { | |
this.route('sites', { path: '/site', resetNamespace: true }, function() { | |
this.route('site', { path: '/:site_id' }); | |
}); | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
beforeModel() { | |
this.transitionTo('sites'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
setupController(controller, model) { | |
controller.set('sites', model); | |
}, | |
model() { | |
return this.get('store').peekAll('site'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
setupController(controller, model) { | |
controller.set('site', model); | |
}, | |
model(params) { | |
return this.get('store').find('site', params.site_id); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.t-link { | |
color: blue; | |
text-decoration: underline; | |
cursor: pointer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.14", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment