mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 05:45:46 +00:00
94dd1849b4
* ui: CSS and component changes to the <EmptyState /> component * ui: Reset the auth-form component back to its initial state Moving forwards we are going to have the auth-form on the page all the time, even when logged in (for relogging in purposes). This means the auth-form will not always be removed from the DOM when you log in. This sets the form back to its idle state before calling onsubmit * ui: Make a public api for modal-dialog with a single close method * ui : Move cache reset somewhere that makes more sense, + single refresh 1. Centralize cache resetting elsewhere, for now the store makes most sense, although I would prefer the Repository class, so using the store is temporary 2. We only need to refresh on login once, unless we have a differing nspace * ui: Ensure visibilitychange events are cleaned up * ui: Only cache DataSource data if we have any, + only clear the cache * ui: Add the modal login dialog to both unauth and auth views This means we can 'relogin' when already logged in * ui: Add new empty states * ui: CSS Tweaks * Remove marketing grays
93 lines
2.6 KiB
JavaScript
93 lines
2.6 KiB
JavaScript
import Service, { inject as service } from '@ember/service';
|
|
|
|
import MultiMap from 'mnemonist/multi-map';
|
|
|
|
// TODO: Expose sizes of things via env vars
|
|
|
|
// caches cursors and previous events when the EventSources are destroyed
|
|
let cache = null;
|
|
// keeps a record of currently in use EventSources
|
|
let sources = null;
|
|
// keeps a count of currently in use EventSources
|
|
let usage = null;
|
|
|
|
export default Service.extend({
|
|
dom: service('dom'),
|
|
consul: service('data-source/protocols/http'),
|
|
settings: service('data-source/protocols/local-storage'),
|
|
|
|
init: function() {
|
|
this._super(...arguments);
|
|
cache = new Map();
|
|
sources = new Map();
|
|
usage = new MultiMap(Set);
|
|
this._listeners = this.dom.listeners();
|
|
},
|
|
resetCache: function() {
|
|
cache = new Map();
|
|
},
|
|
willDestroy: function() {
|
|
this._listeners.remove();
|
|
sources.forEach(function(item) {
|
|
item.close();
|
|
});
|
|
cache = null;
|
|
sources = null;
|
|
usage = null;
|
|
},
|
|
|
|
open: function(uri, ref) {
|
|
let source;
|
|
// Check the cache for an EventSource that is already being used
|
|
// for this uri. If we don't have one, set one up.
|
|
if (uri.indexOf('://') === -1) {
|
|
uri = `consul://${uri}`;
|
|
}
|
|
if (!sources.has(uri)) {
|
|
let [providerName, pathname] = uri.split('://');
|
|
const provider = this[providerName];
|
|
|
|
let configuration = {};
|
|
if (cache.has(uri)) {
|
|
configuration = cache.get(uri);
|
|
}
|
|
source = provider.source(pathname, configuration);
|
|
this._listeners.add(source, {
|
|
close: e => {
|
|
const source = e.target;
|
|
source.removeEventListener('close', close);
|
|
const event = source.getCurrentEvent();
|
|
const cursor = source.configuration.cursor;
|
|
// only cache data if we have any
|
|
if (typeof event !== 'undefined' && typeof cursor !== 'undefined') {
|
|
cache.set(uri, {
|
|
currentEvent: source.getCurrentEvent(),
|
|
cursor: source.configuration.cursor,
|
|
});
|
|
}
|
|
// the data is cached delete the EventSource
|
|
sources.delete(uri);
|
|
},
|
|
});
|
|
sources.set(uri, source);
|
|
} else {
|
|
source = sources.get(uri);
|
|
}
|
|
// set/increase the usage counter
|
|
usage.set(source, ref);
|
|
source.open();
|
|
return source;
|
|
},
|
|
close: function(source, ref) {
|
|
if (source) {
|
|
// decrease the usage counter
|
|
usage.remove(source, ref);
|
|
// if the EventSource is no longer being used
|
|
// close it (data caching is dealt with by the above 'close' event listener)
|
|
if (!usage.has(source)) {
|
|
source.close();
|
|
}
|
|
}
|
|
},
|
|
});
|