edit and delete changes
This commit is contained in:
@@ -49,7 +49,7 @@
|
|||||||
<div class="overlay" [style.display]="showUserForm ? 'block' : 'none'">
|
<div class="overlay" [style.display]="showUserForm ? 'block' : 'none'">
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2>{{translations.addUserButton}}</h2>
|
<h2>{{translations.addUserButton}}</h2>
|
||||||
<form (submit)="addUser(newUser.username, newUser.password)">
|
<form (submit)="formUser(newUser.username, newUser.password)">
|
||||||
<div>
|
<div>
|
||||||
<label for="username">{{translations.username}}:</label>
|
<label for="username">{{translations.username}}:</label>
|
||||||
<input type="text" id="username" name="username" [(ngModel)]="newUser.username">
|
<input type="text" id="username" name="username" [(ngModel)]="newUser.username">
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<td>{{ location.lon }}</td>
|
<td>{{ location.lon }}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-container">
|
<div class="btn-container">
|
||||||
<button class="edit" (click)="editLocation(location)">
|
<button class="edit" (click)="openEditLocationForm(location)">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
class="w-6 h-6">
|
class="w-6 h-6">
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
<div class="overlay" [style.display]="showLocationForm ? 'block' : 'none'">
|
<div class="overlay" [style.display]="showLocationForm ? 'block' : 'none'">
|
||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2>{{translations.addLocationButton}}</h2>
|
<h2>{{translations.addLocationButton}}</h2>
|
||||||
<form (submit)="addLocation(newLocation.location, newLocation.region, newLocation.lat ,newLocation.lon)">
|
<form (submit)="formLocation(newLocation.location, newLocation.region, newLocation.lat ,newLocation.lon)">
|
||||||
<div>
|
<div>
|
||||||
<label for="location">{{translations.location}}:</label>
|
<label for="location">{{translations.location}}:</label>
|
||||||
<input type="text" id="location" name="location" [(ngModel)]="newLocation.location">
|
<input type="text" id="location" name="location" [(ngModel)]="newLocation.location">
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
<div class="form-container">
|
<div class="form-container">
|
||||||
<h2>{{translations.addWaypointButton}}</h2>
|
<h2>{{translations.addWaypointButton}}</h2>
|
||||||
<form
|
<form
|
||||||
(submit)="addWaypoint(newWaypoint.name, newWaypoint.lat, newWaypoint.lon, newWaypoint.description, newWaypoint.img, newWaypoint.locationName)">
|
(submit)="formWaypoint(newWaypoint.name, newWaypoint.lat, newWaypoint.lon, newWaypoint.description, newWaypoint.img, newWaypoint.locationName)">
|
||||||
<div>
|
<div>
|
||||||
<label for="waypointName">{{translations.name}}:</label>
|
<label for="waypointName">{{translations.name}}:</label>
|
||||||
<input type="text" id="waypointName" name="waypointName" [(ngModel)]="newWaypoint.name">
|
<input type="text" id="waypointName" name="waypointName" [(ngModel)]="newWaypoint.name">
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export class ManagementComponent implements OnInit {
|
|||||||
showUserForm: boolean = false;
|
showUserForm: boolean = false;
|
||||||
showLocationForm: boolean = false;
|
showLocationForm: boolean = false;
|
||||||
showWaypointForm: boolean = false;
|
showWaypointForm: boolean = false;
|
||||||
|
edit: boolean = false;
|
||||||
|
id: number = 0;
|
||||||
|
|
||||||
newUser: newUser = {password: "", username: ""};
|
newUser: newUser = {password: "", username: ""};
|
||||||
newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""};
|
newLocation: LocationEntity = {location: "", lat: 0, lon: 0, region: ""};
|
||||||
@@ -70,12 +72,50 @@ export class ManagementComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formUser(username: string, password: string) {
|
||||||
|
if (this.edit) {
|
||||||
|
const user: UserEntity = {id: this.id, username: username, password: password};
|
||||||
|
this.editUser(user);
|
||||||
|
this.edit = false;
|
||||||
|
} else {
|
||||||
|
this.addUser(username, password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formLocation(name: string, region: string, lat: number, lon: number) {
|
||||||
|
if (this.edit) {
|
||||||
|
const location: LocationEntity = {location: name, region: region, lat: lat, lon: lon};
|
||||||
|
this.editLocation(location);
|
||||||
|
this.edit = false;
|
||||||
|
} else {
|
||||||
|
this.addLocation(name, region, lat, lon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) {
|
||||||
|
if (this.edit) {
|
||||||
|
const waypoint: WaypointsEntity = {
|
||||||
|
id: this.id,
|
||||||
|
name: name,
|
||||||
|
lat: lat,
|
||||||
|
lon: lon,
|
||||||
|
description: description,
|
||||||
|
img: image,
|
||||||
|
locationName: locationName
|
||||||
|
};
|
||||||
|
this.editWaypoint(waypoint);
|
||||||
|
this.edit = false;
|
||||||
|
} else {
|
||||||
|
this.addWaypoint(name, lat, lon, description, image, locationName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addUser(username: string, password: string) {
|
addUser(username: string, password: string) {
|
||||||
this.newUser = {username: username, password: password};
|
this.newUser = {username: username, password: password};
|
||||||
this.userService.createUser(this.newUser).subscribe(user => {
|
this.userService.createUser(this.newUser).subscribe(user => {
|
||||||
this.users?.push(user);
|
this.users?.push(user);
|
||||||
});
|
});
|
||||||
this.showUserForm = false;
|
this.closeUserForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
addLocation(name: string, region: string, lat: number, lon: number) {
|
addLocation(name: string, region: string, lat: number, lon: number) {
|
||||||
@@ -85,7 +125,7 @@ export class ManagementComponent implements OnInit {
|
|||||||
this.locationService.createLocation(this.newLocation).subscribe(location => {
|
this.locationService.createLocation(this.newLocation).subscribe(location => {
|
||||||
this.locations?.push(location);
|
this.locations?.push(location);
|
||||||
});
|
});
|
||||||
this.showLocationForm = false;
|
this.closeLocationForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
addWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) {
|
addWaypoint(name: string, lat: number, lon: number, description: string, image: string, locationName: string) {
|
||||||
@@ -100,7 +140,7 @@ export class ManagementComponent implements OnInit {
|
|||||||
this.waypointService.createWaypoint(this.newWaypoint).subscribe(waypoint => {
|
this.waypointService.createWaypoint(this.newWaypoint).subscribe(waypoint => {
|
||||||
this.waypoints?.push(waypoint);
|
this.waypoints?.push(waypoint);
|
||||||
});
|
});
|
||||||
this.showWaypointForm = false;
|
this.closeWaypointForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteLocation(location: string) {
|
deleteLocation(location: string) {
|
||||||
@@ -141,16 +181,21 @@ export class ManagementComponent implements OnInit {
|
|||||||
|
|
||||||
openEditLocationForm(location: LocationEntity) {
|
openEditLocationForm(location: LocationEntity) {
|
||||||
this.newLocation = location;
|
this.newLocation = location;
|
||||||
|
this.edit = true;
|
||||||
this.showLocationForm = true;
|
this.showLocationForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
openEditWaypointForm(waypoint: WaypointsEntity) {
|
openEditWaypointForm(waypoint: WaypointsEntity) {
|
||||||
this.newWaypoint = waypoint;
|
this.newWaypoint = waypoint;
|
||||||
|
this.id = waypoint.id;
|
||||||
|
this.edit = true;
|
||||||
this.showWaypointForm = true;
|
this.showWaypointForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
openEditUserForm(user: UserEntity) {
|
openEditUserForm(user: UserEntity) {
|
||||||
this.newUser = user;
|
this.newUser = user;
|
||||||
|
this.id = user.id;
|
||||||
|
this.edit = true;
|
||||||
this.showUserForm = true;
|
this.showUserForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,23 +203,26 @@ export class ManagementComponent implements OnInit {
|
|||||||
this.showUserForm = true;
|
this.showUserForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeUserForm() {
|
openWaypointForm() {
|
||||||
this.showUserForm = false;
|
this.showWaypointForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
openLocationForm() {
|
openLocationForm() {
|
||||||
this.showLocationForm = true;
|
this.showLocationForm = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
closeLocationForm() {
|
closeUserForm() {
|
||||||
this.showLocationForm = false;
|
this.showUserForm = false;
|
||||||
|
this.newUser = {username: '', password: ''};
|
||||||
}
|
}
|
||||||
|
|
||||||
openWaypointForm() {
|
closeLocationForm() {
|
||||||
this.showWaypointForm = true;
|
this.showLocationForm = false;
|
||||||
|
this.newLocation = {location: '', region: '', lat: 0, lon: 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
closeWaypointForm() {
|
closeWaypointForm() {
|
||||||
this.showWaypointForm = false;
|
this.showWaypointForm = false;
|
||||||
|
this.newWaypoint = {description: "", img: "", lat: 0, locationName: "", lon: 0, name: ""};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateUser(user: UserEntity, id: number) {
|
updateUser(user: UserEntity, id: number) {
|
||||||
return this.http.put<UserEntity>(USER + id, user);
|
return this.http.put<UserEntity>(USER + "/"+id, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteUser(id: number) {
|
deleteUser(id: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user