Skip to content

Commit

Permalink
Updated ResultsComponent
Browse files Browse the repository at this point in the history
Removed Name Input Field and Validator
  • Loading branch information
cstodor committed Apr 15, 2017
1 parent a528d7e commit 3cde35a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
8 changes: 2 additions & 6 deletions ng-src/src/app/components/quiz/results/results.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<div>{{ quizScore }}%</div>
</div>
<div class="register-score">
<form (submit)="registerScore()">
<p>Enter your name to register score:</p>
<label for="name" class="hidden">Name</label>
<input type="text" [(ngModel)]="name" class="name" name="name" placeholder="Enter Your Name">
<button class="btn-register">Register Score</button>
</form>
<p>Register Your Score?</p>
<button (click)="registerScore()" class="btn-register">Yes, Register!</button>
</div>
<div>
<button class="btn-home btn-primary" routerLink="/">BACK TO HOME</button>
Expand Down
22 changes: 9 additions & 13 deletions ng-src/src/app/components/quiz/results/results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit, Output, EventEmitter, OnDestroy } from '@angular/cor
import { Router } from '@angular/router';
// Service
import { QuizService } from '../quiz.service';
import { Auth } from "../../auth/auth.service";

@Component({
selector: 'app-results',
Expand All @@ -12,32 +13,29 @@ export class ResultsComponent implements OnInit {

quizScore: number = null;
@Output() scoreSend = new EventEmitter<number>();
name: String;
profile: any;

constructor(
private _quizService: QuizService,
private router: Router) { }
public _quizService: QuizService,
public router: Router,
public auth: Auth
) { }

ngOnInit() {
// Get Current Score
this.quizScore = this._quizService.score;
this.profile = JSON.parse(localStorage.getItem('profile'));
}

registerScore() {

// result object
const result = {
name: this.name,
name: this.profile.given_name,
score: this.quizScore,
date: new Date()
}

// Name is required!
if (!this._quizService.validateName(result)) {
console.log('Please enter your name!');
return false;
}

// result object registration
this._quizService.registerResult(result).subscribe(data => {
if (data.success) {
Expand All @@ -50,10 +48,9 @@ export class ResultsComponent implements OnInit {
});
}


// Send Score to Quiz Component (parent)
sendScore() {
console.log("sendScore()")
console.log("sendScore()");
this.scoreSend.emit(this.quizScore);
}

Expand All @@ -63,5 +60,4 @@ export class ResultsComponent implements OnInit {
this._quizService.quizDone(false);
}


}

0 comments on commit 3cde35a

Please sign in to comment.