Skip to content

Commit 7088f2c

Browse files
committed
Solve sonar issues regarding window. to replace with globalThis.
Signed-off-by: freddidierRTE <[email protected]>
1 parent 73d3d20 commit 7088f2c

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

frontend/src/app/authentication/AuthHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export abstract class AuthHandler {
6363
}
6464

6565
public getOpfabRouteAfterLogin(): string {
66-
const hash = window.location.hash;
66+
const hash = globalThis.location.hash;
6767
const hashWithoutAuthenticationFields = hash.split('&')[0].split('?')[0];
6868
const hashLength = hash.length;
6969
const routeAfterLogin = hashLength > 2 ? hashWithoutAuthenticationFields.substring(1, hashLength) : '/';

frontend/src/app/authentication/AuthService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class AuthService {
118118
this.removeUserFromStorage();
119119
this.authHandler.logout();
120120
if (this.mode !== AuthenticationMode.IMPLICIT)
121-
window.location.href = ConfigService.getConfigValue('security.logout-url', 'https://opfab.github.io');
121+
globalThis.location.href = ConfigService.getConfigValue('security.logout-url', 'https://opfab.github.io');
122122
}
123123

124124
private goBackToLoginPage() {

frontend/src/app/authentication/CodeAuthenticationHandler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export class CodeAuthenticationHandler extends AuthHandler {
1616
initializeAuthentication() {
1717
let authCode;
1818
const searchCodeString = 'code=';
19-
const foundIndex = window.location.href.indexOf(searchCodeString);
19+
const foundIndex = globalThis.location.href.indexOf(searchCodeString);
2020
if (foundIndex !== -1) {
21-
authCode = window.location.href.substring(foundIndex + searchCodeString.length);
21+
authCode = globalThis.location.href.substring(foundIndex + searchCodeString.length);
2222
} else this.saveOpfabRoute();
2323
this.checkAuthentication().subscribe((token) => {
2424
// no token stored or token invalid
@@ -46,14 +46,14 @@ export class CodeAuthenticationHandler extends AuthHandler {
4646
// so we need to save in the session storage the route before login.
4747
// We do not use the local storage because the local storage is shared between tabs
4848
private saveOpfabRoute() {
49-
const hash = window.location.hash;
49+
const hash = globalThis.location.hash;
5050
const hashLength = hash.length;
5151
const routeAfterLogin = hashLength > 2 ? hash.substring(1, hashLength) : '/';
52-
window.sessionStorage.setItem('route_after_login_for_code_flow', routeAfterLogin);
52+
globalThis.sessionStorage.setItem('route_after_login_for_code_flow', routeAfterLogin);
5353
}
5454

5555
public getOpfabRouteAfterLogin(): string {
56-
return window.sessionStorage.getItem('route_after_login_for_code_flow');
56+
return globalThis.sessionStorage.getItem('route_after_login_for_code_flow');
5757
}
5858

5959
private askToken(code: string): Observable<HttpAuthInfo> {
@@ -69,9 +69,9 @@ export class CodeAuthenticationHandler extends AuthHandler {
6969

7070
private moveToLoginPage() {
7171
if (!this.delegateUrl) {
72-
window.location.href = `${environment.url}auth/code/redirect_uri=${this.getRedirectUri()}`;
72+
globalThis.location.href = `${environment.url}auth/code/redirect_uri=${this.getRedirectUri()}`;
7373
} else {
74-
window.location.href = `${this.delegateUrl}&redirect_uri=${this.getRedirectUri()}`;
74+
globalThis.location.href = `${this.delegateUrl}&redirect_uri=${this.getRedirectUri()}`;
7575
}
7676
}
7777

frontend/src/app/components/core/application-loading/ApplicationLoadingComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class ApplicationLoadingComponent implements OnInit {
161161
// To have a cleaner code , we need to refactor the code
162162
// regarding authentication
163163
private waitForEmptyTokenInStorageToShowLoginForm() {
164-
if (!window.localStorage.getItem('token')) {
164+
if (!globalThis.localStorage.getItem('token')) {
165165
this.showLoginScreen = true;
166166
} else if (!this.applicationLoaded) {
167167
setTimeout(() => this.waitForEmptyTokenInStorageToShowLoginForm(), 100);

frontend/src/app/components/core/application-loading/app-loaded-in-another-tab/AppLoadedInAnotherTabComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class AppLoadedInAnotherTabComponent extends ApplicationLoadingComponent
5050
private isApplicationActive = false;
5151

5252
public async execute(): Promise<boolean> {
53-
this.opfabUrl = window.location.href;
53+
this.opfabUrl = globalThis.location.href;
5454
setTimeout(() => this.checkIfAppLoadedInAnotherTab(), 0);
5555
this.createListenerForDisconnectSignal();
5656
return super.execute();

frontend/src/app/components/core/application-loading/app-loaded-in-another-tab/UrlLockService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class UrlLockService {
3737

3838
public setDisconnectSignalListener(listener: Function): void {
3939
this.disconnectSignalListener = listener;
40-
window.addEventListener('storage', this.listenForDisconnectSignal.bind(this), false);
40+
globalThis.addEventListener('storage', this.listenForDisconnectSignal.bind(this), false);
4141
}
4242

4343
private listenForDisconnectSignal(event): void {

frontend/src/app/components/core/application-loading/loading-in-progress/LoadingInProgressComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class LoadingInProgressComponent implements OnInit, OnDestroy {
3232
}
3333

3434
reloadPage() {
35-
window.location.reload();
35+
globalThis.location.reload();
3636
}
3737

3838
ngOnDestroy() {

frontend/src/app/components/externalappiframe/view/ExternalAppIFrameView.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('ExternalAppIFrame view ', () => {
8383
});
8484

8585
// If a business application is called form a card, it can be called with parameters
86-
// To do that, in the card the window.location is set with the url #/businessconfigparty/menu_id/menuItem_id/
86+
// To do that, in the card the globalThis.location is set with the url #/businessconfigparty/menu_id/menuItem_id/
8787
// then is is possible to add params to the url
8888
// For example: #/businessconfigparty/menu_id/menuItem_id/?myparam=param1&myotherparam=param2
8989
//
@@ -99,7 +99,7 @@ describe('ExternalAppIFrame view ', () => {
9999
});
100100

101101
// If a business application is called form a card, it can be called with parameters
102-
// To do that, in the card the window.location is set with the url #/businessconfigparty/menu_id/menuItem_id
102+
// To do that, in the card the globalThis.location is set with the url #/businessconfigparty/menu_id/menuItem_id
103103
// then is is possible to add params to the url
104104
// For example: #/businessconfigparty/menu_id/menuItem_id?myparam=param1&myotherparam=param2
105105
//

frontend/src/app/components/feed/components/time-line/custom-timeline-chart/CustomTimeLineChartComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class CustomTimelineChartComponent implements OnInit, OnDestroy, OnChange
6868
ngOnInit(): void {
6969
this.computeDimensions();
7070
this.updateRealtime();
71-
window.addEventListener('resize', this.onWindowResize);
71+
globalThis.addEventListener('resize', this.onWindowResize);
7272
}
7373

7474
ngOnChanges(): void {
@@ -180,6 +180,6 @@ export class CustomTimelineChartComponent implements OnInit, OnDestroy, OnChange
180180
ngOnDestroy() {
181181
this.timeLineView.destroy();
182182
this.isDestroyed = true;
183-
window.removeEventListener('resize', this.onWindowResize);
183+
globalThis.removeEventListener('resize', this.onWindowResize);
184184
}
185185
}

frontend/src/app/services/logs/RemoteLoggerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class RemoteLoggerService {
3030
RemoteLoggerService.isActive = true;
3131
RemoteLoggerService.regularlyFlush();
3232
RemoteLoggerService.postLog(
33-
'Remote log activated - ' + packageInfo.opfabVersion + ' - ' + window.navigator.userAgent
33+
'Remote log activated - ' + packageInfo.opfabVersion + ' - ' + globalThis.navigator.userAgent
3434
);
3535
}
3636
} else {

0 commit comments

Comments
 (0)