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}} {{minetestAccount.name}}
</td> </td>
</ng-container> </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-header-row *matHeaderRowDef="minetestAccountsColumns"></tr>
<tr mat-row *matRowDef="let myRowData; columns: minetestAccountsColumns"></tr> <tr mat-row *matRowDef="let myRowData; columns: minetestAccountsColumns"></tr>
</table> </table>
@ -26,11 +39,6 @@
{{'minetest.accounts.error.name' | i18n}} {{'minetest.accounts.error.name' | i18n}}
</mat-error> </mat-error>
</mat-form-field> </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> </div>
</mat-card-content> </mat-card-content>
<mat-card-actions> <mat-card-actions>

View File

@ -1,13 +1,15 @@
import {Component, OnInit, ViewChild} from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import {FormBuilder, FormGroup, Validators, NgForm} from '@angular/forms'; import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import {QuotaService} from '../../../services/quota.service'; import { QuotaService } from '../../../services/quota.service';
import {MinetestAccountsService} from '../../../services/minetest.accounts.service'; import { MinetestAccountsService } from '../../../services/minetest.accounts.service';
import { ConfirmDialog } from '../../../ui/confirm/confirm.component';
@Component({ @Component({
selector: 'app-minetest-accounts', selector: 'app-minetest-accounts',
templateUrl: './accounts.component.html', templateUrl: './accounts.component.html',
styleUrls: ['./accounts.component.scss'] styleUrls: [ './accounts.component.scss' ]
}) })
export class MinetestAccountsComponent implements OnInit { export class MinetestAccountsComponent implements OnInit {
@ -19,53 +21,54 @@ export class MinetestAccountsComponent implements OnInit {
success: boolean; success: boolean;
working: boolean; working: boolean;
minetestAccountsColumns = ["name"]; minetestAccountsColumns = [ "name", "delete" ];
constructor( constructor(
private quotaService: QuotaService, private quotaService: QuotaService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private minetestAccountsService: MinetestAccountsService) {} private minetestAccountsService: MinetestAccountsService,
public dialog: MatDialog) { }
ngOnInit(): void { ngOnInit(): void {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
name: ['', Validators.required], name: [ '', Validators.required ],
}); });
this.update(); this.refresh();
} }
create(): void { create(): void {
this.working = true; this.working = true;
this.minetestAccountsService.create(this.minetestAccount).subscribe(response => { this.minetestAccountsService.create(this.minetestAccount).subscribe(response => {
this.update(); this.refresh();
this.formDirective.resetForm(); this.formDirective.resetForm();
this.minetestAccount = {}; this.minetestAccount = {};
this.working = false; this.working = false;
}, (error) => { }, (error) => {
this.working = false; this.working = false;
if(error.status == 409) { if (error.status == 409) {
let errors = {}; let errors = {};
for(let code of error.error) { for (let code of error.error) {
errors[code.field] = errors[code.field] || {}; errors[ code.field ] = errors[ code.field ] || {};
errors[code.field][code.code] = true; errors[ code.field ][ code.code ] = true;
} }
for(let code in errors) { for (let code in errors) {
this.form.get(code).setErrors(errors[code]); this.form.get(code).setErrors(errors[ code ]);
} }
} }
}) })
} }
update() { refresh() {
this.minetestAccountsQuota = 0; this.minetestAccountsQuota = 0;
this.quotaService.quotas().subscribe((data: any) => { this.quotaService.quotas().subscribe((data: any) => {
for(let quota of data) { for (let quota of data) {
if(quota.name == "minetest_accounts") { if (quota.name == "minetest_accounts") {
this.minetestAccountsQuota = quota.value; this.minetestAccountsQuota = quota.value;
} }
} }
}) })
@ -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); return this.http.post(environment.apiUrl + "/minetest/accounts", minetestAccount);
} }
delete(name) {
return this.http.delete(environment.apiUrl + "/minetest/accounts/" + name);
}
} }