From e4002ce8351859c3ec431aff342843bfaa1cc94d Mon Sep 17 00:00:00 2001 From: reaw55 <58457329+reaw55@users.noreply.github.com> Date: Wed, 8 Dec 2021 22:25:03 +0700 Subject: [PATCH] implement search function --- src/app/data-provider.service.ts | 6 ++++- src/app/home/home.page.ts | 10 ++++---- src/app/tab1/tab1.page.html | 15 +++++++++++- src/app/tab1/tab1.page.ts | 39 ++++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/app/data-provider.service.ts b/src/app/data-provider.service.ts index 5d52aef..394b059 100644 --- a/src/app/data-provider.service.ts +++ b/src/app/data-provider.service.ts @@ -17,12 +17,16 @@ export class DataProviderService { // allData(){ // return this.http.get('https://bc50-104-199-132-26.ngrok.io/alldata'); // } - public url = 'http://6447-35-186-184-86.ngrok.io' + public url = 'http://4255-34-91-36-11.ngrok.io/' insert(dbname: String,colname: String,web: String,cat: String){ //return this.http.get("http://localhost:/insert?dbname="+dbname+"&collectionname="+colname+"&web="+web+"&cat="+cat); return this.http.get(this.url+"/insert?dbname=data&collectionname=testdata&web=com.burbn.instagram&cat=photos"); } + public filter(cat: String){ + return this.http.get(this.url+"/filter?cat="+cat); + } + public getData(listData: any,lineChart: any) { return this.cache.asObservable(); } diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 91ab6f1..efa02ca 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -50,12 +50,12 @@ export class HomePage { this.hideNotice=true this.initializeChecklist(); this.func(); - //this.data=this.myDataProvider.getData(this.showData,this.lineChart); + //this.data=this.myDataProvider.getData(); }; initializeChecklist() { this.checkLabel = "Loading . . ." - this.myDataProvider.getData(null, null).subscribe(data => { + this.myDataProvider.getData(null,null).subscribe(data => { var dataJSON: Array dataJSON = JSON.parse(data.toString()) this.apps = [] @@ -85,9 +85,9 @@ export class HomePage { barChartMethod() { // Now we need to supply a Chart element reference with an object that defines the type of chart we want to use, and the type of data we want to display. //var data; - //console.log(this.myDataProvider.getData(this.showData,this.lineChart)) + //console.log(this.myDataProvider.getData()) var that = this - this.myDataProvider.getData(null, null).subscribe(data => { + this.myDataProvider.getData(null,null).subscribe(data => { var dataJSON: Array dataJSON = JSON.parse(data.toString()) var x = [] @@ -147,7 +147,7 @@ export class HomePage { doughnutChartMethod() { var that = this - this.myDataProvider.getData(null, null).subscribe(data => { + this.myDataProvider.getData(null,null).subscribe(data => { var dataJSON: Array dataJSON = JSON.parse(data.toString()) if (this.doughnutChart != undefined) diff --git a/src/app/tab1/tab1.page.html b/src/app/tab1/tab1.page.html index 2f93266..b6475a6 100644 --- a/src/app/tab1/tab1.page.html +++ b/src/app/tab1/tab1.page.html @@ -6,6 +6,19 @@ - + + + +

web: {{item.web}}

+
category: {{item.category}}
+
Type: {{item.type}}
+
time: {{item.time}}
+
+ + + +
diff --git a/src/app/tab1/tab1.page.ts b/src/app/tab1/tab1.page.ts index 15467c3..5057043 100644 --- a/src/app/tab1/tab1.page.ts +++ b/src/app/tab1/tab1.page.ts @@ -1,4 +1,6 @@ +import { ConstantPool } from '@angular/compiler'; import { Component, OnInit } from '@angular/core'; +import { DataProviderService } from '../data-provider.service'; @Component({ selector: 'app-tab1', @@ -7,9 +9,42 @@ import { Component, OnInit } from '@angular/core'; }) export class Tab1Page implements OnInit { - constructor() { } - + constructor( public myDataProvider: DataProviderService) { } + public itemListData = [] + public current = [] + searchbar: any + cat: String + public page = 0 + private itemperpage = 20 ngOnInit() { } + search(event) { + console.log(this.searchbar); + var that=this + this.myDataProvider.filter(this.searchbar).subscribe((data: Array)=>{ + this.itemListData = data; + //console.log(this.itemListData) + this.page = 1; + that.current = [] + var lowerbound = this.itemperpage*(this.page-1) + var upperbound = this.itemperpage*(this.page); + console.log(this.itemListData); + /* for(var i=lowerbound-1;i