diff --git a/app.go b/app.go index c2e67b0..141c510 100644 --- a/app.go +++ b/app.go @@ -1,6 +1,7 @@ package main import ( + "mime" "path" "path/filepath" @@ -20,6 +21,7 @@ type App struct { func (a *App) start() { a.db.AutoMigrate(&planner.Besucher{}) a.r.Use(CORSMiddleware()) + a.r.Use(HEADERMiddleWare()) a.r.SetTrustedProxies(a.proxyips) a.r.NoRoute((func(c *gin.Context) { dir, file := path.Split(c.Request.RequestURI) @@ -46,6 +48,13 @@ func (a *App) start() { } } +func HEADERMiddleWare() gin.HandlerFunc { + return func(c *gin.Context) { + mime.AddExtensionType(".js", "application/javascript") + c.Next() + } +} + func CORSMiddleware() gin.HandlerFunc { return func(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Origin", "*") diff --git a/ui/src/app/app-routing.module.ts b/ui/src/app/app-routing.module.ts index 44a13df..27e6fe0 100644 --- a/ui/src/app/app-routing.module.ts +++ b/ui/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import { BesucherComponent } from './besucher/besucher.component'; import { ContactComponent } from './contact/contact.component'; import { HomeComponent } from './home/home.component'; import { LocationComponent } from './location/location.component'; +import { ThanksComponent } from './thanks/thanks.component'; import { WegbeschreibungComponent } from './wegbeschreibung/wegbeschreibung.component'; const routes: Routes = [ @@ -11,8 +12,9 @@ const routes: Routes = [ { path: 'home', component: HomeComponent}, { path: 'client',component: BesucherComponent}, { path: 'unserfest',component: LocationComponent}, - { path:'contact', component: ContactComponent}, - {path:'wegbeschreibung', component: WegbeschreibungComponent} + { path: 'contact', component: ContactComponent}, + { path: 'wegbeschreibung', component: WegbeschreibungComponent}, + { path: 'thanks', component: ThanksComponent} ]; @NgModule({ diff --git a/ui/src/app/app.module.ts b/ui/src/app/app.module.ts index 1eb503a..a9ae2a5 100644 --- a/ui/src/app/app.module.ts +++ b/ui/src/app/app.module.ts @@ -18,6 +18,7 @@ import { LocationComponent } from './location/location.component'; import { ContactComponent } from './contact/contact.component'; import { DisclaimerComponent } from './disclaimer/disclaimer.component'; import { WegbeschreibungComponent } from './wegbeschreibung/wegbeschreibung.component'; +import { ThanksComponent } from './thanks/thanks.component'; @NgModule({ declarations: [ @@ -29,7 +30,8 @@ import { WegbeschreibungComponent } from './wegbeschreibung/wegbeschreibung.comp LocationComponent, ContactComponent, DisclaimerComponent, - WegbeschreibungComponent + WegbeschreibungComponent, + ThanksComponent ], imports: [ BrowserModule, diff --git a/ui/src/app/besucher/besucher.component.ts b/ui/src/app/besucher/besucher.component.ts index 36c7ce8..9f0d41c 100644 --- a/ui/src/app/besucher/besucher.component.ts +++ b/ui/src/app/besucher/besucher.component.ts @@ -4,6 +4,7 @@ import { MatRadioModule } from '@angular/material/radio'; import { filter } from 'rxjs'; import { BesucherService } from '../besucher.service'; import { Besucher } from 'src/besucher'; +import { Router, ActivatedRoute } from '@angular/router'; @@ -25,7 +26,7 @@ export class BesucherComponent implements OnInit { BesucherKommtRadio: string = ""; kommt: string[] = ['Ja','Nein']; - constructor(private besucherService: BesucherService) { + constructor(private besucherService: BesucherService, private route: Router ) { } ngOnInit(): void { @@ -36,19 +37,10 @@ export class BesucherComponent implements OnInit { getAll() { this.besucherService.getBesucherList().subscribe((data: Besucher[]) => { this.activeBesuchers = data; - console.log(data); + //console.log(data); }); } - /*getAll() { - this.besucherService.getBesucherList() - .pipe( - filter((data): data is Besucher[] => data instanceof Besucher)) - .subscribe(data => { - this.activeBesuchers = data.filter((a) => !a.come); - this.kommendeBesuchers = data.filter((a) => a.come); - }); - }*/ addBesucher() { var newBesucher : Besucher = { @@ -57,10 +49,12 @@ export class BesucherComponent implements OnInit { id: '', come : this.convertBesucherkommtStringToBoolean(this.BesucherKommtRadio) }; - console.log(newBesucher.come); + this.besucherService.addBesucher(newBesucher).subscribe(() => { - this.getAll(); this.BesucherMessage = ''; + this.BesucherName = ''; + this.route.navigate(['/thanks']); + }) } diff --git a/ui/src/app/thanks/thanks.component.css b/ui/src/app/thanks/thanks.component.css new file mode 100644 index 0000000..e69de29 diff --git a/ui/src/app/thanks/thanks.component.html b/ui/src/app/thanks/thanks.component.html new file mode 100644 index 0000000..f3e3765 --- /dev/null +++ b/ui/src/app/thanks/thanks.component.html @@ -0,0 +1,3 @@ +

Vielen Dank!

+

Ihre Nachricht wurde versendet!

+
Klicken Sie hier um zur Startseite zu kommen
diff --git a/ui/src/app/thanks/thanks.component.spec.ts b/ui/src/app/thanks/thanks.component.spec.ts new file mode 100644 index 0000000..2b27c02 --- /dev/null +++ b/ui/src/app/thanks/thanks.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ThanksComponent } from './thanks.component'; + +describe('ThanksComponent', () => { + let component: ThanksComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ThanksComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ThanksComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ui/src/app/thanks/thanks.component.ts b/ui/src/app/thanks/thanks.component.ts new file mode 100644 index 0000000..5ff502d --- /dev/null +++ b/ui/src/app/thanks/thanks.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-thanks', + templateUrl: './thanks.component.html', + styleUrls: ['./thanks.component.css'] +}) +export class ThanksComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/ui/src/environments/environment.ts b/ui/src/environments/environment.ts index 243b207..d133328 100644 --- a/ui/src/environments/environment.ts +++ b/ui/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - gateway: '', + gateway: 'http://localhost:3001', callback: 'http://localhost:4200/callback', };