Fixed paginator and improved edit page to return to the list page and support checkboxes
This commit is contained in:
parent
bf6e34fd56
commit
ed266d440f
3 changed files with 16 additions and 4 deletions
|
@ -27,7 +27,7 @@ export class ApiService {
|
|||
}
|
||||
|
||||
requestItemCount(url: string): Promise<number> {
|
||||
return this.request('get', url + '/count', {});
|
||||
return this.request('get', url + '/count', {}).then(count => count.count);
|
||||
}
|
||||
|
||||
async logout(): Promise<void> {
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
<div *ngIf="!isLoading; else loading">
|
||||
<form [formGroup]="formGroup">
|
||||
<mat-form-field *ngFor="let field of fields">
|
||||
<div *ngFor="let field of fields">
|
||||
<mat-label>{{ field.title }}</mat-label>
|
||||
<input matInput [formControlName]="field.name" type="text"/>
|
||||
<span [ngSwitch]="getType(item[field.name])">
|
||||
<span *ngSwitchCase="'boolean'"><mat-checkbox [checked]="item[field.name]" [formControlName]="field.name"></mat-checkbox></span>
|
||||
<mat-form-field *ngSwitchDefault>
|
||||
<input matInput [formControlName]="field.name" type="text" [value]="item[field.name]"/>
|
||||
</mat-form-field>
|
||||
</span>
|
||||
</div>
|
||||
<button mat-raised-button color="primary" (click)="submit()">Mentés</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -36,15 +36,22 @@ export class EditComponent<T extends Model> implements OnInit {
|
|||
}
|
||||
|
||||
async submit(): Promise<void> {
|
||||
this.isLoading = true;
|
||||
try {
|
||||
if (this.item) {
|
||||
await this.api.request('patch', this.apiPath + '/' + this.item.id, this.formGroup.value);
|
||||
} else {
|
||||
await this.api.request('post', this.apiPath, this.formGroup.value);
|
||||
}
|
||||
await this.router.navigateByUrl(this.router.url.substring(0, this.router.url.lastIndexOf('/')));
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
}
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
||||
getType(itemElement: any): typeof itemElement {
|
||||
return typeof itemElement;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue