Skip to content

Commit 95882b7

Browse files
committed
set the language, and keep it (only the list refreshing works properly) needs to implement that it reload the full list (and not only for the second click!)
1 parent 2fbef3a commit 95882b7

File tree

3 files changed

+73
-27
lines changed

3 files changed

+73
-27
lines changed

frontend/src/app/app.component.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@
3333
</div>
3434
</nav>
3535

36+
<!--
37+
<ul class="navbar-nav ml-auto">
38+
<li class="nav-item dropdown">
39+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
40+
aria-haspopup="true" aria-expanded="false">
41+
{{ selectedLanguage }}
42+
</a>
43+
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
44+
<a class="dropdown-item" (click)="changeLang('hu')">Magyar</a>
45+
<a class="dropdown-item" (click)="changeLang('en')">English</a>
46+
<a class="dropdown-item" (click)="changeLang('il')">עברית</a>
47+
</div>
48+
</li>
49+
</ul>
50+
-->
51+
52+
3653
<!--<div class="cart-area d-n">
3754
<a href="shopping-detail.html">
3855
<div class="total">19.22 <span> 2</span> </div> <i class="fa fa-shopping-cart"

frontend/src/app/app.component.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
2+
import { Router } from '@angular/router';
23

34
@Component({
45
selector: 'app-root',
@@ -7,19 +8,37 @@ import {Component, OnInit} from '@angular/core';
78
})
89
export class AppComponent implements OnInit {
910
title = 'frontend';
10-
selectedLanguage: string = '';
11+
selectedLanguage: string;
1112

12-
ngOnInit(): void {
13-
14-
}
15-
16-
constructor() {
17-
// this.router.navigate(['/hu/admin/gov-representatives/government', governmentId]);
13+
constructor(private router: Router) {
1814
this.selectedLanguage = window.localStorage.getItem('lang') || 'hu';
1915
}
2016

17+
ngOnInit(): void {}
18+
2119
changeLang(lang: string): void {
20+
// Store selected language in local storage
21+
window.localStorage.setItem('lang', lang);
22+
23+
// Update URL with selected language
24+
const url = this.router.url;
25+
const updatedUrl = url.split('/').map(segment => {
26+
if (segment === 'hu' || segment === 'en' || segment === 'il') {
27+
return lang;
28+
}
29+
return segment;
30+
}).join('/');
31+
this.router.navigateByUrl(updatedUrl);
32+
33+
// Set the selected language in the component
2234
this.selectedLanguage = lang;
2335
}
2436
}
2537

38+
39+
40+
41+
42+
43+
44+

frontend/src/app/government-service/components/representative-list/representative-list.component.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import {Component, NgModule, OnInit} from '@angular/core';
22
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
33
import {
4-
ActivatedRoute
4+
ActivatedRoute, Router
55
} from '@angular/router';
66

77
import {
88
Availability, GovernmentAdminModel,
99
GovernmentRepresentativeService, GovernmentService
1010
} from '../../../../../build/openapi/government-service';
11-
import {Observable, Subject} from "rxjs";
11+
import {Observable} from "rxjs";
1212

1313
@Component({
1414
selector: 'app-representative-list',
@@ -18,21 +18,44 @@ import {Observable, Subject} from "rxjs";
1818

1919
export class RepresentativeListComponent implements OnInit {
2020
representatives: SanitizedRepresentativeAdminModel[] = [];
21-
currentLanguage?: string = 'hu';
21+
currentLanguage: string;
2222
governments$: Observable<GovernmentAdminModel[]> = this.governmentService.renderAllGovernments();
2323
currentGovernmentId?: number;
2424

2525
constructor(
2626
private readonly representativeService: GovernmentRepresentativeService,
2727
private readonly governmentService: GovernmentService,
2828
private sanitizer: DomSanitizer,
29-
private route: ActivatedRoute
30-
) {}
29+
private route: ActivatedRoute,
30+
private router: Router
31+
) {
32+
// Initialize currentLanguage to the language stored in local storage, or to 'hu' if it's not set yet
33+
this.currentLanguage = window.localStorage.getItem('lang') || 'hu';
34+
}
35+
3136

3237
ngOnInit(): void {
3338
this.listRepresentatives();
3439
}
3540

41+
changeLang(lang: string): void {
42+
// Set currentLanguage to the selected language
43+
this.currentLanguage = lang;
44+
// Save currentLanguage to local storage
45+
window.localStorage.setItem('lang', lang);
46+
// Update the URL with the new language
47+
const url = this.router.url;
48+
const updatedUrl = url.split('/').map(segment => {
49+
if (segment === 'hu' || segment === 'en' || segment === 'il') {
50+
return lang;
51+
}
52+
return segment;
53+
}).join('/');
54+
this.router.navigateByUrl(updatedUrl);
55+
// Update the displayed data
56+
this.listRepresentatives();
57+
}
58+
3659
private listRepresentatives() {
3760
this.route.params.subscribe(params => {
3861
const governmentId = params['governmentId'];
@@ -58,19 +81,6 @@ export class RepresentativeListComponent implements OnInit {
5881
});
5982
});
6083
}
61-
/*private listAllRepresentatives() {
62-
this.representativeService.renderAllRepresentatives(this.currentLanguage!).subscribe((data) => {
63-
this.representatives = data.map((representative) => {
64-
console.log("Representatives: " + JSON.stringify(representative));
65-
const government = representative.government;
66-
return {
67-
...representative,
68-
governmentName: government ? government.name : '',
69-
image: this.sanitizer.bypassSecurityTrustUrl(`data:image/png;base64,${representative.image}`),
70-
};
71-
});
72-
});
73-
}*/
7484

7585
private listRepresentativesByGovId(currentLanguage: string, governmentId: number) {
7686
this.currentGovernmentId = governmentId;

0 commit comments

Comments
 (0)