Add support for specifying future services and wildcards

This commit is contained in:
John Cowen 2018-06-08 13:20:13 +01:00 committed by Jack Pearkes
parent 55bc45832e
commit 5575455053
6 changed files with 69 additions and 10 deletions

View File

@ -18,18 +18,31 @@ export default Controller.extend({
});
},
actions: {
createNewLabel: function(term) {
return `Use a future Consul Service called '${term}'`;
},
change: function(e, value, _target) {
// normalize back to standard event
const target = e.target || { ..._target, ...{ name: e, value: value } };
switch (target.name) {
case 'Action':
set(this.changeset, target.name, target.value);
console.log(target.name, target.value, get(this.changeset, target.name));
break;
case 'SourceName':
case 'DestinationName':
set(this.changeset, target.name, get(target.value, 'Name'));
set(this, target.name, target.value);
let name = target.value;
let selected = target.value;
if (typeof name !== 'string') {
name = get(target.value, 'Name');
}
const match = get(this, 'items').filterBy('Name', name);
if (match.length === 0) {
selected = { Name: name };
const items = [selected].concat(this.items.toArray());
set(this, 'items', items);
}
set(this.changeset, target.name, name);
set(this, target.name, selected);
break;
}
},

View File

@ -20,6 +20,13 @@ export default Route.extend(WithIntentionActions, {
item: this.item,
items: get(this, 'servicesRepo').findAllByDatacenter(this.modelFor('dc').dc.Name),
intents: ['allow', 'deny'],
}).then(function(model) {
return {
...model,
...{
items: [{ Name: '*' }].concat(model.items.toArray()),
},
};
});
},
setupController: function(controller, model) {

View File

@ -14,6 +14,13 @@ export default Route.extend(WithAclActions, {
item: get(this, 'repo').findBySlug(params.id, this.modelFor('dc').dc.Name),
items: get(this, 'servicesRepo').findAllByDatacenter(this.modelFor('dc').dc.Name),
intents: ['allow', 'deny'],
}).then(function(model) {
return {
...model,
...{
items: [{ Name: '*' }].concat(model.items.toArray()),
},
};
});
},
setupController: function(controller, model) {

View File

@ -2,28 +2,40 @@
<fieldset>
<label class="type-text{{if item.error.SourceName ' has-error'}}">
<span>Source Service</span>
{{#power-select
{{#power-select-with-create
options=items
searchField='Name'
selected=SourceName
searchPlaceholder='Type service name'
onchange=(action 'change' 'SourceName') as |service|
buildSuggestion=(action 'createNewLabel')
oncreate=(action 'change' 'SourceName')
onchange=(action 'change' 'SourceName') as |service search|
}}
{{#if (eq service.Name '*') }}
* (All Services)
{{else}}
{{service.Name}}
{{/power-select}}
{{/if}}
{{/power-select-with-create}}
<em>Choose a Consul Service, write in a future Consul Service, or write any Service URL</em>
</label>
<label class="type-text{{if item.error.DestinationName ' has-error'}}">
<span>Destination Service</span>
{{#power-select
{{#power-select-with-create
options=items
searchField='Name'
selected=DestinationName
searchPlaceholder='Type service name'
buildSuggestion=(action 'createNewLabel')
oncreate=(action 'change' 'DestinationName')
onchange=(action 'change' 'DestinationName') as |service|
}}
{{#if (eq service.Name '*') }}
* (All Services)
{{else}}
{{service.Name}}
{{/power-select}}
{{/if}}
{{/power-select-with-create}}
<em>Choose a Consul Service, write in a future Consul Service, or write any Service URL</em>
</label>
<div role="radiogroup" class={{if item.error.Action ' has-error'}}>

View File

@ -73,6 +73,7 @@
"ember-math-helpers": "^2.4.0",
"ember-pluralize": "^0.2.0",
"ember-power-select": "^2.0.2",
"ember-power-select-with-create": "^0.6.0",
"ember-resolver": "^4.0.0",
"ember-sinon-qunit": "^2.1.0",
"ember-source": "~2.18.2",

View File

@ -3640,6 +3640,25 @@ ember-pluralize@^0.2.0:
dependencies:
ember-cli-babel "5.1.5"
ember-power-select-with-create@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/ember-power-select-with-create/-/ember-power-select-with-create-0.6.0.tgz#40ac701276379b78efbaedc33fb5f82e49f80674"
dependencies:
ember-cli-babel "^6.6.0"
ember-cli-htmlbars "^2.0.1"
ember-power-select "^2.0.0"
ember-power-select@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/ember-power-select/-/ember-power-select-2.0.3.tgz#a44b62d74ca286e1fdc4b8f3b0ea9a7cf53f34ed"
dependencies:
ember-basic-dropdown "^1.0.0"
ember-cli-babel "^6.11.0"
ember-cli-htmlbars "^2.0.1"
ember-concurrency "^0.8.19"
ember-text-measurer "^0.4.0"
ember-truth-helpers "^2.0.0"
ember-power-select@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/ember-power-select/-/ember-power-select-2.0.2.tgz#e8c9a4f266b5a32847e859ddd4db5b2f95108ee8"