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

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

spring security 2.0

  • Property mode set to 100644
File size: 3.0 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { Router } from '@angular/router';
3import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
4import { LoginRequest } from '../_models/dto/loginRequest';
5import { UserDto } from '../_models/dto/userDto';
6import { Location } from '../_models/location';
7import { LocationService } from '../_services/location.service';
8import { UserService } from '../_services/user.service';
9import { LoginComponent } from './login/login.component';
10import { RegisterComponent } from './register/register.component';
11
12
13@Component({
14 selector: 'app-homepage',
15 templateUrl: './homepage.component.html',
16 styleUrls: ['./homepage.component.css']
17})
18export class HomepageComponent implements OnInit {
19
20 imageURI = 'https://i.pinimg.com/736x/a1/1a/57/a11a572a1ec4e07039bbd04661a3b035.jpg';
21 myLogo = 'http://www.logo-designer.co/wp-content/uploads/2020/02/2020-tripadvisor-new-logo-design-by-mother-design-4.png';
22 responsiveOptions;
23 locations: Location[];
24 villages: Location[];
25 ref: DynamicDialogRef;
26
27 constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
28 private router: Router) {
29 this.responsiveOptions = [
30 {
31 breakpoint: '1024px',
32 numVisible: 3,
33 numScroll: 3
34 },
35 {
36 breakpoint: '768px',
37 numVisible: 2,
38 numScroll: 2
39 },
40 {
41 breakpoint: '560px',
42 numVisible: 1,
43 numScroll: 1
44 }
45 ];
46 this.locations = [];
47 this.villages = [];
48 this.ref = new DynamicDialogRef;
49 }
50
51 ngOnInit(): void {
52/*
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 this.userService.registerUser(user).subscribe(
76 data => {
77 console.log(data);
78
79 }
80 );
81 });
82 }
83
84
85 onClickLogIn() {
86 this.ref = this.dialogService.open(LoginComponent, {
87 header: 'Log in if you already have an account',
88 width: '70%',
89 contentStyle: { "max-height": "500px", "overflow": "auto" },
90 baseZIndex: 10000
91 });
92 this.ref.onClose.subscribe((loginRequest : LoginRequest) => {
93 this.userService.authenticateUser(loginRequest).subscribe(
94 (data : any) => {
95 console.log(data);
96 if(this.userService.isUserLoggedIn()){
97 this.router.navigate(['planners']);
98 }
99 }
100 );
101 });
102 }
103}
Note: See TracBrowser for help on using the repository browser.