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

Last change on this file since bdd6491 was bdd6491, checked in by Ema <ema_spirova@…>, 3 years ago

pre final presentation

  • Property mode set to 100644
File size: 3.3 KB
Line 
1import { HttpErrorResponse } from '@angular/common/http';
2import { Component, OnInit } from '@angular/core';
3import { Router } from '@angular/router';
4import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
5import { LoginRequest } from '../_models/dto/loginRequest';
6import { UserDto } from '../_models/dto/userDto';
7import { Location } from '../_models/location';
8import { LocationService } from '../_services/location.service';
9import { UserService } from '../_services/user.service';
10import { LoginComponent } from './login/login.component';
11import { RegisterComponent } from './register/register.component';
12
13
14@Component({
15 selector: 'app-homepage',
16 templateUrl: './homepage.component.html',
17 styleUrls: ['./homepage.component.css']
18})
19export class HomepageComponent implements OnInit {
20
21 imageURI = 'https://i.pinimg.com/736x/a1/1a/57/a11a572a1ec4e07039bbd04661a3b035.jpg';
22 myLogo = 'http://www.logo-designer.co/wp-content/uploads/2020/02/2020-tripadvisor-new-logo-design-by-mother-design-4.png';
23 responsiveOptions;
24 locations: Location[];
25 villages: Location[];
26 ref: DynamicDialogRef;
27
28 constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
29 private router: Router) {
30 this.responsiveOptions = [
31 {
32 breakpoint: '1024px',
33 numVisible: 3,
34 numScroll: 3
35 },
36 {
37 breakpoint: '768px',
38 numVisible: 2,
39 numScroll: 2
40 },
41 {
42 breakpoint: '560px',
43 numVisible: 1,
44 numScroll: 1
45 }
46 ];
47 this.locations = [];
48 this.villages = [];
49 this.ref = new DynamicDialogRef;
50 }
51
52 ngOnInit(): void {
53 this.locationService.getWeekendGetaways().subscribe(
54 data => {
55 this.locations = data;
56 });
57
58 this.locationService.getVillages().subscribe(
59 village => {
60 this.villages = village;
61 }
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
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.