Skip to content

Commit

Permalink
Merge branch 'feature/add_trainer_on_battle' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
PythoudGuillaume committed Dec 7, 2016
2 parents a103881 + cafb9bd commit ca2703e
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 87 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ionic-angular": "2.0.0-rc.1",
"ionic-native": "2.2.3",
"ionicons": "3.0.0",
"jwt-decode": "^2.1.0",
"moment": "^2.17.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.21"
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { MakeBetPage } from '../pages/makeBet/makeBet';
import { BattlePage } from '../pages/battle/battle';
import { UserPage } from '../pages/user/user';
import { LoginPage } from '../pages/login/login';
import { Signin } from '../pages/signin/signin';
import { MasterService } from '../providers/master-service';

@NgModule({
Expand All @@ -16,7 +16,7 @@ import { MasterService } from '../providers/master-service';
MakeBetPage,
BattlePage,
LoginPage,
Signin
UserPage

],
imports: [
Expand All @@ -29,7 +29,7 @@ import { MasterService } from '../providers/master-service';
MakeBetPage,
BattlePage,
LoginPage,
Signin
UserPage
],
providers: [
MasterService,
Expand Down
22 changes: 18 additions & 4 deletions src/models/models.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
export class Battle {
id: string;
startTime: string;
Teams: [{
TrainerId: string
}]
teams: {
1:{
trainer: number;
Pokemons: number;
};
2:{
trainer: number;
pokemons: number;
};
};
}

export class Trainer{
id: string;
name: string;
gender: string;
country: string;
}

export class Bet {
id: string;
UserId: string;
user: string;
}

export class Login {
Expand Down
37 changes: 25 additions & 12 deletions src/pages/battle/battle.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,30 @@


<ion-content padding>
<h3>Bets:</h3>
Todo: add battle info
<ion-card *ngFor="let bet of bets" >
<ion-card-content >
<ion-card-title (click)="toBattlePage(battle)">
<h2>User #{{bet.UserId}}</h2>
</ion-card-title>
<ion-item>
<button ion-button [navPush]="makeBetPage" [navParams]="bet.id">Bet!!</button>
</ion-item>
</ion-card-content>
</ion-card>
<ion-list *ngFor="let i of [0,1]">
<ion-list-header><h3>Trainer {{i + 1}}: {{trainers[i].name}}</h3></ion-list-header>

<ion-item *ngFor="let pokemon of battle.teams[i+1].pokemons">
<ion-avatar item-left>
<img src='/assets/sprites/pokemon/{{pokemon}}.png'>
</ion-avatar>
<h5>{{pokemon}}</h5>
</ion-item>
</ion-list>
<div *ngIf="masterService.isLogged() ">
<button ion-button full [navPush]="makeBetPage" [navParams]="{event: battle, type: 'battles'}" >BET</button>
<div *ngIf="isAnyBet()">
<h3>Bets:</h3>
<ion-card *ngFor="let bet of bets" >
<ion-card-content >
<ion-card-title (click)="toBattlePage(battle)">
<h2>User #{{bet.user}}</h2>
</ion-card-title>
<ion-item >
<button ion-button [navPush]="makeBetPage" [navParams]="{event: bet, type: 'bets'}">Bet!!</button>
</ion-item>
</ion-card-content>
</ion-card>
</div>
</div>
</ion-content>
19 changes: 15 additions & 4 deletions src/pages/battle/battle.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { NavController, NavParams, Events } from 'ionic-angular';
import { MasterService } from '../../providers/master-service';
import { Battle, Bet} from '../../models/models'
import { Battle, Bet, Trainer} from '../../models/models'
import { MakeBetPage } from '../makeBet/makeBet';

/*
Generated class for the Battle page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on
Ionic pages and navigation.
tes
*/
@Component({
selector: 'page-battle',
Expand All @@ -18,17 +19,27 @@ import { MakeBetPage } from '../makeBet/makeBet';
export class BattlePage {
public bets: Bet[];
public battle: Battle;
public trainers: Trainer[];
public makeBetPage = MakeBetPage;


constructor(public navCtrl: NavController,public params:NavParams, public masterService:MasterService) {
this.battle = params.data;
constructor(public navCtrl: NavController,public params:NavParams, public masterService:MasterService, public events: Events) {
this.battle = params.data.battle;
this.trainers = params.data.trainers;
this.bets = [];
this.load();
}

load() {
this.masterService.loadBetsOfBattle(this.battle.id)
.subscribe((data) => { this.bets = data });
this.events.subscribe('reloadBattlePage',() => {
this.load();
})
}

isAnyBet(){
return (this.bets.length > 0);
}

ionViewDidLoad() {
Expand Down
7 changes: 5 additions & 2 deletions src/pages/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ion-navbar>
<ion-title>Home</ion-title>
<ion-buttons end>
<button ion-button icon-only [navPush]="loginPage">
<button ion-button icon-only (click)="toLogOrUserPage()">
<ion-icon name="person"></ion-icon>
</button>
</ion-buttons>
Expand All @@ -18,9 +18,12 @@ <h2>Next fights!</h2>
Battle #{{battle.id}}
</button>
</ion-card-title>
<ion-item>
<p *ngIf=trainers> {{getTrainer(battle.teams['1'].trainer).name}} vs {{getTrainer(battle.teams['2'].trainer).name}} </p>
</ion-item>
<ion-item>
<p>Start {{getLocalTime(battle.startTime)}} </p>
<button ion-button [navPush]="makeBetPage" [navParams]="battle">Bet!!</button>
<button ion-button *ngIf="masterService.isLogged()" [navPush]="makeBetPage" [navParams]="{event: battle, type: 'battles'}">Bet!!</button>
</ion-item>
</ion-card-content>
</ion-card>
Expand Down
33 changes: 27 additions & 6 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

import { Battle } from '../../models/models';
import { Battle, Trainer} from '../../models/models';
import { MasterService } from '../../providers/master-service';

import { MakeBetPage } from '../makeBet/makeBet';
import { BattlePage } from '../battle/battle';
import { LoginPage } from '../login/login';
import { UserPage } from '../user/user';

import moment from 'moment'

Expand All @@ -19,23 +20,43 @@ import moment from 'moment'

export class HomePage {
public battles: Battle[];
public trainers: Trainer[];

public makeBetPage = MakeBetPage;
public loginPage = LoginPage;
public userPage = UserPage;

constructor(public navCtrl: NavController, public masterService: MasterService) {
this.load();
this.load();
}

load() {
this.masterService.loadBattle()
.subscribe((data) => { this.battles = data });
this.masterService.loadTrainer()
.subscribe((data) => this.trainers = data);
this.masterService.loadBattle()
.subscribe((data) => this.battles = data);
}

getTrainer(id){
return this.trainers.find(t => t.id == id);
}

toBattlePage(battle) {
this.navCtrl.push(BattlePage,battle);
toBattlePage(battle: Battle) {
this.navCtrl.push(BattlePage,{battle: battle,trainers: [this.getTrainer(battle.teams['1'].trainer), this.getTrainer(battle.teams['2'].trainer)]});
};

toLogOrUserPage(){
console.log('click');
if (this.masterService.isLogged()){
console.log("goto user page");
this.navCtrl.push(this.userPage);
} else {
this.navCtrl.push(this.loginPage);
}
}

getLocalTime(time) {
return moment(new Date(time)).fromNow();
}

}
22 changes: 17 additions & 5 deletions src/pages/makeBet/makeBet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Component } from '@angular/core';
import { NavController, NavParams, AlertController } from 'ionic-angular';
import { NavController, NavParams, AlertController, Events } from 'ionic-angular';
import { MasterService } from '../../providers/master-service';


import { Battle } from '../../models/models';
import { BattlesService } from '../../providers/battles-service';
Expand All @@ -12,16 +14,19 @@ import { BattlesService } from '../../providers/battles-service';
*/
@Component({
selector: 'page-makeBet',
templateUrl: 'makeBet.html'
templateUrl: 'makeBet.html',
providers: [MasterService]
})
export class MakeBetPage {
public eventId;
public eventType;
public bet = {
choice:0,
amount:0
};
constructor(public navCtrl: NavController, public params:NavParams, private alertCtrl: AlertController) {
this.eventId = params.data;
constructor(public navCtrl: NavController, public params:NavParams, private alertCtrl: AlertController, public masterService: MasterService, public events: Events) {
this.eventId = params.data.event.id;
this.eventType = params.data.type;
}

logForm() {
Expand All @@ -39,7 +44,13 @@ public bet = {
{
text: 'Accept',
handler: () => {
console.log(this.bet.amount);
this.masterService.postBet(this.eventType,this.eventId,this.bet)
.then(rep => {
this.events.publish('reloadBattlePage');
console.log(rep);
this.navCtrl.pop();
})
.catch(err => console.log(err));
}
}
]
Expand All @@ -48,6 +59,7 @@ public bet = {
alert.present();
}


ionViewDidLoad() {
console.log(this.eventId);
}
Expand Down
31 changes: 0 additions & 31 deletions src/pages/signin/signin.html

This file was deleted.

3 changes: 0 additions & 3 deletions src/pages/signin/signin.scss

This file was deleted.

16 changes: 0 additions & 16 deletions src/pages/signin/signin.ts

This file was deleted.

Loading

0 comments on commit ca2703e

Please sign in to comment.