minetest account deletion

This commit is contained in:
_Bastler 2021-08-15 18:41:50 +02:00
parent ffbcd7fe1a
commit d7fb55a661
3 changed files with 57 additions and 25 deletions

View File

@ -8,6 +8,19 @@
{{minetestAccount.name}}
</td>
</ng-container>
<ng-container matColumnDef="delete">
<th mat-header-cell *matHeaderCellDef class="align-right"> {{'minetest.accounts.delete' | i18n}} </th>
<td mat-cell *matCellDef="let minetestAccount" class="text-right">
<a mat-icon-button color="warn">
<mat-icon matTooltip="{{'minetest.accounts.deletion' | i18n}}">warning</mat-icon>
</a>
<a mat-icon-button>
<mat-icon (click)="confirmDelete(minetestAccount.name)">delete</mat-icon>
</a>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="minetestAccountsColumns"></tr>
<tr mat-row *matRowDef="let myRowData; columns: minetestAccountsColumns"></tr>
</table>
@ -26,11 +39,6 @@
{{'minetest.accounts.error.name' | i18n}}
</mat-error>
</mat-form-field>
<mat-card class="warn">
<mat-card-header>
<mat-card-subtitle>{{'minetest.accounts.deletion' | i18n}}</mat-card-subtitle>
</mat-card-header>
</mat-card>
</div>
</mat-card-content>
<mat-card-actions>

View File

@ -1,8 +1,10 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { QuotaService } from '../../../services/quota.service';
import { MinetestAccountsService } from '../../../services/minetest.accounts.service';
import { ConfirmDialog } from '../../../ui/confirm/confirm.component';
@Component({
selector: 'app-minetest-accounts',
@ -19,12 +21,13 @@ export class MinetestAccountsComponent implements OnInit {
success: boolean;
working: boolean;
minetestAccountsColumns = ["name"];
minetestAccountsColumns = [ "name", "delete" ];
constructor(
private quotaService: QuotaService,
private formBuilder: FormBuilder,
private minetestAccountsService: MinetestAccountsService) {}
private minetestAccountsService: MinetestAccountsService,
public dialog: MatDialog) { }
ngOnInit(): void {
@ -32,14 +35,14 @@ export class MinetestAccountsComponent implements OnInit {
name: [ '', Validators.required ],
});
this.update();
this.refresh();
}
create(): void {
this.working = true;
this.minetestAccountsService.create(this.minetestAccount).subscribe(response => {
this.update();
this.refresh();
this.formDirective.resetForm();
this.minetestAccount = {};
this.working = false;
@ -59,7 +62,7 @@ export class MinetestAccountsComponent implements OnInit {
})
}
update() {
refresh() {
this.minetestAccountsQuota = 0;
this.quotaService.quotas().subscribe((data: any) => {
for (let quota of data) {
@ -74,4 +77,21 @@ export class MinetestAccountsComponent implements OnInit {
})
}
confirmDelete(name) {
const dialogRef = this.dialog.open(ConfirmDialog, {
data: {
'label': 'minetest.accounts.confirmDelete',
'args': [ name ]
}
})
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.minetestAccountsService.delete(name).subscribe((result: any) => {
this.refresh();
})
}
});
}
}

View File

@ -19,4 +19,8 @@ export class MinetestAccountsService {
return this.http.post(environment.apiUrl + "/minetest/accounts", minetestAccount);
}
delete(name) {
return this.http.delete(environment.apiUrl + "/minetest/accounts/" + name);
}
}