diff --git a/ui/packages/consul-ui/app/controllers/dc/services/index.js b/ui/packages/consul-ui/app/controllers/dc/services/index.js deleted file mode 100644 index a61564673..000000000 --- a/ui/packages/consul-ui/app/controllers/dc/services/index.js +++ /dev/null @@ -1,20 +0,0 @@ -import { computed } from '@ember/object'; -import Controller from '@ember/controller'; - -export default class IndexController extends Controller { - @computed('items.[]') - get services() { - return this.items.filter(function(item) { - return item.Kind !== 'connect-proxy'; - }); - } - - @computed('services') - get externalSources() { - const sources = this.services.reduce(function(prev, item) { - return prev.concat(item.ExternalSources || []); - }, []); - // unique, non-empty values, alpha sort - return [...new Set(sources)].filter(Boolean).sort(); - } -} diff --git a/ui/packages/consul-ui/app/controllers/dc/services/show/instances.js b/ui/packages/consul-ui/app/controllers/dc/services/show/instances.js deleted file mode 100644 index 9618d59b3..000000000 --- a/ui/packages/consul-ui/app/controllers/dc/services/show/instances.js +++ /dev/null @@ -1,13 +0,0 @@ -import { computed } from '@ember/object'; -import Controller from '@ember/controller'; - -export default class InstancesController extends Controller { - @computed('items') - get externalSources() { - const sources = this.items.reduce(function(prev, item) { - return prev.concat(item.ExternalSources || []); - }, []); - // unique, non-empty values, alpha sort - return [...new Set(sources)].filter(Boolean).sort(); - } -} diff --git a/ui/packages/consul-ui/app/helpers/collection.js b/ui/packages/consul-ui/app/helpers/collection.js new file mode 100644 index 000000000..5cef73b93 --- /dev/null +++ b/ui/packages/consul-ui/app/helpers/collection.js @@ -0,0 +1,23 @@ +import Helper from '@ember/component/helper'; +import { get } from '@ember/object'; + +import { Collection as Service } from 'consul-ui/models/service'; +import { Collection as ServiceInstance } from 'consul-ui/models/service-instance'; + +const collections = { + service: Service, + 'service-instance': ServiceInstance, +}; +class EmptyCollection {} +export default class CollectionHelper extends Helper { + compute([collection, str], hash) { + if (collection.length > 0) { + // TODO: Looksee if theres ever going to be a public way to get this + const modelName = get(collection, 'firstObject')._internalModel.modelName; + const Collection = collections[modelName]; + return new Collection(collection); + } else { + return new EmptyCollection(); + } + } +} diff --git a/ui/packages/consul-ui/app/models/service-instance.js b/ui/packages/consul-ui/app/models/service-instance.js index dd8631068..09a386a02 100644 --- a/ui/packages/consul-ui/app/models/service-instance.js +++ b/ui/packages/consul-ui/app/models/service-instance.js @@ -2,10 +2,27 @@ import Model, { attr, belongsTo } from '@ember-data/model'; import { fragmentArray } from 'ember-data-model-fragments/attributes'; import { computed, get, set } from '@ember/object'; import { or, filter, alias } from '@ember/object/computed'; +import { tracked } from '@glimmer/tracking'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'Node.Node,Service.ID'; +export const Collection = class Collection { + @tracked items; + + constructor(items) { + this.items = items; + } + + get ExternalSources() { + const sources = this.items.reduce(function(prev, item) { + return prev.concat(item.ExternalSources || []); + }, []); + // unique, non-empty values, alpha sort + return [...new Set(sources)].filter(Boolean).sort(); + } +}; + export default class ServiceInstance extends Model { @attr('string') uid; diff --git a/ui/packages/consul-ui/app/models/service.js b/ui/packages/consul-ui/app/models/service.js index a04d2e599..f55691015 100644 --- a/ui/packages/consul-ui/app/models/service.js +++ b/ui/packages/consul-ui/app/models/service.js @@ -1,9 +1,26 @@ import Model, { attr } from '@ember-data/model'; import { computed, get } from '@ember/object'; +import { tracked } from '@glimmer/tracking'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'Name'; +export const Collection = class Collection { + @tracked items; + + constructor(items) { + this.items = items; + } + + get ExternalSources() { + const sources = this.items.reduce(function(prev, item) { + return prev.concat(item.ExternalSources || []); + }, []); + // unique, non-empty values, alpha sort + return [...new Set(sources)].filter(Boolean).sort(); + } +}; + export default class Service extends Model { @attr('string') uid; @attr('string') Name; diff --git a/ui/packages/consul-ui/app/templates/dc/nodes/show/services.hbs b/ui/packages/consul-ui/app/templates/dc/nodes/show/services.hbs index 462308ec7..52a8f3933 100644 --- a/ui/packages/consul-ui/app/templates/dc/nodes/show/services.hbs +++ b/ui/packages/consul-ui/app/templates/dc/nodes/show/services.hbs @@ -7,13 +7,13 @@ ) ) as |filters|}} {{#let (or sortBy "Status:asc") as |sort|}} - {{#let item.Services as |items|}} + {{#let (reject-by 'Service.Kind' 'connect-proxy' item.Services) as |items|}}
- {{#if (gt services.length 0)}} - No services where found matching that search, or you may not have access to view the services you are searching for. - {{else}} - There don't seem to be any registered services, or you may not have access to view services yet. - {{/if}} -
-+ {{#if (gt services.length 0)}} + No services where found matching that search, or you may not have access to view the services you are searching for. + {{else}} + There don't seem to be any registered services, or you may not have access to view services yet. + {{/if}} +
+