Skip to content

Commit

Permalink
Merge pull request #192 from fga-eps-mds/T71
Browse files Browse the repository at this point in the history
T71 - Resgatar Recompensa na página de Evento
  • Loading branch information
Rdadamos committed Jun 23, 2019
2 parents af4f92d + 9ff435a commit 1d9bf3b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ <h5 class="card-title">
<span data-toggle="tooltip" data-placement="top" title="Total de Participantes"><i class="fas fa-users iconColor"></i> 16</span>
</p>
<p class="card-text">
<span class="text-muted d-block">Recompensas:</span>
<i class="fas fa-shield-alt fa-5x m-2" data-toggle="tooltip" data-placement="top" title="50 pontos de experiência"></i>
<i class="fas fa-sticky-note fa-5x m-2" data-toggle="tooltip" data-placement="top" title="Adesivo"></i>
<i class="fas fa-certificate fa-5x m-2" data-toggle="tooltip" data-placement="top" title="Certificado de Participação"></i>
<span class="text-muted d-block">Recompensa:</span>
<img src="{{rwrd_img}}" data-toggle="tooltip" data-placement="top" title={{rwrd_name}}>
</p>
<div *ngIf="currentId !== creatorId">
<a href="#" class="btn btn-primary d-md-block" *ngIf="logged && !participate" (click)="Participar()">Participar</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ActivatedRoute } from '@angular/router';
import { SafeStyle, DomSanitizer } from '@angular/platform-browser';
import { getId } from 'src/app/helpers/id';
import { getToken } from 'src/app/helpers/token';
import { Reward } from '../../models/reward';
import { RewardService } from '../../services/reward.service';


@Component({
Expand All @@ -18,6 +20,10 @@ import { getToken } from 'src/app/helpers/token';
export class EventDetailComponent implements OnInit, OnDestroy {

private sub: any;
rwrd_id: number;
rwrd_img: string;
rwrd_name: string;
reward: Reward;
event: Event;
date: string;
place: string;
Expand All @@ -40,7 +46,7 @@ export class EventDetailComponent implements OnInit, OnDestroy {
player_participating: Array<Player> = [];


constructor(private route: ActivatedRoute, private service: EventService, private playerservice: PlayerService, private sanitization:DomSanitizer) { }
constructor(private route: ActivatedRoute,private rewardservice: RewardService, private service: EventService, private playerservice: PlayerService, private sanitization:DomSanitizer) { }

ngOnInit() {
this.sub = this.route.params.subscribe(params => {
Expand All @@ -53,54 +59,61 @@ export class EventDetailComponent implements OnInit, OnDestroy {
this.description = this.event.description;
this.image = this.sanitization.bypassSecurityTrustStyle(`url(${this.event.url_image})`);
this.creatorId = this.event.creator_id;
this.evento_id = this.event.id
this.evento_id = this.event.id;
this.rwrd_id = this.event.reward_id;
this.rewardservice.getRewardById(this.rwrd_id)
.then((reward: Reward) => {
this.reward = reward;
this.rwrd_name = this.reward.description;
this.rwrd_img = this.reward.badge_url;
}
);
})
.catch(error => console.log(error));
});
});

this.service.getParticipations()
.then((x: Array<Event_Player>) => {
this.participations = x
for(var i = 0; i < this.participations.length; i++){
if(this.participations[i].player_id === this.currentId &&
if (this.participations[i].player_id === this.currentId &&
this.participations[i].evento_id === this.event.id){
this.participate = true;
this.global_id = this.participations[i].id
this.global_id = this.participations[i].id;
}

}

var m = 0;
for(var z = 0; z < this.participations.length; z++){
var m = 0;
for(var z = 0; z < this.participations.length; z++){
if(this.participations[z].evento_id === this.event.id){
this.playerservice.getPlayerid(this.participations[z].player_id)
.then((x: Player) => {
this.player_participating[m] = x;
this.player_participating[m] = x;
m++;
})
});
}
}
})
});

}

Participar(){
Participar() {
const event_player: Event_Player = new Event_Player(
this.evento_id,
this.currentId,
)
);
this.service.participateEvent(event_player)
.then(x => {
console.log(x);
})
});
console.log(event_player);
}

Deletar(){
Deletar() {
this.service.removeParticipation(this.global_id)
.then(x => {
console.log(x);
})
});
}

ngOnDestroy() {
Expand Down
10 changes: 10 additions & 0 deletions front-end/pret-event/src/app/services/reward.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { AngularFireStorage } from '@angular/fire/storage';
import { finalize } from 'rxjs/operators';
import { Reward } from '../models/reward';
import { resolve, reject } from 'q';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -34,6 +35,15 @@ export class RewardService {
)
)

getRewardById = id =>
new Promise((resolve, reject) =>
this.http.get<Reward>(`${this.url}${id}`)
.subscribe(
data => resolve(data),
error => reject(error),
)
)

registerReward = (reward: Reward, file: any) =>
new Promise(resolve => {
this.ref = this.afStorage.ref(reward.title.toString());
Expand Down

0 comments on commit 1d9bf3b

Please sign in to comment.