Skip to content

Commit ae9e463

Browse files
Edit Game Last version
Co-authored-by: JavierGasparinMunoz <j.gasparino.2020@alumnos.urjc.es>
1 parent d16472e commit ae9e463

File tree

3 files changed

+58
-79
lines changed

3 files changed

+58
-79
lines changed

code/frontend/src/app/components/games/edit-game.component.html

+33-40
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2 class="mt-0">Game Details</h2>
2626
<!-- Country -->
2727
<p>Categories:</p>
2828
<label class="youplay-select">
29-
<select [(ngModel)]="category" aria-placeholder=this.game.category>
29+
<select [(ngModel)]="game.category" value="game.category">
3030
<option value="">Select Category</option>
3131
<option value="Action">Action</option>
3232
<option value="Adventure">Adventure</option>
@@ -38,7 +38,7 @@ <h2 class="mt-0">Game Details</h2>
3838
<option value="Strategy">Strategy</option>
3939
</select>
4040
</label>
41-
<div class="wrong" [class.display-div]="checkEmpty(category)">
41+
<div class="wrong" [class.display-div]="checkEmpty(game.category)">
4242
<p> Select one category! </p>
4343
</div>
4444
<div class="row">
@@ -47,7 +47,7 @@ <h2 class="mt-0">Game Details</h2>
4747
<div class="youplay-input">
4848
<input [(ngModel)]="game.name" value="game.name" />
4949
</div>
50-
<div class="wrong" [class.display-div]="checkEmpty(name)">
50+
<div class="wrong" [class.display-div]="checkEmpty(game.name)">
5151
<p> The name cant be empty! </p>
5252
</div>
5353
</div>
@@ -57,8 +57,8 @@ <h2 class="mt-0">Game Details</h2>
5757
<input
5858
type="number"
5959
step="0.01"
60-
[(ngModel)]="price"
61-
placeholder=this.game.price
60+
[(ngModel)]="game.price"
61+
value = "game.price"
6262
required
6363
/>
6464
</div>
@@ -71,9 +71,9 @@ <h2 class="mt-0">Game Details</h2>
7171
<div class="col-md-4">
7272
<p>OS:</p>
7373
<div class="youplay-input">
74-
<input type="text" [(ngModel)]="os" placeholder=this.game.os required />
74+
<input type="text" [(ngModel)]="game.os" value = "game.os"/>
7575
</div>
76-
<div class="wrong" [class.display-div]="checkEmpty(os)">
76+
<div class="wrong" [class.display-div]="checkEmpty(game.os)">
7777
<p> The OS cant be empty! </p>
7878
</div>
7979
</div>
@@ -82,21 +82,20 @@ <h2 class="mt-0">Game Details</h2>
8282
<div class="youplay-input">
8383
<input
8484
type="text"
85-
[(ngModel)]="processor"
86-
placeholder=this.game.processor
87-
required
85+
[(ngModel)]="game.processor"
86+
value="game.processor"
8887
/>
8988
</div>
90-
<div class="wrong" [class.display-div]="checkEmpty(processor)">
89+
<div class="wrong" [class.display-div]="checkEmpty(game.processor)">
9190
<p> The processor cant be empty! </p>
9291
</div>
9392
</div>
9493
<div class="col-md-4">
9594
<p>Memory:</p>
9695
<div class="youplay-input">
97-
<input type="text" [(ngModel)]="memory" placeholder=this.game.memory required />
96+
<input type="text" [(ngModel)]="game.memory" value="game.memory" />
9897
</div>
99-
<div class="wrong" [class.display-div]="checkEmpty(memory)">
98+
<div class="wrong" [class.display-div]="checkEmpty(game.memory)">
10099
<p> The Memory cant be empty! </p>
101100
</div>
102101
</div>
@@ -108,12 +107,11 @@ <h2 class="mt-0">Game Details</h2>
108107
<div class="youplay-input">
109108
<input
110109
type="text"
111-
[(ngModel)]="directX"
112-
placeholder=this.game.directX
113-
required
110+
[(ngModel)]="game.directX"
111+
value = "game.directX"
114112
/>
115113
</div>
116-
<div class="wrong" [class.display-div]="checkEmpty(directX)">
114+
<div class="wrong" [class.display-div]="checkEmpty(game.directX)">
117115
<p> The DirectX cant be empty! </p>
118116
</div>
119117
</div>
@@ -122,12 +120,11 @@ <h2 class="mt-0">Game Details</h2>
122120
<div class="youplay-input">
123121
<input
124122
type="text"
125-
[(ngModel)]="network"
126-
placeholder=this.game.network
127-
required
123+
[(ngModel)]="game.network"
124+
value = "game.network"
128125
/>
129126
</div>
130-
<div class="wrong" [class.display-div]="checkEmpty(network)">
127+
<div class="wrong" [class.display-div]="checkEmpty(game.network)">
131128
<p> The network cant be empty! </p>
132129
</div>
133130
</div>
@@ -138,12 +135,11 @@ <h2 class="mt-0">Game Details</h2>
138135
<div class="youplay-input">
139136
<input
140137
type="text"
141-
[(ngModel)]="hardDrive"
142-
placeholder=this.game.hardDrive
143-
required
138+
[(ngModel)]="game.hardDrive"
139+
value = "game.hardDrive"
144140
/>
145141
</div>
146-
<div class="wrong" [class.display-div]="checkEmpty(hardDrive)">
142+
<div class="wrong" [class.display-div]="checkEmpty(game.hardDrive)">
147143
<p> The Hard Drive cant be empty! </p>
148144
</div>
149145
</div>
@@ -152,12 +148,11 @@ <h2 class="mt-0">Game Details</h2>
152148
<div class="youplay-input">
153149
<input
154150
type="text"
155-
[(ngModel)]="soundcard"
156-
placeholder=this.game.soundcard
157-
required
151+
[(ngModel)]="game.soundCard"
152+
value= "game.soundCard"
158153
/>
159154
</div>
160-
<div class="wrong" [class.display-div]="checkEmpty(soundcard)">
155+
<div class="wrong" [class.display-div]="checkEmpty(game.soundCard)">
161156
<p> The Sound Card cant be empty! </p>
162157
</div>
163158
</div>
@@ -168,12 +163,11 @@ <h2 class="mt-0">Game Details</h2>
168163
<div class="youplay-input">
169164
<input
170165
type="text"
171-
[(ngModel)]="graphics"
172-
placeholder=this.game.graphics
173-
required
166+
[(ngModel)]="game.graphics"
167+
value = "game.graphics"
174168
/>
175169
</div>
176-
<div class="wrong" [class.display-div]="checkEmpty(graphics)">
170+
<div class="wrong" [class.display-div]="checkEmpty(game.graphics)">
177171
<p> The Graphic cant be empty! </p>
178172
</div>
179173
</div>
@@ -186,7 +180,7 @@ <h2 class="mt-0">Game Details</h2>
186180
</div></label
187181
>
188182
<div class="imageInput">
189-
<input type="file" id='imageUpload' accept="image/jpeg,image/png" (change)="onFileSelected($event)" required/>
183+
<input type="file" id='imageUpload' accept="image/jpeg,image/png" (change)="onFileSelected($event)"/>
190184
</div>
191185

