From 82134784ac480e03eea654199e8cf17d0319f812 Mon Sep 17 00:00:00 2001 From: Adarsh K <adarsh@techware.in> Date: Fri, 22 Nov 2019 11:56:16 +0530 Subject: [PATCH] new changes --- package-lock.json | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- package.json | 3 ++- src/app/addaddresss/addaddresss.page.ts | 1 + src/app/cart/cart.page.html | 46 ++++++++++++++++++++++++++++++++++++++-------- src/app/cart/cart.page.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/app/home/home.module.ts | 1 + src/app/home/home.page.html | 57 ++++++++++++++++----------------------------------------- src/app/home/home.page.scss | 3 ++- src/app/home/home.page.ts | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- src/app/nearby/nearby.page.html | 46 ++++++++++++++++++++++++++++++++++++++-------- src/app/nearby/nearby.page.scss | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/app/nearby/nearby.page.ts | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ src/app/productdetail/productdetail.page.html | 27 ++++++++++++++++++++++----- src/app/productdetail/productdetail.page.scss | 23 +++++++++++++++++++++++ src/app/productdetail/productdetail.page.ts | 23 +++++++++++++++++++++++ src/app/productlist/productlist.page.html | 26 +++++++++++++------------- src/app/productlist/productlist.page.ts | 17 +++++++++++++++-- src/config/address.service.ts | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/config/cart.service.ts | 16 +++++++++++----- src/config/products.service.ts | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- src/config/search.service.ts | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/config/services/address.ts | 25 +++++++++++++++++++++++++ src/config/services/search.ts | 5 +++++ src/global.scss | 8 ++++++++ tsconfig.app.json | 4 +++- 25 files changed, 833 insertions(+), 152 deletions(-) create mode 100644 src/config/address.service.ts create mode 100644 src/config/search.service.ts create mode 100644 src/config/services/address.ts create mode 100644 src/config/services/search.ts diff --git a/package-lock.json b/package-lock.json index 552163e..16a8c8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -394,7 +394,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -603,12 +604,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -627,6 +630,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -806,7 +810,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -862,6 +867,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -905,12 +911,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -1691,6 +1699,11 @@ "@types/node": "*" } }, + "@types/googlemaps": { + "version": "3.38.0", + "resolved": "https://registry.npmjs.org/@types/googlemaps/-/googlemaps-3.38.0.tgz", + "integrity": "sha512-Rp7FnrwyYGnjoxM+/q/4DRqUzvV9JKK1SBRXx8APxU6NNMtYMsWmOMsQOV2U6z8aMFzlUbRv3EDixLcDep8t9w==" + }, "@types/jasmine": { "version": "3.3.16", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.3.16.tgz", @@ -6801,7 +6814,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -6844,7 +6858,8 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", @@ -6855,7 +6870,8 @@ "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -6972,7 +6988,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -6984,6 +7001,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7013,6 +7031,7 @@ "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -7031,6 +7050,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -7111,7 +7131,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -7123,6 +7144,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -7208,7 +7230,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -7244,6 +7267,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -7263,6 +7287,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -7306,12 +7331,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -12465,7 +12492,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -12493,6 +12521,7 @@ "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -12507,7 +12536,8 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", @@ -12518,7 +12548,8 @@ "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -12635,7 +12666,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -12647,6 +12679,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -12661,6 +12694,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -12668,12 +12702,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -12692,6 +12728,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -12772,7 +12809,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -12784,6 +12822,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -12869,7 +12908,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -12905,6 +12945,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -12924,6 +12965,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -12967,12 +13009,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index 05287af..1b78188 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "@ionic-native/status-bar": "^5.12.0", "@ionic/angular": "^4.7.1", "@ionic/storage": "^2.2.0", + "@types/googlemaps": "^3.38.0", "agm-direction": "^0.7.8", "cordova-android": "^8.0.0", "cordova-plugin-device": "^2.0.2", @@ -100,4 +101,4 @@ "android" ] } -} +} \ No newline at end of file diff --git a/src/app/addaddresss/addaddresss.page.ts b/src/app/addaddresss/addaddresss.page.ts index 31d64e4..a4ed196 100644 --- a/src/app/addaddresss/addaddresss.page.ts +++ b/src/app/addaddresss/addaddresss.page.ts @@ -49,6 +49,7 @@ export class AddaddresssPage implements OnInit { ) { } ngOnInit() { + } goToPage(path, data = null) { diff --git a/src/app/cart/cart.page.html b/src/app/cart/cart.page.html index ee9d73e..4cbfcb6 100644 --- a/src/app/cart/cart.page.html +++ b/src/app/cart/cart.page.html @@ -65,14 +65,14 @@ <span class="floatLeft">ITEMS</span> <span class="floatRight" *ngIf="cartService.cartTotal">A$ {{cartService.cartTotal}}</span> <div class="clear"></div> - </h5> + </h5> <ion-grid class="p0" *ngIf="cartService.carts && cartService.carts.length > 0"> <ion-row *ngFor="let carts of cartService.carts"> <ion-col size="6" class="p0"> <h6 class="textLeft">{{carts.prodName}}</h6> </ion-col> <ion-col size="2" class="p0"> - <h6 class="textRight"><strong>1 X</strong></h6> + <h6 class="textRight"><strong>{{carts.qty}} X</strong></h6> </ion-col> <ion-col size="4" class="p0"> <h6 class="textRight"><strong>A$ {{carts.price}}</strong></h6> @@ -89,7 +89,7 @@ <ion-row> <ion-col class="p0"> <h6> - Shamjith KS<br> +00 0000 888 888<br> Carnival InfoparkInfopark Kochi<br> 682030, Kerala, India + {{custAddress.building}},<br/> {{custAddress.landmark}},<br/> {{custAddress.address}} </h6> </ion-col> </ion-row> @@ -101,7 +101,13 @@ <div class="clear"></div> </h5> <div class="payment_method"> - <input type="radio" id="test1" name="radio-group" checked (click)="getwaypaypal()"> + <input type="radio" name="payments" id="cod" name="radio-group" checked="true"> + <label for="paypal"> + <p>COD</p> + </label> + </div> + <!-- <div class="payment_method"> + <input type="radio" name="payments" id="paypal" name="radio-group" checked (click)="getwaypaypal()"> <label for="test1"> <p>PayPal</p> </label> @@ -110,7 +116,7 @@ <input class="card_no borderNone widthFull" placeholder="PayPal ID"> </div> <div class="payment_method"> - <input type="radio" id="test2" name="radio-group" (click)="getwayafterpay()"> + <input type="radio" name="payments" id="afterpay" name="radio-group" (click)="getwayafterpay()"> <label for="test2"> <p>AfterPay</p> </label> @@ -120,14 +126,14 @@ <input class="cv_number" placeholder="CVV"> </div> <div class="payment_method"> - <input type="radio" id="test3" name="radio-group" (click)="getwaypayk()"> + <input type="radio" name="payments" id="payk" name="radio-group" (click)="getwaypayk()"> <label for="test3"> <p>PayK</p> </label> </div> <div class="card_div" [hidden]="gateway !=3"> <input class="card_no borderNone widthFull" placeholder="PafyK ID"> - </div> + </div> --> <div class="delivery_time"> <ul> <li> @@ -144,13 +150,37 @@ <div class="coupon_code"> <input class="" placeholder="COUPON CODE"><button class="add_btn">ADD</button> </div> + <br/> + + <h6> + <span class="floatLeft">PRODUCT COST</span> + <span class="floatRight" *ngIf="cartService.cartTotal">A$ {{cartService.cartTotal}}</span> + <div class="clear"></div> + </h6> + + <h6> + <span class="floatLeft">DELIVERY CHARGE</span> + <span class="floatRight" *ngIf="cartService.cartTotal">A$ {{getDeliveryCharge(cartService.cartTotal)}}</span> + <div class="clear"></div> + </h6> + <h6> + <span class="floatLeft">GST/TAX</span> + <span class="floatRight" *ngIf="cartService.cartTotal">A$ {{getTax(cartService.cartTotal)}}</span> + <div class="clear"></div> + </h6> + <h6 *ngIf="discountApplied"> + <span class="floatLeft">DISCOUNT</span> + <span class="floatRight">(-) A$ {{discount}}</span> + <div class="clear"></div> + </h6> + <hr> <div class="total_div"> <ion-row> <ion-col> <p class="textLeft">Total Price:</p> </ion-col> <ion-col> - <p class="textRight" *ngIf="cartService.cartTotal">A$ {{cartService.cartTotal}}</p> + <p class="textRight" *ngIf="cartService.cartTotal">A$ {{getTotal(cartService.cartTotal)}}</p> </ion-col> </ion-row> </div> diff --git a/src/app/cart/cart.page.ts b/src/app/cart/cart.page.ts index 052a982..1ce148c 100644 --- a/src/app/cart/cart.page.ts +++ b/src/app/cart/cart.page.ts @@ -6,6 +6,10 @@ import { CartsService } from './../../config/cart.service'; import { OrdersService } from './../../config/order.service'; import { ModalController } from '@ionic/angular'; import { DeliverypopPage } from '../deliverypop/deliverypop.page'; +import { ServiceService } from './../../config/service.service'; +import { AddressService } from './../../config/address.service'; +import { AddressList } from './../../config/services/address' +import { zip } from 'rxjs'; @Component({ @@ -20,11 +24,18 @@ export class CartPage implements OnInit { count: any; gateway: any; loader = false; + custId: any; + custAddress: AddressList; cartwizard = { initialSlide: 0, speed: 1000, allowTouchMove: false }; + deliveryCharge: number; + taxAmount: number; + discountApplied: boolean; + discount: number; + totalAmt: number; constructor( private router: Router, @@ -32,16 +43,36 @@ export class CartPage implements OnInit { private location: Location, public cartService: CartsService, public orderService: OrdersService, - public modalController: ModalController + public modalController: ModalController, + public service: ServiceService, + public addressService: AddressService ) { this.currentIndex = 0; this.count = 1; this.gateway = 1; + this.deliveryCharge = 0; + this.taxAmount = 0; + this.discountApplied = false; + this.discount = 0; this.cartService.cartList(); + const users = this.service.get('user').then((data) => { + if (data) { + data = JSON.parse(data); + this.custId = data.uid; + this.addressService.addList(data.uid); + } + }); + } ngOnInit() { + let address = this.addressService.addressList.find(x => x.defaultVal === 1); + if (!address) { + address = this.addressService.addressList[0]; + } + this.custAddress = address; + console.log(address); } getwaypaypal() { @@ -52,6 +83,19 @@ export class CartPage implements OnInit { this.gateway = 2; } + getDeliveryCharge(amount) { + if (amount >= 150) { + this.deliveryCharge = 0; + } else { + this.deliveryCharge = 10; + } + return this.deliveryCharge; + } + + getTax(amount) { + return this.taxAmount = (amount * 10) / 100; + } + getwaypayk() { this.gateway = 3; } @@ -125,4 +169,10 @@ export class CartPage implements OnInit { }); } + getTotal(total) { + const actualTotal = (this.deliveryCharge + this.taxAmount + total) - this.discount; + this.totalAmt = actualTotal; + return actualTotal; + } + } diff --git a/src/app/home/home.module.ts b/src/app/home/home.module.ts index d858c60..da200ba 100644 --- a/src/app/home/home.module.ts +++ b/src/app/home/home.module.ts @@ -9,6 +9,7 @@ import { HomePage } from './home.page'; import { AgmCoreModule } from '@agm/core'; import { AgmDirectionModule } from 'agm-direction'; + import { from } from 'rxjs'; diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html index 81d8c46..9c85bb9 100644 --- a/src/app/home/home.page.html +++ b/src/app/home/home.page.html @@ -5,11 +5,13 @@ </ion-menu-toggle> <div class="nav_title floatLeft relative"> - <input class="search_bar" placeholder="Search here.. eg:shirts, retailers etc..." (click)="clickSearch()"> + <input class="search_bar" placeholder="Search here.. eg:shirts, retailers etc..." (click)="clickSearch()" (input)="searchFun($event.target.value)" #searchText> </div> - <button class="nav_btn nav_search floatRight"> + <button class="nav_btn nav_search floatRight" *ngIf="!searchShow"> </button> + <button class="nav_btn nav_exit floatRight" *ngIf="searchShow" (click)="searchClose()"> + </button> <div class="clear"></div> </div> <ion-content> @@ -21,7 +23,7 @@ <img src="../assets/Group 11_2.png"> </ion-col> <ion-col class="textRight"> - <p class="floatRight" (click)="istoggle()">Territory Queens</p> + <p class="floatRight" (click)="istoggle()">{{address}}</p> </ion-col> </ion-row> </div> @@ -116,49 +118,25 @@ </div> <ion-content class="sort_wrappper"> <agm-map [zoom]="20" [latitude]="lat" [longitude]="lng" [disableDefaultUI]="false" [zoomControl]="false" [backgroundColor]="'rgba(29, 27, 130,0.2)'"> + <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker> </agm-map> <div class="add_address_wrapper"> <h5> <span class="floatLeft">NEW ADDRESS</span> - <span class="floatRight">ADD NEW</span> + <span class="floatRight" (click)="istoggle(); goToPage('nearby')">ADD NEW</span> <div class="clear"></div> </h5> - <ul> - <li> - <div class="floatLeft"> - <input class="styled-checkbox " id="styled-checkbox-1" type="radio" value="value1"> - <label for="styled-checkbox-1"> + <ul *ngIf="addressService.addressList && addressService.addressList.length > 0"> + <li *ngFor="let address of addressService.addressList; let i = index"> + <div class="floatLeft">{{address.default}} + <input class="styled-checkbox" name="addressId" id="styled-checkbox-{{i}}" type="radio" (click)="setDefault(address.addressId)" [value]="address.addressId" #addressType [checked]="address.defaultVal == 1"> + <label for="styled-checkbox-{{i}}"> {{address.addressType}} </label> + </div> <div class="floatLeft"> <p> - Shamjith KS<br> Carnival Infopark, Infopark Kochi <br> 682030, Kerala, India - </p> - </div> - <div class="clear"></div> - </li> - <li> - <div class="floatLeft"> - <input class="styled-checkbox " id="styled-checkbox-2" type="radio" value="value2"> - <label for="styled-checkbox-2"> - </label> - </div> - <div class="floatLeft"> - <p> - Shamjith KS<br> Carnival Infopark, Infopark Kochi <br> 682030, Kerala, India - </p> - </div> - <div class="clear"></div> - </li> - <li> - <div class="floatLeft"> - <input class="styled-checkbox " id="styled-checkbox-3" type="radio" value="value3"> - <label for="styled-checkbox-3"> - </label> - </div> - <div class="floatLeft"> - <p> - Shamjith KS<br> Carnival Infopark, Infopark Kochi <br> 682030, Kerala, India + {{address.building}}, {{address.landmark}}, {{address.address}} </p> </div> <div class="clear"></div> @@ -172,10 +150,7 @@ <div class="search_item_list" *ngIf="searchShow" [@slideInOut]> - <ul (click)="clickSearch()"> - <li>Listing 1</li> - <li>Listing 2</li> - <li>Listing 3</li> - <li>Listing 4</li> + <ul *ngIf="searchService.searchList"> + <li *ngFor="let search of searchService.searchList" (click)="viewPage(search)">{{search.text}}</li> </ul> </div> \ No newline at end of file diff --git a/src/app/home/home.page.scss b/src/app/home/home.page.scss index 8fe855e..935ffe7 100644 --- a/src/app/home/home.page.scss +++ b/src/app/home/home.page.scss @@ -267,7 +267,8 @@ margin: 0px; padding: 0px; color: rgba(176, 174, 199, 1); - padding-left: 5px; + padding-top:5px; + padding-bottom: 5px; } .styled-checkbox { position: absolute; // take it out of document flow diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index c6cc658..f8e8b95 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -1,37 +1,45 @@ import { Component, OnInit } from '@angular/core'; import { Location } from '@angular/common'; import { trigger, transition, animate, style } from '@angular/animations'; +import { MapsAPILoader, MouseEvent } from '@agm/core'; import { Router, ActivatedRoute } from '@angular/router'; import { MenuController } from '@ionic/angular'; import { CenterService } from './../../config/center.service'; import { ShoppersService } from './../../config/shopper.service'; import { CategoriesService } from './../../config/category.service'; import { ServiceService } from './../../config/service.service'; +import { AddressService } from './../../config/address.service'; +import { SearchService } from './../../config/search.service'; +import { ProductsService } from './../../config/products.service'; import { from } from 'rxjs'; -import { ModalController } from "@ionic/angular"; +import { ModalController } from '@ionic/angular'; + @Component({ - selector: "app-home", - templateUrl: "./home.page.html", - styleUrls: ["./home.page.scss"], + selector: 'app-home', + templateUrl: './home.page.html', + styleUrls: ['./home.page.scss'], animations: [ - trigger("slideInOut", [ - transition(":enter", [ - style({ transform: "translateY(100%)" }), - animate("200ms ease-in", style({ transform: "translateY(0%)" })) + trigger('slideInOut', [ + transition(':enter', [ + style({ transform: 'translateY(100%)' }), + animate('200ms ease-in', style({ transform: 'translateY(0%)' })) ]), - transition(":leave", [ - animate("200ms ease-out", style({ transform: "translateY(100%)" })) + transition(':leave', [ + animate('200ms ease-out', style({ transform: 'translateY(100%)' })) ]) ]) ] }) + export class HomePage implements OnInit { isShow = false; searchShow = false; public lat = 51.678418; public lng = 7.809007; - + address: any; + custId: any; + private geoCoder; slideOpts = { slidesPerView: 1.5 }; @@ -44,25 +52,83 @@ export class HomePage implements OnInit { public centerService: CenterService, public shopperService: ShoppersService, public categoriesService: CategoriesService, + public addressService: AddressService, public service: ServiceService, - public modalController: ModalController - ) {} + public modalController: ModalController, + private mapsAPILoader: MapsAPILoader, + private searchService: SearchService, + private productsService: ProductsService + ) { + } ngOnInit() { + this.mapsAPILoader.load().then(() => { + this.setCurrentLocation(); + this.geoCoder = new google.maps.Geocoder(); + }); this.menuCtrl.enable(true); + const users = this.service.get('user').then((data) => { + if (data) { + data = JSON.parse(data); + this.custId = data.uid; + this.addressService.addList(data.uid); + } + }); + } + + private setCurrentLocation() { + if ('geolocation' in navigator) { + navigator.geolocation.getCurrentPosition(position => { + this.lat = position.coords.latitude; + this.lng = position.coords.longitude; + this.getAddress(this.lat, this.lng); + }); + } + } + + getAddress(latitude, longitude) { + this.geoCoder.geocode( + { location: { lat: latitude, lng: longitude } }, + (results, status) => { + console.log(results); + console.log(status); + if (status === 'OK') { + if (results[0]) { + const addressData = results[0].formatted_address.split(', '); + this.address = addressData[0] + ', ' + addressData[1]; + console.log(this.address); + } else { + window.alert('No results found'); + } + } else { + window.alert('Geocoder failed due to: ' + status); + } + } + ); + } + + setDefault(addressId: any) { + this.addressService.setDefaultAddress(addressId, this.custId); } clickSearch() { - this.searchShow = !this.searchShow; + this.searchShow = true; + this.searchService.searchList = []; } + searchClose() { + this.searchShow = false; + } + + + ionViewWillEnter() { this.menuCtrl.enable(true); } goToPage(path, data = null) { console.log(data); - this.service.set("params", data); + this.service.set('params', data); this.router.navigateByUrl(path, { queryParams: data }); document.body.scrollTop = document.documentElement.scrollTop = 0; } @@ -74,5 +140,34 @@ export class HomePage implements OnInit { istoggle() { this.isShow = !this.isShow; } + + viewPage(datas: any) { + console.log(datas); + let data; + let url; + if (datas.type === 'shopper') { + data = datas.data; + this.service.set('params', data); + url = 'productlist'; + } else if (datas.type === 'category') { + data = datas.data; + this.service.set('params', data); + url = 'catstorelist'; + } else { + data = datas.data; + data.size = this.service.splitSep(data.size); + data.tag = this.service.splitSep(data.tag); + data.color = this.service.splitSep(data.color), + url = 'productdetail'; + this.productsService.setProd(data); + } + this.searchClose(); + this.router.navigateByUrl(url, { queryParams: data}); + document.body.scrollTop = document.documentElement.scrollTop = 0; + } + + searchFun(data: string) { + this.searchService.search(data); + } } diff --git a/src/app/nearby/nearby.page.html b/src/app/nearby/nearby.page.html index c59363c..92df0d0 100644 --- a/src/app/nearby/nearby.page.html +++ b/src/app/nearby/nearby.page.html @@ -10,15 +10,45 @@ <ion-content> <div class="nearby_map"> - <agm-map [latitude]="lat" [longitude]="lng" [zoom]="15" [backgroundColor]="'rgba(29, 27, 130,0.2)'"> + <agm-map [latitude]="latitude" [longitude]="longitude" [zoom]="8" [backgroundColor]="'rgba(29, 27, 130,0.2)'"> <agm-marker [latitude]="latitude" [longitude]="longitude" [markerDraggable]="true" (dragEnd)="markerDragEnd($event)"></agm-marker> </agm-map> - <div class="add_address_wrapper"> - <h5>DELIVERY</h5> - <p>{{address}}</p> - <input class="" placeholder="House No./ Building No"> - <input class="" placeholder="Landmark"> - <button class="add_btn">ADD</button> - </div> + <form (ngSubmit)="onSubmit(addressForm.value); addressForm.reset()" #addressForm="ngForm" method="post" class="form-horizontal"> + <div class="add_address_wrapper"> + <h5>DELIVERY</h5> + <p>{{address}}</p> + <input [(ngModel)]="addressForm.building" name="building" #building="ngModel" name="building" required placeholder="House No./ Building No"> + <div class="md-errors-spacer" [hidden]="building.valid || landmark.pristine" class="ion-padding-start"> + Building Name is required + </div> + <input [(ngModel)]="addressForm.landmark" name="landmark" #landmark="ngModel" name="landmark" required placeholder="Landmark"> + <div class="md-errors-spacer" [hidden]="landmark.valid || landmark.pristine" class="ion-padding-start"> + Landmark is required + </div> + <ion-grid> + <ion-row> + <ion-col> + <h6> + <input class="styled-checkbox" id="styled-check-1" type="radio" value="Home" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required> + <label for="styled-check-1"><span>Home</span></label></h6> + </ion-col> + <ion-col> + <h6> + <input class="styled-checkbox" id="styled-check-2" type="radio" value="Work" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required> + <label for="styled-check-2"><span>Office</span></label></h6> + </ion-col> + <ion-col> + <h6> + <input class="styled-checkbox" id="styled-check-3" type="radio" value="Other" [(ngModel)]="addressForm.addressType" name="addressType" #addressType="ngModel" required> + <label for="styled-check-3"><span>Others</span></label></h6> + </ion-col> + </ion-row> + <div class="md-errors-spacer" [hidden]="addressType.valid || addressType.pristine" class="ion-padding-start"> + Address Type is required + </div> + </ion-grid> + <button class="add_btn" type="submit" [disabled]="!addressForm.form.valid">ADD</button> + </div> + </form> </div> </ion-content> \ No newline at end of file diff --git a/src/app/nearby/nearby.page.scss b/src/app/nearby/nearby.page.scss index 7091695..1912554 100644 --- a/src/app/nearby/nearby.page.scss +++ b/src/app/nearby/nearby.page.scss @@ -63,4 +63,54 @@ color: #fff; border-radius: 4px; } + +} + +.styled-checkbox { + position: absolute; // take it out of document flow + opacity: 0; // hide it + &+label { + position: relative; + cursor: pointer; + padding: 0; + } + // Box. + &+label:before { + content: ''; + margin-right: 10px; + display: inline-block; + vertical-align: text-top; + width: 20px; + height: 20px; + border-radius: 10px; + background: white; + border: 1px solid rgba(215, 213, 228, 1); + } + // Box hover + // Box checked + &:checked+label:before { + background: #29285b; + } + // Disabled state label. + &:disabled+label { + color: #b8b8b8; + cursor: auto; + } + // Disabled box. + &:disabled+label:before { + box-shadow: none; + background: #ddd; + } + // Checkmark. Could be replaced with an image + &:checked+label:after { + content: ''; + position: absolute; + left: 6px; + top: 11px; + background: white; + width: 2px; + height: 2px; + box-shadow: 2px 0 0 white, 4px 0 0 white, 4px -2px 0 white, 4px -4px 0 white, 4px -6px 0 white, 4px -8px 0 white; + transform: rotate(45deg); + } } \ No newline at end of file diff --git a/src/app/nearby/nearby.page.ts b/src/app/nearby/nearby.page.ts index 1f38a43..711bd9c 100644 --- a/src/app/nearby/nearby.page.ts +++ b/src/app/nearby/nearby.page.ts @@ -1,20 +1,29 @@ -import {Component,OnInit,ViewChild,ElementRef,NgZone} from "@angular/core"; +import {Component, OnInit, ViewChild, ElementRef, NgZone} from '@angular/core'; import { Location } from '@angular/common'; import { Router, ActivatedRoute } from '@angular/router'; -import { MapsAPILoader, MouseEvent } from "@agm/core"; +import { MapsAPILoader, MouseEvent } from '@agm/core'; +import { Address } from './../../config/services/address'; +import { AddressService } from './../../config/address.service'; +import { ServiceService } from './../../config/service.service'; +import { NgForm } from '@angular/forms'; +import * as firebase from 'firebase'; @Component({ - selector: "app-nearby", - templateUrl: "./nearby.page.html", - styleUrls: ["./nearby.page.scss"] + selector: 'app-nearby', + templateUrl: './nearby.page.html', + styleUrls: ['./nearby.page.scss'] }) + export class NearbyPage implements OnInit { latitude: number; longitude: number; zoom: number; address: string; private geoCoder; - + addressForm: NgForm; + addressData = new Address('', '', '', '', true, '', 0, ''); + successState: boolean; + uid: string; public searchElementRef: ElementRef; constructor( @@ -22,11 +31,21 @@ export class NearbyPage implements OnInit { private route: ActivatedRoute, private location: Location, private mapsAPILoader: MapsAPILoader, - private ngZone: NgZone - ) {} + private ngZone: NgZone, + public addressService: AddressService, + public service: ServiceService + ) { + this.successState = false; + const users = this.service.get('user').then((data) => { + if (data) { + data = JSON.parse(data); + this.uid = data.uid; + } + }); + } ngOnInit() { - //load Places Autocomplete + // load Places Autocomplete this.mapsAPILoader.load().then(() => { this.setCurrentLocation(); this.geoCoder = new google.maps.Geocoder(); @@ -35,7 +54,7 @@ export class NearbyPage implements OnInit { // google maps zoom level private setCurrentLocation() { - if ("geolocation" in navigator) { + if ('geolocation' in navigator) { navigator.geolocation.getCurrentPosition(position => { this.latitude = position.coords.latitude; this.longitude = position.coords.longitude; @@ -58,15 +77,16 @@ export class NearbyPage implements OnInit { (results, status) => { console.log(results); console.log(status); - if (status === "OK") { + if (status === 'OK') { if (results[0]) { this.zoom = 12; this.address = results[0].formatted_address; + console.log(this.address); } else { - window.alert("No results found"); + window.alert('No results found'); } } else { - window.alert("Geocoder failed due to: " + status); + window.alert('Geocoder failed due to: ' + status); } } ); @@ -80,11 +100,30 @@ export class NearbyPage implements OnInit { goBack() { window.history.back(); } + + onSubmit(data: any) { + console.log(data); + const postData: Address = { + address: this.address, + addressType: data.addressType, + building: data.building, + landmark: data.landmark, + defaultVal: 0, + uid: this.uid, + latLng: new firebase.firestore.GeoPoint(this.latitude, this.longitude), + status: true + }; + this.addressService.addressCreate(postData); + this.successState = true; + setTimeout(() => { + this.successState = false; + }, 3000); + } } - interface marker { - lat: number; - lng: number; - label?: string; - draggable: boolean; +interface Marker { + lat: number; + lng: number; + label?: string; + draggable: boolean; } diff --git a/src/app/productdetail/productdetail.page.html b/src/app/productdetail/productdetail.page.html index 0c898f5..6cda855 100644 --- a/src/app/productdetail/productdetail.page.html +++ b/src/app/productdetail/productdetail.page.html @@ -5,14 +5,14 @@ <div class="nav_title floatLeft"> </div> <button class="nav_btn nav_cart floatRight" (click)="goToPage('cart')"> - <div class="not">1</div> + <div class="not" *ngIf="cartService.carts">{{cartService.carts.length}}</div> </button> <div class="clear"></div> </div> <ion-content> <div class="product_detail_wrapper" *ngIf="product"> <div class="product_banner"> - <div class="fav_icon"></div> + <div [ngClass]="checkFavStatus(product.prodId)" (click)="changeFav(product.prodId)"></div> <div class="featured_badge" *ngIf="product.featured">Featured</div> <img [src]="product.image" onerror="this.src='../assets/model1@3x.jpg'"> </div> @@ -22,7 +22,7 @@ <h3>{{product.prodName}}</h3> <p><strong><span><img src="../assets/Path61_2.png"></span>0</strong> {{product.category}}, {{product.subCate}} <br/> - <span *ngFor="let tag of product.tag">#{{tag}}</span> + <span *ngFor="let tag of product.tag">#{{tag}} </span> </p> </ion-col> <ion-col size="4"> @@ -31,7 +31,25 @@ </ion-col> </ion-row> </div> + <div class="product_div_content"> + <h5>Color</h5> + <div class="size_div"> + <ul *ngIf="product.size"> + <ion-slides pager="false" [options]="slideOpts"> + <ion-slide *ngFor="let color of product.color; let i = index"> + <li> + <button id="custom_check_button"> + <label> + <input id="{{color}}" type="radio" name="color" value="{{color}}" (click)="cartService.choose_color(color)" [checked]="i==0"> + <p>{{color}}</p> + </label> + </button> + </li> + </ion-slide> + </ion-slides> + </ul> + </div> <h5>Size</h5> <div class="size_div"> <ul *ngIf="product.size"> @@ -127,8 +145,7 @@ <li (click)="viewProd(similar)"> <div class="product_image"> <img [src]="similar.image" onerror="this.src='../assets/model1@3x.png'"> - <div class="fav_icon"> - </div> + <div [ngClass]="checkFavStatus(similar.prodId)" (click)="changeFav(similar.prodId)"></div> </div> <h5>{{similar.prodName}}</h5> <p>{{similar.price}}</p> diff --git a/src/app/productdetail/productdetail.page.scss b/src/app/productdetail/productdetail.page.scss index f94449b..a39d61b 100644 --- a/src/app/productdetail/productdetail.page.scss +++ b/src/app/productdetail/productdetail.page.scss @@ -14,6 +14,17 @@ top: 15px; right: 15px; } + .fav_fill { + width: 30px; + height: 30px; + background-image: url("../../assets/fav_fill.png"); + background-position: center; + background-repeat: no-repeat; + background-size: 24px; + position: absolute; + top: 15px; + right: 15px; + } .featured_badge { position: absolute; bottom: 20px; @@ -233,6 +244,18 @@ background-repeat: no-repeat; background-size: 24px; } + .fav_fill { + position: absolute; + top: 10px; + right: 10px; + font-size: 27px; + width: 30px; + height: 30px; + background-image: url("../../assets/fav_fill.png"); + background-position: center; + background-repeat: no-repeat; + background-size: 24px; + } img { width: 100%; height: 100%; diff --git a/src/app/productdetail/productdetail.page.ts b/src/app/productdetail/productdetail.page.ts index a1df638..2c6c815 100644 --- a/src/app/productdetail/productdetail.page.ts +++ b/src/app/productdetail/productdetail.page.ts @@ -39,6 +39,8 @@ export class ProductdetailPage implements OnInit { this.service.get('params').then((val) => { this.data = val; }); + this.cartService.cartList(); + console.log(this.prodService.fav); } ngOnInit() { @@ -103,6 +105,7 @@ export class ProductdetailPage implements OnInit { } else { // alert('Product added to cart'); } + this.cartService.cartList(); }); } @@ -110,4 +113,24 @@ export class ProductdetailPage implements OnInit { this.getProd(prod); } + checkFavStatus(index) { + const state = this.prodService.fav.findIndex(x => x === index); + return state > -1 ? 'fav_fill' : 'fav_icon'; + } + + changeFav(index) { + const state = this.prodService.fav.findIndex(x => x === index); + console.log(state); + console.log(this.prodService.fav); + if (state > -1) { + this.prodService.fav.splice(state, 1); + this.prodService.changeFav(index, 'yes'); + } else { + this.prodService.fav.push(index); + this.prodService.changeFav(index, 'no'); + } + return; + console.log(this.prodService.fav); + } + } diff --git a/src/app/productlist/productlist.page.html b/src/app/productlist/productlist.page.html index 940a9e0..1f0f961 100644 --- a/src/app/productlist/productlist.page.html +++ b/src/app/productlist/productlist.page.html @@ -30,7 +30,7 @@ <li *ngFor="let product of prodService.product; let i = index"> <div class="product_image"> <img [src]="product.image" onerror="this.src='../assets/model1@3x.png'" (click)="prodDetails(i)"> - <div class="fav_fill" (click)="changeFav(product.prodId)" *ngIf="checkFavStatus(product.prodId)"> + <div [ngClass]="checkFavStatus(product.prodId)" (click)="changeFav(product.prodId)"> </div> <div class="featured_badge" *ngIf="product.featured">Featured</div> </div> @@ -43,30 +43,30 @@ <div class="sort_inner"> <h4>Sort By</h4> <ul> - <li> - <input class="styled-checkbox" id="styled-checkbox-1" type="radio" value="value1"> + <!-- <li> + <input class="styled-checkbox" id="styled-checkbox-1" type="radio" value="popular" name="sort" (click)="setValue($event.target.value)"> <label for="styled-checkbox-1">Popularity</label> - </li> - <li> - <input class="styled-checkbox" id="styled-checkbox-2" type="radio" value="value2"> + </li> --> + <!-- <li> + <input class="styled-checkbox" id="styled-checkbox-2" type="radio" value="relevance" name="sort" (click)="setValue($event.target.value)"> <label for="styled-checkbox-2">Relevence</label> - </li> + </li> --> <li> - <input class="styled-checkbox" id="styled-checkbox-3" type="radio" value="value3"> + <input class="styled-checkbox" id="styled-checkbox-3" type="radio" value="low" name="sort" (click)="setValue($event.target.value)"> <label for="styled-checkbox-3">Price Low - High</label> </li> <li> - <input class="styled-checkbox" id="styled-checkbox-4" type="radio" value="value4"> + <input class="styled-checkbox" id="styled-checkbox-4" type="radio" value="high" name="sort" (click)="setValue($event.target.value)"> <label for="styled-checkbox-4">Price High - Low</label> </li> - <li> - <input class="styled-checkbox" id="styled-checkbox-5" type="radio" value="value5"> + <!-- <li> + <input class="styled-checkbox" id="styled-checkbox-5" type="radio" value="rate" name="sort" (click)="setValue($event.target.value)"> <label for="styled-checkbox-5">Rating</label> - </li> + </li> --> </ul> <div class="sort_footer"> <button class="cancel floatLeft" (click)="istoggle()">CANCEL</button> - <button class="submit floatRight" (click)="istoggle()">SUBMIT</button> + <button class="submit floatRight" (click)="istoggle(); submit()">SUBMIT</button> <div class="clear"></div> </div> </div> diff --git a/src/app/productlist/productlist.page.ts b/src/app/productlist/productlist.page.ts index 568bdd4..060054e 100644 --- a/src/app/productlist/productlist.page.ts +++ b/src/app/productlist/productlist.page.ts @@ -26,6 +26,7 @@ export class ProductlistPage implements OnInit { onGrid = false; isShow = false; data: any; + sortValue: string; constructor( private router: Router, @@ -69,6 +70,8 @@ export class ProductlistPage implements OnInit { changeFav(index) { const state = this.prodService.fav.findIndex(x => x === index); + console.log(state); + console.log(this.prodService.fav); if (state > -1) { this.prodService.fav.splice(state, 1); this.prodService.changeFav(index, 'yes'); @@ -76,12 +79,22 @@ export class ProductlistPage implements OnInit { this.prodService.fav.push(index); this.prodService.changeFav(index, 'no'); } + return; console.log(this.prodService.fav); } + setValue(value) { + this.sortValue = value; + console.log(this.sortValue); + } + + submit() { + console.log(this.sortValue); + this.prodService.filterSearch(this.sortValue); + } + checkFavStatus(index) { const state = this.prodService.fav.findIndex(x => x === index); - console.log(state); - return state > -1 ? true : true; + return state > -1 ? 'fav_fill' : 'fav_icon'; } } diff --git a/src/config/address.service.ts b/src/config/address.service.ts new file mode 100644 index 0000000..07af94c --- /dev/null +++ b/src/config/address.service.ts @@ -0,0 +1,67 @@ +import { Injectable } from '@angular/core'; +import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore'; +import { AddressList, Address } from './services/address'; +import { database } from 'firebase'; +import { take } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class AddressService { + addressList: AddressList[] = []; + constructor( + public afs: AngularFirestore + ) { + } + + public async addList(userId: string) { + const This = this; + const state = true; + const orderRef: AngularFirestoreCollection<any> = this.afs.collection('address', ref => ref.where('status', '==', state) + .where('uid', '==', userId)); + orderRef.valueChanges().pipe( + take(1) // Here you can limit to only emit once, using the take operator + ).subscribe((value) => { + this.addressList = []; + const res = value; + if (res.length > 0) { + res.forEach((item) => { + console.log(item); + const address: AddressList = { + address: item.address, + addressType: item.addressType, + latLng: item.latLng, + defaultVal: item.defaultVal, + building: item. building, + landmark: item.landmark, + addressId: item.addressId + }; + this.addressList.push(address); + }); + console.log(this.addressList); + } else { + // alert('No Orders Found'); + } + }); + } + + addressCreate(data: Address) { + this.afs.collection('address').add({}).then((docRef) => { + data.addressId = docRef.id; + this.afs.collection('address').doc(data.addressId).set(data).then(() => { + console.log('Address created Successfully'); + }); + }); + } + + setDefaultAddress(addId: string, userId: string) { + this.afs.collection('address', ref => ref.where('uid', '==', userId)).get().forEach((item) => { + return item.docs.map(m => { + return this.afs.doc(`address/${m.id}`).update({defaultVal: 0}); + }); + }); + this.afs.collection('address').doc(addId).update({defaultVal: 1}).then(() => { + console.log('Address updated Successfully'); + }); + } +} diff --git a/src/config/cart.service.ts b/src/config/cart.service.ts index 312ff3b..a948d42 100644 --- a/src/config/cart.service.ts +++ b/src/config/cart.service.ts @@ -8,6 +8,7 @@ import * as firebase from 'firebase'; import { take } from 'rxjs/operators'; import { User } from './services/user'; import { from } from 'rxjs'; +import undefined = require('firebase/empty-import'); @Injectable({ providedIn: 'root' @@ -27,8 +28,8 @@ export class CartsService { public router: Router, public service: ServiceService ) { - this.size = 'Small'; this.custId = ''; + this.carts = []; const users = this.service.get('user').then((data) => { if (data) { data = JSON.parse(data); @@ -44,18 +45,20 @@ export class CartsService { this.prodId = product.prodId; const prodRef = firebase.firestore().collection('products').doc(this.prodId); + this.size = this.size === undefined ? product.size[0] : this.size; + this.color = this.color === undefined ? product.color[0] : this.color; + const cartRef: AngularFirestoreCollection<any> = this.afs.collection('carts', ref => ref.where('size', '==', this.size) - .where('color', '==', Object.keys(product.color)[0]) + .where('color', '==', this.color) .where('custId', '==', this.custId) .where('product', '==', prodRef) ); - ; cartRef.valueChanges().pipe(take(1)).subscribe((value) => { console.log(value); if (value.length === 0) { product.image = product.image === undefined ? '../assets/model1@3x.jpg' : product.image; const cart: Cart = { - color: Object.keys(product.color)[0], + color: this.color, custId: this.custId, shopperId: product.shopperId, product: firebase.firestore().doc(`products/${this.prodId}`), @@ -87,7 +90,6 @@ export class CartsService { console.log('Booking Successfully'); document.body.scrollTop = document.documentElement.scrollTop = 0; }); - } }); } @@ -137,6 +139,10 @@ export class CartsService { this.size = size; } + choose_color(color: string) { + this.color = color; + } + removeCount(index) { // tslint:disable-next-line:radix const qty = this.carts[index].qty > 1 ? this.carts[index].qty - 1 : this.carts[index].qty; diff --git a/src/config/products.service.ts b/src/config/products.service.ts index 150e9d9..6c1fe91 100644 --- a/src/config/products.service.ts +++ b/src/config/products.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { AngularFirestore, AngularFirestoreDocument, AngularFirestoreCollection } from '@angular/fire/firestore'; import { Products } from './services/product'; import { ServiceService } from './../config/service.service'; +import { take } from 'rxjs/operators'; @Injectable({ providedIn: 'root' @@ -16,6 +17,8 @@ export class ProductsService { public afs: AngularFirestore, public service: ServiceService ) { + this.product = []; + this.fav = []; this.service.get('user').then(data => { this.user = JSON.parse(data); this.getFavlist(this.user.uid); @@ -43,6 +46,68 @@ export class ProductsService { brand: item.brand, category: item.category, shopperId: item.shopperId, + color: this.service.splitSep(item.color), + discount: item.discount, + featured: item.featured, + image: item.image, + price: item.price, + qty: item.qty, + shopper: item.shopper, + skuCode: item.skuCode, + status: item.status, + size: this.service.splitSep(item.size), + subCate: item.subCate, + tag: this.service.splitSep(item.tag) + }; + this.product.push(prod); + }); + console.log(this.product); + } else { + // alert('No Products Found'); + } + }); + } + + public async filterSearch(sortValue: string) { + const This = this; + const state = true; + console.log(sortValue); + + + + let field, order; + if (sortValue === 'low') { + field = 'price'; + order = 'asc'; + } + + if (sortValue === 'high') { + field = 'price'; + order = 'desc'; + } + + if (sortValue === 'rate') { + // field = 'price'; + // order = 'desc'; + } + + // tslint:disable-next-line:max-line-length + const prodRef: AngularFirestoreCollection<any> = this.afs.collection(`products`, ref => ref.where('status', '==', state).orderBy(field, order)); + prodRef.valueChanges().subscribe((value) => { + this.product = []; + const res = value; + if (res.length > 0) { + res.forEach((item) => { + console.log(item.size); + const prod: Products = { + prodId: item.prodId, + prodName: item.prodName, + prodCode: item.prodCode, + prodDesc: item.prodDesc, + prodStatus: item.prodStatus, + brand: item.brand, + category: item.category, + shopperId: item.shopperId, color: item.color, discount: item.discount, featured: item.featured, @@ -65,6 +130,8 @@ export class ProductsService { }); } + + similarProd(shopperId, category, subCate, prodId) { const This = this; @@ -117,24 +184,49 @@ export class ProductsService { public async getFavlist(userId: string) { const favRef: AngularFirestoreDocument<any> = this.afs.collection(`favourite`).doc(userId); - favRef.valueChanges().subscribe((value) => { - if (Object.keys(value).length > 0) { - this.fav = this.service.splitSep(value); - console.log(this.fav); + favRef.valueChanges().pipe( + take(1) // Here you can limit to only emit once, using the take operator + ).subscribe((value) => { + if (value !== undefined) { + if (Object.keys(value).length > 0) { + this.fav = this.service.splitSep(value); + console.log(this.fav); + } + console.log(value); } - console.log(value); }); } public async changeFav(index, type) { - console.log(index, type); - if (type === 'yes') { - this.afs.collection('favourite').doc(this.user.uid).update({ - [index]: true + console.log(index, type, this.user.uid); + if (type === 'no') { + this.afs.collection('favourite').doc(this.user.uid).valueChanges().pipe( + take(1) // Here you can limit to only emit once, using the take operator + ).subscribe((value) => { + if (value === undefined) { + this.afs.collection('favourite').doc(this.user.uid).set({ + [index]: true + }); + } else { + console.log(value); + value[index] = true; + console.log(value); + this.afs.collection('favourite').doc(this.user.uid).set(value); + } }); } else { - this.afs.collection(`favourite`).doc(this.user.uid).update({ - [index]: null + this.afs.collection('favourite').doc(this.user.uid).valueChanges().pipe( + take(1) // Here you can limit to only emit once, using the take operator + ).subscribe((value) => { + console.log(value); + if (value !== undefined) { + value[index] = undefined; + Object.keys(value).forEach(key => value[key] === undefined ? delete value[key] : ''); + console.log(value); + this.afs.collection('favourite').doc(this.user.uid).set(value); + } else { + console.log(value); + } }); } } diff --git a/src/config/search.service.ts b/src/config/search.service.ts new file mode 100644 index 0000000..7243477 --- /dev/null +++ b/src/config/search.service.ts @@ -0,0 +1,83 @@ +import { Injectable } from '@angular/core'; +import { AngularFirestore, AngularFirestoreCollection } from '@angular/fire/firestore'; +import { Search } from './services/search'; +import { database } from 'firebase'; +import { take } from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class SearchService { + searchList: Search[] = []; + constructor( + public afs: AngularFirestore + ) { + } + + public async search(inputText: string) { + if (inputText === '') { + this.searchList = []; + return; + } + const This = this; + const state = true; + this.searchList = []; + // tslint:disable-next-line:max-line-length + const orderRef: AngularFirestoreCollection<any> = this.afs.collection('shoppers', ref => ref.where('status', '==', state).orderBy('name').startAt(inputText).endAt(inputText + '\uf8ff').limit(5)); + orderRef.valueChanges().subscribe((value) => { + const res = value; + if (res.length > 0) { + res.forEach((item) => { + console.log(item); + const shopper: Search = { + text: item.name, + data: item, + type: 'shopper' + }; + this.searchList.push(shopper); + }); + } + }); + + // tslint:disable-next-line:max-line-length + const prodRef: AngularFirestoreCollection<any> = this.afs.collection('products', ref => ref.where('status', '==', state).orderBy('prodName').startAt(inputText).endAt(inputText + '\uf8ff').limit(5)); + prodRef.valueChanges().subscribe((values) => { + const result = values; + if (result.length > 0) { + result.forEach((item) => { + console.log(item); + const prod: Search = { + text: item.prodName, + data: item, + type: 'product' + }; + this.searchList.push(prod); + }); + console.log(this.searchList); + } + }); + + // tslint:disable-next-line:max-line-length + const feaRef: AngularFirestoreCollection<any> = this.afs.collection('category', ref => ref.where('status', '==', state).orderBy('catName').startAt(inputText).endAt(inputText + '\uf8ff').limit(5)); + feaRef.valueChanges().subscribe((values) => { + const result = values; + if (result.length > 0) { + result.forEach((item) => { + console.log(item); + const prod: Search = { + text: item.catName, + data: item, + type: 'category' + }; + this.searchList.push(prod); + }); + console.log(this.searchList); + } + }); + + } + + + + +} diff --git a/src/config/services/address.ts b/src/config/services/address.ts new file mode 100644 index 0000000..988ab43 --- /dev/null +++ b/src/config/services/address.ts @@ -0,0 +1,25 @@ +export class Address { + constructor( + public address: string, + public building: string, + public addressType: string, + public landmark: string, + public status: boolean, + public uid: string, + public defaultVal: number, + public latLng: any, + public addressId?: string, + ) { + + } +} + +export interface AddressList { + addressId: string; + address: string; + addressType: string; + defaultVal: number; + building: string; + latLng: any; + landmark: string; +} diff --git a/src/config/services/search.ts b/src/config/services/search.ts new file mode 100644 index 0000000..a72aaa9 --- /dev/null +++ b/src/config/services/search.ts @@ -0,0 +1,5 @@ +export interface Search { + type: string; + data: any; + text: any; +} diff --git a/src/global.scss b/src/global.scss index 11f94fa..bb327bf 100644 --- a/src/global.scss +++ b/src/global.scss @@ -505,6 +505,14 @@ app-deliverypop { } } +.nav_exit { + background-image: url("./assets/Group17_2.png"); + img { + width: 25px; + display: none; + } +} + .nav_cart { background-image: url("./assets/cart_icon.png"); img { diff --git a/tsconfig.app.json b/tsconfig.app.json index 31f8397..4e9fe65 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -2,7 +2,9 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/app", - "types": [] + "types": [ + "googlemaps" + ] }, "include": [ "src/**/*.ts" -- libgit2 0.27.1