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
RevLine 
[bdd6491]1import { HttpErrorResponse } from '@angular/common/http';
[b738035]2import { identifierModuleUrl } from '@angular/compiler';
[59329aa]3import { Component, OnInit } from '@angular/core';
[84d0fbb]4import { Router } from '@angular/router';
[b738035]5import { MessageService } from 'primeng/api';
[1ad8e64]6import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
[84d0fbb]7import { LoginRequest } from '../_models/dto/loginRequest';
8import { UserDto } from '../_models/dto/userDto';
[59329aa]9import { Location } from '../_models/location';
10import { LocationService } from '../_services/location.service';
[84d0fbb]11import { UserService } from '../_services/user.service';
12import { LoginComponent } from './login/login.component';
[1ad8e64]13import { RegisterComponent } from './register/register.component';
[59329aa]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[];
[1ad8e64]27 ref: DynamicDialogRef;
[59329aa]28
[84d0fbb]29 constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
[b738035]30 private router: Router, private messageService: MessageService) {
[59329aa]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 = [];
[1ad8e64]50 this.ref = new DynamicDialogRef;
[59329aa]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 }
[1ad8e64]65
[84d0fbb]66 onClickSignUp() {
[1ad8e64]67 this.ref = this.dialogService.open(RegisterComponent, {
68 header: 'Register form',
69 width: '70%',
70 contentStyle: { "max-height": "500px", "overflow": "auto" },
71 baseZIndex: 10000
[84d0fbb]72 });
73
74 this.ref.onClose.subscribe((user: UserDto) => {
[bdd6491]75 if (user) {
76 this.userService.registerUser(user).subscribe(
77 data => {
78 console.log(data);
79 }
80 );
81 }
82 },
83 err => {
[b738035]84 console.log("oops");
[bdd6491]85 });
[84d0fbb]86 }
87
[bdd6491]88
[84d0fbb]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 });
[bdd6491]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 }
[84d0fbb]104 }
[bdd6491]105 );
106 }
[84d0fbb]107 });
[1ad8e64]108 }
[bdd6491]109
110 ngOnDestroy() {
111 if (this.ref) {
112 this.ref.close();
113 }
114 }
[59329aa]115}
Note: See TracBrowser for help on using the repository browser.