192186
<label for="imageUploads">
@@ -195,18 +189,17 @@ <h2 class="mt-0">Game Details</h2>
195189
</div></label
196190
>
197191
<div class="imageInput">
198-
<input id='imageUploads'type="file" multiple accept="image/jpeg,image/png" (change)="onFilesSelected($event)" required/>
192+
<input id='imageUploads'type="file" multiple accept="image/jpeg,image/png" (change)="onFilesSelected($event)"/>
199193
</div>
200194
<p>Description:</p>
201195
<div class="youplay-textarea">
202196
<textarea
203-
[(ngModel)]="description"
197+
[(ngModel)]="game.description"
204198
rows="5"
205-
placeholder=this.game.description
206-
required
199+
value="game.description"
207200
></textarea>
208201
</div>
209-
<div class="wrong" [class.display-div]="checkEmpty(description)">
202+
<div class="wrong" [class.display-div]="checkEmpty(game.description)">
210203
<p> The Description cant be empty! </p>
211204
</div>
212205
<!-- /Billing Information -->
@@ -215,7 +208,7 @@ <h2 class="mt-0">Game Details</h2>
215208
</div>
216209
<!-- Order Button -->
217210
<div class="align-right">
218-
<a class="btn btn-default db" (click)="edit($event)">Create Game</a>
211+
<a class="btn btn-default db" (click)="edit($event)">Edit Game</a>
219212
</div>
220213
<!-- /Order Button -->
221214
</div>

code/frontend/src/app/components/games/edit-game.component.ts

