2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2021-04-13 16:56:59 +00:00
|
|
|
import { later, next } from '@ember/runloop';
|
2018-08-08 20:49:04 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2019-10-15 18:32:58 +00:00
|
|
|
import { AbortError } from '@ember-data/adapter/error';
|
2018-08-09 02:34:56 +00:00
|
|
|
import RSVP from 'rsvp';
|
2020-06-11 21:23:00 +00:00
|
|
|
import { action } from '@ember/object';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@classic
|
|
|
|
export default class ApplicationRoute extends Route {
|
|
|
|
@service config;
|
|
|
|
@service system;
|
|
|
|
@service store;
|
|
|
|
@service token;
|
2017-10-23 17:21:44 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
queryParams = {
|
2018-08-04 01:18:51 +00:00
|
|
|
region: {
|
|
|
|
refreshModel: true,
|
|
|
|
},
|
2020-06-11 21:23:00 +00:00
|
|
|
};
|
2018-08-04 01:18:51 +00:00
|
|
|
|
2017-09-28 17:04:33 +00:00
|
|
|
resetController(controller, isExiting) {
|
|
|
|
if (isExiting) {
|
|
|
|
controller.set('error', null);
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2021-04-01 18:21:30 +00:00
|
|
|
async beforeModel(transition) {
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
let promises;
|
2021-04-01 18:21:30 +00:00
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
// service:router#transitionTo can cause this to rerun because of refreshModel on
|
|
|
|
// the region query parameter, this skips rerunning the detection/loading queries.
|
|
|
|
if (transition.queryParamsOnly) {
|
|
|
|
promises = Promise.resolve(true);
|
2021-04-01 18:21:30 +00:00
|
|
|
} else {
|
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
let exchangeOneTimeToken;
|
|
|
|
|
|
|
|
if (transition.to.queryParams.ott) {
|
|
|
|
exchangeOneTimeToken = this.get('token').exchangeOneTimeToken(transition.to.queryParams.ott);
|
|
|
|
} else {
|
|
|
|
exchangeOneTimeToken = Promise.resolve(true);
|
|
|
|
}
|
2021-04-01 18:21:30 +00:00
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
try {
|
|
|
|
await exchangeOneTimeToken;
|
|
|
|
} catch (e) {
|
|
|
|
this.controllerFor('application').set('error', e);
|
|
|
|
}
|
2020-01-20 20:57:01 +00:00
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
const fetchSelfTokenAndPolicies = this.get('token.fetchSelfTokenAndPolicies')
|
|
|
|
.perform()
|
|
|
|
.catch();
|
2020-11-06 14:21:38 +00:00
|
|
|
|
ui: Change global search to use fuzzy search API (#10412)
This updates the UI to use the new fuzzy search API. It’s a drop-in
replacement so the / shortcut to jump to search is preserved, and
results can be cycled through and chosen via arrow keys and the
enter key.
It doesn’t use everything returned by the API:
* deployments and evaluations: these match by id, doesn’t seem like
people would know those or benefit from quick navigation to them
* namespaces: doesn’t seem useful as they currently function
* scaling policies
* tasks: the response doesn’t include an allocation id, which means they
can’t be navigated to in the UI without an additional query
* CSI volumes: aren’t actually returned by the API
Since there’s no API to check the server configuration and know whether
the feature has been disabled, this adds another query in
route:application#beforeModel that acts as feature detection: if the
attempt to query fails (500), the global search field is hidden.
Upon having added another query on load, I realised that beforeModel was
being triggered any time service:router#transitionTo was being called,
which happens upon navigating to a search result, for instance, because
of refreshModel being present on the region query parameter. This PR
adds a check for transition.queryParamsOnly and skips rerunning the
onload queries (token permissions check, license check, fuzzy search
feature detection).
Implementation notes:
* there are changes to unrelated tests to ignore the on-load feature
detection query
* some lifecycle-related guards against undefined were required to
address failures when navigating to an allocation
* the minimum search length of 2 characters is hard-coded as there’s
currently no way to determine min_term_length in the UI
2021-04-28 18:31:05 +00:00
|
|
|
const fetchLicense = this.get('system.fetchLicense')
|
|
|
|
.perform()
|
|
|
|
.catch();
|
|
|
|
|
|
|
|
const checkFuzzySearchPresence = this.get('system.checkFuzzySearchPresence')
|
|
|
|
.perform()
|
|
|
|
.catch();
|
|
|
|
|
|
|
|
promises = await RSVP.all([
|
|
|
|
this.get('system.regions'),
|
|
|
|
this.get('system.defaultRegion'),
|
|
|
|
fetchLicense,
|
|
|
|
fetchSelfTokenAndPolicies,
|
|
|
|
checkFuzzySearchPresence,
|
|
|
|
]);
|
|
|
|
}
|
2021-04-01 18:21:30 +00:00
|
|
|
|
|
|
|
if (!this.get('system.shouldShowRegions')) return promises;
|
|
|
|
|
|
|
|
const queryParam = transition.to.queryParams.region;
|
|
|
|
const defaultRegion = this.get('system.defaultRegion.region');
|
|
|
|
const currentRegion = this.get('system.activeRegion') || defaultRegion;
|
|
|
|
|
|
|
|
// Only reset the store if the region actually changed
|
|
|
|
if (
|
|
|
|
(queryParam && queryParam !== currentRegion) ||
|
|
|
|
(!queryParam && currentRegion !== defaultRegion)
|
|
|
|
) {
|
|
|
|
this.store.unloadAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set('system.activeRegion', queryParam || defaultRegion);
|
|
|
|
|
|
|
|
return promises;
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2018-08-02 22:56:11 +00:00
|
|
|
|
2021-04-13 16:56:59 +00:00
|
|
|
// Model is being used as a way to propagate the region and
|
|
|
|
// one time token query parameters for use in setupController.
|
2021-04-29 20:00:59 +00:00
|
|
|
model(
|
|
|
|
{ region },
|
|
|
|
{
|
|
|
|
to: {
|
|
|
|
queryParams: { ott },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
) {
|
2021-04-13 16:56:59 +00:00
|
|
|
return {
|
|
|
|
region,
|
|
|
|
hasOneTimeToken: ott,
|
|
|
|
};
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2018-08-13 23:18:06 +00:00
|
|
|
|
2021-04-13 16:56:59 +00:00
|
|
|
setupController(controller, { region, hasOneTimeToken }) {
|
|
|
|
if (region === this.get('system.defaultRegion.region')) {
|
2018-08-10 01:12:26 +00:00
|
|
|
next(() => {
|
|
|
|
controller.set('region', null);
|
2018-08-08 20:49:04 +00:00
|
|
|
});
|
2018-08-10 01:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 16:56:59 +00:00
|
|
|
super.setupController(...arguments);
|
|
|
|
|
|
|
|
if (hasOneTimeToken) {
|
|
|
|
// Hack to force clear the OTT query parameter
|
|
|
|
later(() => {
|
|
|
|
controller.set('oneTimeToken', '');
|
|
|
|
}, 500);
|
|
|
|
}
|
2020-06-11 21:23:00 +00:00
|
|
|
}
|
2018-08-02 22:56:11 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
didTransition() {
|
|
|
|
if (!this.get('config.isTest')) {
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2017-09-28 17:04:33 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
willTransition() {
|
|
|
|
this.controllerFor('application').set('error', null);
|
|
|
|
}
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
@action
|
|
|
|
error(error) {
|
|
|
|
if (!(error instanceof AbortError)) {
|
|
|
|
this.controllerFor('application').set('error', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|