2020-10-01 08:33:22 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
|
|
|
class State {
|
|
|
|
constructor(name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
matches(match) {
|
|
|
|
return this.name === match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class Outlet extends Component {
|
2021-03-08 12:15:54 +00:00
|
|
|
@service('routlet') routlet;
|
2020-10-01 08:33:22 +00:00
|
|
|
@service('router') router;
|
|
|
|
|
2021-03-08 12:15:54 +00:00
|
|
|
@tracked element;
|
|
|
|
@tracked routeName;
|
2020-10-01 08:33:22 +00:00
|
|
|
@tracked state;
|
|
|
|
@tracked previousState;
|
2021-03-08 12:15:54 +00:00
|
|
|
@tracked endTransition;
|
2020-10-01 08:33:22 +00:00
|
|
|
|
2021-10-26 18:26:04 +00:00
|
|
|
@tracked route;
|
|
|
|
|
2021-03-08 12:15:54 +00:00
|
|
|
get model() {
|
|
|
|
return this.args.model || {};
|
2020-10-01 08:33:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 19:16:21 +00:00
|
|
|
get name() {
|
|
|
|
return this.args.name;
|
|
|
|
}
|
|
|
|
|
2020-10-01 08:33:22 +00:00
|
|
|
setAppRoute(name) {
|
2021-10-11 15:03:59 +00:00
|
|
|
if (name !== 'loading' || name === 'oidc-provider-debug') {
|
2021-03-08 12:15:54 +00:00
|
|
|
const doc = this.element.ownerDocument.documentElement;
|
2020-10-01 08:33:22 +00:00
|
|
|
if (doc.classList.contains('ember-loading')) {
|
|
|
|
doc.classList.remove('ember-loading');
|
|
|
|
}
|
|
|
|
doc.dataset.route = name;
|
|
|
|
this.setAppState('idle');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setAppState(state) {
|
2021-03-08 12:15:54 +00:00
|
|
|
const doc = this.element.ownerDocument.documentElement;
|
|
|
|
doc.dataset.state = state;
|
2020-10-01 08:33:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 12:15:54 +00:00
|
|
|
@action
|
|
|
|
attributeChanged(prop, value) {
|
|
|
|
switch (prop) {
|
|
|
|
case 'element':
|
|
|
|
this.element = value;
|
|
|
|
if (this.args.name === 'application') {
|
|
|
|
this.setAppState('loading');
|
|
|
|
this.setAppRoute(this.router.currentRouteName);
|
|
|
|
}
|
|
|
|
break;
|
2021-10-26 18:26:04 +00:00
|
|
|
case 'model':
|
2022-09-15 08:43:17 +00:00
|
|
|
if (typeof this.route !== 'undefined') {
|
2022-01-07 19:16:21 +00:00
|
|
|
this.route._model = value;
|
|
|
|
}
|
2021-10-26 18:26:04 +00:00
|
|
|
break;
|
2021-03-08 12:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-01 08:33:22 +00:00
|
|
|
|
2021-03-08 12:15:54 +00:00
|
|
|
@action transitionEnd($el) {
|
|
|
|
if (typeof this.endTransition === 'function') {
|
|
|
|
this.endTransition();
|
|
|
|
}
|
2020-10-01 08:33:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
startLoad(transition) {
|
2021-03-08 12:15:54 +00:00
|
|
|
const outlet = this.routlet.findOutlet(transition.to.name) || 'application';
|
2020-10-01 08:33:22 +00:00
|
|
|
if (this.args.name === outlet) {
|
|
|
|
this.previousState = this.state;
|
|
|
|
this.state = new State('loading');
|
2021-03-08 12:15:54 +00:00
|
|
|
this.endTransition = this.routlet.transition();
|
2022-10-05 10:32:48 +00:00
|
|
|
let duration;
|
|
|
|
if (this.element) {
|
|
|
|
// if we have no transition-duration set immediately end the transition
|
|
|
|
duration = window.getComputedStyle(this.element).getPropertyValue('transition-duration');
|
|
|
|
} else {
|
|
|
|
duration = 0;
|
|
|
|
}
|
|
|
|
|
2021-03-08 12:15:54 +00:00
|
|
|
if (parseFloat(duration) === 0) {
|
|
|
|
this.endTransition();
|
|
|
|
}
|
2020-10-01 08:33:22 +00:00
|
|
|
}
|
|
|
|
if (this.args.name === 'application') {
|
|
|
|
this.setAppState('loading');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
endLoad(transition) {
|
|
|
|
if (this.state.matches('loading')) {
|
|
|
|
this.previousState = this.state;
|
|
|
|
this.state = new State('idle');
|
|
|
|
}
|
|
|
|
if (this.args.name === 'application') {
|
|
|
|
this.setAppRoute(this.router.currentRouteName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
connect() {
|
2021-03-08 12:15:54 +00:00
|
|
|
this.routlet.addOutlet(this.args.name, this);
|
2020-10-01 08:33:22 +00:00
|
|
|
this.previousState = this.state = new State('idle');
|
|
|
|
this.router.on('routeWillChange', this.startLoad);
|
|
|
|
this.router.on('routeDidChange', this.endLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
disconnect() {
|
2021-03-08 12:15:54 +00:00
|
|
|
this.routlet.removeOutlet(this.args.name);
|
2020-10-01 08:33:22 +00:00
|
|
|
this.router.off('routeWillChange', this.startLoad);
|
|
|
|
this.router.off('routeDidChange', this.endLoad);
|
|
|
|
}
|
|
|
|
}
|