mirror of https://github.com/portainer/portainer
feat(app): clear env when log out [EE-4791] (#8218)
parent
123754cee7
commit
701410d259
|
@ -1,14 +1,8 @@
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
export function onStartupAngular($rootScope, $state, LocalStorage, cfpLoadingBar, $transitions, HttpRequestHelper, EndpointProvider) {
|
export function onStartupAngular($rootScope, $state, LocalStorage, cfpLoadingBar, $transitions, HttpRequestHelper) {
|
||||||
$rootScope.$state = $state;
|
$rootScope.$state = $state;
|
||||||
const defaultTitle = document.title;
|
|
||||||
|
|
||||||
$transitions.onEnter({}, () => {
|
|
||||||
const endpoint = EndpointProvider.currentEndpoint();
|
|
||||||
document.title = endpoint ? `${defaultTitle} | ${endpoint.Name}` : `${defaultTitle}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Workaround to prevent the loading bar from going backward
|
// Workaround to prevent the loading bar from going backward
|
||||||
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ping } from '@/docker/services/ping';
|
import { ping } from '@/docker/services/ping';
|
||||||
|
import { environmentStore } from '@/react/hooks/current-environment-store';
|
||||||
import {
|
import {
|
||||||
Environment,
|
Environment,
|
||||||
EnvironmentType,
|
EnvironmentType,
|
||||||
|
@ -9,6 +10,8 @@ interface State {
|
||||||
pingInterval: NodeJS.Timer | null;
|
pingInterval: NodeJS.Timer | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_TITLE = 'Portainer';
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
export function EndpointProvider() {
|
export function EndpointProvider() {
|
||||||
const state: State = {
|
const state: State = {
|
||||||
|
@ -16,6 +19,12 @@ export function EndpointProvider() {
|
||||||
pingInterval: null,
|
pingInterval: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environmentStore.subscribe((state) => {
|
||||||
|
if (!state.environmentId) {
|
||||||
|
setCurrentEndpoint(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return { endpointID, setCurrentEndpoint, currentEndpoint, clean };
|
return { endpointID, setCurrentEndpoint, currentEndpoint, clean };
|
||||||
|
|
||||||
function endpointID() {
|
function endpointID() {
|
||||||
|
@ -40,6 +49,10 @@ export function EndpointProvider() {
|
||||||
JSON.stringify(undefined)
|
JSON.stringify(undefined)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.title = endpoint
|
||||||
|
? `${DEFAULT_TITLE} | ${endpoint.Name}`
|
||||||
|
: `${DEFAULT_TITLE}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentEndpoint() {
|
function currentEndpoint() {
|
||||||
|
@ -48,6 +61,7 @@ export function EndpointProvider() {
|
||||||
|
|
||||||
function clean() {
|
function clean() {
|
||||||
setCurrentEndpoint(null);
|
setCurrentEndpoint(null);
|
||||||
|
environmentStore.getState().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { useCurrentStateAndParams, useRouter } from '@uirouter/react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { X, Slash } from 'lucide-react';
|
import { X, Slash } from 'lucide-react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import angular from 'angular';
|
|
||||||
import { useStore } from 'zustand';
|
import { useStore } from 'zustand';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -13,7 +12,6 @@ import {
|
||||||
import { getPlatformType } from '@/react/portainer/environments/utils';
|
import { getPlatformType } from '@/react/portainer/environments/utils';
|
||||||
import { useEnvironment } from '@/react/portainer/environments/queries/useEnvironment';
|
import { useEnvironment } from '@/react/portainer/environments/queries/useEnvironment';
|
||||||
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
import { isBE } from '@/react/portainer/feature-flags/feature-flags.service';
|
||||||
import { EndpointProviderInterface } from '@/portainer/services/endpointProvider';
|
|
||||||
import { environmentStore } from '@/react/hooks/current-environment-store';
|
import { environmentStore } from '@/react/hooks/current-environment-store';
|
||||||
|
|
||||||
import { Icon } from '@@/Icon';
|
import { Icon } from '@@/Icon';
|
||||||
|
@ -112,16 +110,6 @@ function useCurrentEnvironment() {
|
||||||
return { query: useEnvironment(envStore.environmentId), clearEnvironment };
|
return { query: useEnvironment(envStore.environmentId), clearEnvironment };
|
||||||
|
|
||||||
function clearEnvironment() {
|
function clearEnvironment() {
|
||||||
const $injector = angular.element(document).injector();
|
|
||||||
$injector.invoke(
|
|
||||||
/* @ngInject */ (EndpointProvider: EndpointProviderInterface) => {
|
|
||||||
EndpointProvider.setCurrentEndpoint(null);
|
|
||||||
if (!params.endpointId && !params.environmentId) {
|
|
||||||
document.title = 'Portainer';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (params.endpointId || params.environmentId) {
|
if (params.endpointId || params.environmentId) {
|
||||||
router.stateService.go('portainer.home');
|
router.stateService.go('portainer.home');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue