latest
This commit is contained in:
@@ -14,6 +14,7 @@ import { NavBarComponent } from './components/nav-bar/nav-bar.component';
|
||||
import { LoginService } from './services/login.service';
|
||||
import { UserService } from './services/user.service';
|
||||
import { PaymentService } from './services/payment.service';
|
||||
import { ShippingService } from './services/shipping.service';
|
||||
import { MyAccountComponent } from './components/my-account/my-account.component';
|
||||
import { MyProfileComponent } from './components/my-profile/my-profile.component';
|
||||
|
||||
@@ -35,7 +36,8 @@ import { MyProfileComponent } from './components/my-profile/my-profile.component
|
||||
providers: [
|
||||
LoginService,
|
||||
UserService,
|
||||
PaymentService
|
||||
PaymentService,
|
||||
ShippingService
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<br>
|
||||
<div>
|
||||
<p *ngIf="defaultPaymentSet">Default payment set successfully!</p>
|
||||
<md-tab-group (selectedIndexChange)="selectedIndexChange($event)" [selectedIndex]="selectedBillingTab">
|
||||
<md-tab-group (selectedIndexChange)="selectedBillingChange($event)" [selectedIndex]="selectedBillingTab">
|
||||
<md-tab label="List of Credit Cards">
|
||||
<form (ngSubmit)="setDefaultPayment()" method="post">
|
||||
<table class="table">
|
||||
@@ -252,7 +252,7 @@
|
||||
<br>
|
||||
<div>
|
||||
<p *ngIf="defaultShippingSet">Default shipping address set successfully!</p>
|
||||
<md-tab-group (selectedIndexChange)="selectedIndexChange($event)" [selectedIndex]="selectedShippingTab">
|
||||
<md-tab-group (selectedIndexChange)="selectedShippingChange($event)" [selectedIndex]="selectedShippingTab">
|
||||
<md-tab label="List of Shipping Addresses">
|
||||
<form (ngSubmit)="setDefaultShipping()" method="post">
|
||||
<table class="table">
|
||||
@@ -269,7 +269,7 @@
|
||||
<input type="radio" name="defaultUserShippingId" [(ngModel)]="defaultUserShippingId" [value]="userShipping.id" />
|
||||
<span>default</span>
|
||||
</td>
|
||||
<td>Shipping Address</td>
|
||||
<td>{{userShipping.userShippingStreet1}}, {{userShipping.userShippingCity}}, {{userShipping.userShippingState}}</td>
|
||||
<td>
|
||||
<a md-button (click)="onUpdateShipping(userShipping)"><i
|
||||
class="fa fa-pencil"></i></a>
|
||||
@@ -283,7 +283,7 @@
|
||||
</form>
|
||||
</md-tab>
|
||||
<md-tab label="Add(Update) Shipping Address">
|
||||
<form (ngSubmit)="onNewShippingAddress()" method="post">
|
||||
<form (ngSubmit)="onNewShipping()" method="post">
|
||||
<input hidden="hidden" name="id" [(ngModel)]="userShipping.id" />
|
||||
<!--Shipping Address-->
|
||||
<div class="form-group">
|
||||
@@ -325,7 +325,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<button type="submit" class="btn btn-primary btn-lg">Save All</button>
|
||||
<button md-raised-button type="submit" class="mat-primary">Save All</button>
|
||||
</form>
|
||||
</md-tab>
|
||||
</md-tab-group>
|
||||
|
||||
@@ -4,6 +4,7 @@ import {Router} from "@angular/router";
|
||||
import {LoginService} from "../../services/login.service";
|
||||
import {UserService} from "../../services/user.service";
|
||||
import {PaymentService} from "../../services/payment.service";
|
||||
import {ShippingService} from "../../services/shipping.service";
|
||||
import {User} from '../../models/user';
|
||||
import {UserPayment} from '../../models/user-payment';
|
||||
import {UserBilling} from '../../models/user-billing';
|
||||
@@ -35,19 +36,34 @@ export class MyProfileComponent implements OnInit {
|
||||
private userPayment: UserPayment = new UserPayment();
|
||||
private userBilling: UserBilling = new UserBilling();
|
||||
private userPaymentList: UserPayment[] = [];
|
||||
private stateList: string[] = [];
|
||||
private userShipping: UserShipping = new UserShipping();
|
||||
private userShippingList: UserShipping[] = [];
|
||||
private stateList: string[] = [];
|
||||
|
||||
private selectedProfileTab:number = 0;
|
||||
private selectedBillingTab:number = 0;
|
||||
private selectedShippingTab:number = 0;
|
||||
|
||||
private defaultUserPaymentId:number;
|
||||
private defaultPaymentSet:boolean;
|
||||
|
||||
constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){
|
||||
private defaultUserShippingId:number;
|
||||
private defaultShippingSet: boolean;
|
||||
|
||||
constructor (
|
||||
private paymentService:PaymentService,
|
||||
private shippingService:ShippingService,
|
||||
private loginService: LoginService,
|
||||
private userService: UserService,
|
||||
private router: Router
|
||||
){
|
||||
}
|
||||
|
||||
selectedIndexChange(val :number ){
|
||||
selectedShippingChange(val :number ){
|
||||
this.selectedShippingTab=val;
|
||||
}
|
||||
|
||||
selectedBillingChange(val :number ){
|
||||
this.selectedBillingTab=val;
|
||||
}
|
||||
|
||||
@@ -118,7 +134,6 @@ export class MyProfileComponent implements OnInit {
|
||||
onUpdatePayment(payment:UserPayment) {
|
||||
this.userPayment = payment;
|
||||
this.userBilling = payment.userBilling;
|
||||
this.selectedBillingTab=1;
|
||||
}
|
||||
|
||||
onRemovePayment(id:number) {
|
||||
@@ -148,16 +163,68 @@ export class MyProfileComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
onNewShipping () {
|
||||
this.shippingService.newShipping(this.userShipping).subscribe(
|
||||
res => {
|
||||
this.getCurrentUser();
|
||||
this.selectedShippingTab = 0;
|
||||
},
|
||||
error => {
|
||||
console.log(error.text());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onUpdateShipping(shipping:UserShipping) {
|
||||
this.userShipping = shipping;
|
||||
this.selectedShippingTab=1;
|
||||
}
|
||||
|
||||
onRemoveShipping(id:number) {
|
||||
this.shippingService.removeShipping(id).subscribe(
|
||||
res => {
|
||||
this.getCurrentUser();
|
||||
|
||||
},
|
||||
error => {
|
||||
console.log(error.text());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
setDefaultShipping() {
|
||||
this.defaultShippingSet=false;
|
||||
this.shippingService.setDefaultShipping(this.defaultUserShippingId).subscribe(
|
||||
res => {
|
||||
this.getCurrentUser();
|
||||
this.defaultShippingSet=true;
|
||||
// this.selectedProfileTab = 2;
|
||||
// this.selectedBillingTab = 0;
|
||||
},
|
||||
error => {
|
||||
console.log(error.text());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getCurrentUser() {
|
||||
this.userService.getCurrentUser().subscribe(
|
||||
res => {
|
||||
this.user=res.json();
|
||||
this.userPaymentList = this.user.userPaymentList;
|
||||
this.userShippingList = this.user.userShippingList;
|
||||
|
||||
for (let index in this.userPaymentList) {
|
||||
if (this.userPaymentList[index].defaultPayment) {
|
||||
this.defaultUserPaymentId=this.userPaymentList[index].id;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i in this.userShippingList) {
|
||||
if (this.userShippingList[i].userShippingDefault) {
|
||||
this.defaultUserShippingId=this.userShippingList[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -191,5 +258,7 @@ export class MyProfileComponent implements OnInit {
|
||||
this.defaultPaymentSet=false;
|
||||
|
||||
this.userShipping.userShippingState="";
|
||||
this.defaultShippingSet=false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {UserPayment} from './user-payment';
|
||||
import {UserShipping} from './user-shipping';
|
||||
|
||||
export class User {
|
||||
public id: number;
|
||||
@@ -10,4 +11,5 @@ export class User {
|
||||
public phone: string;
|
||||
public enabled: boolean;
|
||||
public userPaymentList: UserPayment[];
|
||||
public userShippingList: UserShipping[];
|
||||
}
|
||||
|
||||
16
store-front/src/app/services/shipping.service.spec.ts
Normal file
16
store-front/src/app/services/shipping.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
|
||||
import { TestBed, async, inject } from '@angular/core/testing';
|
||||
import { ShippingService } from './shipping.service';
|
||||
|
||||
describe('ShippingService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ShippingService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should ...', inject([ShippingService], (service: ShippingService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
41
store-front/src/app/services/shipping.service.ts
Normal file
41
store-front/src/app/services/shipping.service.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {AppConst} from '../constants/app-const';
|
||||
import {Http, Headers} from '@angular/http';
|
||||
import {UserShipping} from '../models/user-shipping';
|
||||
|
||||
@Injectable()
|
||||
export class ShippingService {
|
||||
private serverPath:string = AppConst.serverPath;
|
||||
|
||||
constructor(private http:Http) { }
|
||||
|
||||
newShipping(shipping: UserShipping) {
|
||||
let url = this.serverPath+"/shipping/add";
|
||||
|
||||
let tokenHeader = new Headers ({
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth-token' : localStorage.getItem("xAuthToken")
|
||||
});
|
||||
return this.http.post(url, JSON.stringify(shipping), {headers : tokenHeader});
|
||||
}
|
||||
|
||||
removeShipping(id: number) {
|
||||
let url = this.serverPath+"/shipping/remove";
|
||||
|
||||
let tokenHeader = new Headers ({
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth-token' : localStorage.getItem("xAuthToken")
|
||||
});
|
||||
return this.http.post(url, id, {headers : tokenHeader});
|
||||
}
|
||||
|
||||
setDefaultShipping(id: number) {
|
||||
let url = this.serverPath+"/shipping/setDefault";
|
||||
|
||||
let tokenHeader = new Headers ({
|
||||
'Content-Type': 'application/json',
|
||||
'x-auth-token' : localStorage.getItem("xAuthToken")
|
||||
});
|
||||
return this.http.post(url, id, {headers : tokenHeader});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user