[SPA] Angular app-shell + host/player routing skeleton (#157) #164
3
frontend/angular/.gitignore
vendored
Normal file
3
frontend/angular/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
dist/
|
||||
.angular/
|
||||
36
frontend/angular/angular.json
Normal file
36
frontend/angular/angular.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"projects": {
|
||||
"wpp-angular-shell": {
|
||||
"projectType": "application",
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular/build:application",
|
||||
"options": {
|
||||
"outputPath": "dist/wpp-angular-shell",
|
||||
"index": "src/index.html",
|
||||
"browser": "src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [],
|
||||
"styles": ["src/styles.css"],
|
||||
"outputHashing": "none"
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular/build:dev-server",
|
||||
"options": {
|
||||
"buildTarget": "wpp-angular-shell:build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cli": {
|
||||
"analytics": false
|
||||
}
|
||||
}
|
||||
7185
frontend/angular/package-lock.json
generated
Normal file
7185
frontend/angular/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
frontend/angular/package.json
Normal file
25
frontend/angular/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "wpp-angular-shell",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "ng serve",
|
||||
"build": "ng build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular/common": "^19.2.0",
|
||||
"@angular/compiler": "^19.2.0",
|
||||
"@angular/core": "^19.2.0",
|
||||
"@angular/platform-browser": "^19.2.0",
|
||||
"@angular/router": "^19.2.0",
|
||||
"rxjs": "~7.8.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zone.js": "~0.15.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/build": "^19.2.0",
|
||||
"@angular/cli": "^19.2.0",
|
||||
"@angular/compiler-cli": "^19.2.0",
|
||||
"typescript": "~5.7.2"
|
||||
}
|
||||
}
|
||||
4
frontend/angular/src/app/app.component.css
Normal file
4
frontend/angular/src/app/app.component.css
Normal file
@@ -0,0 +1,4 @@
|
||||
.shell { font-family: Arial, sans-serif; margin: 1rem; }
|
||||
.shell__header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #ddd; padding-bottom: 0.75rem; }
|
||||
.shell__header nav { display: flex; gap: 0.75rem; }
|
||||
.shell__content { margin-top: 1rem; }
|
||||
13
frontend/angular/src/app/app.component.html
Normal file
13
frontend/angular/src/app/app.component.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<main class="shell">
|
||||
<header class="shell__header">
|
||||
<h1>WPP Angular Shell</h1>
|
||||
<nav>
|
||||
<a routerLink="/host">Host</a>
|
||||
<a routerLink="/player">Player</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section class="shell__content">
|
||||
<router-outlet></router-outlet>
|
||||
</section>
|
||||
</main>
|
||||
20
frontend/angular/src/app/app.component.ts
Normal file
20
frontend/angular/src/app/app.component.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { Router, RouterLink, RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
standalone: true,
|
||||
imports: [RouterOutlet, RouterLink],
|
||||
templateUrl: './app.component.html',
|
||||
styleUrl: './app.component.css',
|
||||
})
|
||||
export class AppComponent {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
constructor() {
|
||||
const shellRoute = document.body.dataset['wppShellRoute'];
|
||||
if (shellRoute === '/host' || shellRoute === '/player') {
|
||||
void this.router.navigateByUrl(shellRoute);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
frontend/angular/src/app/app.config.ts
Normal file
7
frontend/angular/src/app/app.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideRouter, withHashLocation } from '@angular/router';
|
||||
import { routes } from './app.routes';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideRouter(routes, withHashLocation())],
|
||||
};
|
||||
14
frontend/angular/src/app/app.routes.ts
Normal file
14
frontend/angular/src/app/app.routes.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
path: 'host',
|
||||
loadComponent: () => import('./features/host/host-shell.component').then((m) => m.HostShellComponent),
|
||||
},
|
||||
{
|
||||
path: 'player',
|
||||
loadComponent: () => import('./features/player/player-shell.component').then((m) => m.PlayerShellComponent),
|
||||
},
|
||||
{ path: '', pathMatch: 'full', redirectTo: 'player' },
|
||||
{ path: '**', redirectTo: 'player' },
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-host-shell',
|
||||
standalone: true,
|
||||
template: `
|
||||
<h2>Host route placeholder</h2>
|
||||
<p>Host flow flyttes hertil i kommende SPA-issues.</p>
|
||||
`,
|
||||
})
|
||||
export class HostShellComponent {}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-player-shell',
|
||||
standalone: true,
|
||||
template: `
|
||||
<h2>Player route placeholder</h2>
|
||||
<p>Player flow flyttes hertil i kommende SPA-issues.</p>
|
||||
`,
|
||||
})
|
||||
export class PlayerShellComponent {}
|
||||
12
frontend/angular/src/index.html
Normal file
12
frontend/angular/src/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>WPP Angular Shell</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
7
frontend/angular/src/main.ts
Normal file
7
frontend/angular/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { appConfig } from './app/app.config';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
4
frontend/angular/src/styles.css
Normal file
4
frontend/angular/src/styles.css
Normal file
@@ -0,0 +1,4 @@
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
9
frontend/angular/tsconfig.app.json
Normal file
9
frontend/angular/tsconfig.app.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": []
|
||||
},
|
||||
"files": ["src/main.ts"],
|
||||
"include": ["src/**/*.d.ts"]
|
||||
}
|
||||
22
frontend/angular/tsconfig.json
Normal file
22
frontend/angular/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "bundler",
|
||||
"importHelpers": true,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"lib": ["ES2022", "dom"]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,11 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>WPP SPA</title>
|
||||
<title>WPP SPA Shell</title>
|
||||
<link rel="stylesheet" href="{{ spa_asset_base }}/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
<app-root data-wpp-shell-route="{{ shell_route }}"></app-root>
|
||||
<body data-wpp-shell-route="{{ shell_route }}" data-wpp-shell-kind="{{ shell_kind }}">
|
||||
<app-root data-wpp-shell-route="{{ shell_route }}" data-wpp-shell-kind="{{ shell_kind }}">Indlæser Angular app-shell…</app-root>
|
||||
<script type="module" src="{{ spa_asset_base }}/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -994,8 +994,33 @@ class UiScreenTests(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "<app-root")
|
||||
self.assertContains(response, "data-wpp-shell-route=\"/host\"")
|
||||
self.assertContains(response, "data-wpp-shell-kind=\"host\"")
|
||||
self.assertContains(response, "/static/frontend/angular/browser/main.js")
|
||||
|
||||
@override_settings(USE_SPA_UI=True)
|
||||
def test_host_screen_deeplink_preserves_spa_path_when_feature_flag_enabled(self):
|
||||
self.client.login(username="host_ui", password="secret123")
|
||||
|
||||
response = self.client.get(
|
||||
reverse("lobby:host_screen_deeplink", kwargs={"spa_path": "guess/round-1"})
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "<app-root")
|
||||
self.assertContains(response, "data-wpp-shell-route=\"/host/guess/round-1\"")
|
||||
self.assertContains(response, "data-wpp-shell-kind=\"host\"")
|
||||
|
||||
@override_settings(USE_SPA_UI=True)
|
||||
def test_host_screen_deeplink_normalizes_redundant_slashes_when_feature_flag_enabled(self):
|
||||
self.client.login(username="host_ui", password="secret123")
|
||||
|
||||
response = self.client.get("/lobby/ui/host//guess///round-1//")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "<app-root")
|
||||
self.assertContains(response, "data-wpp-shell-route=\"/host/guess/round-1\"")
|
||||
self.assertContains(response, "data-wpp-shell-kind=\"host\"")
|
||||
|
||||
@override_settings(USE_SPA_UI=True)
|
||||
def test_player_screen_can_render_angular_shell_when_feature_flag_enabled(self):
|
||||
response = self.client.get(reverse("lobby:player_screen"))
|
||||
@@ -1003,6 +1028,7 @@ class UiScreenTests(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "<app-root")
|
||||
self.assertContains(response, "data-wpp-shell-route=\"/player\"")
|
||||
self.assertContains(response, "data-wpp-shell-kind=\"player\"")
|
||||
self.assertContains(response, "/static/frontend/angular/browser/main.js")
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,13 @@ from fupogfakta.models import Category
|
||||
from .feature_flags import use_spa_ui
|
||||
|
||||
|
||||
def _render_spa_shell(request, shell_route: str):
|
||||
def _render_spa_shell(request, shell_route: str, shell_kind: str):
|
||||
return render(
|
||||
request,
|
||||
"lobby/spa_shell.html",
|
||||
{
|
||||
"shell_route": shell_route,
|
||||
"shell_kind": shell_kind,
|
||||
"spa_asset_base": settings.WPP_SPA_ASSET_BASE,
|
||||
},
|
||||
)
|
||||
@@ -21,7 +22,12 @@ def _render_spa_shell(request, shell_route: str):
|
||||
@login_required
|
||||
def host_screen(request, spa_path=None):
|
||||
if use_spa_ui():
|
||||
return _render_spa_shell(request, "/host")
|
||||
host_route = "/host"
|
||||
if spa_path:
|
||||
normalized_spa_path = "/".join(segment for segment in spa_path.split("/") if segment)
|
||||
if normalized_spa_path:
|
||||
host_route = f"/host/{normalized_spa_path}"
|
||||
return _render_spa_shell(request, host_route, "host")
|
||||
|
||||
categories = Category.objects.filter(is_active=True).order_by("name")
|
||||
return render(request, "lobby/host_screen.html", {"categories": categories})
|
||||
@@ -29,6 +35,6 @@ def host_screen(request, spa_path=None):
|
||||
|
||||
def player_screen(request):
|
||||
if use_spa_ui():
|
||||
return _render_spa_shell(request, "/player")
|
||||
return _render_spa_shell(request, "/player", "player")
|
||||
|
||||
return render(request, "lobby/player_screen.html")
|
||||
|
||||
@@ -99,7 +99,6 @@ STATIC_ROOT = BASE_DIR / 'staticfiles'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
|
||||
USE_SPA_UI_RAW = env('USE_SPA_UI')
|
||||
if USE_SPA_UI_RAW is None:
|
||||
# Backward-compatible fallback while cutover is rolling out.
|
||||
|
||||
Reference in New Issue
Block a user