ui: Prefer `cursor` over `index`, add `configuration` option to repos (#5042)
This commit is contained in:
parent
864ffdf79b
commit
6311859877
|
@ -4,7 +4,6 @@ import { get } from '@ember/object';
|
|||
import {
|
||||
HEADERS_SYMBOL as HTTP_HEADERS_SYMBOL,
|
||||
HEADERS_INDEX as HTTP_HEADERS_INDEX,
|
||||
HEADERS_DIGEST as HTTP_HEADERS_DIGEST,
|
||||
} from 'consul-ui/utils/http/consul';
|
||||
export default Serializer.extend({
|
||||
// this could get confusing if you tried to override
|
||||
|
@ -44,8 +43,7 @@ export default Serializer.extend({
|
|||
},
|
||||
normalizeMeta: function(store, primaryModelClass, headers, payload, id, requestType) {
|
||||
const meta = {
|
||||
index: headers[HTTP_HEADERS_INDEX],
|
||||
digest: headers[HTTP_HEADERS_DIGEST],
|
||||
cursor: headers[HTTP_HEADERS_INDEX],
|
||||
date: headers['date'],
|
||||
};
|
||||
if (requestType === 'query') {
|
||||
|
|
|
@ -14,16 +14,24 @@ export default Service.extend({
|
|||
},
|
||||
//
|
||||
store: service('store'),
|
||||
findAllByDatacenter: function(dc) {
|
||||
return get(this, 'store').query(this.getModelName(), {
|
||||
findAllByDatacenter: function(dc, configuration = {}) {
|
||||
const query = {
|
||||
dc: dc,
|
||||
});
|
||||
};
|
||||
if (typeof configuration.cursor !== 'undefined') {
|
||||
query.index = configuration.cursor;
|
||||
}
|
||||
return get(this, 'store').query(this.getModelName(), query);
|
||||
},
|
||||
findBySlug: function(slug, dc) {
|
||||
return get(this, 'store').queryRecord(this.getModelName(), {
|
||||
id: slug,
|
||||
findBySlug: function(slug, dc, configuration = {}) {
|
||||
const query = {
|
||||
dc: dc,
|
||||
});
|
||||
id: slug,
|
||||
};
|
||||
if (typeof configuration.cursor !== 'undefined') {
|
||||
query.index = configuration.cursor;
|
||||
}
|
||||
return get(this, 'store').queryRecord(this.getModelName(), query);
|
||||
},
|
||||
create: function(obj) {
|
||||
// TODO: This should probably return a Promise
|
||||
|
|
|
@ -13,7 +13,7 @@ export default RepositoryService.extend({
|
|||
return PRIMARY_KEY;
|
||||
},
|
||||
// this one gives you the full object so key,values and meta
|
||||
findBySlug: function(key, dc) {
|
||||
findBySlug: function(key, dc, configuration = {}) {
|
||||
if (isFolder(key)) {
|
||||
const id = JSON.stringify([dc, key]);
|
||||
let item = get(this, 'store').peekRecord(this.getModelName(), id);
|
||||
|
@ -24,23 +24,31 @@ export default RepositoryService.extend({
|
|||
}
|
||||
return Promise.resolve(item);
|
||||
}
|
||||
return get(this, 'store').queryRecord(this.getModelName(), {
|
||||
const query = {
|
||||
id: key,
|
||||
dc: dc,
|
||||
});
|
||||
};
|
||||
if (typeof configuration.cursor !== 'undefined') {
|
||||
query.index = configuration.cursor;
|
||||
}
|
||||
return get(this, 'store').queryRecord(this.getModelName(), query);
|
||||
},
|
||||
// this one only gives you keys
|
||||
// https://www.consul.io/api/kv.html
|
||||
findAllBySlug: function(key, dc) {
|
||||
findAllBySlug: function(key, dc, configuration = {}) {
|
||||
if (key === '/') {
|
||||
key = '';
|
||||
}
|
||||
const query = {
|
||||
id: key,
|
||||
dc: dc,
|
||||
separator: '/',
|
||||
};
|
||||
if (typeof configuration.cursor !== 'undefined') {
|
||||
query.index = configuration.cursor;
|
||||
}
|
||||
return this.get('store')
|
||||
.query(this.getModelName(), {
|
||||
id: key,
|
||||
dc: dc,
|
||||
separator: '/',
|
||||
})
|
||||
.query(this.getModelName(), query)
|
||||
.then(function(items) {
|
||||
return items.filter(function(item) {
|
||||
return key !== get(item, 'Key');
|
||||
|
|
|
@ -8,11 +8,15 @@ export default RepositoryService.extend({
|
|||
getModelName: function() {
|
||||
return modelName;
|
||||
},
|
||||
findByNode: function(node, dc) {
|
||||
return get(this, 'store').query(this.getModelName(), {
|
||||
findByNode: function(node, dc, configuration = {}) {
|
||||
const query = {
|
||||
id: node,
|
||||
dc: dc,
|
||||
});
|
||||
};
|
||||
if (typeof configuration.cursor !== 'undefined') {
|
||||
query.index = configuration.cursor;
|
||||
}
|
||||
return get(this, 'store').query(this.getModelName(), query);
|
||||
},
|
||||
// TODO: Why Key? Probably should be findBySlug like the others
|
||||
findByKey: function(slug, dc) {
|
||||
|
|
Loading…
Reference in New Issue