2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-01 08:33:22 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2021-09-15 18:50:11 +00:00
|
|
|
import { get, setProperties, action } from '@ember/object';
|
2021-02-19 16:42:16 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2022-01-12 09:27:00 +00:00
|
|
|
import resolve from 'consul-ui/utils/path/resolve';
|
2020-10-01 08:33:22 +00:00
|
|
|
|
2020-10-19 16:30:30 +00:00
|
|
|
import { routes } from 'consul-ui/router';
|
|
|
|
|
2020-10-01 08:33:22 +00:00
|
|
|
export default class BaseRoute extends Route {
|
2021-05-26 16:43:46 +00:00
|
|
|
@service('container') container;
|
|
|
|
@service('env') env;
|
2021-02-19 16:42:16 +00:00
|
|
|
@service('repository/permission') permissions;
|
2021-05-26 16:43:46 +00:00
|
|
|
@service('router') router;
|
2022-01-04 16:08:06 +00:00
|
|
|
@service('routlet') routlet;
|
2021-02-19 16:42:16 +00:00
|
|
|
|
ui: Adds initial CRUD for partitions (#11188)
* Add `is` and `test` helpers in a similar vein to `can`
Adds 2 new helpers in a similar vein to ember-cans can:
- `is` allows you to use vocab/phrases such as (is "something model") which calls isSomething() on the models ability.
- `test` allows you to use vocab/phrases such as (test "is something model") or (test "can something model")which calls isSomething() / canSomething() on the models ability. Mostly using the is helper and the can helper. It's basically the is/can helper combined.
* Adds TextInput component + related modifiers/helpers/machines/services (#11189)
Adds a few new components/modifiers/helpers to aid building forms.
- state-chart helper, used in lieu of a more generic approach for requiring our statecharts.
- A few modifications to our existing disabled modifier.
- A new 'validation' modifier, a super small form validation approach built to make use of state charts (optionally). Eventually we should be able to replace our current validation approach (ember-changeset-validations + extra deps) with this.
- A new TextInput component, which is the first of our new components specifically to make it easy to build forms with validations. This is still a WIP, I left some comments in pointing out where this one would be progressed, but as we don't need the planned functionality yet, I left it where it was. All of this will be fleshed out more at a later date.
Documentation is included for all of ^
* ui: Adds initial CRUD for partitions (#11190)
Adds basic CRUD support for partitions. Engineering-wise probably the biggest takeaway here is that we needed to write very little javascript code to add this entire feature, and the little javascript we did need to write was very straightforwards. Everything is pretty much just HTML. Another note to make is that both ember-changeset and ember-data (model layer things) are now completely abstracted away from the view layer of the application.
New components:
- Consul::Partition::Form
- Consul::Partition::List
- Consul::Partition::Notifications
- Consul::Partition::SearchBar
- Consul::Partition::Selector
See additional documentation here for more details
New Route templates:
- index.hbs partition listing/searching/filtering
- edit.hbs partition editing and creation
Additionally:
There is some additional debug work here for better observability and to prevent any errors regarding our href-to usage when a dc is not available in our documentation site.
Our softDelete functionality has been DRYed out a little to be used across two repos.
isLinkable was removed from our ListCollection component for lists like upstream and service listing, and instead use our new is helper from within the ListCollection, meaning we've added a few more lighterweight templateOnly components.
* ui: Exclude all debug-like files from the build (#11211)
This PR adds **/*-debug.* to our test/prod excluded files (realised I needed to add test-support.js also so added that here as its more or less the same thing). Conditionally juggling ES6 static imports (specifically debug ones) for this was also getting a little hairy, so I moved it all to use the same approach as our conditional routes. All in all it brings the vendor build back down to ~430kb gzipped.
2021-10-08 15:29:30 +00:00
|
|
|
_setRouteName() {
|
|
|
|
super._setRouteName(...arguments);
|
2022-01-05 09:34:28 +00:00
|
|
|
|
|
|
|
const template = get(routes, `${this.routeName}._options.template`);
|
|
|
|
if (typeof template !== 'undefined') {
|
2022-01-12 09:27:00 +00:00
|
|
|
this.templateName = resolve(this.routeName.split('.').join('/'), template);
|
ui: Adds initial CRUD for partitions (#11188)
* Add `is` and `test` helpers in a similar vein to `can`
Adds 2 new helpers in a similar vein to ember-cans can:
- `is` allows you to use vocab/phrases such as (is "something model") which calls isSomething() on the models ability.
- `test` allows you to use vocab/phrases such as (test "is something model") or (test "can something model")which calls isSomething() / canSomething() on the models ability. Mostly using the is helper and the can helper. It's basically the is/can helper combined.
* Adds TextInput component + related modifiers/helpers/machines/services (#11189)
Adds a few new components/modifiers/helpers to aid building forms.
- state-chart helper, used in lieu of a more generic approach for requiring our statecharts.
- A few modifications to our existing disabled modifier.
- A new 'validation' modifier, a super small form validation approach built to make use of state charts (optionally). Eventually we should be able to replace our current validation approach (ember-changeset-validations + extra deps) with this.
- A new TextInput component, which is the first of our new components specifically to make it easy to build forms with validations. This is still a WIP, I left some comments in pointing out where this one would be progressed, but as we don't need the planned functionality yet, I left it where it was. All of this will be fleshed out more at a later date.
Documentation is included for all of ^
* ui: Adds initial CRUD for partitions (#11190)
Adds basic CRUD support for partitions. Engineering-wise probably the biggest takeaway here is that we needed to write very little javascript code to add this entire feature, and the little javascript we did need to write was very straightforwards. Everything is pretty much just HTML. Another note to make is that both ember-changeset and ember-data (model layer things) are now completely abstracted away from the view layer of the application.
New components:
- Consul::Partition::Form
- Consul::Partition::List
- Consul::Partition::Notifications
- Consul::Partition::SearchBar
- Consul::Partition::Selector
See additional documentation here for more details
New Route templates:
- index.hbs partition listing/searching/filtering
- edit.hbs partition editing and creation
Additionally:
There is some additional debug work here for better observability and to prevent any errors regarding our href-to usage when a dc is not available in our documentation site.
Our softDelete functionality has been DRYed out a little to be used across two repos.
isLinkable was removed from our ListCollection component for lists like upstream and service listing, and instead use our new is helper from within the ListCollection, meaning we've added a few more lighterweight templateOnly components.
* ui: Exclude all debug-like files from the build (#11211)
This PR adds **/*-debug.* to our test/prod excluded files (realised I needed to add test-support.js also so added that here as its more or less the same thing). Conditionally juggling ES6 static imports (specifically debug ones) for this was also getting a little hairy, so I moved it all to use the same approach as our conditional routes. All in all it brings the vendor build back down to ~430kb gzipped.
2021-10-08 15:29:30 +00:00
|
|
|
}
|
2022-01-05 09:34:28 +00:00
|
|
|
|
|
|
|
const queryParams = get(routes, `${this.routeName}._options.queryParams`);
|
|
|
|
if (typeof queryParams !== 'undefined') {
|
ui: Adds initial CRUD for partitions (#11188)
* Add `is` and `test` helpers in a similar vein to `can`
Adds 2 new helpers in a similar vein to ember-cans can:
- `is` allows you to use vocab/phrases such as (is "something model") which calls isSomething() on the models ability.
- `test` allows you to use vocab/phrases such as (test "is something model") or (test "can something model")which calls isSomething() / canSomething() on the models ability. Mostly using the is helper and the can helper. It's basically the is/can helper combined.
* Adds TextInput component + related modifiers/helpers/machines/services (#11189)
Adds a few new components/modifiers/helpers to aid building forms.
- state-chart helper, used in lieu of a more generic approach for requiring our statecharts.
- A few modifications to our existing disabled modifier.
- A new 'validation' modifier, a super small form validation approach built to make use of state charts (optionally). Eventually we should be able to replace our current validation approach (ember-changeset-validations + extra deps) with this.
- A new TextInput component, which is the first of our new components specifically to make it easy to build forms with validations. This is still a WIP, I left some comments in pointing out where this one would be progressed, but as we don't need the planned functionality yet, I left it where it was. All of this will be fleshed out more at a later date.
Documentation is included for all of ^
* ui: Adds initial CRUD for partitions (#11190)
Adds basic CRUD support for partitions. Engineering-wise probably the biggest takeaway here is that we needed to write very little javascript code to add this entire feature, and the little javascript we did need to write was very straightforwards. Everything is pretty much just HTML. Another note to make is that both ember-changeset and ember-data (model layer things) are now completely abstracted away from the view layer of the application.
New components:
- Consul::Partition::Form
- Consul::Partition::List
- Consul::Partition::Notifications
- Consul::Partition::SearchBar
- Consul::Partition::Selector
See additional documentation here for more details
New Route templates:
- index.hbs partition listing/searching/filtering
- edit.hbs partition editing and creation
Additionally:
There is some additional debug work here for better observability and to prevent any errors regarding our href-to usage when a dc is not available in our documentation site.
Our softDelete functionality has been DRYed out a little to be used across two repos.
isLinkable was removed from our ListCollection component for lists like upstream and service listing, and instead use our new is helper from within the ListCollection, meaning we've added a few more lighterweight templateOnly components.
* ui: Exclude all debug-like files from the build (#11211)
This PR adds **/*-debug.* to our test/prod excluded files (realised I needed to add test-support.js also so added that here as its more or less the same thing). Conditionally juggling ES6 static imports (specifically debug ones) for this was also getting a little hairy, so I moved it all to use the same approach as our conditional routes. All in all it brings the vendor build back down to ~430kb gzipped.
2021-10-08 15:29:30 +00:00
|
|
|
this.queryParams = queryParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 17:32:51 +00:00
|
|
|
redirect(model, transition) {
|
2022-01-05 09:34:28 +00:00
|
|
|
let to = get(routes, `${this.routeName}._options.redirect`);
|
2021-09-22 17:32:51 +00:00
|
|
|
if (typeof to !== 'undefined') {
|
|
|
|
// TODO: Does this need to return?
|
|
|
|
// Almost remember things getting strange if you returned from here
|
|
|
|
// which is why I didn't do it originally so be sure to look properly if
|
|
|
|
// you feel like adding a return
|
2022-01-12 09:27:00 +00:00
|
|
|
this.replaceWith(
|
2022-09-15 08:43:17 +00:00
|
|
|
resolve(this.routeName.split('.').join('/'), to).split('/').join('.'),
|
2022-01-12 09:27:00 +00:00
|
|
|
model
|
|
|
|
);
|
2021-09-22 17:32:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 15:45:09 +00:00
|
|
|
/**
|
|
|
|
* By default any empty string query parameters should remove the query
|
|
|
|
* parameter from the URL. This is the most common behavior if you don't
|
|
|
|
* require this behavior overwrite this method in the specific Route for the
|
|
|
|
* specific queryParam key.
|
|
|
|
* If the behaviour should be different add an empty: [] parameter to the
|
|
|
|
* queryParameter configuration to configure what is deemed 'empty'
|
|
|
|
*/
|
|
|
|
serializeQueryParam(value, key, type) {
|
2021-02-19 16:42:16 +00:00
|
|
|
if (typeof value !== 'undefined') {
|
2020-12-01 15:45:09 +00:00
|
|
|
const empty = get(this, `queryParams.${key}.empty`);
|
2021-02-19 16:42:16 +00:00
|
|
|
if (typeof empty === 'undefined') {
|
2020-12-01 15:45:09 +00:00
|
|
|
// by default any queryParams when an empty string mean undefined,
|
|
|
|
// therefore remove the queryParam from the URL
|
2021-02-19 16:42:16 +00:00
|
|
|
if (value === '') {
|
2020-12-01 15:45:09 +00:00
|
|
|
value = undefined;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const possible = empty[0];
|
|
|
|
let actual = value;
|
2021-02-19 16:42:16 +00:00
|
|
|
if (Array.isArray(actual)) {
|
2020-12-01 15:45:09 +00:00
|
|
|
actual = actual.split(',');
|
|
|
|
}
|
2022-09-15 08:43:17 +00:00
|
|
|
const diff = possible.filter((item) => !actual.includes(item));
|
2021-02-19 16:42:16 +00:00
|
|
|
if (diff.length === 0) {
|
2020-12-01 15:45:09 +00:00
|
|
|
value = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2021-02-19 16:42:16 +00:00
|
|
|
|
2021-10-01 10:07:58 +00:00
|
|
|
// TODO: this is only required due to intention_id trying to do too much
|
|
|
|
// therefore we need to change the route parameter intention_id to just
|
|
|
|
// intention or id or similar then we can revert to only returning a model if
|
|
|
|
// we have searchProps (or a child route overwrites model)
|
2021-09-15 18:50:11 +00:00
|
|
|
model() {
|
|
|
|
const model = {};
|
|
|
|
if (
|
|
|
|
typeof this.queryParams !== 'undefined' &&
|
|
|
|
typeof this.queryParams.searchproperty !== 'undefined'
|
|
|
|
) {
|
|
|
|
model.searchProperties = this.queryParams.searchproperty.empty[0];
|
|
|
|
}
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2020-10-19 16:30:30 +00:00
|
|
|
/**
|
|
|
|
* Set the routeName for the controller so that it is available in the template
|
|
|
|
* for the route/controller.. This is mainly used to give a route name to the
|
|
|
|
* Outlet component
|
|
|
|
*/
|
2020-10-01 08:33:22 +00:00
|
|
|
setupController(controller, model) {
|
|
|
|
setProperties(controller, {
|
2021-09-15 18:50:11 +00:00
|
|
|
...model,
|
2020-10-01 08:33:22 +00:00
|
|
|
routeName: this.routeName,
|
|
|
|
});
|
|
|
|
super.setupController(...arguments);
|
|
|
|
}
|
2021-02-19 16:42:16 +00:00
|
|
|
|
2021-05-26 16:43:46 +00:00
|
|
|
optionalParams() {
|
|
|
|
return this.container.get(`location:${this.env.var('locationType')}`).optionalParams();
|
|
|
|
}
|
|
|
|
|
2020-10-19 16:30:30 +00:00
|
|
|
/**
|
2022-01-04 16:08:06 +00:00
|
|
|
* Normalizes any params passed into ember `model` hooks, plus of course
|
|
|
|
* anywhere else where `paramsFor` is used. This means the entire ember app
|
|
|
|
* is now changed so that all paramsFor calls returns normalized params
|
|
|
|
* instead of raw ones. For example we use this largely for URLs for the KV
|
|
|
|
* store: /kv/*key > /ui/kv/%25-kv-name/%25-here > key = '%-kv-name/%-here'
|
2020-10-19 16:30:30 +00:00
|
|
|
*/
|
|
|
|
paramsFor(name) {
|
2022-01-04 16:08:06 +00:00
|
|
|
return this.routlet.normalizeParamsFor(this.routeName, super.paramsFor(...arguments));
|
2020-10-19 16:30:30 +00:00
|
|
|
}
|
2021-09-15 18:50:11 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
async replaceWith(routeName, obj) {
|
|
|
|
await Promise.resolve();
|
|
|
|
let params = [];
|
|
|
|
if (typeof obj === 'string') {
|
|
|
|
params = [obj];
|
|
|
|
}
|
|
|
|
if (typeof obj !== 'undefined' && !Array.isArray(obj) && typeof obj !== 'string') {
|
|
|
|
params = Object.values(obj);
|
|
|
|
}
|
|
|
|
return super.replaceWith(routeName, ...params);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async transitionTo(routeName, obj) {
|
|
|
|
await Promise.resolve();
|
|
|
|
let params = [];
|
|
|
|
if (typeof obj === 'string') {
|
|
|
|
params = [obj];
|
|
|
|
}
|
|
|
|
if (typeof obj !== 'undefined' && !Array.isArray(obj) && typeof obj !== 'string') {
|
|
|
|
params = Object.values(obj);
|
|
|
|
}
|
2023-03-20 22:41:47 +00:00
|
|
|
return this.router.transitionTo(routeName, ...params);
|
2021-09-15 18:50:11 +00:00
|
|
|
}
|
2020-10-01 08:33:22 +00:00
|
|
|
}
|