Skip to content

Commit

Permalink
Remove postMessage from form A, B, C and D
Browse files Browse the repository at this point in the history
  • Loading branch information
claudioballardini01 committed Oct 6, 2023
1 parent d6d2c2b commit 2d2ef66
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { EXTERNAL_URI, INTERNAL_URI } from "src/app/app.constants";
import { TranslateConfigService } from "src/app/shared/services/translate-config.service";

Expand All @@ -7,20 +7,31 @@ import { TranslateConfigService } from "src/app/shared/services/translate-config
templateUrl: "./main.component.html",
styleUrls: ["./main.component.scss"],
})
export class MainComponent {
export class MainComponent implements OnInit {
constructor(private translateConfigService: TranslateConfigService) {
const currentLang = this.translateConfigService.getDefaultLanguage();
this.translateConfigService.setLanguage(currentLang);
this.translateConfigService.setDefaultLanguage();

window.addEventListener("message", this.listener.bind(this), false);
//window.addEventListener("message", this.messageListener.bind(this), false);
}

private listener(event: MessageEvent) {
if (event.origin === EXTERNAL_URI) {
this.translateConfigService.setLanguage(event.data);
ngOnInit() {
if (window.addEventListener) {
window.addEventListener("storage", this.storageListener, false);
}
}

private storageListener() {
const lang = localStorage.getItem("lang");
if (lang || typeof lang === "string") this.translateConfigService.setLanguage(lang);
else this.translateConfigService.setDefaultLanguage();
}

// private messageListener(event: MessageEvent) {
// if (event.origin === EXTERNAL_URI) {
// this.translateConfigService.setLanguage(event.data);
// }
// }

send() {
// TODO
//window.parent.postMessage('', EXTERNAL_URI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export class TranslateConfigService {
this.currentLang = localStorage.getItem("lang");
}

getDefaultLanguage() {
if (this.currentLang) {
this.translate.setDefaultLang(this.currentLang);
} else {
setDefaultLanguage() {
if (!this.currentLang || typeof this.currentLang !== "string") {
this.currentLang = "en";
localStorage.setItem("lang", this.currentLang);
this.translate.setDefaultLang(this.currentLang);
}

this.translate.setDefaultLang(this.currentLang);
this.translate.use(this.currentLang);
return this.currentLang;
}

Expand Down
35 changes: 25 additions & 10 deletions small_claim_form/small_claim_form/form_a/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
let isWarningStepVisible = false;

this.initializeLanguage();
window.addEventListener("message", this.listener.bind(this), false);
if (window.addEventListener) {
//window.addEventListener("message", this.messageListener.bind(this), false);
window.addEventListener("storage", this.storageListener, false);
}

document.addEventListener("DOMContentLoaded", () => {
document;
Expand All @@ -63,14 +66,26 @@
}, 1000);
});

function listener(event) {
if (event.origin === EXTERNAL_URI) {
currentLang = event.data;
resetForm();
initializeForm().then(() => {
translatePage();
});
}
// function messageListener(event) {
// if (event.origin === EXTERNAL_URI) {
// currentLang = event.data;
// resetForm();
// initializeForm().then(() => {
// translatePage();
// });
// }
// }

function storageListener() {
const lang = localStorage.getItem("lang");

if (!lang || typeof lang !== "string") this.initializeLanguage();
else currentLang = lang;

resetForm();
initializeForm().then(() => {
translatePage();
});
}

function initializeForm() {
Expand Down Expand Up @@ -119,7 +134,7 @@

function initializeLanguage() {
currentLang = localStorage.getItem("lang");
if (!currentLang) {
if (!currentLang || typeof this.currentLang !== "string") {
currentLang = "en";
localStorage.setItem("lang", currentLang);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { Component } from '@angular/core';
import { EXTERNAL_URI } from 'src/app/app.constants';
import { TranslateConfigService } from 'src/app/shared/services/translate-config.service';
import { Component, OnInit } from "@angular/core";
import { EXTERNAL_URI } from "src/app/app.constants";
import { TranslateConfigService } from "src/app/shared/services/translate-config.service";

@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.scss']
selector: "app-main",
templateUrl: "./main.component.html",
styleUrls: ["./main.component.scss"],
})
export class MainComponent {
export class MainComponent implements OnInit {
constructor(private translateConfigService: TranslateConfigService) {
const currentLang = this.translateConfigService.getDefaultLanguage();
this.translateConfigService.setLanguage(currentLang);
this.translateConfigService.setDefaultLanguage();

window.addEventListener('message', this.listener.bind(this), false);
//window.addEventListener('message', this.messageListener.bind(this), false);
}

private listener(event: MessageEvent) {
if (event.origin === EXTERNAL_URI) {
this.translateConfigService.setLanguage(event.data);
ngOnInit() {
if (window.addEventListener) {
window.addEventListener("storage", this.storageListener, false);
}
}

private storageListener() {
const lang = localStorage.getItem("lang");
if (lang || typeof lang === "string")
this.translateConfigService.setLanguage(lang);
else this.translateConfigService.setDefaultLanguage();
}

// private messageListener(event: MessageEvent) {
// if (event.origin === EXTERNAL_URI) {
// this.translateConfigService.setLanguage(event.data);
// }
// }

send() {
// TODO
//window.parent.postMessage('', EXTERNAL_URI);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Injectable } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";

@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class TranslateConfigService {
currentLang: any;

constructor(
private translate: TranslateService,
) {
this.currentLang = localStorage.getItem('lang');
constructor(private translate: TranslateService) {
this.currentLang = localStorage.getItem("lang");
}

getDefaultLanguage(){
if (this.currentLang) {
this.translate.setDefaultLang(this.currentLang);
} else {
this.currentLang = 'en';
localStorage.setItem('lang', this.currentLang);
this.translate.setDefaultLang(this.currentLang);
setDefaultLanguage() {
if (!this.currentLang || typeof this.currentLang !== "string") {
this.currentLang = "en";
localStorage.setItem("lang", this.currentLang);
}

this.translate.setDefaultLang(this.currentLang);
this.translate.use(this.currentLang);
return this.currentLang;
}

setLanguage(setLang: string) {
this.translate.use(setLang);
localStorage.setItem('lang', setLang);
localStorage.setItem("lang", setLang);
}

getCurrentLang() {
return localStorage.getItem('lang');
return localStorage.getItem("lang");
}

}
11 changes: 0 additions & 11 deletions small_claim_form/small_claim_form/form_b/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@
let simplificatinBoxTooltipStyle;
let isWarningStepVisible = false;

// this.initializeLanguage();
// window.addEventListener("message", this.listener.bind(this), false);

// document.addEventListener("DOMContentLoaded", () => {
// document;
// initializeForm();
// setInterval(function () {
// $("[data-bs-toggle='tooltip']").tooltip();
// }, 1000);
// });

function listener(event) {
if (event.origin === EXTERNAL_URI) {
currentLang = event.data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { Component } from '@angular/core';
import { EXTERNAL_URI } from 'src/app/app.constants';
import { TranslateConfigService } from 'src/app/shared/services/translate-config.service';
import { Component, OnInit } from "@angular/core";
import { EXTERNAL_URI } from "src/app/app.constants";
import { TranslateConfigService } from "src/app/shared/services/translate-config.service";

@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.scss']
selector: "app-main",
templateUrl: "./main.component.html",
styleUrls: ["./main.component.scss"],
})
export class MainComponent {
export class MainComponent implements OnInit {
constructor(private translateConfigService: TranslateConfigService) {
const currentLang = this.translateConfigService.getDefaultLanguage();
this.translateConfigService.setLanguage(currentLang);
this.translateConfigService.setDefaultLanguage();

window.addEventListener('message', this.listener.bind(this), false);
//window.addEventListener('message', this.messageListener.bind(this), false);
}

private listener(event: MessageEvent) {
if (event.origin === EXTERNAL_URI) {
this.translateConfigService.setLanguage(event.data);
ngOnInit() {
if (window.addEventListener) {
window.addEventListener("storage", this.storageListener, false);
}
}

private storageListener() {
const lang = localStorage.getItem("lang");
if (lang || typeof lang === "string")
this.translateConfigService.setLanguage(lang);
else this.translateConfigService.setDefaultLanguage();
}

// private messageListener(event: MessageEvent) {
// if (event.origin === EXTERNAL_URI) {
// this.translateConfigService.setLanguage(event.data);
// }
// }

send() {
// TODO
//window.parent.postMessage('', EXTERNAL_URI);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Injectable } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";

@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class TranslateConfigService {
currentLang: any;

constructor(
private translate: TranslateService,
) {
this.currentLang = localStorage.getItem('lang');
constructor(private translate: TranslateService) {
this.currentLang = localStorage.getItem("lang");
}

getDefaultLanguage(){
if (this.currentLang) {
this.translate.setDefaultLang(this.currentLang);
} else {
this.currentLang = 'en';
localStorage.setItem('lang', this.currentLang);
this.translate.setDefaultLang(this.currentLang);
setDefaultLanguage() {
if (!this.currentLang || typeof this.currentLang !== "string") {
this.currentLang = "en";
localStorage.setItem("lang", this.currentLang);
}

this.translate.setDefaultLang(this.currentLang);
this.translate.use(this.currentLang);
return this.currentLang;
}

setLanguage(setLang: string) {
this.translate.use(setLang);
localStorage.setItem('lang', setLang);
localStorage.setItem("lang", setLang);
}

getCurrentLang() {
return localStorage.getItem('lang');
return localStorage.getItem("lang");
}

}
Loading

0 comments on commit 2d2ef66

Please sign in to comment.