Skip to content

Commit fbd1da2

Browse files
Added basic version of popup, angular material UI, added type, refactoring.
1 parent e7dd59f commit fbd1da2

20 files changed

+207
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ docker-compose up --build
144144
<img src="frontForNow.PNG" width=600>
145145
</p>
146146

147-
- Front end with search function.
147+
- Front end with search function and clicking will show country with relevant information.
148148

149-
- As being back end developer front end is low priority, but for now it has somewhat working list! Focusing now back end tests.
149+
- ⚠️make error page.⚠️
150150

151151
## How to run the front end.
152152

country-service-front/angular.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"src/assets"
2424
],
2525
"styles": [
26+
"src/custom-theme.scss",
2627
"src/styles.css"
2728
],
2829
"scripts": []

country-service-front/package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

country-service-front/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"private": true,
1212
"dependencies": {
1313
"@angular/animations": "^14.0.0",
14+
"@angular/cdk": "~13.0.0-next.7+89.sha-a662737",
1415
"@angular/common": "^14.0.0",
1516
"@angular/compiler": "^14.0.0",
1617
"@angular/core": "^14.0.0",
1718
"@angular/forms": "^14.0.0",
19+
"@angular/material": "~13.0.0-next.7+89.sha-a662737",
1820
"@angular/platform-browser": "^14.0.0",
1921
"@angular/platform-browser-dynamic": "^14.0.0",
2022
"@angular/router": "^14.3.0",
@@ -35,4 +37,4 @@
3537
"karma-jasmine-html-reporter": "~2.0.0",
3638
"typescript": "~4.7.2"
3739
}
38-
}
40+
}

country-service-front/src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { HttpClientModule } from '@angular/common/http';
88
import { AppRoutingModule } from './app-routing.module';
99
import { SearchComponent } from './search/search.component';
1010
import { FormsModule } from '@angular/forms';
11+
import { MatDialogModule } from '@angular/material/dialog'; // Correct import for MatDialogModule
12+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; // Required for animations
1113

