Skip to content

Commit ccd80b3

Browse files
committed
found the problem with ngBuild:
angular/devkit#816
1 parent 68a0f93 commit ccd80b3

File tree

6 files changed

+48
-37
lines changed

6 files changed

+48
-37
lines changed

src/app/auth/auth.service.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class AuthService {
1515
// Kald der skal ske når man kommer in på siden, her skal den logge dig ud automatisk, hvis din session er udløbet
1616
const token = localStorage.getItem('token');
1717
if ( token !== null) {
18-
this.validate2(token).subscribe(() => {}, (error: HttpErrorResponse) => {
18+
this.validate(token).subscribe(() => {}, (error: HttpErrorResponse) => {
1919
console.log(error);
2020
if (error.status === 401) {
2121
this.loggedIn = false;
@@ -65,23 +65,6 @@ export class AuthService {
6565
}
6666
);
6767
}
68-
validate2(stringtoken: string): Observable <any> {
69-
if (stringtoken.length < 1 || stringtoken === null) { return; }
70-
let token;
71-
try {
72-
token = JSON.parse(stringtoken).access_token;
73-
} catch (e) {
74-
console.log(e);
75-
}
76-
const body = new HttpParams()
77-
.set('authorization', token);
78-
return this.http.post('https://www.localghost.dk/hangman/oauth/validate',
79-
body.toString(),
80-
{
81-
headers: new HttpHeaders().set('Authorization', 'Bearer ' + token)
82-
}
83-
);
84-
}
8568
logoutRemoveToken() {
8669
localStorage.removeItem('token');
8770
this.loggedIn = false;

src/app/auth/header/header.component.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ export class HeaderComponent implements OnInit, OnDestroy {
1818
isModalShown: boolean;
1919
tokenSubscription: Subscription;
2020
// laver en observable til at tjekke den token vi bruger, det skal bruges i setName i denne klasse.
21-
observeToken;
21+
observeToken$;
2222
ngOnInit(): void {
2323
this.isModalShown = false;
24-
this.observeToken = new Observable((observer) => {
24+
this.observeToken$ = new Observable((observer) => {
2525
observer.next(localStorage.getItem('token'));
2626
observer.complete();
2727
});
2828
// Når man har været på siden i et stykke tid, her vil den automatisk vise en modal, som logger dig ud ved klik.
2929
this.tokenSubscription = TimerObservable.create(9000, 10000).subscribe(() => {
3030
const token = localStorage.getItem('token');
3131
if (token !== null) {
32-
this.auth.validate2(token).subscribe(() => {}, (error: HttpErrorResponse) => {
32+
this.auth.validate(token).subscribe(() => {}, (error: HttpErrorResponse) => {
3333
console.log(error);
3434
if (error.status === 401 && this.auth.loggedIn) {
3535
this.showModal();
@@ -54,7 +54,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
5454
setName() {
5555
if (this.auth.loggedIn) {
5656
// sætter name property til at være JSON objectets first name
57-
this.observeToken.subscribe((res: string) => {
57+
this.observeToken$.subscribe((res: string) => {
5858
const tokenObj = JSON.parse(res);
5959
this.name = tokenObj.user.firstname;
6060
});

src/app/core/game-server.service.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Injectable} from '@angular/core';
22
import {HttpClient, HttpHeaders} from '@angular/common/http';
33
import {map} from 'rxjs/operators';
4+
import {GameModel} from '../shared/game.model';
45

56
// Overvej at bruge intercepter
67

@@ -11,7 +12,7 @@ export class GameServerService {
1112
getHighscores() {
1213
return this.http.get('https://www.localghost.dk/hangman/api/hangman/highscores'
1314
).pipe(
14-
map((res: Response) => {
15+
map((res: GameModel) => {
1516
return res;
1617
})
1718
);
@@ -21,7 +22,7 @@ export class GameServerService {
2122
return this.http.get('https://www.localghost.dk/hangman/api/hangman/game',
2223
{headers: new HttpHeaders().set('Authorization', 'Bearer ' + token)}
2324
).pipe(
24-
map((res: Response) => {
25+
map((res: GameModel) => {
2526
return res;
2627
})
2728
);
@@ -31,7 +32,7 @@ export class GameServerService {
3132
return this.http.post('https://www.localghost.dk/hangman/api/hangman/game', null,
3233
{headers: new HttpHeaders().set('Authorization', 'Bearer ' + token)}
3334
).pipe(
34-
map((res: Response) => {
35+
map((res: GameModel) => {
3536
return res;
3637
})
3738
);
@@ -41,7 +42,7 @@ export class GameServerService {
4142
return this.http.put('https://www.localghost.dk/hangman/api/hangman/game', null,
4243
{headers: new HttpHeaders().set('Authorization', 'Bearer ' + token)}
4344
).pipe(
44-
map((res: Response) => {
45+
map((res: GameModel) => {
4546
return res;
4647
})
4748
);
@@ -51,7 +52,7 @@ export class GameServerService {
5152
return this.http.post('https://www.localghost.dk/hangman/api/hangman/guess/' + letter, null,
5253
{headers: new HttpHeaders().set('Authorization', 'Bearer ' + token)}
5354
).pipe(
54-
map((res: Response) => {
55+
map((res: GameModel) => {
5556
return res;
5657
})
5758
);

src/app/core/game/game.component.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
</div>
77
<hr>
88
<div *ngIf="game.hasGameBegun || game.gameHasBeenWon || game.gameHasBeenLost">
9-
<p><span class="word-description">{{game.wordExampleBefore}}</span> <span class="word">{{game.visibleWord}}</span> <span class="word-description">{{game.wordExampleAfter}}</span></p>
9+
<p><span class="word-description">{{game.wordExampleBefore}}</span>
10+
<span class="word" *ngIf="game.hasGameBegun">{{game.visibleWord}}</span>
11+
<span class="word" *ngIf="game.gameHasBeenWon || game.gameHasBeenLost">{{game.finalGuessWord}}</span>
12+
<span class="word-description">{{game.wordExampleAfter}}</span></p>
1013
<p class="word-description" style="font-style: italic" *ngIf="game.wordDefinition?.length">{{'Definition: '+game.wordDefinition}}</p>
1114
<p style="font-style: italic">
1215
<span *ngIf="game.wordSynonyms.length>0">Synonyms: </span>
13-
<span *ngFor="let synonym of game.wordSynonyms">{{synonym+ ', '}}</span>
16+
<span *ngFor="let synonym of game.wordSynonyms; let i = index">{{synonym}}<span *ngIf="i<game.wordSynonyms.length-1">, </span></span>
1417
</p>
1518
</div>
1619
<div>

src/app/core/game/game.component.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {HttpErrorResponse} from '@angular/common/http';
33
import {Router} from '@angular/router';
44
import {ToastrService} from 'ngx-toastr';
55
import {GameServerService} from '../game-server.service';
6+
import {GameModel} from '../../shared/game.model';
67

78
@Component({
89
selector: 'app-game',
@@ -19,7 +20,7 @@ export class GameComponent implements OnInit {
1920
buttonLetters: string[];
2021
images: string[];
2122
letters: string[];
22-
game: any;
23+
game: GameModel;
2324
constructor(private serverService: GameServerService, private router: Router, private toastr: ToastrService) {}
2425
ngOnInit() {
2526
this.loading = false;
@@ -32,7 +33,7 @@ export class GameComponent implements OnInit {
3233
, './assets/GRAFIK/forkert5.png', './assets/GRAFIK/forkert6.png'];
3334
this.letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
3435
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
35-
this.game = <any>{
36+
this.game = {
3637
gameHasBeenLost: false,
3738
gameHasBeenWon: false,
3839
hasGameBegun: false,
@@ -54,7 +55,7 @@ export class GameComponent implements OnInit {
5455
newGame() {
5556
this.loading = true;
5657
this.serverService.getGame().subscribe(
57-
(response: Response) => {
58+
response => {
5859
this.loading = false;
5960
this.game = response;
6061
this.toastr.success('Previous game loaded.');
@@ -72,7 +73,7 @@ export class GameComponent implements OnInit {
7273
this.sessionExpired = true;
7374
} else if (error.status !== 400) {this.toastr.error('An error occurred, check the console'); console.log(error); } else {
7475
this.serverService.restartGame().subscribe(
75-
(restartResponse: Response) => {
76+
(restartResponse: GameModel) => {
7677
console.log('This is a restart response:');
7778
this.game = restartResponse;
7879
console.log(restartResponse);
@@ -91,7 +92,7 @@ export class GameComponent implements OnInit {
9192
onStartGameClicked() {
9293
this.loading = true;
9394
this.serverService.startGame().subscribe(
94-
(response: Response) => {
95+
response => {
9596
this.game = response;
9697
this.gameStatus = 'You can start guessing the new game now!';
9798
this.greenText = '';
@@ -101,7 +102,7 @@ export class GameComponent implements OnInit {
101102
console.log(error.status.toString());
102103
console.log(error.error.error_message);
103104
this.serverService.restartGame().subscribe(
104-
(restartResponse: Response) => {
105+
(restartResponse: GameModel) => {
105106
console.log('This is a restart response:');
106107
this.game = restartResponse;
107108
this.loading = false;
@@ -117,13 +118,18 @@ export class GameComponent implements OnInit {
117118
}
118119
onLetterClick(letter: string) {
119120
this.game.usedLetters.push(letter);
120-
this.serverService.guessLetter(letter).subscribe((res: Response) => {
121-
this.game = res;
121+
this.serverService.guessLetter(letter).subscribe(res => {
122+
this.game.visibleWord = res.visibleWord;
123+
this.game.gameHasBeenLost = res.gameHasBeenLost;
124+
this.game.gameHasBeenWon = res.gameHasBeenWon;
125+
this.game.lastGuessedLetterIsCorrect = res.lastGuessedLetterIsCorrect;
122126
if (this.game.gameHasBeenLost) {
127+
this.game = res;
123128
this.greenText = '';
124129
this.redText = 'You have lost, ';
125130
this.gameStatus = 'try again';
126131
} else if (this.game.gameHasBeenWon) {
132+
this.game = res;
127133
this.redText = '';
128134
this.greenText = 'Great job, ';
129135
this.gameStatus = 'you won the game!';

src/app/shared/game.model.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface GameModel {
2+
gameHasBeenLost: boolean;
3+
gameHasBeenWon: boolean;
4+
hasGameBegun: boolean;
5+
isGameOver: boolean;
6+
lastGuessedLetterIsCorrect: boolean;
7+
score: number;
8+
time: string;
9+
usedLetters: string[];
10+
visibleWord: string;
11+
wrongLettersCount: number;
12+
finalGuessWord: string;
13+
wordExampleBefore: string;
14+
wordExampleAfter: string;
15+
wordDefinition: string;
16+
wordSynonyms: string;
17+
18+
}

0 commit comments

Comments
 (0)