Compare commits
merge into: gowrisankar_hexa:master
gowrisankar_hexa:branch-gowri
gowrisankar_hexa:gauravAngular
gowrisankar_hexa:gauravMain
gowrisankar_hexa:gauravtest
gowrisankar_hexa:kris-branch
gowrisankar_hexa:master
pull from: gowrisankar_hexa:gauravAngular
gowrisankar_hexa:branch-gowri
gowrisankar_hexa:gauravAngular
gowrisankar_hexa:gauravMain
gowrisankar_hexa:gauravtest
gowrisankar_hexa:kris-branch
gowrisankar_hexa:master
8 Commits
master
...
gauravAngu
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
d4d8e79dcf |
some products are added and minor css work
|
4 years ago |
|
|
f92f396581 |
some products are added
|
4 years ago |
|
|
69b198a38b |
added search functionality
|
4 years ago |
|
|
f07e354031 |
adding to cart is working fine and flushing details to db is not implemented yet
|
4 years ago |
|
|
84744ca3ef |
the show cart is working and able to show details of cart added and add to cart function is not implemented yet
|
4 years ago |
|
|
9c63fdd9ba |
home page done but add to cart functionality is remaing
|
4 years ago |
|
|
95ffcbac35 |
adding home Component
|
4 years ago |
|
|
4ee348ff6f |
adding home component
|
4 years ago |
20 changed files with 521 additions and 79 deletions
Split View
Diff Options
-
30Angular-UrbanBazaar/package-lock.json
-
12Angular-UrbanBazaar/src/app/app-routing.module.ts
-
2Angular-UrbanBazaar/src/app/app.component.html
-
4Angular-UrbanBazaar/src/app/app.module.ts
-
44Angular-UrbanBazaar/src/app/components/cart/cart.component.css
-
52Angular-UrbanBazaar/src/app/components/cart/cart.component.html
-
25Angular-UrbanBazaar/src/app/components/cart/cart.component.spec.ts
-
36Angular-UrbanBazaar/src/app/components/cart/cart.component.ts
-
45Angular-UrbanBazaar/src/app/components/home/home.component.css
-
21Angular-UrbanBazaar/src/app/components/home/home.component.html
-
25Angular-UrbanBazaar/src/app/components/home/home.component.spec.ts
-
50Angular-UrbanBazaar/src/app/components/home/home.component.ts
-
113Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html
-
17Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.ts
-
7Angular-UrbanBazaar/src/app/models/cart.spec.ts
-
13Angular-UrbanBazaar/src/app/models/cart.ts
-
16Angular-UrbanBazaar/src/app/services/cart.service.spec.ts
-
78Angular-UrbanBazaar/src/app/services/cart.service.ts
-
9Angular-UrbanBazaar/src/app/services/product.service.ts
-
1Angular-UrbanBazaar/src/index.html
@ -1,15 +1,21 @@ |
|||
import { NgModule } from '@angular/core'; |
|||
import { RouterModule, Routes } from '@angular/router'; |
|||
import { CartComponent } from './components/cart/cart.component'; |
|||
import { HomeComponent } from './components/home/home.component'; |
|||
import { UserProfileDetailsComponent } from './components/user-profile-details/user-profile-details.component'; |
|||
import { UserShowComponent } from './components/user-show/user-show.component'; |
|||
|
|||
const routes: Routes = [ |
|||
{path:'showAllUsers', component: UserShowComponent}, |
|||
{path:'profile', component: UserProfileDetailsComponent}, |
|||
{path: '', component: HomeComponent}, |
|||
{path: 'showAllUsers', component: UserShowComponent}, |
|||
{path: 'profile', component: UserProfileDetailsComponent}, |
|||
{path: 'showCart', component: CartComponent}, |
|||
]; |
|||
|
|||
@NgModule({ |
|||
imports: [RouterModule.forRoot(routes)], |
|||
exports: [RouterModule] |
|||
|
|||
|
|||
exports: [RouterModule] |
|||
}) |
|||
export class AppRoutingModule { } |
|||
@ -1,3 +1,3 @@ |
|||
<app-page-nav-bar></app-page-nav-bar> |
|||
|
|||
<!-- <app-home></app-home> --> |
|||
<router-outlet></router-outlet> |
|||
@ -0,0 +1,44 @@ |
|||
.card |
|||
{ |
|||
height: 60vh; |
|||
margin: 25px; |
|||
padding: 25px; |
|||
} |
|||
|
|||
.center{ |
|||
position: absolute; |
|||
top: 50%; |
|||
left: 50%; |
|||
transform: translate(-50%,-50%); |
|||
text-align: center; |
|||
} |
|||
h4,h6{ |
|||
font-weight: 400; |
|||
} |
|||
.shopNow{ |
|||
padding: 5%; |
|||
background-color: rgb(79 79 243); |
|||
color: aliceblue; |
|||
border-radius: 15px; |
|||
border-color: white; |
|||
} |
|||
.card-table{ |
|||
position: relative; |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: center; |
|||
|
|||
} |
|||
.CartButtons{ |
|||
border-radius: 15px; |
|||
border-color:antiquewhite ; |
|||
background-color: beige; |
|||
} |
|||
/* .center .btn{ |
|||
font-size: 14px !important; |
|||
margin-top: 20px !important; |
|||
font-weight: 400; |
|||
padding: 12px 72px; |
|||
border-radius: 3px !important; |
|||
|
|||
} */ |
|||
@ -0,0 +1,52 @@ |
|||
<ng-container *ngIf="cartdetails.length !=0"> |
|||
<div class="container"> |
|||
<div class="card-table"> |
|||
<div class="card-product"> |
|||
<div class="table tabe-responsive"> |
|||
<thead> |
|||
<tr> |
|||
<th>S.No</th> |
|||
<th>ProductName</th> |
|||
<th>ProductPrice</th> |
|||
|
|||
<th>Action</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
<tr *ngFor="let c of cartdetails; let i = index"> |
|||
<td>{{i+1}}</td> |
|||
<td>{{c.productname}}</td> |
|||
<td>{{c.productprice}}</td> |
|||
<td> |
|||
<button class="CartButtons" (click)="removeItem(c)">Delete</button> |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td colspan="4"></td> |
|||
<td><button (click)=emptyCart() class="CartButtons">Empty Cart</button></td> |
|||
<td><button routerLink='/' class="CartButtons">Shop More</button></td> |
|||
<td><button class="CartButtons">Checkout</button></td> |
|||
<td><strong>Grand Total : Rs.{{grandTotal}}</strong></td> |
|||
</tr> |
|||
</tbody> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
|
|||
<ng-container *ngIf="cartdetails.length==0"> |
|||
<div class="container"> |
|||
<div class="card"> |
|||
<h5 class="card-title">My Cart</h5> |
|||
</div> |
|||
|
|||
<div class="center"> |
|||
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT9q9U7YaUc27iaqP1bbyD3g6GSLqlRmAFbeQ&usqp=CAU" |
|||
alt=""> |
|||
<h4>Your cart is empty!</h4> |
|||
<h6>Add item to it now</h6> |
|||
<button class="shopNow" routerLink='/'>Shop Now</button> |
|||
</div> |
|||
</div> |
|||
</ng-container> |
|||
@ -0,0 +1,25 @@ |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { CartComponent } from './cart.component'; |
|||
|
|||
describe('CartComponent', () => { |
|||
let component: CartComponent; |
|||
let fixture: ComponentFixture<CartComponent>; |
|||
|
|||
beforeEach(async () => { |
|||
await TestBed.configureTestingModule({ |
|||
declarations: [ CartComponent ] |
|||
}) |
|||
.compileComponents(); |
|||
}); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(CartComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,36 @@ |
|||
import { Component, OnInit } from '@angular/core'; |
|||
import { Observable } from 'rxjs'; |
|||
import { Cart } from 'src/app/models/cart'; |
|||
import { CartService } from 'src/app/services/cart.service'; |
|||
|
|||
@Component({ |
|||
selector: 'app-cart', |
|||
templateUrl: './cart.component.html', |
|||
styleUrls: ['./cart.component.css'] |
|||
}) |
|||
export class CartComponent implements OnInit { |
|||
|
|||
public cartdetails:any =[]; |
|||
public grandTotal!: number; |
|||
|
|||
constructor(private cartservice:CartService) { |
|||
// this.cartdetails = this.cartservice.showAllOrder();
|
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.cartservice.getProducts() |
|||
.subscribe(res=>{ |
|||
this.cartdetails = res; |
|||
this.grandTotal = this.cartservice.getTotalPrice(); |
|||
}) |
|||
} |
|||
removeItem(item:any){ |
|||
this.cartservice.removeCartItem(item); |
|||
} |
|||
|
|||
emptyCart() |
|||
{ |
|||
this.cartservice.removeAllCart(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
body { |
|||
padding-top: 10px; |
|||
padding-left: 10px; |
|||
padding-right: 10px; |
|||
padding-bottom: 10px; |
|||
} |
|||
|
|||
.showCart{ |
|||
position: fixed; |
|||
left: 1195px; |
|||
top: 61px; |
|||
border-radius: 15px; |
|||
padding: 10px; |
|||
border-color: antiquewhite; |
|||
} |
|||
|
|||
.AddToCart{ |
|||
border-radius: 10px; |
|||
border-color: antiquewhite; |
|||
color: rgb(0, 0, 0); |
|||
background-color: rgb(248, 229, 247); |
|||
font-weight: 600; |
|||
} |
|||
.card{ |
|||
max-width: 200px; |
|||
border-width: 1px; |
|||
border-color:antiquewhite; |
|||
text-align: center; |
|||
margin-top: 11px; |
|||
font-family: Arial, Helvetica, sans-serif; |
|||
border-radius: 12px; |
|||
box-shadow: 0.5em; |
|||
} |
|||
|
|||
.price { |
|||
color: grey; |
|||
font-size: 16px; |
|||
} |
|||
.cardParent{ |
|||
display: flex; |
|||
justify-content: space-between; |
|||
flex-direction: row; |
|||
flex-grow:auto; |
|||
flex-wrap: wrap; |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
|
|||
<body> |
|||
<form class="form-inline my-2 my-lg-0"> |
|||
<input class="form-control mr-sm-2" type="text" |
|||
[(ngModel)]="searchValue" id="searchValue" [ngModelOptions]="{standalone: true}" |
|||
placeholder="Search" aria-label="Search"> |
|||
<button class="btn btn-outline-success my-2 my-sm-0" |
|||
type="submit" (click)="searchProduct()">Search</button> |
|||
</form> |
|||
<button class="showCart" (click)="showCart()">Show Cart</button> |
|||
|
|||
<div class="cardParent"> |
|||
<div class="card" *ngFor="let i of Searchedproducts"> |
|||
<img src="{{i.productimage}}" style="width:85%"> |
|||
<h5>{{i.productname}}</h5> |
|||
<p class="price">Rs. {{i.productprice}} <br> |
|||
Weight: {{i.productweight}} Kg</p> |
|||
<p><button class="AddToCart" (click)=addCart(i)>Add to Cart</button></p> |
|||
</div> |
|||
</div> |
|||
</body> |
|||
@ -0,0 +1,25 @@ |
|||
import { ComponentFixture, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { HomeComponent } from './home.component'; |
|||
|
|||
describe('HomeComponent', () => { |
|||
let component: HomeComponent; |
|||
let fixture: ComponentFixture<HomeComponent>; |
|||
|
|||
beforeEach(async () => { |
|||
await TestBed.configureTestingModule({ |
|||
declarations: [ HomeComponent ] |
|||
}) |
|||
.compileComponents(); |
|||
}); |
|||
|
|||
beforeEach(() => { |
|||
fixture = TestBed.createComponent(HomeComponent); |
|||
component = fixture.componentInstance; |
|||
fixture.detectChanges(); |
|||
}); |
|||
|
|||
it('should create', () => { |
|||
expect(component).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,50 @@ |
|||
import { Component, OnInit } from '@angular/core'; |
|||
import { ProductService } from './../../services/product.service'; |
|||
import { Observable } from 'rxjs'; |
|||
import { Product } from './../../models/product'; |
|||
import { ActivatedRoute, Router } from '@angular/router'; |
|||
import { CartService } from 'src/app/services/cart.service'; |
|||
import { Cart } from 'src/app/models/cart'; |
|||
import { ThrowStmt } from '@angular/compiler'; |
|||
|
|||
@Component({ |
|||
selector: 'app-home', |
|||
templateUrl: './home.component.html', |
|||
styleUrls: ['./home.component.css'] |
|||
}) |
|||
export class HomeComponent implements OnInit { |
|||
|
|||
public products: Product[]; |
|||
public Searchedproducts: Product[]; |
|||
searchValue : string = ""; |
|||
|
|||
constructor(private productservice: ProductService, |
|||
private router: Router, |
|||
private cartservice: CartService, |
|||
) {} |
|||
|
|||
public showCart(){ |
|||
this.router.navigateByUrl('/showCart'); |
|||
} |
|||
|
|||
addCart(item:any){ |
|||
this.cartservice.addtoCart(item); |
|||
} |
|||
|
|||
searchProduct() { |
|||
if(this.searchValue=="") { |
|||
this.Searchedproducts = this.products; |
|||
} else { |
|||
// this.productservice.searchProduct(this.searchValue).subscribe(
|
|||
// res => {this.Searchedproducts = res;}
|
|||
// );
|
|||
this.Searchedproducts = this.products.filter(p => p.productname.toLocaleLowerCase().includes(this.searchValue)); |
|||
} |
|||
} |
|||
|
|||
ngOnInit(): void { |
|||
this.productservice.showAllProduct().subscribe(res=>{ |
|||
this.products = res; |
|||
this.Searchedproducts = res; |
|||
}) |
|||
}} |
|||
@ -1,72 +1,43 @@ |
|||
<p>page-nav-bar works!</p> |
|||
<nav class="navbar navbar-expand-lg navbar-light bg-light"> |
|||
<a class="navbar-brand" href="#">Urban Bazaar</a> |
|||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> |
|||
<span class="navbar-toggler-icon"></span> |
|||
</button> |
|||
|
|||
<nav class="navbar navbar-icon-top navbar-expand-lg navbar-dark bg-dark"> |
|||
<a class="navbar-brand" href="#">Navbar</a> |
|||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> |
|||
<span class="navbar-toggler-icon"></span> |
|||
</button> |
|||
|
|||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> |
|||
<ul class="navbar-nav mr-auto"> |
|||
<li class="nav-item active"> |
|||
<a class="nav-link" href="#"> |
|||
<i class="fa fa-home"></i> |
|||
Home |
|||
<span class="sr-only">(current)</span> |
|||
</a> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<a class="nav-link" href="#"> |
|||
<i class="fa fa-envelope-o"> |
|||
<span class="badge badge-danger">11</span> |
|||
</i> |
|||
Link |
|||
</a> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<a class="nav-link disabled" href="#"> |
|||
<i class="fa fa-envelope-o"> |
|||
<span class="badge badge-warning">11</span> |
|||
</i> |
|||
Disabled |
|||
</a> |
|||
</li> |
|||
<li class="nav-item dropdown"> |
|||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
|||
<i class="fa fa-envelope-o"> |
|||
<span class="badge badge-primary">11</span> |
|||
</i> |
|||
Dropdown |
|||
</a> |
|||
<div class="dropdown-menu" aria-labelledby="navbarDropdown"> |
|||
<a class="dropdown-item" href="#">Action</a> |
|||
<a class="dropdown-item" href="#">Another action</a> |
|||
<div class="dropdown-divider"></div> |
|||
<a class="dropdown-item" href="#">Something else here</a> |
|||
</div> |
|||
</li> |
|||
</ul> |
|||
<ul class="navbar-nav "> |
|||
<li class="nav-item"> |
|||
<a class="nav-link" href="#"> |
|||
<i class="fa fa-bell"> |
|||
<span class="badge badge-info">11</span> |
|||
</i> |
|||
Test |
|||
</a> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<a class="nav-link" href="#"> |
|||
<i class="fa fa-globe"> |
|||
<span class="badge badge-success">11</span> |
|||
</i> |
|||
Test |
|||
</a> |
|||
</li> |
|||
</ul> |
|||
<form class="form-inline my-2 my-lg-0"> |
|||
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search"> |
|||
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> |
|||
</form> |
|||
</div> |
|||
</nav> |
|||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> |
|||
<ul class="navbar-nav mr-auto"> |
|||
<li class="nav-item active"> |
|||
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<a class="nav-link" href="#">Link</a> |
|||
</li> |
|||
<li class="nav-item dropdown"> |
|||
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
|||
Dropdown |
|||
</a> |
|||
<div class="dropdown-menu" aria-labelledby="navbarDropdown"> |
|||
<a class="dropdown-item" href="#">Action</a> |
|||
<a class="dropdown-item" href="#">Another action</a> |
|||
<div class="dropdown-divider"></div> |
|||
<a class="dropdown-item" href="#">Something else here</a> |
|||
</div> |
|||
</li> |
|||
<li class="nav-item"> |
|||
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> |
|||
</li> |
|||
|
|||
<!-- Dropdown --> |
|||
<li class="nav-item dropdown" dropdown> |
|||
<a dropdownToggle mdbWavesEffect type="button" class="nav-link dropdown-toggle waves-light" mdbWavesEffect> |
|||
<!-- <mdb-icon fas icon="user"></mdb-icon> --> |
|||
Profile<span class="caret"></span></a> |
|||
<div *dropdownMenu class="dropdown-menu dropdown-menu-right dropdown dropdown-primary" role="menu"> |
|||
<a class="dropdown-item waves-light" mdbWavesEffect href="#">My account</a> |
|||
<a class="dropdown-item waves-light" mdbWavesEffect href="#">Log out</a> |
|||
</div> |
|||
</li> |
|||
</ul> |
|||
|
|||
</div> |
|||
</nav> |
|||
@ -0,0 +1,7 @@ |
|||
import { Cart } from './cart'; |
|||
|
|||
describe('Cart', () => { |
|||
it('should create an instance', () => { |
|||
expect(new Cart()).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,13 @@ |
|||
export class Cart { |
|||
|
|||
public productid : number; |
|||
public productname : string; |
|||
public productprice : number; |
|||
public productweight : number; |
|||
public productshortdesc : string; |
|||
public productlongdesc : string; |
|||
public productimage : string; |
|||
public productcategoryid : number; |
|||
|
|||
constructor() {} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
import { TestBed } from '@angular/core/testing'; |
|||
|
|||
import { CartService } from './cart.service'; |
|||
|
|||
describe('CartService', () => { |
|||
let service: CartService; |
|||
|
|||
beforeEach(() => { |
|||
TestBed.configureTestingModule({}); |
|||
service = TestBed.inject(CartService); |
|||
}); |
|||
|
|||
it('should be created', () => { |
|||
expect(service).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,78 @@ |
|||
import { HttpClient } from '@angular/common/http'; |
|||
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast'; |
|||
import { Injectable } from '@angular/core'; |
|||
import { BehaviorSubject, Observable } from 'rxjs'; |
|||
import { Cart } from '../models/cart'; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root' |
|||
}) |
|||
export class CartService { |
|||
|
|||
private _url : String = "http://localhost:9000"; |
|||
constructor(private _http : HttpClient) { } |
|||
|
|||
// public showAllOrder():Observable<Cart[]>
|
|||
// {
|
|||
// return this._http.get<Cart[]>(this._url+"/showCart");
|
|||
// }
|
|||
|
|||
public cartListItem: any=[] |
|||
public productList = new BehaviorSubject<any>([]) |
|||
// public addOrder(cart:Cart)
|
|||
// {
|
|||
// this._http.post(this._url+"/addCart",cart)
|
|||
// }
|
|||
|
|||
getProducts() |
|||
{ |
|||
return this.productList.asObservable(); |
|||
} |
|||
|
|||
setProduct(product:any) |
|||
{ |
|||
this.cartListItem.push(...product); |
|||
this.productList.next(product); |
|||
} |
|||
|
|||
addtoCart(product:any) |
|||
{ |
|||
this.cartListItem.push(product); |
|||
this.productList.next(this.cartListItem) |
|||
this.getTotalPrice(); |
|||
// console.log(this.cartListItem);
|
|||
} |
|||
|
|||
getTotalPrice():number{ |
|||
let grandTotal=0; |
|||
this.cartListItem.map((a:any)=>{ |
|||
grandTotal+=a.productprice; |
|||
}) |
|||
return grandTotal; |
|||
} |
|||
|
|||
removeCartItem(product:any) |
|||
{ |
|||
this.cartListItem.map((a:any,index:any)=>{ |
|||
if(product.productid === a.productid) |
|||
{ |
|||
this.cartListItem.splice(index,1); |
|||
} |
|||
}) |
|||
this.productList.next(this.cartListItem); |
|||
} |
|||
|
|||
removeAllCart() |
|||
{ |
|||
this.cartListItem=[] |
|||
this.productList.next(this.cartListItem); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue