Browse Source

search functionality updtd

rjsmall90 6 years ago
parent
commit
e8658406c6

+ 2
- 0
src/app/app.module.ts View File

14
 import { StatusBar } from '@ionic-native/status-bar';
14
 import { StatusBar } from '@ionic-native/status-bar';
15
 import { SplashScreen } from '@ionic-native/splash-screen';
15
 import { SplashScreen } from '@ionic-native/splash-screen';
16
 import { ConnectionProvider } from '../providers/connection/connection';
16
 import { ConnectionProvider } from '../providers/connection/connection';
17
+import { DistrictProvider } from '../providers/connection/district';
17
 
18
 
18
 @NgModule({
19
 @NgModule({
19
   declarations: [
20
   declarations: [
42
     StatusBar,
43
     StatusBar,
43
     SplashScreen,
44
     SplashScreen,
44
     ConnectionProvider,
45
     ConnectionProvider,
46
+    DistrictProvider, 
45
     {provide: ErrorHandler, useClass: IonicErrorHandler}
47
     {provide: ErrorHandler, useClass: IonicErrorHandler}
46
     
48
     
47
   ]
49
   ]

+ 7
- 0
src/app/component/school.ts View File

1
+export class School {
2
+
3
+
4
+    constructor(public name: string) {
5
+
6
+    }
7
+}

+ 11
- 4
src/pages/search/search.html View File

8
     </ion-title>
8
     </ion-title>
9
   </ion-navbar>
9
   </ion-navbar>
10
 </ion-header>
10
 </ion-header>
11
-<ion-content padding style="background:url(assets/img/XevfnYbMSbmzquaF2tvl_final_spitball.jpg) no-repeat center;background-size:cover;" id="page3">
12
-  <form id="searchHomePage-form3">
13
-    <ion-searchbar placeholder="Enter Name or School Here" name="" id="searchHomePage-search1"></ion-searchbar>
14
-  </form>
11
+<ion-content padding style="background:url(assets/imgs/final_spitball.jpg) no-repeat center;background-size:cover;" id="page3">
12
+    <ion-searchbar 
13
+    placeholder="Enter Teacher Name or School Here" name="" id="searchHomePage-search1"
14
+    (ionInput)="getSchool($event)"
15
+    [spellcheck]="true">
16
+    </ion-searchbar>
17
+    <ion-list *ngFor= "let school of filterSchools">
18
+    <ion-list-header>
19
+        {{school.name}}
20
+    </ion-list-header>
21
+</ion-list>
15
   <h4 id="searchHomePage-heading2" style="color:#FF0000;"></h4>
22
   <h4 id="searchHomePage-heading2" style="color:#FF0000;"></h4>
16
   <form id="searchHomePage-form8">
23
   <form id="searchHomePage-form8">
17
     <ion-item id="searchHomePage-textarea1">
24
     <ion-item id="searchHomePage-textarea1">

+ 36
- 2
src/pages/search/search.ts View File

1
 import { Component } from '@angular/core';
1
 import { Component } from '@angular/core';
2
 import { NavController } from 'ionic-angular';
2
 import { NavController } from 'ionic-angular';
3
+import { ConnectionProvider } from './../../providers/connection/connection';
4
+import { DistrictProvider } from './../../providers/connection/district';
5
+
6
+
3
 
7
 
4
 @Component({
8
 @Component({
5
   selector: 'page-search',
9
   selector: 'page-search',
6
   templateUrl: 'search.html'
10
   templateUrl: 'search.html'
7
 })
11
 })
8
 export class SearchPage {
12
 export class SearchPage {
13
+    listOfSchools: any; 
14
+    filterSchools: any;
9
 
15
 
10
-  constructor(public navCtrl: NavController) {
16
+  constructor(public navCtrl: NavController, public conn: ConnectionProvider, public dist: DistrictProvider) {
11
   }
17
   }
18
+    ngOnInit(): void {
19
+        //Called after the constructor, initializing input properties, and the first call to ngOnChanges.
20
+        //Add 'implements OnInit' to the class.
21
+        this.dist.getAllSchools().subscribe(data => this.setData(data))
22
+    }
23
+
24
+    setData(data: any) {
25
+        this.listOfSchools = this.dist.parseData(data);
26
+        this.filterSchools = this.listOfSchools;
27
+    }
28
+
29
+    getSchool(event: any) {
30
+        this.filterSchools = this.listOfSchools
31
+        let val = event.target.value;
32
+
33
+        if (val && val.trim() != '') {
34
+            this.filterSchools = this.filterSchools.filter((item) => {
35
+             return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
36
+            });
37
+        }
38
+
39
+    }
40
+}
41
+
42
+
43
+
44
+    
45
+
46
+  
12
   
47
   
13
-}

+ 4
- 0
src/providers/connection/connection.ts View File

20
   return this.http.post(this.apiUrl + partialPath, data);
20
   return this.http.post(this.apiUrl + partialPath, data);
21
 }
21
 }
22
 
22
 
23
+get(partialPath: string, data: any) {
24
+  return this.http.get(this.apiUrl + partialPath, data);
25
+}
26
+
23
 
27
 
24
 
28
 
25
 }
29
 }

+ 31
- 0
src/providers/connection/district.ts View File

1
+import { HttpClient } from '@angular/common/http';
2
+import { Injectable } from '@angular/core';
3
+import { School } from './../../app/component/school'
4
+
5
+@Injectable()
6
+export class DistrictProvider {
7
+
8
+    public districtAPI = 'https://data.delaware.gov/api/views/wky5-77bt/rows.json?accessType=DOWNLOAD'
9
+
10
+    constructor(public http: HttpClient) {
11
+            console.log('Hello DistrictProvider Provider');
12
+
13
+    }
14
+
15
+    getAllSchools() {
16
+
17
+        return this.http.get(this.districtAPI) //.map((response: any) => {
18
+            // if (response.data.length > 0) {
19
+            //     return response.data[0].images.original.url;
20
+            // } else {
21
+            //     return console.log('error');
22
+        //     }
23
+        // });
24
+    }
25
+
26
+    parseData(data: any) {
27
+        return data["data"].map(school => new School(school[13]))
28
+    }
29
+
30
+
31
+}