Skip to content

Commit

Permalink
Merge branch 'Primeros-pasos-angular' of https://github.com/CodeURJC-…
Browse files Browse the repository at this point in the history
…DAW-2019-20/webapp9 into Primeros-pasos-angular
  • Loading branch information
JorgeCarreras2 committed Mar 31, 2020
2 parents 9b9b39c + 49cd858 commit 4e151e2
Show file tree
Hide file tree
Showing 21 changed files with 616 additions and 15 deletions.
6 changes: 5 additions & 1 deletion Angular/lucia-no-te-enfades-pp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@
"ts-node": "~8.3.0",
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
},
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"styles.css"
]
}
5 changes: 3 additions & 2 deletions Angular/lucia-no-te-enfades-pp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { UserService } from './_servicies/user.service';

import { RocketleagueComponent } from './rocketleague/rocketleague.component';

import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { RouterModule } from "@angular/router";

@NgModule({
declarations: [
AppComponent,
LoginComponent,


],

imports: [
BrowserModule,
NgbModule,
Expand Down
33 changes: 33 additions & 0 deletions Angular/lucia-no-te-enfades-pp/src/app/players.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';

import { Player } from './player.model';
import { Team } from './team.model';

const BASE_URL = 'https://127.0.0.1:8443/api/player/';

@Injectable({ providedIn: 'root' })
export class PlayersService {

constructor(private httpClient: HttpClient){}

getPlayerByUserId(userId: number): Observable<Player> {
return this.httpClient.get(BASE_URL + userId).pipe(
catchError(error => this.handleError(error))
)as Observable<Player>;
}

updatePlayerTeam(idPlayer: number, team: Team) {
return this.httpClient.put(BASE_URL + idPlayer + "/team", team).pipe(
catchError(error => this.handleError(error))
)
}

private handleError(error: any) {
console.error(error);
return Observable.throw("Server error (" + error.status + "): " + error.text())
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<html lang="en">

<head>

<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>Rocket League</title>

<!-- Bootstrap core CSS -->
<link href="/core/bootstrap.min.css" rel="stylesheet">

<link
href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic"
rel="stylesheet" type="text/css">

<!-- Custom styles for this template -->
<link href="/css/RocketLeague/landing-page.min.css" rel="stylesheet">

</head>

<body>

<!-- NavBar -->
<!--
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#"> <img
src="/imgs/Navbar/web-icon-white.png" width="30" height="30" alt="">
</a> <a class="navbar-brand">eTournaments</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarCollapse" aria-controls="navbarCollapse"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<form action="index">
<input type="submit" class="nav-link" value="Home">
</form>
</li>
<li class="nav-item active">{{#noloaded}}
<form action="login">
<input type="submit" class="nav-link" value="Sign In">
</form> {{/noloaded}} {{#adminNo}}{{^noloaded}}
<form action="profile" method="get">
<input type="submit" class="nav-link" value="{{user.username}}">
<input type="hidden" name="_csrf" value="{{token}}" /> <input
type="hidden" name="id" value="{{user.iduser}}" />
</form> {{/noloaded}} {{/adminNo}}
</li>
<li class="nav-item active">
<form action="leaderBoard">
<input type="submit" class="nav-link" value="Leaderboard">
</form>
</li>
{{#admin}}
<li class="nav-item active">
<form action="tournamentCreation">
<input type="submit" class="nav-link" value="Create new tournament">
<input type="hidden" name="_csrf" value="{{token}}">
</form>
</li>
{{/admin}}
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item active">{{#noloaded}}
<form action="register">
<input type="submit" class="nav-link" value="Register"> <input
type="hidden" name="_csrf" value="{{token}}" />
</form> {{/noloaded}} {{^noloaded}}
<form action="/logout" method="post">
<input type="submit" class="nav-link" value="Log Out"> <input
type="hidden" name="_csrf" value="{{token}}" />
</form> {{/noloaded}}
</li>
</ul>
</div>
</nav>
</header>
-->

<!-- Masthead -->
<header class="masthead text-white text-center">
<div class="overlay"></div>
<div class="container">
<div class="row">
<div class="col-xl-9 mx-auto">
<h1 class="mb-5">TOURNAMENTS</h1>
</div>
</div>
</div>
</header>

<!-- Icons Grid -->
<section class="features-icons bg-light text-center">
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3">
<i><a
href="https://store.steampowered.com/app/252950/Rocket_League/"><img
src="/imgs/Tournament/steam-Icon.png" alt="Responsive image"
height="200px" width="200px" /></a></i>
<h3>Download Rocket League on Steam</h3>
</div>
</div>
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-5 mb-lg-0 mb-lg-3">
<i><a
href="https://www.twitch.tv/directory/game/Rocket%20League"><img
src="/imgs/Tournament/twitch-icon.png" height="200px"
width="200px"></a></i>
<h3>See on Twitch</h3>
</div>
</div>
<div class="col-lg-4">
<div class="features-icons-item mx-auto mb-0 mb-lg-3">
<i>
<form action="info">
<input type="image" src="/imgs/Tournament/info-icon.png"
width="200px" height="200px" alt="submit">
</form>
</i>
<h3>Get more information about this game</h3>
</div>
</div>
</div>
</div>
</section>

<!-- Image Showcases -->
<section class="showcase">
<div class="container-fluid p-0">
<ng-template ngFor let-elem [ngForOf]="tournaments">
<div class="row no-gutters">
<div class="col-lg-6 text-white showcase-img"
style="background-image: url('/imgs/Tournament/defaultTournament.png');"></div>
<div class="col-lg-6 my-auto showcase-text">
<h2>{{elem.name}} Tournament</h2>
<p class="lead mb-0">{{elem.description}}</p>
<div style="text-align: center">
<!--Aun no está cambiado no se si va aqui el action o en el component.ts-->
<form action="/{{name}}">
<input type="submit" class="button" value="Go to tournament">
<input type="hidden" name="_csrf" value="{{token}}">
</form>
</div>
</div>
</div>
</ng-template>
</div>
</section>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';

import { RocketleagueService } from './rocketleague.service';

import { Tournament } from '../tournament/tournament.model';

@Component({
selector: 'rocketleague',
templateUrl:'./rocketleague.component.html'
})

export class RocketleagueComponent{
tournament: Tournament;

constructor(private rocketleagueService: RocketleagueService){}

tournamentsOnHtml(){
this.rocketleagueService.getTournaments().subscribe(
tournament => {
let tournaments: any = tournament;
},
error => console.error('Error finding tournaments ' + error)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';

import { Tournament } from '../tournament/tournament.model';

const BASE_URL = 'https://127.0.0.1:8443/api/';

@Injectable({ providedIn: 'root' })
export class RocketleagueService{
constructor(private httpClient: HttpClient){}

getTournaments(): Observable<Tournament[]> {
return this.httpClient.get(BASE_URL + './rocketleague.component.html').pipe(
catchError(error => this.handleError(error))
) as Observable<Tournament[]>;
}

private handleError(error: any) {
console.error(error);
return Observable.throw("Server error (" + error.status + "): " + error.text())
}
}
58 changes: 56 additions & 2 deletions Angular/lucia-no-te-enfades-pp/src/app/team.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component } from '@angular/core';

import { TeamsService } from './teams.service';
import { UsersService } from './users.service';
import { PlayersService } from './players.service';

import { Team } from './team.model';
import { Player } from './player.model';
import { User } from './user.model';
Expand All @@ -16,13 +19,64 @@ export class TeamFormComponent {
user2: User;
user3: User;

constructor(private teamsService: TeamsService){}
constructor(private teamsService: TeamsService, private usersService: UsersService, private playersService: PlayersService){}

save() {
this.teamsService.addTeam(this.team).subscribe(
team => { },
team => {
let data: any = team;
let idTeam = data.idTeam;
this.readUser(idTeam);
},
error => console.error('Error creating new Team: ' + error)
);
}

readUser(idTeam: number){
this.usersService.getUserByUserName(this.user1.userName).subscribe(
user => {
let data: any = user;
let idUser = data.idUser;
this.changePlayerTeam(idUser);
},
error => console.error('Error finding user ' + error)
);

this.usersService.getUserByUserName(this.user2.userName).subscribe(
user => {
let data: any = user;
let idUser = data.idUser;
this.changePlayerTeam(idUser);
},
error => console.error('Error finding user ' + error)
);

this.usersService.getUserByUserName(this.user3.userName).subscribe(
user => {
let data: any = user;
let idUser = data.idUser;
this.changePlayerTeam(idUser);
},
error => console.error('Error finding user ' + error)
);
}

changePlayerTeam(idUser: number){
this.playersService.getPlayerByUserId(idUser).subscribe(
player => {
let data: any = player;
let idPlayer = data.idPlayer;
this.changeTeam(idPlayer, data);
},
error => console.error('Error finding player ' + error)
);
}

changeTeam(idPlayer: number, team: Team){
this.playersService.updatePlayerTeam(idPlayer, team).subscribe(
player =>{},
error => console.error('Error updating team ' + error)
);
}

}
2 changes: 1 addition & 1 deletion Angular/lucia-no-te-enfades-pp/src/app/teams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { catchError } from 'rxjs/operators';

import { Team } from './team.model';

const BASE_URL = 'https://127.0.0.1:8443/teams/';
const BASE_URL = 'https://127.0.0.1:8443/api/teams/';

@Injectable({ providedIn: 'root' })
export class TeamsService {
Expand Down
Loading

0 comments on commit 4e151e2

Please sign in to comment.