[bdd6491] | 1 | import { HttpErrorResponse } from '@angular/common/http';
|
---|
[59329aa] | 2 | import { Component, OnInit } from '@angular/core';
|
---|
[84d0fbb] | 3 | import { Router } from '@angular/router';
|
---|
[1ad8e64] | 4 | import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
---|
[84d0fbb] | 5 | import { LoginRequest } from '../_models/dto/loginRequest';
|
---|
| 6 | import { UserDto } from '../_models/dto/userDto';
|
---|
[59329aa] | 7 | import { Location } from '../_models/location';
|
---|
| 8 | import { LocationService } from '../_services/location.service';
|
---|
[84d0fbb] | 9 | import { UserService } from '../_services/user.service';
|
---|
| 10 | import { LoginComponent } from './login/login.component';
|
---|
[1ad8e64] | 11 | import { RegisterComponent } from './register/register.component';
|
---|
[59329aa] | 12 |
|
---|
| 13 |
|
---|
| 14 | @Component({
|
---|
| 15 | selector: 'app-homepage',
|
---|
| 16 | templateUrl: './homepage.component.html',
|
---|
| 17 | styleUrls: ['./homepage.component.css']
|
---|
| 18 | })
|
---|
| 19 | export 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[];
|
---|
[1ad8e64] | 26 | ref: DynamicDialogRef;
|
---|
[59329aa] | 27 |
|
---|
[84d0fbb] | 28 | constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService,
|
---|
| 29 | private router: Router) {
|
---|
[59329aa] | 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 = [];
|
---|
[1ad8e64] | 49 | this.ref = new DynamicDialogRef;
|
---|
[59329aa] | 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 | );
|
---|
[bdd6491] | 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) => {
|
---|
[bdd6491] | 75 | if (user) {
|
---|
| 76 | this.userService.registerUser(user).subscribe(
|
---|
| 77 | data => {
|
---|
| 78 | console.log(data);
|
---|
| 79 | }
|
---|
| 80 | );
|
---|
| 81 | }
|
---|
| 82 | },
|
---|
| 83 | err => {
|
---|
| 84 |
|
---|
| 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 | }
|
---|