source: trip-planner-front/src/app/homepage/homepage.component.ts

Last change on this file was b738035, checked in by Ema <ema_spirova@…>, 2 years ago

signup/login server errors on front and remove location from planner

  • Property mode set to 100644
File size: 3.3 KB
Line 
1import { HttpErrorResponse } from '@angular/common/http';
2import { identifierModuleUrl } from '@angular/compiler';
3import { Component, OnInit } from '@angular/core';
4import { Router } from '@angular/router';
5import { MessageService } from 'primeng/api';
6import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
7import { LoginRequest } from '../_models/dto/loginRequest';
8import { UserDto } from '../_models/dto/userDto';
9import { Location } from '../_models/location';
10import { LocationService } from '../_services/location.service';
11import { UserService } from '../_services/user.service';
12import { LoginComponent } from './login/login.component';
13import { RegisterComponent } from './register/register.component';
14
15
16@Component({
17 selector: 'app-homepage',
18 templateUrl: './homepage.component.html',
19 styleUrls: ['./homepage.component.css']
20})
21export class HomepageComponent implements OnInit {
22
23 imageURI = 'https://i.pinimg.com/736x/a1/1a/57/a11a572a1ec4e07039bbd04661a3b035.jpg';
24 responsiveOptions;
25 locations: Location[];
26 villages: Location[];
27 ref: DynamicDialogRef;
28
29 constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
30 private router: Router, private messageService: MessageService) {
31 this.responsiveOptions = [
32 {
33 breakpoint: '1024px',
34 numVisible: 3,
35 numScroll: 3
36 },
37 {
38 breakpoint: '768px',
39 numVisible: 2,
40 numScroll: 2
41 },
42 {
43 breakpoint: '560px',
44 numVisible: 1,
45 numScroll: 1
46 }
47 ];
48 this.locations = [];
49 this.villages = [];
50 this.ref = new DynamicDialogRef;
51 }
52
53 ngOnInit(): void {
54 this.locationService.getWeekendGetaways().subscribe(
55 data => {
56 this.locations = data;
57 });
58
59 this.locationService.getVillages().subscribe(
60 village => {
61 this.villages = village;
62 }
63 );
64 }
65
66 onClickSignUp() {
67 this.ref = this.dialogService.open(RegisterComponent, {
68 header: 'Register form',
69 width: '70%',
70 contentStyle: { "max-height": "500px", "overflow": "auto" },
71 baseZIndex: 10000
72 });
73
74 this.ref.onClose.subscribe((user: UserDto) => {
75 if (user) {
76 this.userService.registerUser(user).subscribe(
77 data => {
78 console.log(data);
79 }
80 );
81 }
82 },
83 err => {
84 console.log("oops");
85 });
86 }
87
88
89 onClickLogIn() {
90 this.ref = this.dialogService.open(LoginComponent, {
91 header: 'Log in if you already have an account',
92 width: '70%',
93 contentStyle: { "max-height": "500px", "overflow": "auto" },
94 baseZIndex: 10000
95 });
96 this.ref.onClose.subscribe((loginRequest: LoginRequest) => {
97 if (loginRequest) {
98 this.userService.authenticateUser(loginRequest).subscribe(
99 (data: any) => {
100 console.log(data);
101 if (this.userService.isUserLoggedIn()) {
102 this.router.navigate(['planners']);
103 }
104 }
105 );
106 }
107 });
108 }
109
110 ngOnDestroy() {
111 if (this.ref) {
112 this.ref.close();
113 }
114 }
115}
Note: See TracBrowser for help on using the repository browser.