This commit is contained in:
jonaswinkler
2021-01-04 00:38:29 +01:00
parent e07128a145
commit 111ed38cce
4 changed files with 31 additions and 4 deletions

View File

@@ -1,8 +1,14 @@
<div class="form-group">
<label [for]="inputId">{{title}}</label>
<input type="number" class="form-control" [class.is-invalid]="error" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)">
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
<div class="input-group" [class.is-invalid]="error">
<input type="number" class="form-control" [id]="inputId" [(ngModel)]="value" (change)="onChange(value)" [class.is-invalid]="error">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-addon1" (click)="nextAsn()" [disabled]="value">+1</button>
</div>
</div>
<div class="invalid-feedback">
{{error}}
</div>
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
</div>

View File

@@ -1,5 +1,7 @@
import { Component, forwardRef } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { FILTER_ASN_ISNULL } from 'src/app/data/filter-rule-type';
import { DocumentService } from 'src/app/services/rest/document.service';
import { AbstractInputComponent } from '../abstract-input';
@Component({
@@ -14,8 +16,24 @@ import { AbstractInputComponent } from '../abstract-input';
})
export class NumberComponent extends AbstractInputComponent<number> {
constructor() {
constructor(private documentService: DocumentService) {
super()
}
nextAsn() {
if (this.value) {
return
}
this.documentService.listFiltered(1, 1, "archive_serial_number", true, [{rule_type: FILTER_ASN_ISNULL, value: "false"}]).subscribe(
results => {
if (results.count > 0) {
this.value = results.results[0].archive_serial_number + 1
} else {
this.value + 1
}
this.onChange(this.value)
}
)
}
}