1214
@NgModule({
1315
declarations: [
@@ -21,6 +23,8 @@ import { FormsModule } from '@angular/forms';
2123
HttpClientModule,
2224
FormsModule,
2325
AppRoutingModule,
26+
MatDialogModule,
27+
BrowserAnimationsModule,
2428
],
2529
providers: [],
2630
bootstrap: [AppComponent]

country-service-front/src/app/body/body.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ul {
1414
}
1515

1616
ul li a {
17-
min-height: 4rem;
17+
min-height: 4.5rem;
1818
min-width: 15rem;
1919
display: flex;
2020
margin: 0.5rem;

country-service-front/src/app/body/body.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<ul>
44
<li *ngFor="let country of countries">
5-
<a>
5+
<a (click)="openDialog(country)">
66
<div><b>{{country.name}}</b></div>
77
<div>{{country.country_code}}</div>
88
</a>

country-service-front/src/app/body/body.component.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { Component, OnInit } from '@angular/core';
22
import { CountryService } from '../services/country/country.service';
33
import { Country } from '../types/Country';
44
import { ActivatedRoute } from '@angular/router';
5-
import { Countries } from '../types/Countries';
5+
import { MatDialog } from '@angular/material/dialog'; // Import MatDialog service
66
import { map } from 'rxjs';
7+
import { CountryDialogComponent } from '../country-dialog-component/country-dialog.component';
78

89
@Component({
910
selector: 'app-body',
@@ -16,16 +17,14 @@ export class BodyComponent implements OnInit {
1617

1718
searchCountry : string = ''; //Filtering by search
1819

19-
constructor(private cs: CountryService, private route: ActivatedRoute) { }
20-
21-
20+
constructor(private cs: CountryService, private route: ActivatedRoute, private dialog: MatDialog ) { }
2221

2322
ngOnInit(): void {
2423

25-
2624
this.route.params.subscribe(params => {
2725

2826
console.log(params);
27+
2928
this.searchCountry = params['searchCountry']; //Filtering by search
3029

3130
if (this.searchCountry && this.searchCountry.trim() !== '') {
@@ -47,11 +46,25 @@ export class BodyComponent implements OnInit {
4746
);
4847

4948
} else {
50-
//call from home page
49+
//call to get all countries
5150
this.cs.getAllCountries().subscribe(allCountries => {
5251
this.countries = allCountries;
5352
});
5453
}
5554
});
5655
}
56+
57+
openDialog(country: Country): void {
58+
var countryName = country.name;
59+
this.cs.getInformationAboutCountry(countryName).subscribe( //Click happened
60+
(data) => {
61+
this.dialog.open(CountryDialogComponent, {
62+
data: data
63+
});
64+
},
65+
(error) => {
66+
console.error('Error fetching country data', error);
67+
}
68+
);
69+
}
5770
}

country-service-front/src/app/country-dialog-component/country-dialog-component.component.css

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div mat-dialog-content>
2+
<div>
3+
<img [src]="data.flag_file_url" alt="Flag of {{ data.name }}" style="width: 20rem; height: auto;">
4+
</div>
5+
<p><strong>Country Name:</strong> {{ data.name }}</p>
6+
<p><strong>Country Code:</strong> {{ data.country_code }}</p>
7+
<p><strong>Capital:</strong> {{ data.capital }}</p>
8+
<p><strong>Population:</strong> {{ data.population}}</p>
9+
</div>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { CountryDialogComponent } from './country-dialog.component';
4+
5+
describe('CountryDialogComponentComponent', () => {
6+
let component: CountryDialogComponent;
7+
let fixture: ComponentFixture<CountryDialogComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ CountryDialogComponent ]
12+
})
13+
.compileComponents();
14+
15+
fixture = TestBed.createComponent(CountryDialogComponent);
16+
component = fixture.componentInstance;
17+
fixture.detectChanges();
18+
});
19+
20+
it('should create', () => {
21+
expect(component).toBeTruthy();
22+
});
23+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component, Inject, OnInit } from '@angular/core';
2+
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
3+
import { MatDialogRef } from '@angular/material/dialog';
4+
5+
@Component({
6+
selector: 'app-country-dialog-component',
7+
templateUrl: './country-dialog-component.component.html',
8+
styleUrls: ['./country-dialog-component.component.css']
9+
})
10+
export class CountryDialogComponent implements OnInit {
11+
12+
constructor( public dialogRef: MatDialogRef<CountryDialogComponent>,
13+
@Inject(MAT_DIALOG_DATA) public data: any ) {} //Country data comes here
14+
15+
ngOnInit(): void {
16+
}
17+
18+
onClose(): void {
19+
this.dialogRef.close();
20+
}
21+
}

country-service-front/src/app/search/search.component.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ div {
66
margin-bottom: 1.5rem;
77
}
88

9-
109
div input {
1110
border-radius: 10rem 0 0 10rem;
1211
border: 3px solid #00005e;
1312
border-right: none;
14-
height: 2.5rem;
13+
height: 1.0rem;
1514
width: 20rem;
1615
background-color: white;
1716
color: #00005e;

country-service-front/src/app/search/search.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Action } from 'rxjs/internal/scheduler/Action';
1010
})
1111
export class SearchComponent implements OnInit {
1212

13-
@Input() searchCountry : string = ''; //Input form parent. Route won't send to multiple component.
13+
@Input() searchCountry : string = ''; //Input form parent. Route won't send params to multiple component, so we catch it here.
1414

1515
constructor(private route : ActivatedRoute, private router : Router) { }
1616

country-service-front/src/app/services/country/country.service.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import { Injectable } from '@angular/core';
2-
import { Countries } from 'src/app/types/Countries';
32
import { Country } from 'src/app/types/Country';
43
import { HttpClient } from '@angular/common/http';
54
import { map, Observable } from 'rxjs';
65
import { environment } from 'src/environments/environment';
6+
import { CountryInformation } from 'src/app/types/CountryInformation';
77

88

99
@Injectable({
1010
providedIn: 'root'
1111
})
1212
export class CountryService {
1313

14-
private apiUrl = environment.apiUrl;
14+
private getAllCountriesUrl = environment.getCountriesBaseUrl;
15+
private getInformationAboutCountryUrl = environment.getCountriesBaseUrl;
1516

1617
constructor(private http: HttpClient) {
1718
}
1819

20+
21+
//TODO(Heikki) Ensure exactly what’s being returned and if it’s in then the expected form
22+
getInformationAboutCountry(countryCode: string): Observable<CountryInformation> {
23+
const url = this.getInformationAboutCountryUrl + `${countryCode}`;
24+
return this.http.get<CountryInformation>(url);
25+
}
26+
1927
//TODO(Heikki) Ensure exactly what’s being returned and if it’s in then the expected form
2028
getAllCountries(): Observable<Country[]> {
21-
return this.http.get<{ countries: Country[] }>(this.apiUrl).pipe(
29+
return this.http.get<{ countries: Country[] }>(this.getAllCountriesUrl).pipe(
2230
map(response => response.countries)); //For now, unwrap the result into Country[]
2331
}
2432

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface CountryInformation {
2+
name: string;
3+
country_code: string;
4+
capital: string;
5+
population: number;
6+
flag_file_url: string;
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
// Custom Theming for Angular Material
3+
// For more information: https://material.angular.io/guide/theming
4+
@use '@angular/material' as mat;
5+
// Plus imports for other components in your app.
6+
7+
// Include the common styles for Angular Material. We include this here so that you only
8+
// have to load a single css file for Angular Material in your app.
9+
// Be sure that you only ever include this mixin once!
10+
@include mat.core();
11+
12+
// Define the palettes for your theme using the Material Design palettes available in palette.scss
13+
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
14+
// hue. Available color palettes: https://material.io/design/color/
15+
$country-service-front-primary: mat.define-palette(mat.$indigo-palette);
16+
$country-service-front-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
17+
18+
// The warn palette is optional (defaults to red).
19+
$country-service-front-warn: mat.define-palette(mat.$red-palette);
20+
21+
// Create the theme object. A theme consists of configurations for individual
22+
// theming systems such as "color" or "typography".
23+
$country-service-front-theme: mat.define-light-theme((
24+
color: (
25+
primary: $country-service-front-primary,
26+
accent: $country-service-front-accent,
27+
warn: $country-service-front-warn,
28+
)
29+
));
30+
31+
// Include theme styles for core and each component used in your app.
32+
// Alternatively, you can import and @include the theme mixins for each component
33+
// that you are using.
34+
@include mat.all-component-themes($country-service-front-theme);

0 commit comments

Comments
 (0)