Browse Source

search api by id

Rachelle 6 years ago
parent
commit
39beb62639

+ 44
- 0
MyPassionProjectClient/src/pages/game-search/game-search.html View File

@@ -0,0 +1,44 @@
1
+<ion-header>
2
+  <ion-navbar>
3
+    <ion-buttons start>
4
+      <button ion-button menuToggle>
5
+        <ion-icon name="menu"></ion-icon>
6
+      </button>
7
+    </ion-buttons>
8
+    <ion-title>Search Games</ion-title>
9
+  </ion-navbar>
10
+</ion-header>
11
+
12
+
13
+<ion-content padding>
14
+
15
+  <ion-searchbar [(ngModel)]="searchTerm" (search)="searchGame($event)" placeholder="Search Games" debounce="500"></ion-searchbar>
16
+  <ion-list>
17
+    <ion-item-sliding *ngFor="let game of searchResult">
18
+      <ion-item>
19
+      <ion-thumbnail item-start>
20
+        <img src={{game.thumbnail}}>
21
+      </ion-thumbnail>
22
+      <h2>{{game.name}}</h2>
23
+      <p>{{game.mechanics}}</p>
24
+      <button ion-button clear item-end>View</button>
25
+        </ion-item>
26
+
27
+
28
+      <ion-item-options side="left">
29
+        <button ion-button color="primary" (click)="doAddToOwnedAndPlayedList()">
30
+          <ion-icon name="add"></ion-icon> Owned and Played
31
+        </button>
32
+      </ion-item-options>
33
+
34
+      <ion-item-options side="right">
35
+      <button ion-button color="primary" (click)="doAddToOwnedList()">
36
+      <ion-icon name="add"></ion-icon> Owned
37
+      </button>
38
+        <button ion-button color="secondary" (click)="doAddToPlayedList()">
39
+          <ion-icon name="add"></ion-icon> Played
40
+        </button>
41
+      </ion-item-options>
42
+    </ion-item-sliding>
43
+  </ion-list>
44
+</ion-content>

+ 17
- 0
MyPassionProjectClient/src/pages/game-search/game-search.module.ts View File

@@ -0,0 +1,17 @@
1
+import { NgModule } from '@angular/core';
2
+import { IonicPageModule } from 'ionic-angular';
3
+import { GameSearchPage } from './game-search';
4
+import { BggGameSearch } from '../../providers/bggGames-service';
5
+
6
+@NgModule({
7
+  declarations: [
8
+    GameSearchPage,
9
+  ],
10
+  imports: [
11
+    IonicPageModule.forChild(GameSearchPage),
12
+  ],
13
+  providers: [
14
+    BggGameSearch
15
+  ],
16
+})
17
+export class GameSearchPageModule {}

+ 3
- 0
MyPassionProjectClient/src/pages/game-search/game-search.scss View File

@@ -0,0 +1,3 @@
1
+page-game-search {
2
+
3
+}

+ 59
- 0
MyPassionProjectClient/src/pages/game-search/game-search.ts View File

@@ -0,0 +1,59 @@
1
+import { Component } from '@angular/core';
2
+import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angular';
3
+import { BggGameSearch } from '../../providers/bggGames-service';
4
+ 
5
+@IonicPage()
6
+@Component({
7
+  selector: 'page-game-search',
8
+  templateUrl: 'game-search.html',
9
+})
10
+export class GameSearchPage {
11
+    game: any;
12
+    searchResult: any;
13
+    searchTerm: '';
14
+
15
+  constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController, public bggGames: BggGameSearch) {
16
+  }
17
+  
18
+    ionViewDidLoad() {
19
+    }
20
+
21
+    searchGame(){
22
+      console.log("search method called");
23
+      this.bggGames.searchGame(this.searchTerm).subscribe(games=>{
24
+        this.searchResult = games;
25
+        this.searchResult = Array.of(this.searchResult);
26
+      })
27
+      ;
28
+    }
29
+
30
+  doAddToOwnedList() {
31
+      let toast = this.toastCtrl.create({
32
+        message: 'Game Added To MyGames',
33
+        duration: 2000,
34
+        position: 'bottom'
35
+      });
36
+      toast.present();
37
+
38
+  }
39
+
40
+  doAddToPlayedList() {
41
+    let toast = this.toastCtrl.create({
42
+      message: 'Game Added To PlayedGames',
43
+      duration: 2000,
44
+      position: 'bottom'
45
+    });
46
+    toast.present();
47
+
48
+  }
49
+
50
+  doAddToOwnedAndPlayedList() {
51
+    let toast = this.toastCtrl.create({
52
+      message: 'Game Added To MyPlayedGames',
53
+      duration: 2000,
54
+      position: 'bottom'
55
+    });
56
+    toast.present();
57
+
58
+  }
59
+}

