Last active
October 13, 2016 18:59
-
-
Save raido/50ddbf20ee82ea4038abf6c2c633da18 to your computer and use it in GitHub Desktop.
Praamid Ember
This file contains hidden or 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'; | |
import Ember from 'ember'; | |
export default DS.Adapter.extend({ | |
queryRecord(store, type, query) { | |
var url = "https://www.praamid.ee/online/events"; | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
Ember.$.getJSON(url, query).then(function(data) { | |
Ember.run(null, resolve, data); | |
}, function(jqXHR) { | |
jqXHR.then = null; // tame jQuery's ill mannered promises | |
Ember.run(null, reject, jqXHR); | |
}); | |
}); | |
} | |
}); |
This file contains hidden or 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.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or 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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
import Ember from 'ember'; | |
const { computed } = Ember; | |
export default Model.extend({ | |
items: hasMany('event'), | |
sortedItems: computed('items', function() { | |
return this.get('items').sortBy('startUnixTime'); | |
}) | |
}); |
This file contains hidden or 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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
const { computed } = Ember; | |
export default Model.extend({ | |
freeSlots: attr('number'), | |
dtstart: attr('date'), | |
dtend: attr('date'), | |
startUnixTime: computed('dtstart', function() { | |
return this.get('dtstart').getTime(); | |
}), | |
startTime: computed('dtstart', function() { | |
return this.get('dtstart').toLocaleTimeString(); | |
}), | |
endTime: computed('dtend', function() { | |
return this.get('dtend').toLocaleTimeString(); | |
}), | |
day: computed('dtstart', function() { | |
return this.get('dtstart').toLocaleDateString(); | |
}) | |
}); |
This file contains hidden or 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'; | |
const { RSVP } = Ember; | |
export default Ember.Route.extend({ | |
model() { | |
return new RSVP.hash({ | |
today: this.store.queryRecord('direction', { | |
direction: 'RH', | |
'departure-date': '2016-10-14' | |
}), | |
tomorrow: this.store.queryRecord('direction', { | |
direction: 'RH', | |
'departure-date': '2016-10-15' | |
}), | |
dayAfterTomorrow: this.store.queryRecord('direction', { | |
direction: 'RH', | |
'departure-date': '2016-10-16' | |
}) | |
}); | |
} | |
}); |
This file contains hidden or 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.JSONSerializer.extend(DS.EmbeddedRecordsMixin, { | |
attrs: { | |
items: { embedded: 'always' } | |
}, | |
normalizeResponse(store, primaryModelClass, payload, id, requestType) { | |
payload.id = payload.items[0].uid; | |
payload.items.forEach((item) => { | |
item.id = item.uid; | |
}); | |
return this._super(...arguments); | |
} | |
}); |
This file contains hidden or 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.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "beta", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "beta", | |
"ember-testing": "beta" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment