Last active
May 25, 2022 20:58
-
-
Save rossjha/c042669a7ef039f8cd70bb0f347cd037 to your computer and use it in GitHub Desktop.
provider example
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.RESTAdapter.extend({ | |
host: 'https://604630b1f0c6dc00177b180b.mockapi.io', | |
namespace: 'api/v1', | |
pathForType() { | |
return 'appointment-queries' | |
} | |
}); |
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 Component from '@ember/component'; | |
import { task } from 'ember-concurrency'; | |
import { get, set } from '@ember/object'; | |
import { inject as service } from '@ember/service'; | |
export default Component.extend({ | |
// Services | |
store: service(), | |
// Lifecycle hooks | |
init() { | |
this._super(...arguments); | |
set(this, 'appointmentQueries', []); | |
get(this, 'fetchAppointmentQueriesTask').perform(); | |
}, | |
// Functions | |
fetchAppointmentQueriesTask: task(function* () { | |
try { | |
const appointmentQueries = yield get(this, 'store').findAll('appointment-query'); | |
set(this, 'appointmentQueries', appointmentQueries); | |
} catch (adapterErrors) { | |
console.error(adapterErrors); | |
} | |
}), | |
createAppointmentQuery(params) { | |
return get(this, 'store').createRecord('appointment-query', params); | |
}, | |
saveAppointmentQueryTask: (function* (model) { | |
try { | |
yield model.save(); | |
console.log('Appointment query created successfully'); | |
get(this, 'fetchAppointmentQueriesTask').perform(); | |
} catch(adapterErrors) { | |
console.error(adapterErrors); | |
} | |
}) | |
}); |
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 Controller from '@ember/controller'; | |
import { get, set } from '@ember/object'; | |
import { isBlank } from '@ember/utils'; | |
export default Controller.extend({ | |
// Properties | |
queryParams: ['state'], | |
state: null, | |
// Functions | |
actions: { | |
selectAppointmentQuery(appointmentQueryId) { | |
if (isBlank(appointmentQueryId)) { | |
return; | |
} | |
const appointmentQuery = get(this, 'store').peekRecord('appointment-query', appointmentQueryId); | |
set(this, 'state', appointmentQuery.get('params.state')) | |
} | |
} | |
}); |
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 { helper } from '@ember/component/helper'; | |
export default helper(function eq([param1, param2]) { | |
return param1 === param2; | |
}); |
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 Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
export const schema = { | |
// Attributes | |
name: attr('string'), | |
params: attr() | |
}; | |
export default Model.extend(schema); |
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.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "2.18.2", | |
"ember-template-compiler": "2.18.2", | |
"ember-testing": "2.18.2" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "2.18.5", | |
"ember-concurrency": "0.7.19" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment