Skip to content

Commit a1e406f

Browse files
committed
Add dev platform module
1 parent 91868e9 commit a1e406f

14 files changed

+223
-5
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ $ npm start
1111

1212
A visit to `localhost:4200` shows the application.
1313

14+
## Bookings local development
15+
16+
Serve the bookings microfrontend inside the train-platform application (does not support live-reload for microfrontend):
17+
```
18+
npm start train-platform
19+
npm run ng run bookings:build:local-web-components && npx http-server projects/bookings/dist --port 4201
20+
```
21+
22+
Serve the bookings microfrontend in isolation using the angular dev server:
23+
```
24+
npm start bookings
25+
```
26+
1427
## Benefits of microfrontends
1528

1629
- Vertical services (backend and frontend are fully owned by one team, see [micro-frontends.org](https://micro-frontends.org/))

angular.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@
190190
"with": "projects/bookings/src/environments/environment.prod.ts"
191191
}
192192
]
193+
},
194+
"local-web-components": {
195+
"fileReplacements": [
196+
{
197+
"replace": "projects/bookings/src/environments/environment.ts",
198+
"with": "projects/bookings/src/environments/environment.local-web-components.ts"
199+
}
200+
]
193201
}
194202
}
195203
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>Bookings DEV Platform</h2>
2+
<ul *ngFor="let journey of journeys">
3+
<li>
4+
<a [routerLink]="['bookings', 'journey', journey.id]"
5+
>Journey {{ journey.id }}</a
6+
>
7+
</li>
8+
</ul>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'mf-dev-platform-page',
5+
templateUrl: './dev-platform-page.component.html',
6+
})
7+
export class DevPlatformPageComponent {
8+
journeys: { id: string }[] = [{ id: '1' }, { id: '2' }];
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { CommonModule } from '@angular/common';
2+
import { NgModule } from '@angular/core';
3+
import { FormsModule } from '@angular/forms';
4+
import { RouterModule } from '@angular/router';
5+
import { BookingModule } from '../app/booking.module';
6+
import { DevPlatformPageComponent } from './dev-platform-page/dev-platform-page.component';
7+
import { DevPlatformComponent } from './dev-platform/dev-platform.component';
8+
9+
@NgModule({
10+
declarations: [DevPlatformComponent, DevPlatformPageComponent],
11+
imports: [
12+
CommonModule,
13+
FormsModule,
14+
RouterModule.forRoot([
15+
{
16+
path: '',
17+
pathMatch: 'full',
18+
component: DevPlatformPageComponent,
19+
data: { title: 'Journeys' },
20+
},
21+
]),
22+
BookingModule,
23+
],
24+
bootstrap: [DevPlatformComponent],
25+
})
26+
export class DevPlatformModule {}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
:host {
2+
--background-color: white;
3+
--font-color: black;
4+
display: block;
5+
background-color: var(--background-color);
6+
color: var(--font-color);
7+
height: 100vh;
8+
padding: 8px;
9+
}
10+
11+
:host.dark {
12+
--background-color: black;
13+
--font-color: white;
14+
}
15+
16+
nav {
17+
height: 40px;
18+
width: 100%;
19+
display: flex;
20+
flex-direction: row;
21+
justify-content: space-between;
22+
}
23+
24+
ul {
25+
list-style: none;
26+
padding: 0;
27+
margin: 0;
28+
display: flex;
29+
flex-direction: row;
30+
flex-wrap: nowrap;
31+
}
32+
33+
li {
34+
line-height: 40px;
35+
vertical-align: middle;
36+
padding-left: 0.5rem;
37+
padding-right: 0.5rem;
38+
}
39+
40+
.active-nav-item {
41+
cursor: default;
42+
text-decoration: none;
43+
}
44+
45+
.page-options {
46+
display: flex;
47+
flex-direction: row;
48+
flex-wrap: nowrap;
49+
gap: 1rem;
50+
line-height: 40px;
51+
}
52+
53+
label {
54+
margin-right: 0.5rem;
55+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<nav>
2+
<ul>
3+
<li>
4+
<a routerLink="/" routerLinkActive="active-nav-item" [routerLinkActiveOptions]="{exact: true}">Home</a>
5+
</li>
6+
</ul>
7+
<div class="page-options">
8+
<div>
9+
<label>Theme:</label>
10+
<select [ngModel]="theme" (ngModelChange)="updateTheme($event)">
11+
<option value="light">Light</option>
12+
<option value="dark">Dark</option>
13+
</select>
14+
</div>
15+
<div>
16+
<label>Language:</label>
17+
<select [ngModel]="language" (ngModelChange)="updateLanguage($event)">
18+
<option value="en">English</option>
19+
<option value="de">Deutsch</option>
20+
</select>
21+
</div>
22+
</div>
23+
</nav>
24+
25+
<mf-booking></mf-booking>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Component, HostBinding, OnInit } from '@angular/core';
2+
import { Title } from '@angular/platform-browser';
3+
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
4+
import { TranslateService } from '@ngx-translate/core';
5+
import { filter, map } from 'rxjs/operators';
6+
7+
@Component({
8+
selector: 'mf-dev-platform',
9+
templateUrl: './dev-platform.component.html',
10+
styleUrls: ['./dev-platform.component.css'],
11+
})
12+
export class DevPlatformComponent implements OnInit {
13+
language: 'en' | 'de' = 'en';
14+
@HostBinding('class') theme: 'light' | 'dark' = 'light';
15+
16+
constructor(
17+
private router: Router,
18+
private titleService: Title,
19+
private translateService: TranslateService
20+
) {}
21+
22+
ngOnInit(): void {
23+
this.updatePageTitleOnRouteChange();
24+
}
25+
26+
updateTheme(theme: 'light' | 'dark'): void {
27+
this.theme = theme;
28+
}
29+
30+
updateLanguage(lang: 'en' | 'de'): void {
31+
this.language = lang;
32+
this.translateService.use(lang);
33+
}
34+
35+
private updatePageTitleOnRouteChange() {
36+
this.router.events
37+
.pipe(
38+
filter((event) => event instanceof NavigationEnd),
39+
map(() => {
40+
let route: ActivatedRoute = this.router.routerState.root;
41+
let routeTitle = '';
42+
while (route!.firstChild) {
43+
route = route.firstChild;
44+
}
45+
if (route.snapshot.data['title']) {
46+
routeTitle = route!.snapshot.data['title'];
47+
}
48+
return routeTitle;
49+
})
50+
)
51+
.subscribe((title) => {
52+
if (title) {
53+
this.titleService.setTitle(`${title} - Microtrains`);
54+
}
55+
});
56+
}
57+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const environment = {
2+
production: false,
3+
embedded: true,
4+
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const environment = {
2-
production: true
2+
production: true,
3+
embedded: true,
34
};

0 commit comments

Comments
 (0)