+10-21
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,16 @@ import { GameService } from 'src/app/services/game.service';
99
})
1010
export class EditGameComponent implements OnInit {
1111
game: Game;
12-
category:string;
13-
name: string;
14-
price: number;
15-
os: string;
16-
processor: string;
17-
memory: string;
18-
directX: string;
19-
network: string;
20-
hardDrive: string;
21-
soundcard: string;
22-
graphics: string;
23-
imageField: File = null;
24-
imageFields: File[];
25-
description: string;
2612
displayed: boolean = true;
2713

2814
constructor(private gameService: GameService, private router: Router) { }
2915

3016
ngOnInit(): void {
3117
this.gameService.getGameById(+this.router.url.split('/')[2]).subscribe((response) => {
3218
this.game = response.game;
19+
},
20+
(error) => {
21+
this.router.navigate(['error/403']);
3322
}
3423
);
3524
}
@@ -42,7 +31,7 @@ export class EditGameComponent implements OnInit {
4231
}
4332

4433
checkPrice() {
45-
if (typeof this.price === 'number' && !Number.isNaN(this.price) && Number.isFinite(this.price) && this.price % 1 !== 0){
34+
if (typeof this.game.price === 'number' && !Number.isNaN(this.game.price) && Number.isFinite(this.game.price) && this.game.price % 1 !== 0){
4635
return;
4736
}else{
4837
return "Price must be a number";
@@ -51,18 +40,18 @@ export class EditGameComponent implements OnInit {
5140

5241
onFilesSelected(event: any) {
5342
if (event.target.files.length > 0) {
54-
this.imageFields = event.target.files;
43+
this.game.gameplayImages = event.target.files;
5544
}
5645
}
5746

5847
onFileSelected(event: any) {
59-
this.imageField = event.target.files[0];
48+
this.game.titleImage = event.target.files[0];
6049
}
6150

6251
edit(event: any) {
6352
event.preventDefault();
6453

65-
if (!this.checkEmpty(this.name) || !this.checkEmpty(this.category ) || !this.checkEmpty(this.os) || !this.checkEmpty(this.processor) || !this.checkEmpty(this.memory) || !this.checkEmpty(this.directX) || !this.checkEmpty(this.network) || !this.checkEmpty(this.hardDrive) || !this.checkEmpty(this.soundcard) || !this.checkEmpty(this.graphics) || !this.checkEmpty(this.description)) {
54+
if (!this.checkEmpty(this.game.name) || !this.checkEmpty(this.game.category ) || !this.checkEmpty(this.game.os) || !this.checkEmpty(this.game.processor) || !this.checkEmpty(this.game.memory) || !this.checkEmpty(this.game.directX) || !this.checkEmpty(this.game.network) || !this.checkEmpty(this.game.hardDrive) || !this.checkEmpty(this.game.soundCard) || !this.checkEmpty(this.game.graphics) || !this.checkEmpty(this.game.description)) {
6655
this.displayed = false;
6756
return;
6857
}
@@ -72,17 +61,17 @@ export class EditGameComponent implements OnInit {
7261
return;
7362
}
7463

75-
if (this.imageField == null){
64+
if (this.game.titleImage == null){
7665
this.displayed = false;
7766
return;
7867
}
7968

80-
if (this.imageFields == null || this.imageFields.length == 0){
69+
if (this.game.gameplayImages == null || this.game.gameplayImages.length == 0){
8170
this.displayed = false;
8271
return;
8372
}
8473

85-
this.gameService.editGame(this.name, this.category, this.price, this.os, this.processor, this.memory, this.directX, this.network, this.hardDrive, this.soundcard, this.graphics, this.imageField, this.imageFields, this.description).subscribe((response) => {
74+
this.gameService.editGame(this.game).subscribe((response) => {
8675
this.router.navigate(['/game/' + this.game.id]);
8776
},
8877
error => {

code/frontend/src/app/services/game.service.ts

+15-18
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,27 @@ export class GameService {
8787
) as Observable<any>;
8888
}
8989

90-
editGame(name: string, category: string, price: number, os: string, processor: string, memory: string, directX: string, network: string, hardDrive: string, soundcard: string, graphics: string, imageField: File, imageFields: File[], description: string) {
90+
editGame(game: Game) {
9191
const formData = new FormData();
92-
formData.append('name', name);
93-
formData.append('category', category);
94-
formData.append('price', price.toString());
95-
formData.append('os', os);
96-
formData.append('processor', processor);
97-
formData.append('memory', memory);
98-
formData.append('directX', directX);
99-
formData.append('network', network);
100-
formData.append('hardDrive', hardDrive);
101-
formData.append('soundcard', soundcard);
102-
formData.append('graphics', graphics);
103-
formData.append('imageField', imageField);
104-
for (let i = 0; i < imageFields.length; i++) {
105-
formData.append('imageFields', imageFields[i]);
106-
}
107-
formData.append('description', description);
108-
return this.http.put("/api/games/", formData).pipe( map((response: any) => {
92+
formData.append('name', game.name);
93+
formData.append('category', game.category);
94+
formData.append('price', game.price.toString());
95+
formData.append('os', game.os);
96+
formData.append('processor', game.processor);
97+
formData.append('memory', game.memory);
98+
formData.append('directX', game.directX);
99+
formData.append('network', game.network);
100+
formData.append('hardDrive', game.hardDrive);
101+
formData.append('soundcard', game.soundCard);
102+
formData.append('graphics', game.graphics);
103+
formData.append('description', game.description);
104+
return this.http.put("/api/games/" + game.id, formData).pipe( map((response: any) => {
109105
return response;
110106
}),
111107
catchError((error: any) => {
112108
return throwError('Something went wrong');
113109
})
114110
) as Observable<any>;
115111
}
112+
116113
}

0 commit comments

Comments
 (0)