open-consul/ui-v2/app/utils/dom/event-source/proxy.js
John Cowen 81f209d71e UI: ACL Roles (#5635)
Adds support for ACL Roles and Service Identities CRUD, along with necessary changes to Tokens, and the CSS improvements required.

Also includes refinements/improvements for easier testing of deeply nested components.

1. ember-data adapter/serializer/model triplet for Roles
2. repository, form/validations and searching filter for Roles
3. Moves potentially, repeated, or soon to to repeated functionality
into a mixin (mainly for 'many policy' relationships)
4. A few styling tweaks for little edge cases around roles
5. Router additions, Route, Controller and templates for Roles

Also see: 

* UI: ACL Roles cont. plus Service Identities (#5661 and #5720)
2019-05-01 18:22:37 +00:00

57 lines
1.9 KiB
JavaScript

import { get, set } from '@ember/object';
export default function(ObjProxy, ArrProxy, createListeners) {
return function(source, data = []) {
let Proxy = ObjProxy;
// TODO: Why are these two separate?
// And when is data ever a string?
if (typeof data !== 'string' && typeof get(data, 'length') !== 'undefined') {
data = data.filter(function(item) {
return !get(item, 'isDestroyed') && !get(item, 'isDeleted') && get(item, 'isLoaded');
});
}
if (typeof data !== 'string' && typeof get(data, 'length') !== 'undefined') {
Proxy = ArrProxy;
}
const proxy = Proxy.create({
content: data,
closed: false,
error: null,
init: function() {
this.listeners = createListeners();
this.listeners.add(source, 'message', e => set(this, 'content', e.data));
this.listeners.add(source, 'open', () => set(this, 'closed', false));
this.listeners.add(source, 'close', () => set(this, 'closed', true));
this.listeners.add(source, 'error', e => set(this, 'error', e.error));
},
configuration: source.configuration,
addEventListener: function(type, handler) {
// Force use of computed for messages
// Temporarily disable this restriction
// if (type !== 'message') {
this.listeners.add(source, type, handler);
// }
},
getCurrentEvent: function() {
return source.getCurrentEvent(...arguments);
},
removeEventListener: function() {
return source.removeEventListener(...arguments);
},
dispatchEvent: function() {
return source.dispatchEvent(...arguments);
},
close: function() {
return source.close(...arguments);
},
reopen: function() {
return source.reopen(...arguments);
},
willDestroy: function() {
this.listeners.remove();
},
});
return proxy;
};
}