Changeset 84d0fbb for trip-planner-front
- Timestamp:
- 12/19/21 19:39:00 (3 years ago)
- Branches:
- master
- Children:
- bdd6491
- Parents:
- 1ad8e64
- Location:
- trip-planner-front/src/app
- Files:
-
- 6 added
- 1 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/_models/dto/plannerDto.ts
r1ad8e64 r84d0fbb 1 import { Location } from "../location";2 1 3 2 export class PlannerDto{ -
trip-planner-front/src/app/_models/planner.ts
r1ad8e64 r84d0fbb 1 1 export class Planner{ 2 2 3 id: number; 3 4 name: string; -
trip-planner-front/src/app/_services/planner.service.ts
r1ad8e64 r84d0fbb 1 import { HttpClient } from "@angular/common/http";1 import { HttpClient, HttpHeaders } from "@angular/common/http"; 2 2 import { Injectable } from "@angular/core"; 3 3 import { Observable } from "rxjs"; … … 8 8 providedIn: 'root' 9 9 }) 10 export class PlannerService{ 11 10 export class PlannerService { 11 12 httpHeaders: HttpHeaders = new HttpHeaders({ 13 'Authorization': ''+sessionStorage.getItem("token"), 14 'Accept': 'application/json', 15 'Content-Type': 'application/json' 16 }); 17 18 12 19 constructor(private httpClient: HttpClient){ 13 20 } 14 21 22 15 23 getAllPlanners():Observable<Planner[]>{ 16 let url = "http://localhost:8080/api/planners"; 17 return this.httpClient.get<Planner[]>(url); 24 let url = "http://localhost:8080/api/planners/user"; 25 console.log("SERVID: " + sessionStorage.getItem("token")); 26 console.log(this.httpHeaders.get('Authorization')) ; 27 return this.httpClient.get<Planner[]>(url, {headers: this.httpHeaders}); 18 28 } 19 29 20 postInitialPlanner(planner: Planner): Observable< Object>{30 postInitialPlanner(planner: Planner): Observable<Planner>{ 21 31 let url = "http://localhost:8080/api/planner/new"; 22 32 return this.httpClient.post<Planner>(url, planner); … … 25 35 updatePlanner(id: number, plannerDto : PlannerDto):Observable<Planner>{ 26 36 let url = "http://localhost:8080/api/edit/planner/" + id; 27 return this.httpClient.put<Planner>(url, plannerDto );37 return this.httpClient.put<Planner>(url, plannerDto, {headers: this.httpHeaders}); 28 38 } 29 39 -
trip-planner-front/src/app/app-routing.module.ts
r1ad8e64 r84d0fbb 1 1 import { NgModule } from '@angular/core'; 2 2 import { RouterModule, Routes } from '@angular/router'; 3 import { AuthGuard } from './auth/auth.guard'; 3 4 import { HomepageComponent } from './homepage/homepage.component'; 5 import { LoginComponent } from './homepage/login/login.component'; 4 6 import { LocationDetailsComponent } from './location/location-details/location-details.component'; 5 7 import { LocationComponent } from './location/location.component'; … … 14 16 {path: 'locations', component: LocationComponent}, 15 17 {path: '', component: HomepageComponent}, 18 {path: '', component:LoginComponent}, 16 19 {path: 'location', component: LocationDetailsComponent} 17 20 ]; -
trip-planner-front/src/app/app.module.ts
r1ad8e64 r84d0fbb 4 4 import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; 5 5 import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 6 import { HttpClient, HttpClientModule } from '@angular/common/http';6 import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; 7 7 import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 8 8 import { CategoryService } from './_services/cateogry.service'; … … 47 47 import { RegisterComponent } from './homepage/register/register.component'; 48 48 import { LoginComponent } from './homepage/login/login.component'; 49 import { AuthGuard } from './auth/auth.guard'; 50 import { AuthInterceptor } from './auth/auth.interceptor'; 49 51 50 52 @NgModule({ … … 109 111 PlannerService, 110 112 { 111 provide: MatDialogRef, 112 useValue: {} 113 provide: MatDialogRef, 114 useValue: {}, 115 116 }, 117 { 118 provide: HTTP_INTERCEPTORS, 119 useClass: AuthInterceptor, 120 multi: true 113 121 }, 114 122 DialogService, 115 123 MessageService, 116 ConfirmationService 117 124 ConfirmationService, 125 AuthGuard 118 126 ], 119 127 -
trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.ts
r1ad8e64 r84d0fbb 12 12 13 13 planner: Planner; 14 plannerDto: PlannerDto;15 14 16 15 constructor( private ref: DynamicDialogRef) { 17 16 this.planner = new Planner; 18 this.plannerDto = new PlannerDto();19 17 } 20 18 21 19 ngOnInit(): void { 22 20 this.planner = new Planner(); 23 this.plannerDto = new PlannerDto();24 21 } 25 22 -
trip-planner-front/src/app/homepage/homepage.component.html
r1ad8e64 r84d0fbb 21 21 </li> 22 22 <li class="nav-item"> 23 <button class="btn btn-dark" >Sign in</button>23 <button class="btn btn-dark" (click)="onClickLogIn()">Sign in</button> 24 24 </li> 25 25 </ul> … … 30 30 <img src={{imageURI}} /> 31 31 <h4></h4> 32 33 32 <!-- 33 <div class="content-section implementation carousel-demo" style="padding-top: 2em;"> 34 34 <div class="card"> 35 35 <p-carousel [value]="locations" [numVisible]="3" [numScroll]="3" [circular]="false" … … 91 91 </div> 92 92 </div> 93 --> 94 93 95 </main> 94 96 <br> -
trip-planner-front/src/app/homepage/homepage.component.ts
r1ad8e64 r84d0fbb 1 1 import { Component, OnInit } from '@angular/core'; 2 import { Router } from '@angular/router'; 2 3 import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog'; 4 import { LoginRequest } from '../_models/dto/loginRequest'; 5 import { UserDto } from '../_models/dto/userDto'; 3 6 import { Location } from '../_models/location'; 4 7 import { LocationService } from '../_services/location.service'; 8 import { UserService } from '../_services/user.service'; 9 import { LoginComponent } from './login/login.component'; 5 10 import { RegisterComponent } from './register/register.component'; 6 11 … … 20 25 ref: DynamicDialogRef; 21 26 22 constructor(private locationService: LocationService, private dialogService: DialogService) { 27 constructor(private locationService: LocationService, private dialogService: DialogService, private userService: UserService, 28 private router: Router) { 23 29 this.responsiveOptions = [ 24 30 { … … 44 50 45 51 ngOnInit(): void { 46 52 /* 47 53 this.locationService.getWeekendGetaways().subscribe( 48 54 data => { … … 55 61 } 56 62 ); 63 */ 57 64 } 58 65 59 onClickSignUp(){ 60 console.log("VLEGOV"); 66 onClickSignUp() { 61 67 this.ref = this.dialogService.open(RegisterComponent, { 62 68 header: 'Register form', … … 64 70 contentStyle: { "max-height": "500px", "overflow": "auto" }, 65 71 baseZIndex: 10000 66 }); 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 }); 67 102 } 68 103 } -
trip-planner-front/src/app/homepage/login/login.component.html
r1ad8e64 r84d0fbb 1 <p>login works!</p> 1 <div class="p-col-12 p-md-4"> 2 <div class="p-inputgroup"> 3 <span class="p-inputgroup-addon"><i class="pi pi-user"></i></span> 4 <input type="text" pInputText placeholder="Email address (Username)" 5 [(ngModel)]="loginRequest.username" name="username"> 6 </div> 7 </div> 8 <div class="p-col-12 p-md-4"> 9 <div class="p-inputgroup"> 10 <span class="p-inputgroup-addon"><i class="pi pi-password"></i></span> 11 <input type="password" pInputText placeholder="Password" name="password" [(ngModel)]="loginRequest.password"> 12 </div> 13 </div> 14 15 <div class="p-col-12 p-md-4"> 16 <button pButton pRipple label="Log in" class="p-button-secondary" type="submit" 17 (click)="onFormLogIn(loginRequest)"></button> 18 </div> -
trip-planner-front/src/app/homepage/login/login.component.ts
r1ad8e64 r84d0fbb 1 1 import { Component, OnInit } from '@angular/core'; 2 import { Router } from '@angular/router'; 3 import { DynamicDialogRef } from 'primeng/dynamicdialog'; 4 import { LoginRequest } from 'src/app/_models/dto/loginRequest'; 5 import { UserService } from 'src/app/_services/user.service'; 2 6 3 7 @Component({ … … 8 12 export class LoginComponent implements OnInit { 9 13 10 constructor() { } 14 15 loginRequest : LoginRequest; 16 17 constructor(private ref: DynamicDialogRef, private router: Router, private userService : UserService) { 18 this.loginRequest = new LoginRequest(); 19 20 } 11 21 12 22 ngOnInit(): void { 13 23 } 14 24 25 onFormLogIn(loginRequest){ 26 this.ref.close(loginRequest); 27 28 } 15 29 } -
trip-planner-front/src/app/homepage/register/register.component.html
r1ad8e64 r84d0fbb 1 <div class="p-grid p-fluid"> 2 <div class="p-col-12 p-md-4"> 3 <div class="p-inputgroup"> 4 <span class="p-inputgroup-addon"><i class="pi pi-user"></i></span> 5 <input type="text" pInputText placeholder="Full name"> 1 2 <div class="p-grid p-fluid"> 3 <div class="p-col-12 p-md-4"> 4 <div class="p-inputgroup"> 5 <span class="p-inputgroup-addon"><i class="pi pi-user"></i></span> 6 <input type="text" pInputText placeholder="Full name" [(ngModel)]="user.fullName" name="fullName" 7 > 8 </div> 6 9 </div> 7 </div> 8 9 <div class="p-col-12 p-md-4"> 10 <div class="p-inputgroup"> 11 <span class="p-inputgroup-addon"><i class="pi pi-user"></i></span> 12 <input type="text" pInputText placeholder="Ema address (Username)"> 10 11 <div class="p-col-12 p-md-4"> 12 <div class="p-inputgroup"> 13 <span class="p-inputgroup-addon"><i class="pi pi-user"></i></span> 14 <input type="text" pInputText placeholder="Email address (Username)" [(ngModel)]="user.username" name="username" 15 > 16 </div> 13 17 </div> 14 </div> 15 <div class="p-col-12 p-md-4"> 16 <div class="p-inputgroup"> 17 <span class="p-inputgroup-addon"><i class="pi pi-password"></i></span> 18 <input type="text" pInputText placeholder="Password"> 18 <div class="p-col-12 p-md-4"> 19 <div class="p-inputgroup"> 20 <span class="p-inputgroup-addon"><i class="pi pi-password"></i></span> 21 <input type="password" pInputText placeholder="Password" [(ngModel)]="user.password" name="password" 22 > 23 </div> 19 24 </div> 20 </div> 21 <div class="p-col-12 p-md-4"> 22 <div class="p-inputgroup"> 23 <span class="p-inputgroup-addon"><i class="pi pi-password"></i></span> 24 <input type="text" pInputText placeholder="Repeat password"> 25 <div class="p-col-12 p-md-4"> 26 <div class="p-inputgroup"> 27 <span class="p-inputgroup-addon"><i class="pi pi-password"></i></span> 28 <input type="password" pInputText placeholder="Repeat password" [(ngModel)]="user.confirmPassword" name="confirmPassword" 29 > 30 </div> 25 31 </div> 26 </div> 27 28 <div class="p-col-12 p-md-4"> 29 <button pButton pRipple type="button" label="Submit" class="p-button-secondary"></button> 30 </div> 31 </div> 32 33 <div class="p-col-12 p-md-4"> 34 <button pButton pRipple label="Submit" class="p-button-secondary" type="submit" (click)="onFormSubmitSignUp(user)"></button> 35 </div> 36 </div> -
trip-planner-front/src/app/homepage/register/register.component.ts
r1ad8e64 r84d0fbb 1 1 import { Component, OnInit } from '@angular/core'; 2 import { DynamicDialogRef } from 'primeng/dynamicdialog'; 3 import { UserDto } from 'src/app/_models/dto/userDto'; 2 4 3 5 @Component({ … … 8 10 export class RegisterComponent implements OnInit { 9 11 10 constructor() { } 12 user : UserDto; 13 14 constructor(private ref: DynamicDialogRef) { 15 this.user = new UserDto(); 16 } 11 17 12 18 ngOnInit(): void { 13 19 } 14 20 21 onFormSubmitSignUp(user){ 22 this.ref.close(user); 23 //window.location.reload(); 24 } 15 25 } -
trip-planner-front/src/app/planner/planner.component.ts
r1ad8e64 r84d0fbb 7 7 import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog'; 8 8 import { MessageService, PrimeNGConfig } from 'primeng/api'; 9 import { UserDto } from '../_models/dto/userDto'; 10 import { UserService } from '../_services/user.service'; 9 11 10 12 … … 20 22 plannerDto: PlannerDto; 21 23 ref: DynamicDialogRef; 22 24 user: UserDto; 23 25 24 26 constructor(private plannerService: PlannerService, private router: Router, 25 private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService) { 27 private dialogService: DialogService, private primengConfig: PrimeNGConfig, private messageService: MessageService, 28 private userService : UserService) { 26 29 this.planners = []; 27 30 this.plannerDto = new PlannerDto(); 28 31 this.ref = new DynamicDialogRef; 32 this.user = new UserDto(); 29 33 } 30 34 … … 36 40 data => { 37 41 this.planners = data; 42 localStorage.getItem("token"); 38 43 } 39 ); 44 ); 40 45 } 41 46
Note:
See TracChangeset
for help on using the changeset viewer.