+ 16
- 16
MyPassionProjectClient/src/pages/games/games.ts View File

@@ -19,25 +19,25 @@ export class GamesPage {
19 19
     ;
20 20
   }
21 21
   
22
-  ionViewDidLoad() {
23
-  }
22
+    ionViewDidLoad() {
23
+    }
24 24
 
25
-  getItems(ev: any) {
26
-    // Reset items back to all of the items
27
-    this.filteredGames = this.games;
28
-    // set val to the value of the searchbar
29
-    const val = ev.target.value;
30
-    // if the value is an empty string don't filter the items
31
-    if (val && val.trim() != '') {
32
-      this.filterGamesBySearch(val);
25
+    getItems(ev: any) {
26
+      // Reset items back to all of the items
27
+      this.filteredGames = this.games;
28
+      // set val to the value of the searchbar
29
+      const val = ev.target.value;
30
+      // if the value is an empty string don't filter the items
31
+      if (val && val.trim() != '') {
32
+        this.filterGamesBySearch(val);
33
+      }
33 34
     }
34
-  }
35 35
 
36
-filterGamesBySearch(searchTerm){
37
-  this.filteredGames = this.games.filter((games) => {
38
-      return games.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1;
39
-  });    
40
-}
36
+  filterGamesBySearch(searchTerm){
37
+    this.filteredGames = this.games.filter((games) => {
38
+        return games.name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1;
39
+    });    
40
+  }
41 41
 
42 42
   doAddToOwnedList() {
43 43
       let toast = this.toastCtrl.create({

+ 1
- 0
MyPassionProjectClient/src/pages/menu/menu.ts View File

@@ -28,6 +28,7 @@ export class MenuPage {
28 28
   pages: PageInterface[] = [
29 29
     { title: 'Home', pageName: 'TabsPage', tabComponent: 'ProfilePage', index: 0, icon: 'home' },
30 30
     { title: 'Games', pageName: 'TabsPage', tabComponent: 'GamesPage', index: 1, icon: 'search' },
31
+    { title: 'Game Search', pageName: 'TabsPage', tabComponent: 'GameSearchPage', index: 1, icon: 'search' },
31 32
     { title: 'Friends', pageName: 'TabsPage', tabComponent: 'FriendsPage', index: 2, icon: 'contacts' },
32 33
   ];
33 34
 

+ 1
- 0
MyPassionProjectClient/src/pages/tabs/tabs.html View File

@@ -1,5 +1,6 @@
1 1
 <ion-tabs>
2 2
     <ion-tab [root]="profileRoot" tabTitle="Home" tabIcon="home"></ion-tab>
3 3
     <ion-tab [root]="gamesRoot" tabTitle="Games" tabIcon="search"></ion-tab>
4
+    <ion-tab [root]="gameSearchRoot" tabTitle="GameSearch" tabIcon="search"></ion-tab>
4 5
     <ion-tab [root]="friendsRoot" tabTitle="Friends" tabIcon="contacts"></ion-tab>
5 6
 </ion-tabs>

+ 1
- 4
MyPassionProjectClient/src/pages/tabs/tabs.ts View File

@@ -15,13 +15,10 @@ import {IonicPage, NavController, NavParams} from 'ionic-angular';
15 15
 })
16 16
 export class TabsPage {
17 17
 
18
-  // homeRoot = 'HomePage'
19
-  // friendsRoot = 'FriendsPage'
20
-  // gamesRoot = 'GamesPage'
21
-
22 18
   profileRoot: any = 'ProfilePage';
23 19
   friendsRoot: any = 'FriendsPage';
24 20
   gamesRoot: any = 'GamesPage';
21
+  gameSearchRoot: any = 'GameSearchPage';
25 22
   myIndex: number;
26 23
 
27 24
 

+ 14
- 0
MyPassionProjectClient/src/providers/bggGames-service.ts View File

@@ -0,0 +1,14 @@
1
+import {Injectable} from "@angular/core";
2
+import {HttpClient} from "@angular/common/http";
3
+
4
+@Injectable()
5
+export class BggGameSearch{
6
+  public API = "https://bgg-json.azurewebsites.net/thing/";
7
+
8
+  constructor(public http: HttpClient){
9
+  }
10
+
11
+  searchGame(gameId: String){
12
+    return this.http.get(this.API+gameId);
13
+  }
14
+}