[59329aa] | 1 | import { Component, OnInit } from '@angular/core';
|
---|
[84d0fbb] | 2 | import { Router } from '@angular/router';
|
---|
[1ad8e64] | 3 | import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
---|
[84d0fbb] | 4 | import { LoginRequest } from '../_models/dto/loginRequest';
|
---|
| 5 | import { UserDto } from '../_models/dto/userDto';
|
---|
[59329aa] | 6 | import { Location } from '../_models/location';
|
---|
| 7 | import { LocationService } from '../_services/location.service';
|
---|
[84d0fbb] | 8 | import { UserService } from '../_services/user.service';
|
---|
| 9 | import { LoginComponent } from './login/login.component';
|
---|
[1ad8e64] | 10 | import { RegisterComponent } from './register/register.component';
|
---|
[59329aa] | 11 |
|
---|
| 12 |
|
---|
| 13 | @Component({
|
---|
| 14 | selector: 'app-homepage',
|
---|
| 15 | templateUrl: './homepage.component.html',
|
---|
| 16 | styleUrls: ['./homepage.component.css']
|
---|
| 17 | })
|
---|
| 18 | export 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[];
|
---|
[1ad8e64] | 25 | ref: DynamicDialogRef;
|
---|
[59329aa] | 26 |
|
---|
[84d0fbb] | 27 | constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
|
---|
| 28 | private router: Router) {
|
---|
[59329aa] | 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 = [];
|
---|
[1ad8e64] | 48 | this.ref = new DynamicDialogRef;
|
---|
[59329aa] | 49 | }
|
---|
| 50 |
|
---|
| 51 | ngOnInit(): void {
|
---|
[84d0fbb] | 52 | /*
|
---|
[59329aa] | 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 | );
|
---|
[84d0fbb] | 63 | */
|
---|
[59329aa] | 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) => {
|
---|
| 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 | });
|
---|
[1ad8e64] | 102 | }
|
---|
[59329aa] | 103 | }
|
---|