refactor: 💡 apply type to host catalog and distribute down

This commit is contained in:
Randall Morey committed 2021-12-15 13:15:31 -05:00
1 parent be20491d2e
commit ac5710979a
6 files changed
+37 -56

No files matched your search

-7
View File
@@ -7,11 +7,4 @@ export default class HostModel extends GeneratedHostModel {
* @type {FragmentHostAttributesModel}
*/
@fragment('fragment-host-attributes', { defaultValue: {} }) attributes;
/**
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
}
+3 -3
View File
@@ -18,9 +18,9 @@ export default factory.extend({
},
withChildren: trait({
afterCreate(hostCatalog, server) {
const { scope } = hostCatalog;
const hosts = server.createList('host', 10, { scope, hostCatalog });
server.createList('host-set', 3, { scope, hostCatalog, hosts });
const { scope, type } = hostCatalog;
const hosts = server.createList('host', 10, { scope, hostCatalog, type });
server.createList('host-set', 3, { scope, hostCatalog, hosts, type });
},
}),
});
@@ -5,7 +5,7 @@ import { random, date, datatype } from 'faker';
* GeneratedHostCatalogModelFactory
*/
export default Factory.extend({
type: 'static',
type: () => random.arrayElement(['static', 'plugin']),
name: () => random.words(),
description: () => random.words(),
created_time: () => date.recent(),
@@ -5,7 +5,7 @@ import { random, date, internet, datatype } from 'faker';
* GeneratedHostModelFactory
*/
export default Factory.extend({
type: () => random.arrayElement(['static', 'plugin']),
type: 'static',
name: () => random.words(),
description: () => random.words(),
created_time: () => date.recent(),
-10
View File
@@ -22,14 +22,4 @@ module('Unit | Model | host', function (hooks) {
});
assert.equal(model.attributes.address, '127.0.0.1');
});
test('it has isStatic function and returns the expected values', async function (assert) {
assert.expect(3);
const store = this.owner.lookup('service:store');
const modelA = store.createRecord('host', { type: 'static' });
const modelB = store.createRecord('host', { type: 'plugin' });
assert.equal(typeof modelA.isStatic, 'boolean');
assert.true(modelA.isStatic);
assert.false(modelB.isStatic);
});
});
@@ -11,41 +11,39 @@
</table.header>
<table.body as |body|>
{{#each @model as |host|}}
{{#if host.isStatic}}
<body.row as |row|>
<row.headerCell>
{{#if (can 'read model' host)}}
<LinkTo
@route='scopes.scope.host-catalogs.host-catalog.hosts.host'
@model={{host.id}}
>
{{host.displayName}}
</LinkTo>
{{else}}
{{host.displayName}}
{{/if}}
<p>{{host.description}}</p>
</row.headerCell>
<row.cell>
<Rose::Badge>
{{t (concat 'resources.host.types.' host.type)}}
</Rose::Badge>
</row.cell>
<row.cell>
<Copyable
@text={{host.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
<body.row as |row|>
<row.headerCell>
{{#if (can 'read model' host)}}
<LinkTo
@route='scopes.scope.host-catalogs.host-catalog.hosts.host'
@model={{host.id}}
>
<code>{{host.id}}</code>
</Copyable>
</row.cell>
<row.cell>
<code>{{host.attributes.address}}</code>
</row.cell>
</body.row>
{{/if}}
{{host.displayName}}
</LinkTo>
{{else}}
{{host.displayName}}
{{/if}}
<p>{{host.description}}</p>
</row.headerCell>
<row.cell>
<Rose::Badge>
{{t (concat 'resources.host.types.' host.type)}}
</Rose::Badge>
</row.cell>
<row.cell>
<Copyable
@text={{host.id}}
@buttonText={{t 'actions.copy-to-clipboard'}}
@acknowledgeText={{t 'states.copied'}}
>
<code>{{host.id}}</code>
</Copyable>
</row.cell>
<row.cell>
<code>{{host.attributes.address}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>