minetest account deletion
This commit is contained in:
parent
ffbcd7fe1a
commit
d7fb55a661
@ -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>
|
||||
|
@ -1,13 +1,15 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, Validators, NgForm} from '@angular/forms';
|
||||
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 { QuotaService } from '../../../services/quota.service';
|
||||
import { MinetestAccountsService } from '../../../services/minetest.accounts.service';
|
||||
import { ConfirmDialog } from '../../../ui/confirm/confirm.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-minetest-accounts',
|
||||
templateUrl: './accounts.component.html',
|
||||
styleUrls: ['./accounts.component.scss']
|
||||
styleUrls: [ './accounts.component.scss' ]
|
||||
})
|
||||
export class MinetestAccountsComponent implements OnInit {
|
||||
|
||||
@ -19,53 +21,54 @@ 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 {
|
||||
|
||||
this.form = this.formBuilder.group({
|
||||
name: ['', Validators.required],
|
||||
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;
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if(error.status == 409) {
|
||||
if (error.status == 409) {
|
||||
let errors = {};
|
||||
for(let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
}
|
||||
|
||||
for(let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
update() {
|
||||
refresh() {
|
||||
this.minetestAccountsQuota = 0;
|
||||
this.quotaService.quotas().subscribe((data: any) => {
|
||||
for(let quota of data) {
|
||||
if(quota.name == "minetest_accounts") {
|
||||
for (let quota of data) {
|
||||
if (quota.name == "minetest_accounts") {
|
||||
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();
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user