Allow child adapters specify special xhr keys

This is necessary for the namespace query param
This commit is contained in:
Michael Lange 2018-03-22 18:57:20 -07:00
parent d85673d7c6
commit ca98d6b0c8
2 changed files with 20 additions and 4 deletions

View file

@ -46,6 +46,18 @@ export default Watchable.extend({
return url;
},
xhrKey(url, method, options = {}) {
const namespace = options.data && options.data.namespace;
if (namespace) {
return `${url}?namespace=${namespace}`;
}
return url;
},
relationshipFallbackLinks: {
summary: '/summary',
},
findAllocations(job) {
const url = `${this.buildURL('job', job.get('id'), job, 'findRecord')}/allocations`;
return this.ajax(url, 'GET', { data: this.buildQuery() }).then(allocs => {

View file

@ -13,30 +13,34 @@ export default ApplicationAdapter.extend({
return {};
}),
ajaxOptions(url) {
ajaxOptions() {
const ajaxOptions = this._super(...arguments);
const key = this.xhrKey(...arguments);
const previousBeforeSend = ajaxOptions.beforeSend;
ajaxOptions.beforeSend = function(jqXHR) {
if (previousBeforeSend) {
previousBeforeSend(...arguments);
}
this.get('xhrs')[url] = jqXHR;
this.get('xhrs')[key] = jqXHR;
jqXHR.always(() => {
delete this.get('xhrs')[url];
delete this.get('xhrs')[key];
});
};
return ajaxOptions;
},
xhrKey(url /* method, options */) {
return url;
},
findAll(store, type, sinceToken, snapshotRecordArray, additionalParams = {}) {
const params = assign(this.buildQuery(), additionalParams);
const url = this.urlForFindAll(type.modelName);
if (get(snapshotRecordArray || {}, 'adapterOptions.watch')) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelFindAll(type.modelName);
}
return this.ajax(url, 'GET', {