ui: Run Ember native class code mod (#9093)

* ui: Apply native class codemod to all services

* ui: Apply native class codemod to routes

* ui: Apply native class codemod to controllers

* Fix up ember proxy `content` issue

* Add a CreateTime on policy creation

* Minor formatting

* Convert child based saving to use ec instead of custom approach

* Remove custom event source repo wrapping initializer

* Repos here are no longer proxy objects revert to using them normally

* Remove areas of code that were used to set up source backed repos
This commit is contained in:
John Cowen 2020-11-09 09:25:35 +00:00 committed by GitHub
parent eaafa5c17d
commit ef01ea18f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
150 changed files with 1878 additions and 1612 deletions

View File

@ -1,4 +1,6 @@
<div ...attributes>
<div
...attributes
>
{{yield}}
<YieldSlot @name="create">{{yield}}</YieldSlot>
<label class="type-text">

View File

@ -3,6 +3,8 @@ import { get, set, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';
import Slotted from 'block-slots';
export default Component.extend(Slotted, {
@ -43,6 +45,25 @@ export default Component.extend(Slotted, {
}
return options;
}),
save: task(function*(item, items, success = function() {}) {
const repo = this.repo;
try {
item = yield repo.persist(item);
this.actions.change.apply(this, [
{
target: {
name: 'items[]',
value: items,
},
},
items,
item,
]);
success();
} catch (e) {
this.error({ error: e });
}
}),
actions: {
search: function(term) {
// TODO: make sure we can either search before things are loaded
@ -60,37 +81,7 @@ export default Component.extend(Slotted, {
reset: function() {
this.form.clear({ Datacenter: this.dc, Namespace: this.nspace });
},
save: function(item, items, success = function() {}) {
// Specifically this saves an 'new' option/child
// and then adds it to the selectedOptions, not options
const repo = this.repo;
set(item, 'CreateTime', new Date().getTime());
// TODO: temporary async
// this should be `set(this, 'item', repo.persist(item));`
// need to be sure that its saved before adding/closing the modal for now
// and we don't open the modal on prop change yet
item = repo.persist(item);
this._listeners.add(item, {
message: e => {
this.actions.change.apply(this, [
{
target: {
name: 'items[]',
value: items,
},
},
items,
e.data,
]);
item.willDestroy();
success();
},
error: e => {
item.willDestroy();
this.error(e);
},
});
},
remove: function(item, items) {
const prop = this.repo.getSlugKey();
const value = get(item, prop);

View File

@ -24,7 +24,10 @@
<PolicyForm @form={{form}} @nspace={{nspace}} @dc={{dc}} @allowServiceIdentity={{allowServiceIdentity}} />
</BlockSlot>
<BlockSlot @name="actions" as |close|>
<button type="submit" {{action 'save' item items (queue (action close) (action 'reset'))}} disabled={{if (or item.isSaving item.isPristine item.isInvalid) 'disabled'}}>
<button type="submit"
onclick={{perform this.save item items (queue (action close) (action 'reset'))}}
disabled={{if (or item.isSaving item.isPristine item.isInvalid) 'disabled'}}
>
{{#if item.isSaving }}
<div class="progress indeterminate"></div>
{{/if}}

View File

@ -7,7 +7,7 @@ const ERROR_INVALID_POLICY = 'Invalid service policy';
const ERROR_NAME_EXISTS = 'Invalid Policy: A Policy with Name';
export default ChildSelectorComponent.extend({
repo: service('repository/policy/component'),
repo: service('repository/policy'),
name: 'policy',
type: 'policy',
allowIdentity: true,
@ -16,9 +16,10 @@ export default ChildSelectorComponent.extend({
this._super(...arguments);
const source = this.source;
if (source) {
const event = 'save';
this._listeners.add(source, {
save: e => this.actions[event].bind(this)(...e.data),
save: e => {
this.save.perform(...e.data);
},
});
}
},

View File

@ -35,7 +35,10 @@
<BlockSlot @name="actions" as |close|>
{{#if (eq state 'role')}}
<button type="submit" {{action 'save' item items (queue (action close) (action 'reset'))}} disabled={{if (or item.isSaving item.isPristine item.isInvalid) 'disabled'}}>
<button type="submit"
onclick={{perform this.save item items (queue (action close) (action 'reset'))}}
disabled={{if (or item.isSaving item.isPristine item.isInvalid) 'disabled'}}
>
{{#if item.isSaving }}
<div class="progress indeterminate"></div>
{{/if}}

View File

@ -6,7 +6,7 @@ import { alias } from '@ember/object/computed';
import { CallableEventSource as EventSource } from 'consul-ui/utils/dom/event-source';
export default ChildSelectorComponent.extend({
repo: service('repository/role/component'),
repo: service('repository/role'),
dom: service('dom'),
name: 'role',
type: 'role',

View File

@ -1,77 +1,82 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
import { get } from '@ember/object';
import { get, action } from '@ember/object';
import transitionable from 'consul-ui/utils/routing/transitionable';
export default Controller.extend({
router: service('router'),
store: service('store'),
feedback: service('feedback'),
actions: {
// TODO: We currently do this in the controller instead of the router
// as the nspace and dc variables aren't available directly on the Route
// look to see if we can move this up there so we can empty the Controller
// out again
reauthorize: function(e) {
// TODO: For the moment e isn't a real event
// it has data which is potentially the token
// and type which is the logout/authorize/use action
// used for the feedback service.
this.feedback.execute(
() => {
// TODO: Currently we clear cache from the ember-data store
// ideally this would be a static method of the abstract Repository class
// once we move to proper classes for services take another look at this.
this.store.clear();
//
const params = {};
if (e.data) {
const token = e.data;
// TODO: Do I actually need to check to see if nspaces are enabled here?
if (typeof this.nspace !== 'undefined') {
const nspace = get(token, 'Namespace') || this.nspace.Name;
// you potentially have a new namespace
// if you do redirect to it
if (nspace !== this.nspace.Name) {
params.nspace = `~${nspace}`;
}
export default class ApplicationController extends Controller {
@service('router')
router;
@service('store')
store;
@service('feedback')
feedback;
// TODO: We currently do this in the controller instead of the router
// as the nspace and dc variables aren't available directly on the Route
// look to see if we can move this up there so we can empty the Controller
// out again
@action
reauthorize(e) {
// TODO: For the moment e isn't a real event
// it has data which is potentially the token
// and type which is the logout/authorize/use action
// used for the feedback service.
this.feedback.execute(
() => {
// TODO: Currently we clear cache from the ember-data store
// ideally this would be a static method of the abstract Repository class
// once we move to proper classes for services take another look at this.
this.store.clear();
//
const params = {};
if (e.data) {
const token = e.data;
// TODO: Do I actually need to check to see if nspaces are enabled here?
if (typeof this.nspace !== 'undefined') {
const nspace = get(token, 'Namespace') || this.nspace.Name;
// you potentially have a new namespace
// if you do redirect to it
if (nspace !== this.nspace.Name) {
params.nspace = `~${nspace}`;
}
}
const container = getOwner(this);
const routeName = this.router.currentRoute.name;
const route = container.lookup(`route:${routeName}`);
// Refresh the application route as everything including the main nav needs refreshing
return container
.lookup('route:application')
.refresh()
.promise.catch(function(e) {
// passthrough
// if you are on an error page a refresh of the application route will reject
// thats ok as we then transition to the actual route you were trying
// to get to originally anyway
})
.then(res => {
// Use transitionable if we need to change a section of the URL
// or routeName and currentRouteName aren't equal (i.e. error page)
if (
routeName !== this.router.currentRouteName ||
typeof params.nspace !== 'undefined'
) {
return route.transitionTo(
...transitionable(this.router.currentRoute, params, container)
);
} else {
return res;
}
});
},
e.type,
function(type, e) {
return type;
},
{}
);
},
},
});
}
const container = getOwner(this);
const routeName = this.router.currentRoute.name;
const route = container.lookup(`route:${routeName}`);
// Refresh the application route as everything including the main nav needs refreshing
return container
.lookup('route:application')
.refresh()
.promise.catch(function(e) {
// passthrough
// if you are on an error page a refresh of the application route will reject
// thats ok as we then transition to the actual route you were trying
// to get to originally anyway
})
.then(res => {
// Use transitionable if we need to change a section of the URL
// or routeName and currentRouteName aren't equal (i.e. error page)
if (
routeName !== this.router.currentRouteName ||
typeof params.nspace !== 'undefined'
) {
return route.transitionTo(
...transitionable(this.router.currentRoute, params, container)
);
} else {
return res;
}
});
},
e.type,
function(type, e) {
return type;
},
{}
);
}
}

View File

@ -1,3 +1,3 @@
import Controller from '@ember/controller';
export default Controller.extend({});
export default class DcController extends Controller {}

View File

@ -1,2 +1,2 @@
import Controller from './edit';
export default Controller.extend();
export default class CreateController extends Controller {}

View File

@ -1,6 +1,7 @@
import { action } from '@ember/object';
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
filterBy: {
as: 'type',
},
@ -8,10 +9,10 @@ export default Controller.extend({
as: 'filter',
replace: true,
},
},
actions: {
sendClone: function(item) {
this.send('clone', item);
},
},
});
};
@action
sendClone(item) {
this.send('clone', item);
}
}

View File

@ -1,2 +1,2 @@
import Controller from './edit';
export default Controller.extend();
export default class CreateController extends Controller {}

View File

@ -1,14 +1,17 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
builder: service('form'),
init: function() {
this._super(...arguments);
import Controller from '@ember/controller';
export default class EditController extends Controller {
@service('form')
builder;
init() {
super.init(...arguments);
this.form = this.builder.form('policy');
},
setProperties: function(model) {
}
setProperties(model) {
// essentially this replaces the data with changesets
this._super(
super.setProperties(
Object.keys(model).reduce((prev, key, i) => {
switch (key) {
case 'item':
@ -18,5 +21,5 @@ export default Controller.extend({
return prev;
}, model)
);
},
});
}
}

View File

@ -1,6 +1,6 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
dc: 'dc',
type: 'type',
@ -8,5 +8,5 @@ export default Controller.extend({
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,2 +1,2 @@
import Controller from './edit';
export default Controller.extend();
export default class CreateController extends Controller {}

View File

@ -1,14 +1,17 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
builder: service('form'),
init: function() {
this._super(...arguments);
import Controller from '@ember/controller';
export default class EditController extends Controller {
@service('form')
builder;
init() {
super.init(...arguments);
this.form = this.builder.form('role');
},
setProperties: function(model) {
}
setProperties(model) {
// essentially this replaces the data with changesets
this._super(
super.setProperties(
Object.keys(model).reduce((prev, key, i) => {
switch (key) {
case 'item':
@ -18,5 +21,5 @@ export default Controller.extend({
return prev;
}, model)
);
},
});
}
}

View File

@ -1,10 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,2 +1,2 @@
import Controller from './edit';
export default Controller.extend();
export default class CreateController extends Controller {}

View File

@ -1,10 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,12 +1,12 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
access: 'access',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,9 +1,9 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,12 +1,12 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
status: 'status',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,14 +1,16 @@
import Controller from '@ember/controller';
import { get, computed } from '@ember/object';
export default Controller.extend({
queryParams: {
export default class ServicesController extends Controller {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
checks: computed('item.Checks.[]', function() {
};
@computed('item.Checks.[]')
get checks() {
const checks = {};
get(this, 'item.Checks')
.filter(item => {
@ -22,5 +24,5 @@ export default Controller.extend({
});
return checks;
}),
});
}
}

View File

@ -1,2 +1,2 @@
import Controller from './edit';
export default Controller.extend();
export default class CreateController extends Controller {}

View File

@ -1,10 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
},
},
});
};
}

View File

@ -1,8 +1,8 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
status: 'status',
source: 'source',
@ -10,17 +10,21 @@ export default Controller.extend({
search: {
as: 'filter',
},
},
services: computed('items.[]', function() {
};
@computed('items.[]')
get services() {
return this.items.filter(function(item) {
return item.Kind !== 'connect-proxy';
});
}),
externalSources: computed('services', function() {
}
@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();
}),
});
}
}

View File

@ -1,27 +1,28 @@
import Controller from '@ember/controller';
import { get } from '@ember/object';
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
import { get, action } from '@ember/object';
export default Controller.extend({
notify: service('flashMessages'),
actions: {
error: function(e) {
if (e.target.readyState === 1) {
// OPEN
if (get(e, 'error.errors.firstObject.status') === '404') {
this.notify.add({
destroyOnClick: false,
sticky: true,
type: 'warning',
action: 'update',
});
[e.target, this.proxy].forEach(function(item) {
if (item && typeof item.close === 'function') {
item.close();
}
});
}
export default class InstanceController extends Controller {
@service('flashMessages')
notify;
@action
error(e) {
if (e.target.readyState === 1) {
// OPEN
if (get(e, 'error.errors.firstObject.status') === '404') {
this.notify.add({
destroyOnClick: false,
sticky: true,
type: 'warning',
action: 'update',
});
[e.target, this.proxy].forEach(function(item) {
if (item && typeof item.close === 'function') {
item.close();
}
});
}
},
},
});
}
}
}

View File

@ -1,36 +1,41 @@
import Controller from '@ember/controller';
import { get } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
export default Controller.extend({
dom: service('dom'),
notify: service('flashMessages'),
item: alias('items.firstObject'),
actions: {
error: function(e) {
if (e.target.readyState === 1) {
// OPEN
if (get(e, 'error.errors.firstObject.status') === '404') {
this.notify.add({
destroyOnClick: false,
sticky: true,
type: 'warning',
action: 'update',
});
}
[
e.target,
this.intentions,
this.chain,
this.proxies,
this.gatewayServices,
this.topology,
].forEach(function(item) {
if (item && typeof item.close === 'function') {
item.close();
}
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { get, action } from '@ember/object';
export default class ShowController extends Controller {
@service('dom')
dom;
@service('flashMessages')
notify;
@alias('items.firstObject')
item;
@action
error(e) {
if (e.target.readyState === 1) {
// OPEN
if (get(e, 'error.errors.firstObject.status') === '404') {
this.notify.add({
destroyOnClick: false,
sticky: true,
type: 'warning',
action: 'update',
});
}
},
},
});
[
e.target,
this.intentions,
this.chain,
this.proxies,
this.gatewayServices,
this.topology,
].forEach(function(item) {
if (item && typeof item.close === 'function') {
item.close();
}
});
}
}
}

View File

@ -1,8 +1,8 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class InstancesController extends Controller {
queryParams = {
sortBy: 'sort',
status: 'status',
source: 'source',
@ -10,12 +10,14 @@ export default Controller.extend({
as: 'filter',
replace: true,
},
},
externalSources: computed('items', function() {
};
@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();
}),
});
}
}

View File

@ -1,10 +1,10 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class IndexController extends Controller {
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,12 +1,12 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class ServicesController extends Controller {
queryParams = {
sortBy: 'sort',
instance: 'instance',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,12 +1,12 @@
import Controller from '@ember/controller';
export default Controller.extend({
queryParams: {
export default class UpstreamsController extends Controller {
queryParams = {
sortBy: 'sort',
instance: 'instance',
search: {
as: 'filter',
replace: true,
},
},
});
};
}

View File

@ -1,54 +0,0 @@
import { env } from 'consul-ui/env';
export function initialize(container) {
if (env('CONSUL_UI_DISABLE_REALTIME')) {
return;
}
[]
.concat(
['policy', 'role'].map(function(item) {
// create repositories that return a promise resolving to an EventSource
return {
service: `repository/${item}/component`,
extend: 'repository/type/component',
// Inject our original respository that is used by this class
// within the callable of the EventSource
services: {
content: `repository/${item}`,
},
};
})
)
.concat([
{
service: 'form',
services: {
role: 'repository/role/component',
policy: 'repository/policy/component',
},
},
])
.forEach(function(definition) {
if (typeof definition.extend !== 'undefined') {
// Create the class instances that we need
container.register(
`service:${definition.service}`,
container.resolveRegistration(`service:${definition.extend}`).extend({})
);
}
Object.keys(definition.services).forEach(function(name) {
const servicePath = definition.services[name];
// inject its dependencies, this could probably detect the type
// but hardcode this for the moment
if (typeof definition.route !== 'undefined') {
container.inject(`route:${definition.route}`, name, `service:${servicePath}`);
} else {
container.inject(`service:${definition.service}`, name, `service:${servicePath}`);
}
});
});
}
export default {
initialize,
};

View File

@ -20,7 +20,11 @@ export default Model.extend({
defaultValue: '',
}),
// frontend only for ordering where CreateIndex can't be used
CreateTime: attr('date', { defaultValue: 0 }),
CreateTime: attr('number', {
defaultValue: function() {
return new Date().getTime();
},
}),
//
isGlobalManagement: computed('ID', function() {
return this.ID === MANAGEMENT_ID;

View File

@ -1,7 +1,7 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash, Promise } from 'rsvp';
import { get } from '@ember/object';
import { get, action } from '@ember/object';
// TODO: We should potentially move all these nspace related things
// up a level to application.js
@ -23,11 +23,17 @@ const findActiveNspace = function(nspaces, nspace) {
}
return found;
};
export default Route.extend({
repo: service('repository/dc'),
nspacesRepo: service('repository/nspace/disabled'),
settingsRepo: service('settings'),
model: function(params) {
export default class DcRoute extends Route {
@service('repository/dc')
repo;
@service('repository/nspace/disabled')
nspacesRepo;
@service('settings')
settingsRepo;
model(params) {
const app = this.modelFor('application');
return hash({
nspace: this.nspacesRepo.getActive(),
@ -61,44 +67,45 @@ export default Route.extend({
return model;
}
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
// the model here is actually required for the entire application
// but we need to wait until we are in this route so we know what the dc
// and or nspace is if the below changes please revists the comments
// in routes/application:model
this.controllerFor('application').setProperties(model);
},
actions: {
// TODO: This will eventually be deprecated please see
// https://deprecations.emberjs.com/v3.x/#toc_deprecate-router-events
willTransition: function(transition) {
this._super(...arguments);
if (
typeof transition !== 'undefined' &&
(transition.from.name.endsWith('nspaces.create') ||
transition.from.name.startsWith('nspace.dc.acls.tokens'))
) {
// Only when we create, reload the nspaces in the main menu to update them
// as we don't block for those
// And also when we [Use] a token reload the nspaces that you are able to see,
// including your permissions for being able to manage namespaces
// Potentially we should just do this on every single transition
// but then we would need to check to see if nspaces are enabled
const controller = this.controllerFor('application');
Promise.all([
this.nspacesRepo.findAll(),
this.nspacesRepo.authorize(get(controller, 'dc.Name'), get(controller, 'nspace.Name')),
]).then(([nspaces, permissions]) => {
if (typeof controller !== 'undefined') {
controller.setProperties({
nspaces: nspaces,
permissions: permissions,
});
}
});
}
},
},
});
}
// TODO: This will eventually be deprecated please see
// https://deprecations.emberjs.com/v3.x/#toc_deprecate-router-events
@action
willTransition(transition) {
undefined;
if (
typeof transition !== 'undefined' &&
(transition.from.name.endsWith('nspaces.create') ||
transition.from.name.startsWith('nspace.dc.acls.tokens'))
) {
// Only when we create, reload the nspaces in the main menu to update them
// as we don't block for those
// And also when we [Use] a token reload the nspaces that you are able to see,
// including your permissions for being able to manage namespaces
// Potentially we should just do this on every single transition
// but then we would need to check to see if nspaces are enabled
const controller = this.controllerFor('application');
Promise.all([
this.nspacesRepo.findAll(),
this.nspacesRepo.authorize(get(controller, 'dc.Name'), get(controller, 'nspace.Name')),
]).then(([nspaces, permissions]) => {
if (typeof controller !== 'undefined') {
controller.setProperties({
nspaces: nspaces,
permissions: permissions,
});
}
});
}
}
}

View File

@ -1,3 +1,3 @@
import Route from 'consul-ui/routing/route';
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
export default Route.extend(WithBlockingActions, {});
export default class AclsRoute extends Route.extend(WithBlockingActions) {}

View File

@ -1,17 +1,21 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithAclActions from 'consul-ui/mixins/acl/with-actions';
export default Route.extend(WithAclActions, {
templateName: 'dc/acls/edit',
repo: service('repository/acl'),
beforeModel: function() {
export default class CreateRoute extends Route.extend(WithAclActions) {
templateName = 'dc/acls/edit';
@service('repository/acl')
repo;
beforeModel() {
this.repo.invalidate();
},
model: function(params) {
}
model(params) {
this.item = this.repo.create({
Datacenter: this.modelFor('dc').dc.Name,
});
@ -20,14 +24,16 @@ export default Route.extend(WithAclActions, {
item: this.item,
types: ['management', 'client'],
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
deactivate: function() {
}
deactivate() {
if (get(this.item, 'isNew')) {
this.item.destroyRecord();
}
},
});
}
}

View File

@ -1,20 +1,25 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithAclActions from 'consul-ui/mixins/acl/with-actions';
export default Route.extend(WithAclActions, {
repo: service('repository/acl'),
settings: service('settings'),
model: function(params) {
export default class EditRoute extends Route.extend(WithAclActions) {
@service('repository/acl')
repo;
@service('settings')
settings;
model(params) {
return hash({
item: this.repo.findBySlug(params.id, this.modelFor('dc').dc.Name),
types: ['management', 'client'],
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,20 +1,25 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithAclActions from 'consul-ui/mixins/acl/with-actions';
export default Route.extend(WithAclActions, {
repo: service('repository/acl'),
settings: service('settings'),
queryParams: {
export default class IndexRoute extends Route.extend(WithAclActions) {
@service('repository/acl')
repo;
@service('settings')
settings;
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
beforeModel: function(transition) {
};
beforeModel(transition) {
return this.settings.findBySlug('token').then(token => {
// If you don't have a token set or you have a
// token set with AccessorID set to not null (new ACL mode)
@ -25,15 +30,17 @@ export default Route.extend(WithAclActions, {
this.replaceWith('dc.acls.tokens');
}
});
},
model: function(params) {
}
model(params) {
return hash({
items: this.repo.findAllByDatacenter(this.modelFor('dc').dc.Name),
token: this.settings.findBySlug('token'),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,6 +1,6 @@
import Route from './edit';
import CreatingRoute from 'consul-ui/mixins/creating-route';
export default Route.extend(CreatingRoute, {
templateName: 'dc/acls/policies/edit',
});
export default class CreateRoute extends Route.extend(CreatingRoute) {
templateName = 'dc/acls/policies/edit';
}

View File

@ -1,18 +1,22 @@
import SingleRoute from 'consul-ui/routing/single';
import { inject as service } from '@ember/service';
import SingleRoute from 'consul-ui/routing/single';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithPolicyActions from 'consul-ui/mixins/policy/with-actions';
export default SingleRoute.extend(WithPolicyActions, {
repo: service('repository/policy'),
tokenRepo: service('repository/token'),
model: function(params) {
export default class EditRoute extends SingleRoute.extend(WithPolicyActions) {
@service('repository/policy')
repo;
@service('repository/token')
tokenRepo;
model(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
const tokenRepo = this.tokenRepo;
return this._super(...arguments).then(model => {
return super.model(...arguments).then(model => {
return hash({
...model,
...{
@ -29,9 +33,10 @@ export default SingleRoute.extend(WithPolicyActions, {
},
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,19 +1,22 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithPolicyActions from 'consul-ui/mixins/policy/with-actions';
export default Route.extend(WithPolicyActions, {
repo: service('repository/policy'),
queryParams: {
export default class IndexRoute extends Route.extend(WithPolicyActions) {
@service('repository/policy')
repo;
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
return hash({
...this.repo.status({
items: this.repo.findAllByDatacenter(
@ -22,9 +25,10 @@ export default Route.extend(WithPolicyActions, {
),
}),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,6 +1,6 @@
import Route from './edit';
import CreatingRoute from 'consul-ui/mixins/creating-route';
export default Route.extend(CreatingRoute, {
templateName: 'dc/acls/roles/edit',
});
export default class CreateRoute extends Route.extend(CreatingRoute) {
templateName = 'dc/acls/roles/edit';
}

View File

@ -1,18 +1,22 @@
import SingleRoute from 'consul-ui/routing/single';
import { inject as service } from '@ember/service';
import SingleRoute from 'consul-ui/routing/single';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithRoleActions from 'consul-ui/mixins/role/with-actions';
export default SingleRoute.extend(WithRoleActions, {
repo: service('repository/role'),
tokenRepo: service('repository/token'),
model: function(params) {
export default class EditRoute extends SingleRoute.extend(WithRoleActions) {
@service('repository/role')
repo;
@service('repository/token')
tokenRepo;
model(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
const tokenRepo = this.tokenRepo;
return this._super(...arguments).then(model => {
return super.model(...arguments).then(model => {
return hash({
...model,
...{
@ -28,9 +32,10 @@ export default SingleRoute.extend(WithRoleActions, {
},
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,19 +1,22 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithRoleActions from 'consul-ui/mixins/role/with-actions';
export default Route.extend(WithRoleActions, {
repo: service('repository/role'),
queryParams: {
export default class IndexRoute extends Route.extend(WithRoleActions) {
@service('repository/role')
repo;
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
return hash({
...this.repo.status({
items: this.repo.findAllByDatacenter(
@ -22,9 +25,10 @@ export default Route.extend(WithRoleActions, {
),
}),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,6 +1,6 @@
import Route from './edit';
import CreatingRoute from 'consul-ui/mixins/creating-route';
export default Route.extend(CreatingRoute, {
templateName: 'dc/acls/tokens/edit',
});
export default class CreateRoute extends Route.extend(CreatingRoute) {
templateName = 'dc/acls/tokens/edit';
}

View File

@ -1,14 +1,18 @@
import SingleRoute from 'consul-ui/routing/single';
import { inject as service } from '@ember/service';
import SingleRoute from 'consul-ui/routing/single';
import { hash } from 'rsvp';
import WithTokenActions from 'consul-ui/mixins/token/with-actions';
export default SingleRoute.extend(WithTokenActions, {
repo: service('repository/token'),
settings: service('settings'),
model: function(params, transition) {
return this._super(...arguments).then(model => {
export default class EditRoute extends SingleRoute.extend(WithTokenActions) {
@service('repository/token')
repo;
@service('settings')
settings;
model(params, transition) {
return super.model(...arguments).then(model => {
return hash({
...model,
...{
@ -17,9 +21,10 @@ export default SingleRoute.extend(WithTokenActions, {
},
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,19 +1,24 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import WithTokenActions from 'consul-ui/mixins/token/with-actions';
export default Route.extend(WithTokenActions, {
repo: service('repository/token'),
settings: service('settings'),
queryParams: {
export default class IndexRoute extends Route.extend(WithTokenActions) {
@service('repository/token')
repo;
@service('settings')
settings;
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
beforeModel: function(transition) {
};
beforeModel(transition) {
return this.settings.findBySlug('token').then(token => {
// If you have a token set with AccessorID set to null (legacy mode)
// then rewrite to the old acls
@ -23,8 +28,9 @@ export default Route.extend(WithTokenActions, {
this.replaceWith('dc.acls');
}
});
},
model: function(params) {
}
model(params) {
return hash({
...this.repo.status({
items: this.repo.findAllByDatacenter(
@ -35,9 +41,10 @@ export default Route.extend(WithTokenActions, {
nspace: this.modelFor('nspace').nspace.substr(1),
token: this.settings.findBySlug('token'),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,7 +1,7 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
beforeModel: function() {
export default class IndexRoute extends Route {
beforeModel() {
this.transitionTo('dc.services');
},
});
}
}

View File

@ -1,5 +1,5 @@
import Route from './edit';
export default Route.extend({
templateName: 'dc/intentions/edit',
});
export default class CreateRoute extends Route {
templateName = 'dc/intentions/edit';
}

View File

@ -1,10 +1,12 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
export default Route.extend({
repo: service('repository/intention'),
model: function({ intention_id }, transition) {
export default class EditRoute extends Route {
@service('repository/intention')
repo;
model({ intention_id }, transition) {
const dc = this.modelFor('dc').dc.Name;
const nspace = '*';
return hash({
@ -17,9 +19,10 @@ export default Route.extend({
Datacenter: dc,
}),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,21 +1,23 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
queryParams: {
export default class IndexRoute extends Route {
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
return {
dc: this.modelFor('dc').dc.Name,
nspace: this.modelFor('nspace').nspace.substr(1) || 'default',
};
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,5 +1,5 @@
import Route from './edit';
export default Route.extend({
templateName: 'dc/kv/edit',
});
export default class CreateRoute extends Route {
templateName = 'dc/kv/edit';
}

View File

@ -1,14 +1,18 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import ascend from 'consul-ui/utils/ascend';
export default Route.extend({
repo: service('repository/kv'),
sessionRepo: service('repository/session'),
model: function(params) {
export default class EditRoute extends Route {
@service('repository/kv')
repo;
@service('repository/session')
sessionRepo;
model(params) {
const create =
this.routeName
.split('.')
@ -46,9 +50,10 @@ export default Route.extend({
}
return model;
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,12 +1,13 @@
import Route from './index';
export default Route.extend({
templateName: 'dc/kv/index',
beforeModel: function(transition) {
this._super(...arguments);
export default class FolderRoute extends Route {
templateName = 'dc/kv/index';
beforeModel(transition) {
super.beforeModel(...arguments);
const params = this.paramsFor('dc.kv.folder');
if (params.key === '/' || params.key == null) {
return this.transitionTo('dc.kv.index');
}
},
});
}
}

View File

@ -1,18 +1,21 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
import { get, action } from '@ember/object';
import isFolder from 'consul-ui/utils/isFolder';
export default Route.extend({
queryParams: {
export default class IndexRoute extends Route {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
repo: service('repository/kv'),
beforeModel: function() {
};
@service('repository/kv')
repo;
beforeModel() {
// we are index or folder, so if the key doesn't have a trailing slash
// add one to force a fake findBySlug
const params = this.paramsFor(this.routeName);
@ -20,8 +23,9 @@ export default Route.extend({
if (!isFolder(key)) {
return this.replaceWith(this.routeName, key + '/');
}
},
model: function(params) {
}
model(params) {
let key = params.key || '/';
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
@ -43,17 +47,18 @@ export default Route.extend({
},
});
});
},
actions: {
error: function(e) {
if (e.errors && e.errors[0] && e.errors[0].status == '404') {
return this.transitionTo('dc.kv.index');
}
throw e;
},
},
setupController: function(controller, model) {
this._super(...arguments);
}
@action
error(e) {
if (e.errors && e.errors[0] && e.errors[0].status == '404') {
return this.transitionTo('dc.kv.index');
}
throw e;
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,3 +1,3 @@
import Route from './create';
export default Route.extend();
export default class RootCreateRoute extends Route {}

View File

@ -1,26 +1,30 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
export default Route.extend({
data: service('data-source/service'),
queryParams: {
export default class IndexRoute extends Route {
@service('data-source/service')
data;
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = '*';
return hash({
items: this.data.source(uri => uri`/${nspace}/${dc}/nodes`),
leader: this.data.source(uri => uri`/${nspace}/${dc}/leader`),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,10 +1,12 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
export default Route.extend({
data: service('data-source/service'),
model: function(params) {
export default class ShowRoute extends Route {
@service('data-source/service')
data;
model(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
const name = params.name;
@ -18,9 +20,10 @@ export default Route.extend({
tomography: this.data.source(uri => uri`/${nspace}/${dc}/coordinates/for-node/${name}`),
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class HealthchecksRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,8 +1,8 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
afterModel: function(model, transition) {
export default class IndexRoute extends Route {
afterModel(model, transition) {
const parent = this.routeName
.split('.')
.slice(0, -1)
@ -11,5 +11,5 @@ export default Route.extend({
// so check the length here.
const to = get(model, 'item.Checks.length') > 0 ? 'healthchecks' : 'services';
this.replaceWith(`${parent}.${to}`, model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class MetadataRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
model: function() {
export default class RttRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
afterModel: function(model, transition) {
}
afterModel(model, transition) {
if (!get(model, 'tomography.distances')) {
const parent = this.routeName
.split('.')
@ -17,9 +18,10 @@ export default Route.extend({
.join('.');
this.replaceWith(parent);
}
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,21 +1,23 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
queryParams: {
export default class ServicesRoute extends Route {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
model: function() {
};
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,13 +1,20 @@
import Route from 'consul-ui/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithBlockingActions from 'consul-ui/mixins/with-blocking-actions';
export default Route.extend(WithBlockingActions, {
data: service('data-source/service'),
sessionRepo: service('repository/session'),
feedback: service('feedback'),
model: function() {
export default class SessionsRoute extends Route.extend(WithBlockingActions) {
@service('data-source/service')
data;
@service('repository/session')
sessionRepo;
@service('feedback')
feedback;
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
@ -21,19 +28,20 @@ export default Route.extend(WithBlockingActions, {
node: node,
sessions: this.data.source(uri => uri`/${nspace}/${dc}/sessions/for-node/${node}`),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
actions: {
invalidateSession: function(item) {
const route = this;
return this.feedback.execute(() => {
return this.sessionRepo.remove(item).then(() => {
route.refresh();
});
}, 'delete');
},
},
});
}
@action
invalidateSession(item) {
const route = this;
return this.feedback.execute(() => {
return this.sessionRepo.remove(item).then(() => {
route.refresh();
});
}, 'delete');
}
}

View File

@ -1,14 +1,15 @@
import Route from './edit';
import CreatingRoute from 'consul-ui/mixins/creating-route';
export default Route.extend(CreatingRoute, {
templateName: 'dc/nspaces/edit',
beforeModel: function() {
export default class CreateRoute extends Route.extend(CreatingRoute) {
templateName = 'dc/nspaces/edit';
beforeModel() {
// we need to skip CreatingRoute.beforeModel here
// TODO(octane): ideally we'd like to call Route.beforeModel
// but its not clear how to do that with old ember
// maybe it will be more normal with modern ember
// up until now we haven't been calling super here anyway
// so this is probably ok until we can skip a parent super
},
});
}
}

View File

@ -1,15 +1,18 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithNspaceActions from 'consul-ui/mixins/nspace/with-actions';
export default Route.extend(WithNspaceActions, {
repo: service('repository/nspace'),
isCreate: function(params, transition) {
export default class EditRoute extends Route.extend(WithNspaceActions) {
@service('repository/nspace')
repo;
isCreate(params, transition) {
return transition.targetName.split('.').pop() === 'create';
},
model: function(params, transition) {
}
model(params, transition) {
const repo = this.repo;
const create = this.isCreate(...arguments);
const dc = this.modelFor('dc').dc.Name;
@ -27,9 +30,10 @@ export default Route.extend(WithNspaceActions, {
)
: repo.findBySlug(params.name),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,25 +1,31 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import WithNspaceActions from 'consul-ui/mixins/nspace/with-actions';
export default Route.extend(WithNspaceActions, {
data: service('data-source/service'),
repo: service('repository/nspace'),
queryParams: {
export default class IndexRoute extends Route.extend(WithNspaceActions) {
@service('data-source/service')
data;
@service('repository/nspace')
repo;
queryParams = {
sortBy: 'sort',
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
return hash({
items: this.data.source(uri => uri`/*/*/namespaces`),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,10 +1,12 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
export default Route.extend({
data: service('data-source/service'),
queryParams: {
export default class IndexRoute extends Route {
@service('data-source/service')
data;
queryParams = {
search: {
as: 'filter',
replace: true,
@ -13,8 +15,9 @@ export default Route.extend({
status: {
as: 'status',
},
},
model: function(params) {
};
model(params) {
let terms = params.s || '';
// we check for the old style `status` variable here
// and convert it to the new style filter=status:critical
@ -37,9 +40,10 @@ export default Route.extend({
terms: terms !== '' ? terms.split('\n') : [],
items: this.data.source(uri => uri`/${nspace}/${dc}/services`),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,11 +1,13 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
export default Route.extend({
data: service('data-source/service'),
model: function(params) {
export default class InstanceRoute extends Route {
@service('data-source/service')
data;
model(params) {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1) || 'default';
return hash({
@ -47,9 +49,10 @@ export default Route.extend({
});
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
model: function() {
export default class AddressesRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
afterModel: function(model, transition) {
}
afterModel(model, transition) {
if (get(model, 'item.Service.Kind') !== 'mesh-gateway') {
const parent = this.routeName
.split('.')
@ -17,9 +18,10 @@ export default Route.extend({
.join('.');
this.replaceWith(parent);
}
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
model: function() {
export default class ExposedpathsRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
afterModel: function(model, transition) {
}
afterModel(model, transition) {
if (
get(model, 'item.Kind') !== 'connect-proxy' ||
get(model, 'item.Proxy.Expose.Paths.length') < 1
@ -20,9 +21,10 @@ export default Route.extend({
.join('.');
this.replaceWith(parent);
}
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class HealthchecksRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class MetadataRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class ProxyRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
model: function() {
export default class UpstreamsRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
afterModel: function(model, transition) {
}
afterModel(model, transition) {
if (get(model, 'item.Service.Kind') !== 'connect-proxy') {
const parent = this.routeName
.split('.')
@ -17,9 +18,10 @@ export default Route.extend({
.join('.');
this.replaceWith(parent);
}
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,7 +1,7 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
redirect: function(model, transition) {
export default class NotfoundRoute extends Route {
redirect(model, transition) {
this.replaceWith('dc.services.instance', model.name, model.node, model.id);
},
});
}
}

View File

@ -1,12 +1,16 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
export default Route.extend({
data: service('data-source/service'),
config: service('ui-config'),
model: function(params, transition) {
export default class ShowRoute extends Route {
@service('data-source/service')
data;
@service('ui-config')
config;
model(params, transition) {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
return hash({
@ -54,9 +58,10 @@ export default Route.extend({
),
});
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,8 +1,8 @@
import Route from '@ember/routing/route';
import { get } from '@ember/object';
export default Route.extend({
afterModel: function(model, transition) {
export default class IndexRoute extends Route {
afterModel(model, transition) {
const parent = this.routeName
.split('.')
.slice(0, -1)
@ -33,5 +33,5 @@ export default Route.extend({
}
this.replaceWith(`${parent}.${to}`, parentModel);
},
});
}
}

View File

@ -1,21 +1,23 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
queryParams: {
export default class InstancesRoute extends Route {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
model: function() {
};
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,8 +1,8 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
setupController: function(controller, model) {
this._super(...arguments);
export default class IntentionsRoute extends Route {
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,5 +1,5 @@
import Route from './edit';
export default Route.extend({
templateName: 'dc/services/show/intentions/edit',
});
export default class CreateRoute extends Route {
templateName = 'dc/services/show/intentions/edit';
}

View File

@ -1,16 +1,17 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function(params, transition) {
export default class EditRoute extends Route {
model(params, transition) {
return {
nspace: '*',
dc: this.paramsFor('dc').dc,
service: this.paramsFor('dc.services.show').name,
src: params.intention_id,
};
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,21 +1,23 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
queryParams: {
export default class IndexRoute extends Route {
queryParams = {
search: {
as: 'filter',
replace: true,
},
},
model: function(params) {
};
model(params) {
return {
dc: this.modelFor('dc').dc.Name,
nspace: this.modelFor('nspace').nspace.substr(1) || 'default',
slug: this.paramsFor('dc.services.show').name,
};
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
import { get } from '@ember/object';
export default Route.extend({
model: function() {
export default class RoutingRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
afterModel: function(model, transition) {
}
afterModel(model, transition) {
if (!get(model, 'chain')) {
const parent = this.routeName
.split('.')
@ -17,9 +18,10 @@ export default Route.extend({
.join('.');
this.replaceWith(parent);
}
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,10 +1,12 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
export default Route.extend({
data: service('data-source/service'),
model: function() {
export default class ServicesRoute extends Route {
@service('data-source/service')
data;
model() {
const dc = this.modelFor('dc').dc.Name;
const nspace = this.modelFor('nspace').nspace.substr(1);
const parent = this.routeName
@ -17,9 +19,10 @@ export default Route.extend({
nspace: nspace,
gatewayServices: this.data.source(uri => uri`/${nspace}/${dc}/gateways/for-service/${name}`),
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from 'consul-ui/routing/route';
export default Route.extend({
model: function() {
export default class TagsRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,15 +1,16 @@
import Route from '@ember/routing/route';
export default Route.extend({
model: function() {
export default class TopologyRoute extends Route {
model() {
const parent = this.routeName
.split('.')
.slice(0, -1)
.join('.');
return this.modelFor(parent);
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
});
}
}

View File

@ -1,5 +1,5 @@
import Route from './services';
export default Route.extend({
templateName: 'dc/services/show/upstreams',
});
export default class UpstreamsRoute extends Route {
templateName = 'dc/services/show/upstreams';
}

View File

@ -1,16 +1,19 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get } from '@ember/object';
export default Route.extend({
repo: service('repository/dc'),
model: function(params) {
export default class IndexRoute extends Route {
@service('repository/dc')
repo;
model(params) {
return hash({
item: this.repo.getActive(),
});
},
afterModel: function({ item }, transition) {
}
afterModel({ item }, transition) {
this.transitionTo('dc.services', get(item, 'Name'));
},
});
}
}

View File

@ -1,10 +1,10 @@
import Route from 'consul-ui/routing/route';
import Error from '@ember/error';
export default Route.extend({
beforeModel: function() {
export default class NotfoundRoute extends Route {
beforeModel() {
const e = new Error('Page not found');
e.code = 404;
throw e;
},
});
}
}

View File

@ -1,14 +1,18 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { getOwner } from '@ember/application';
import { env } from 'consul-ui/env';
import transitionable from 'consul-ui/utils/routing/transitionable';
const DEFAULT_NSPACE_PARAM = '~default';
export default Route.extend({
repo: service('repository/dc'),
router: service('router'),
export default class NspaceRoute extends Route {
@service('repository/dc')
repo;
@service('router')
router;
// The ember router seems to change the priority of individual routes
// depending on whether they are wildcard routes or not.
// This means that the namespace routes will be recognized before kv ones
@ -22,7 +26,7 @@ export default Route.extend({
// information that we generated onto the route, which leaves us with the route
// we actually want. Using this final route information we redirect the user
// to where they wanted to go.
beforeModel: function(transition) {
beforeModel(transition) {
if (!this.paramsFor('nspace').nspace.startsWith('~')) {
const url = `${env('rootURL')}${DEFAULT_NSPACE_PARAM}${transition.intent.url}`;
const route = this.router.recognize(url);
@ -37,13 +41,14 @@ export default Route.extend({
...params.slice(1),
]);
}
},
model: function(params) {
}
model(params) {
return hash({
item: this.repo.getActive(),
nspace: params.nspace,
});
},
}
/**
* We need to redirect if someone doesn't specify the section they want,
@ -64,5 +69,5 @@ export default Route.extend({
this.transitionTo('dc.services', model.nspace);
}
}
},
});
}
}

View File

@ -1,14 +1,22 @@
import Route from 'consul-ui/routing/route';
import { inject as service } from '@ember/service';
import Route from 'consul-ui/routing/route';
import { hash } from 'rsvp';
import { get, set } from '@ember/object';
import { get, set, action } from '@ember/object';
export default Route.extend({
client: service('client/http'),
repo: service('settings'),
dcRepo: service('repository/dc'),
nspacesRepo: service('repository/nspace/disabled'),
model: function(params) {
export default class SettingsRoute extends Route {
@service('client/http')
client;
@service('settings')
repo;
@service('repository/dc')
dcRepo;
@service('repository/nspace/disabled')
nspacesRepo;
model(params) {
const app = this.modelFor('application');
return hash({
item: this.repo.findAll(),
@ -20,23 +28,24 @@ export default Route.extend({
}
return model;
});
},
setupController: function(controller, model) {
this._super(...arguments);
}
setupController(controller, model) {
super.setupController(...arguments);
controller.setProperties(model);
},
actions: {
update: function(slug, item) {
switch (slug) {
case 'client':
if (!get(item, 'client.blocking')) {
this.client.abort();
}
break;
}
this.repo.persist({
[slug]: item,
});
},
},
});
}
@action
update(slug, item) {
switch (slug) {
case 'client':
if (!get(item, 'client.blocking')) {
this.client.abort();
}
break;
}
this.repo.persist({
[slug]: item,
});
}
}

View File

@ -1,7 +1,7 @@
import Service from '@ember/service';
import atob from 'consul-ui/utils/atob';
export default Service.extend({
execute: function() {
export default class AtobService extends Service {
execute() {
return atob(...arguments);
},
});
}
}

View File

@ -1,7 +1,7 @@
import Service from '@ember/service';
import btoa from 'consul-ui/utils/btoa';
export default Service.extend({
execute: function() {
export default class BtoaService extends Service {
execute() {
return btoa(...arguments);
},
});
}
}

View File

@ -13,17 +13,20 @@ const validators = {
'intention-permission-http-header': intentionPermissionHttpHeaderValidator,
};
export default Service.extend({
schema: service('schema'),
export default class ChangeService extends Service {
@service('schema')
schema;
init: function() {
this._super(...arguments);
init() {
super.init(...arguments);
this._validators = new Map();
},
willDestroy: function() {
}
willDestroy() {
this._validators = null;
},
changesetFor: function(modelName, model, options = {}) {
}
changesetFor(modelName, model, options = {}) {
const validator = this.validatorFor(modelName, options);
let changeset;
if (validator) {
@ -36,8 +39,9 @@ export default Service.extend({
changeset = createChangeset(model);
}
return changeset;
},
validatorFor: function(modelName, options = {}) {
}
validatorFor(modelName, options = {}) {
if (!this._validators.has(modelName)) {
const factory = validators[modelName];
let validator;
@ -47,5 +51,5 @@ export default Service.extend({
this._validators.set(modelName, validator);
}
return this._validators.get(modelName);
},
});
}
}

View File

@ -1,22 +1,29 @@
import Service, { inject as service } from '@ember/service';
export default Service.extend({
dom: service('dom'),
env: service('env'),
data: service('data-source/service'),
sources: service('repository/type/event-source'),
init: function() {
this._super(...arguments);
export default class ConnectionsService extends Service {
@service('dom')
dom;
@service('env')
env;
@service('data-source/service')
data;
init() {
super.init(...arguments);
this._listeners = this.dom.listeners();
this.connections = new Set();
this.addVisibilityChange();
},
willDestroy: function() {
}
willDestroy() {
this._listeners.remove();
this.purge();
this._super(...arguments);
},
addVisibilityChange: function() {
super.willDestroy(...arguments);
}
addVisibilityChange() {
// when the user hides the tab, abort all connections
this._listeners.add(this.dom.document(), {
visibilitychange: e => {
@ -25,8 +32,9 @@ export default Service.extend({
}
},
});
},
whenAvailable: function(e) {
}
whenAvailable(e) {
// if the user has hidden the tab (hidden browser/tab switch)
// any aborted errors should restart
const doc = this.dom.document();
@ -43,15 +51,17 @@ export default Service.extend({
});
}
return Promise.resolve(e);
},
purge: function(statusCode = 0) {
}
purge(statusCode = 0) {
[...this.connections].forEach(function(connection) {
// Cancelled
connection.abort(statusCode);
});
this.connections = new Set();
},
acquire: function(request) {
}
acquire(request) {
if (this.connections.size >= this.env.var('CONSUL_HTTP_MAX_CONNECTIONS')) {
const closed = this.data.closed();
let connection = [...this.connections].find(item => {
@ -79,8 +89,9 @@ export default Service.extend({
}
}
this.connections.add(request);
},
release: function(request) {
}
release(request) {
this.connections.delete(request);
},
});
}
}

View File

@ -71,26 +71,38 @@ const parseBody = function(strs, ...values) {
};
const CLIENT_HEADERS = [CACHE_CONTROL, 'X-Request-ID', 'X-Range', 'Refresh'];
export default Service.extend({
dom: service('dom'),
connections: service('client/connections'),
transport: service('client/transports/xhr'),
settings: service('settings'),
init: function() {
this._super(...arguments);
export default class HttpService extends Service {
@service('dom')
dom;
@service('client/connections')
connections;
@service('client/transports/xhr')
transport;
@service('settings')
settings;
init() {
super.init(...arguments);
this._listeners = this.dom.listeners();
},
willDestroy: function() {
}
willDestroy() {
this._listeners.remove();
this._super(...arguments);
},
url: function() {
super.willDestroy(...arguments);
}
url() {
return parseURL(...arguments);
},
body: function() {
}
body() {
return parseBody(...arguments);
},
requestParams: function(strs, ...values) {
}
requestParams(strs, ...values) {
// first go to the end and remove/parse the http body
const [body, ...urlVars] = this.body(...arguments);
// with whats left get the method off the front
@ -151,8 +163,9 @@ export default Service.extend({
// also see https://github.com/hashicorp/consul/issues/3804
params.headers[CONTENT_TYPE] = 'application/json; charset=utf-8';
return params;
},
fetchWithToken: function(path, params) {
}
fetchWithToken(path, params) {
return this.settings.findBySlug('token').then(token => {
return fetch(`${path}`, {
...params,
@ -162,8 +175,9 @@ export default Service.extend({
},
});
});
},
request: function(cb) {
}
request(cb) {
const client = this;
return cb(function(strs, ...values) {
const params = client.requestParams(...arguments);
@ -208,17 +222,21 @@ export default Service.extend({
});
});
});
},
whenAvailable: function(e) {
}
whenAvailable(e) {
return this.connections.whenAvailable(e);
},
abort: function() {
}
abort() {
return this.connections.purge(...arguments);
},
acquire: function() {
}
acquire() {
return this.connections.acquire(...arguments);
},
release: function() {
}
release() {
return this.connections.release(...arguments);
},
});
}
}

View File

@ -7,11 +7,12 @@ import HTTPError from 'consul-ui/utils/http/error';
const xhr = createXHR(createHeaders());
export default Service.extend({
xhr: function(options) {
export default class XhrService extends Service {
xhr(options) {
return xhr(options);
},
request: function(params) {
}
request(params) {
const request = new Request(params.method, params.url, {
['x-request-id']: params.clientHeaders['x-request-id'],
body: params.data || {},
@ -57,5 +58,5 @@ export default Service.extend({
return request;
};
return request;
},
});
}
}

View File

@ -16,12 +16,13 @@ class ClipboardCallback extends Clipboard {
}
}
export default Service.extend({
storage: window.localStorage,
key: 'clipboard',
execute: function(trigger) {
export default class LocalStorageService extends Service {
storage = window.localStorage;
key = 'clipboard';
execute(trigger) {
return new ClipboardCallback(trigger, val => {
this.storage.setItem(this.key, val);
});
},
});
}
}

View File

@ -2,8 +2,8 @@ import Service from '@ember/service';
import Clipboard from 'clipboard';
export default Service.extend({
execute: function(trigger) {
export default class OsService extends Service {
execute(trigger) {
return new Clipboard(trigger);
},
});
}
}

Some files were not shown because too many files have changed in this diff Show More