Commit 63b9e7a1 by Adarsh K

search-model

parent a271ff43
...@@ -2,27 +2,14 @@ ...@@ -2,27 +2,14 @@
<button class="nav_btn nav_back floatLeft" (click)="closeModal()"> <button class="nav_btn nav_back floatLeft" (click)="closeModal()">
</button> </button>
<div class="nav_title floatLeft relative"> <div class="nav_title floatLeft relative">
<input class="search_bar" placeholder="Search here.. eg:shirts, retailers etc..."> <input class="search_bar" placeholder="Search here.. eg:shirts, retailers etc..." (click)="clickSearch()" (input)="searchFun($event.target.value)" #searchText>
</div> </div>
<button class="nav_btn nav_close floatRight" (click)="closeModal()"> <button class="nav_btn nav_close floatRight" (click)="closeModal()">
</button> </button>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
<div class="search_item_list"> <div class="search_item_list">
<ul> <ul *ngIf="searchService.searchList">
<li>Item </li> <li *ngFor="let search of searchService.searchList" (click)="viewPage(search)">{{search.text}} </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
<li>Item </li>
</ul> </ul>
</div> </div>
\ No newline at end of file
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from "@ionic/angular"; import { Router, ActivatedRoute } from '@angular/router';
import { ModalController, NavParams } from '@ionic/angular';
import { SearchService } from './../../config/search.service';
import { ServiceService } from './../../config/service.service';
import { ProductsService } from './../../config/products.service';
@Component({ @Component({
selector: "app-searchmodal", selector: 'app-searchmodal',
templateUrl: "./searchmodal.page.html", templateUrl: './searchmodal.page.html',
styleUrls: ["./searchmodal.page.scss"] styleUrls: ['./searchmodal.page.scss']
}) })
export class SearchmodalPage implements OnInit { export class SearchmodalPage implements OnInit {
searchShow = false;
constructor( constructor(
private modalController: ModalController, private modalController: ModalController,
private navParams: NavParams private navParams: NavParams,
private searchService: SearchService,
public service: ServiceService,
private productsService: ProductsService,
private router: Router
) {} ) {}
ngOnInit() {} ngOnInit() {
this.searchService.searchList = [];
}
async closeModal() { async closeModal() {
await this.modalController.dismiss(); await this.modalController.dismiss();
} }
searchFun(data: string) {
this.searchShow = true;
this.searchService.search(data);
}
clickSearch() {
this.searchShow = true;
this.searchService.searchList = [];
}
viewPage(datas: any) {
this.closeModal();
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;
}
searchClose() {
this.closeModal();
this.searchShow = false;
}
} }
import { Injectable } from "@angular/core"; import { Injectable } from '@angular/core';
import { import {
AngularFirestore, AngularFirestore,
AngularFirestoreCollection AngularFirestoreCollection
} from "@angular/fire/firestore"; } from '@angular/fire/firestore';
import { Search } from "./services/search"; import { Search } from './services/search';
import { database } from "firebase"; import { database } from 'firebase';
import { take } from "rxjs/operators"; import { take } from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: "root" providedIn: 'root'
}) })
export class SearchService { export class SearchService {
searchList: Search[] = []; searchList: Search[] = [];
constructor(public afs: AngularFirestore) {} constructor(public afs: AngularFirestore) {}
public async search(inputText: string) { public async search(inputText: string) {
if (inputText === "") { if (inputText === '') {
this.searchList = []; this.searchList = [];
return; return;
} }
...@@ -24,13 +24,13 @@ export class SearchService { ...@@ -24,13 +24,13 @@ export class SearchService {
this.searchList = []; this.searchList = [];
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length
const orderRef: AngularFirestoreCollection<any> = this.afs.collection( const orderRef: AngularFirestoreCollection<any> = this.afs.collection(
"shoppers", 'shoppers',
ref => ref =>
ref ref
.where("status", "==", state) .where('status', '==', state)
.orderBy("name") .orderBy('name')
.startAt(inputText.toUpperCase()) .startAt(inputText.toUpperCase())
.endAt(inputText.toLowerCase() + "\uf8ff") .endAt(inputText.toLowerCase() + '\uf8ff')
.limit(5) .limit(5)
); );
orderRef.valueChanges().subscribe(value => { orderRef.valueChanges().subscribe(value => {
...@@ -41,7 +41,7 @@ export class SearchService { ...@@ -41,7 +41,7 @@ export class SearchService {
const shopper: Search = { const shopper: Search = {
text: item.name, text: item.name,
data: item, data: item,
type: "shopper" type: 'shopper'
}; };
this.searchList.push(shopper); this.searchList.push(shopper);
}); });
...@@ -50,13 +50,13 @@ export class SearchService { ...@@ -50,13 +50,13 @@ export class SearchService {
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length
const prodRef: AngularFirestoreCollection<any> = this.afs.collection( const prodRef: AngularFirestoreCollection<any> = this.afs.collection(
"products", 'products',
ref => ref =>
ref ref
.where("status", "==", state) .where('status', '==', state)
.orderBy("prodName") .orderBy('prodName')
.startAt(inputText.toUpperCase()) .startAt(inputText.toUpperCase())
.endAt(inputText.toLowerCase() + "\uf8ff") .endAt(inputText.toLowerCase() + '\uf8ff')
.limit(5) .limit(5)
); );
prodRef.valueChanges().subscribe(values => { prodRef.valueChanges().subscribe(values => {
...@@ -67,7 +67,7 @@ export class SearchService { ...@@ -67,7 +67,7 @@ export class SearchService {
const prod: Search = { const prod: Search = {
text: item.prodName, text: item.prodName,
data: item, data: item,
type: "product" type: 'product'
}; };
this.searchList.push(prod); this.searchList.push(prod);
}); });
...@@ -77,13 +77,13 @@ export class SearchService { ...@@ -77,13 +77,13 @@ export class SearchService {
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length
const feaRef: AngularFirestoreCollection<any> = this.afs.collection( const feaRef: AngularFirestoreCollection<any> = this.afs.collection(
"category", 'category',
ref => ref =>
ref ref
.where("status", "==", state) .where('status', '==', state)
.orderBy("catName") .orderBy('catName')
.startAt(inputText.toUpperCase()) .startAt(inputText.toUpperCase())
.endAt(inputText.toLowerCase() + "\uf8ff") .endAt(inputText.toLowerCase() + '\uf8ff')
.limit(5) .limit(5)
); );
feaRef.valueChanges().subscribe(values => { feaRef.valueChanges().subscribe(values => {
...@@ -94,7 +94,7 @@ export class SearchService { ...@@ -94,7 +94,7 @@ export class SearchService {
const prod: Search = { const prod: Search = {
text: item.catName, text: item.catName,
data: item, data: item,
type: "category" type: 'category'
}; };
this.searchList.push(prod); this.searchList.push(prod);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment