Fixed paginator and improved edit page to return to the list page and support checkboxes

This commit is contained in:
Norbi Peti 2022-02-05 19:05:24 +01:00
parent bf6e34fd56
commit ed266d440f
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 16 additions and 4 deletions

View file

@ -27,7 +27,7 @@ export class ApiService {
} }
requestItemCount(url: string): Promise<number> { 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> { async logout(): Promise<void> {

View file

@ -1,9 +1,14 @@
<div *ngIf="!isLoading; else loading"> <div *ngIf="!isLoading; else loading">
<form [formGroup]="formGroup"> <form [formGroup]="formGroup">
<mat-form-field *ngFor="let field of fields"> <div *ngFor="let field of fields">
<mat-label>{{ field.title }}</mat-label> <mat-label>{{ field.title }}</mat-label>
<input matInput [formControlName]="field.name" type="text"/> <span [ngSwitch]="getType(item[field.name])">
</mat-form-field> <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> <button mat-raised-button color="primary" (click)="submit()">Mentés</button>
</form> </form>
</div> </div>

View file

@ -36,15 +36,22 @@ export class EditComponent<T extends Model> implements OnInit {
} }
async submit(): Promise<void> { async submit(): Promise<void> {
this.isLoading = true;
try { try {
if (this.item) { if (this.item) {
await this.api.request('patch', this.apiPath + '/' + this.item.id, this.formGroup.value); await this.api.request('patch', this.apiPath + '/' + this.item.id, this.formGroup.value);
} else { } else {
await this.api.request('post', this.apiPath, this.formGroup.value); 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) { } catch (e) {
alert(e); alert(e);
} }
this.isLoading = false;
}
getType(itemElement: any): typeof itemElement {
return typeof itemElement;
} }
} }