Skip to content
Snippets Groups Projects
Commit a6e24850 authored by alec.schmidt's avatar alec.schmidt
Browse files

frontend refactor done

parent 8dd3a614
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ export type User = {
id: number;
username: string;
password: string;
type: string;
admin: boolean;
};
export type QandA = {
......
......@@ -3,12 +3,12 @@
<table>
<thead>
<th>Username</th>
<th>Type</th>
<th>Admin</th>
</thead>
<tbody>
<tr *ngFor="let user of users">
<td>{{user.username}}</td>
<td>{{user.type}}</td>
<td>{{user.admin}}</td>
<td><button (click)="showUpdateModal(user)">UPDATE</button></td>
<td><button (click)="deleteUser(user)">DELETE</button></td>
</tr>
......
......@@ -53,6 +53,7 @@ export class AdminComponent implements OnInit {
}
showUpdateModal(user: User){
this.modalUpdate = false;
this.userToEdit = user;
this.modalUpdate = true;
}
......
......@@ -4,7 +4,7 @@
<br>
<input type="password" placeholder="Password" formControlName="password">
<br>
<input type="type" placeholder="player" formControlName="type">
<label>Admin</label><input type="checkbox" formControlName="admin">
<br>
<button type="submit">Create</button><button (click)="closeModal.emit()">Close</button>
</form>
\ No newline at end of file
......@@ -19,20 +19,20 @@ export class CreateUserComponent {
this.createUser = new FormGroup({
username: new FormControl('', Validators.required),
password: new FormControl('', Validators.required),
type: new FormControl('player', Validators.required)
admin: new FormControl(false, Validators.required)
});
}
onSubmit() {
const username = this.createUser.get("username")!.value;
const password = this.createUser.get("password")!.value;
const type = this.createUser.get("type")!.value;
const type = this.createUser.get("admin")!.value;
const user: User = {
id: undefined,
username : username,
password: password,
type: type
admin: type
}
this.userController.addUserAdmin(user);
......
......@@ -59,7 +59,7 @@ export class AuthenticationService {
if (user === null)
return false;
return user.type === 'admin';
return user.admin;
}
getUsername(): string {
......
......@@ -30,7 +30,7 @@ export class SignupComponent {
onSubmit(): void {
const user: User = {
id: undefined,
type: undefined,
admin: undefined,
username: this.signupForm.get('username')!.value,
password: this.signupForm.get('password')!.value
}
......
......@@ -2,7 +2,7 @@
<form [formGroup]="updateUser" (ngSubmit)="onSubmit()">
<input type="text" formControlName="username">
<br>
<input type="text" formControlName="type">
<label>Admin</label><input type="checkbox" formControlName="admin">
<br>
<button type="submit">Update</button><button (click)="closeModal.emit();">Close</button>
</form>
\ No newline at end of file
......@@ -20,19 +20,20 @@ export class UpdateUserComponent implements OnInit {
ngOnInit(): void {
this.updateUser = new FormGroup({
username: new FormControl(this.user.username, Validators.required),
type: new FormControl(this.user.type, Validators.required)
admin: new FormControl(this.user.admin, Validators.required)
});
}
onSubmit() {
const username = this.updateUser.get("username")!.value;
const type = this.updateUser.get("type")!.value;
const type = this.updateUser.get("admin")!.value;
const userToEdit: User = {
id: this.user.id,
username : username,
password: undefined,
type: type
admin: type
}
this.userController.updateUser(userToEdit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment