John Cowen f2accb0bd1 ui: Move routes to use data-sources (#8321)
* Add uri identifiers to all data source things and make them the same

1. Add uri identitifer to data-source service
2. Make <EventSource /> and <DataSource /> as close as possible
3. Add extra `.closed` method to get a list of inactive/closed/closing
data-sources from elsewhere

* Make the connections cleanup the least worst connection when required

* Pass the uri/request id through all the things

* Better user erroring

* Make event sources close on error

* Allow <DataLoader /> data slot to be configurable

* Allow the <DataWriter /> removed state to be configurable

* Don't error if meta is undefined

* Stitch together all the repositories into the data-source/sink

* Use data.source over repositories

* Add missing  <EventSource /> components

* Fix up the views/templates

* Disable all the old route based blocking query things

* We still need the repo for the mixin for the moment

* Don't default to default, default != ''
2020-07-17 13:43:16 +00:00

31 lines
1.1 KiB
JavaScript

import Service, { inject as service } from '@ember/service';
import { get } from '@ember/object';
import { BlockingEventSource as EventSource } from 'consul-ui/utils/dom/event-source';
import { ifNotBlocking } from 'consul-ui/services/settings';
import { restartWhenAvailable } from 'consul-ui/services/client/http';
import maybeCall from 'consul-ui/utils/maybe-call';
export default Service.extend({
client: service('client/http'),
settings: service('settings'),
source: function(find, configuration) {
return new EventSource((configuration, source) => {
const close = source.close.bind(source);
const deleteCursor = () => (configuration.cursor = undefined);
//
return maybeCall(deleteCursor, ifNotBlocking(this.settings))().then(() => {
return find(configuration)
.then(maybeCall(close, ifNotBlocking(this.settings)))
.then(function(res) {
if (typeof get(res || {}, 'meta.cursor') === 'undefined') {
close();
}
return res;
})
.catch(restartWhenAvailable(this.client));
});
}, configuration);
},
});