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