Compare commits

...

8 Commits

20 changed files with 521 additions and 79 deletions
Split View
  1. 30
      Angular-UrbanBazaar/package-lock.json
  2. 12
      Angular-UrbanBazaar/src/app/app-routing.module.ts
  3. 2
      Angular-UrbanBazaar/src/app/app.component.html
  4. 4
      Angular-UrbanBazaar/src/app/app.module.ts
  5. 44
      Angular-UrbanBazaar/src/app/components/cart/cart.component.css
  6. 52
      Angular-UrbanBazaar/src/app/components/cart/cart.component.html
  7. 25
      Angular-UrbanBazaar/src/app/components/cart/cart.component.spec.ts
  8. 36
      Angular-UrbanBazaar/src/app/components/cart/cart.component.ts
  9. 45
      Angular-UrbanBazaar/src/app/components/home/home.component.css
  10. 21
      Angular-UrbanBazaar/src/app/components/home/home.component.html
  11. 25
      Angular-UrbanBazaar/src/app/components/home/home.component.spec.ts
  12. 50
      Angular-UrbanBazaar/src/app/components/home/home.component.ts
  13. 113
      Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html
  14. 17
      Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.ts
  15. 7
      Angular-UrbanBazaar/src/app/models/cart.spec.ts
  16. 13
      Angular-UrbanBazaar/src/app/models/cart.ts
  17. 16
      Angular-UrbanBazaar/src/app/services/cart.service.spec.ts
  18. 78
      Angular-UrbanBazaar/src/app/services/cart.service.ts
  19. 9
      Angular-UrbanBazaar/src/app/services/product.service.ts
  20. 1
      Angular-UrbanBazaar/src/index.html

30
Angular-UrbanBazaar/package-lock.json

@ -2579,6 +2579,16 @@
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
"dev": true
},
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dev": true,
"optional": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
@ -4694,6 +4704,13 @@
"escape-string-regexp": "^1.0.5"
}
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"dev": true,
"optional": true
},
"fill-range": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
@ -7001,6 +7018,13 @@
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==",
"dev": true
},
"nan": {
"version": "2.15.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz",
"integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==",
"dev": true,
"optional": true
},
"nanoid": {
"version": "3.1.25",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz",
@ -11594,7 +11618,11 @@
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz",
"integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==",
"dev": true,
"optional": true
"optional": true,
"requires": {
"bindings": "^1.5.0",
"nan": "^2.12.1"
}
},
"glob-parent": {
"version": "3.1.0",

12
Angular-UrbanBazaar/src/app/app-routing.module.ts

@ -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 { }

2
Angular-UrbanBazaar/src/app/app.component.html

@ -1,3 +1,3 @@
<app-page-nav-bar></app-page-nav-bar>
<!-- <app-home></app-home> -->
<router-outlet></router-outlet>

4
Angular-UrbanBazaar/src/app/app.module.ts

@ -9,6 +9,8 @@ import { UserShowComponent } from './components/user-show/user-show.component';
import { UserAddComponent } from './components/user-add/user-add.component';
import { UserProfileDetailsComponent } from './components/user-profile-details/user-profile-details.component';
import { PageNavBarComponent } from './components/page-nav-bar/page-nav-bar.component';
import { HomeComponent } from './components/home/home.component';
import { CartComponent } from './components/cart/cart.component';
@NgModule({
declarations: [
@ -17,6 +19,8 @@ import { PageNavBarComponent } from './components/page-nav-bar/page-nav-bar.comp
UserAddComponent,
UserProfileDetailsComponent,
PageNavBarComponent,
HomeComponent,
CartComponent,
],
imports: [
BrowserModule,

44
Angular-UrbanBazaar/src/app/components/cart/cart.component.css

@ -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;
} */

52
Angular-UrbanBazaar/src/app/components/cart/cart.component.html

@ -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>

25
Angular-UrbanBazaar/src/app/components/cart/cart.component.spec.ts

@ -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();
});
});

36
Angular-UrbanBazaar/src/app/components/cart/cart.component.ts

@ -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();
}
}

45
Angular-UrbanBazaar/src/app/components/home/home.component.css

@ -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;
}

21
Angular-UrbanBazaar/src/app/components/home/home.component.html

@ -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>

25
Angular-UrbanBazaar/src/app/components/home/home.component.spec.ts

@ -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();
});
});

50
Angular-UrbanBazaar/src/app/components/home/home.component.ts

@ -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;
})
}}

113
Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.html

@ -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>

17
Angular-UrbanBazaar/src/app/components/page-nav-bar/page-nav-bar.component.ts

@ -1,4 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { ProductService } from 'src/app/services/product.service';
import { Product } from 'src/app/models/product';
import { Router } from '@angular/router';
@Component({
selector: 'app-page-nav-bar',
@ -7,7 +11,18 @@ import { Component, OnInit } from '@angular/core';
})
export class PageNavBarComponent implements OnInit {
constructor() { }
searchValue: string = "";
products : Observable<Product[]>
constructor(private _productService : ProductService, private router: Router) { }
clickme() {
alert('searchValue: '+this.searchValue);
this.products = this._productService.searchProduct(this.searchValue);
this._productService.search = this.searchValue;
// this.router.navigate(["/search", {search: this.searchValue}]);
}
ngOnInit(): void {
}

7
Angular-UrbanBazaar/src/app/models/cart.spec.ts

@ -0,0 +1,7 @@
import { Cart } from './cart';
describe('Cart', () => {
it('should create an instance', () => {
expect(new Cart()).toBeTruthy();
});
});

13
Angular-UrbanBazaar/src/app/models/cart.ts

@ -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() {}
}

16
Angular-UrbanBazaar/src/app/services/cart.service.spec.ts

@ -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();
});
});

78
Angular-UrbanBazaar/src/app/services/cart.service.ts

@ -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);
}
}

9
Angular-UrbanBazaar/src/app/services/product.service.ts

@ -2,17 +2,22 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Product } from '../models/product';
import {map} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ProductService {
private _url : String = "http://localhost:9000";
search : string;
constructor(private _http : HttpClient) { }
public showAllProduct() : Observable<Product[]> {
return this._http.get<Product[]>(this._url+"/showAllProducts");
public showAllProduct(){
return this._http.get<any>(this._url+"/showAllProducts")
.pipe(map((res:any)=>{
return res;
}))
}
public searchProduct(name : string) : Observable<Product[]> {

1
Angular-UrbanBazaar/src/index.html

@ -7,6 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<app-root></app-root>

Loading…
Cancel
Save