insert manually reference changes

This commit is contained in:
amentis 2024-04-30 12:39:01 +03:00
parent 683552707f
commit f0f4319721
9 changed files with 76 additions and 55 deletions

View File

@ -847,6 +847,7 @@ public class DescriptionServiceImpl implements DescriptionService {
newReference.setId(UUID.randomUUID()); newReference.setId(UUID.randomUUID());
newReference.setDescriptionId(newDescription.getId()); newReference.setDescriptionId(newDescription.getId());
newReference.setReferenceId(descriptionReference.getReferenceId()); newReference.setReferenceId(descriptionReference.getReferenceId());
newReference.setData(descriptionReference.getData());
newReference.setCreatedAt(Instant.now()); newReference.setCreatedAt(Instant.now());
newReference.setUpdatedAt(Instant.now()); newReference.setUpdatedAt(Instant.now());
newReference.setIsActive(IsActive.Active); newReference.setIsActive(IsActive.Active);

View File

@ -23,4 +23,6 @@ public interface ReferenceService {
void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException; void deleteAndSave(UUID id) throws MyForbiddenException, InvalidApplicationException;
List<Reference> searchReferenceData(ReferenceSearchLookup lookup) throws MyNotFoundException, InvalidApplicationException; List<Reference> searchReferenceData(ReferenceSearchLookup lookup) throws MyNotFoundException, InvalidApplicationException;
Boolean findReference(String reference, UUID referenceTypeId);
} }

View File

@ -159,6 +159,14 @@ public class ReferenceServiceImpl implements ReferenceService {
this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id)); this.deleterFactory.deleter(ReferenceDeleter.class).deleteAndSaveByIds(List.of(id));
} }
public Boolean findReference(String reference, UUID referenceTypeId){
if (this.conventionService.isNullOrEmpty(reference) || !this.conventionService.isValidGuid(referenceTypeId)) return false;
ReferenceQuery query = this.queryFactory.query(ReferenceQuery.class).references(reference).typeIds(referenceTypeId).isActive(IsActive.Active);
if (query != null && query.count() > 0) return true;
return false;
}
@Override @Override
public List<Reference> searchReferenceData(ReferenceSearchLookup lookup) throws MyNotFoundException, InvalidApplicationException { public List<Reference> searchReferenceData(ReferenceSearchLookup lookup) throws MyNotFoundException, InvalidApplicationException {
int initialOffset = 0; int initialOffset = 0;

View File

@ -105,6 +105,19 @@ public class ReferenceController {
return references; return references;
} }
@GetMapping("find/{referenceTypeId}")
public Boolean findReference(@PathVariable("referenceTypeId") UUID referenceTypeId, @RequestParam("reference") String reference) throws MyNotFoundException {
logger.debug("search with db definition {}", Reference.class.getSimpleName());
this.censorFactory.censor(ReferenceCensor.class).censor(null, null);
Boolean result = this.referenceService.findReference(reference, referenceTypeId);
this.auditService.track(AuditableAction.Reference_Query, "reference", reference);
return result;
}
@GetMapping("{id}") @GetMapping("{id}")
public Reference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException { public Reference get(@PathVariable("id") UUID id, FieldSet fieldSet) throws MyApplicationException, MyForbiddenException, MyNotFoundException {
logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id).And("fields", fieldSet)); logger.debug(new MapLogEntry("retrieving" + Reference.class.getSimpleName()).And("id", id).And("fields", fieldSet));

View File

@ -46,6 +46,14 @@ export class ReferenceService {
return this.http.post<Reference[]>(url, q).pipe(catchError((error: any) => throwError(error))); return this.http.post<Reference[]>(url, q).pipe(catchError((error: any) => throwError(error)));
} }
findReference(reference: string, referenceTypeId: Guid): Observable<Boolean> {
const url = `${this.apiBase}/find/${referenceTypeId}`;
const options = { params: { reference: reference } };
return this.http.get<Boolean>(url, options).pipe(catchError((error: any) => throwError(error)));
}
getSingle(id: Guid, reqFields: string[] = []): Observable<Reference> { getSingle(id: Guid, reqFields: string[] = []): Observable<Reference> {
const url = `${this.apiBase}/${id}`; const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } }; const options = { params: { f: reqFields } };

View File

@ -149,7 +149,7 @@
[hidden]="this.step === 0" [hidden]="this.step === 0"
[linkToScroll]="linkToScroll" [linkToScroll]="linkToScroll"
[validationErrorModel]="editorModel.validationErrorModel" [validationErrorModel]="editorModel.validationErrorModel"
[isNew]="isNew" [isNew]="isNew || isCopy"
(fieldsetFocusChange)="fieldsetIdWithFocus = $event" (fieldsetFocusChange)="fieldsetIdWithFocus = $event"
></app-description-form> ></app-description-form>
</div> </div>

View File

@ -11,12 +11,12 @@
<div mat-dialog-content class="row"> <div mat-dialog-content class="row">
<div *ngFor="let field of systemFields;"> <div *ngFor="let field of systemFields;">
<div class="col-12"> <div class="col-12">
<mat-form-field class="w-100"> <mat-form-field class="w-100" *ngIf="formGroup.get(field)">
<mat-label>{{field}}</mat-label> <mat-label>{{field}}</mat-label>
<input matInput type="text" [name]="field" [formControl]="formGroup.get(field)"> <input matInput type="text" [name]="field" [formControl]="formGroup.get(field)">
<i matSuffix class="fa fa-spinner fa-spin" *ngIf="field == systemFields[0] && formGroup.get(field).pending && !referenceExists"></i> <i matSuffix class="fa fa-spinner fa-spin" *ngIf="field == systemFields[0] && formGroup.get(field).pending && !referenceExists"></i>
<mat-icon *ngIf="field == systemFields[0] && !formGroup.get(field).pending && formGroup.get(field).dirty && formGroup.get(field).valid && !referenceExists" class="text-success" matSuffix>check</mat-icon> <mat-icon *ngIf="field == systemFields[0] && !formGroup.get(field).pending && formGroup.get(field).dirty && formGroup.get(field).valid && !referenceExists" class="text-success" matSuffix>check</mat-icon>
<mat-icon *ngIf="field == systemFields[0] && !formGroup.get(field).pending && formGroup.get(field).dirty && formGroup.get(field).invalid || referenceExists" class="text-danger" matSuffix>clear</mat-icon> <mat-icon *ngIf="field == systemFields[0] && !formGroup.get(field).pending && formGroup.get(field).dirty && (formGroup.get(field).invalid || referenceExists)" class="text-danger" matSuffix>clear</mat-icon>
<small *ngIf="field == systemFields[0] && referenceExists" class="text-danger">{{'REFERENCE-FIELD.REFERENCE-DIALOG-EDITOR.IDENTIFIER-EXISTS' | translate}}</small> <small *ngIf="field == systemFields[0] && referenceExists" class="text-danger">{{'REFERENCE-FIELD.REFERENCE-DIALOG-EDITOR.IDENTIFIER-EXISTS' | translate}}</small>
<mat-error *ngIf="formGroup.get(field).hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="formGroup.get(field).hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
@ -37,7 +37,7 @@
</div> </div>
<div mat-dialog-actions class="row"> <div mat-dialog-actions class="row">
<div class="ml-auto col-auto"><button mat-raised-button type="button" mat-dialog-close>Cancel</button></div> <div class="ml-auto col-auto"><button mat-raised-button type="button" mat-dialog-close>Cancel</button></div>
<div class="col-auto"><button mat-button color="primary" [disabled]="!isFormValid" (click)="send()" type="button">Save</button></div> <div class="col-auto"><button mat-button color="primary" [disabled]="!isFormValid()" (click)="send()" type="button">Save</button></div>
</div> </div>
</form> </form>
</div> </div>

View File

@ -5,9 +5,10 @@ import { ReferenceSourceType } from '@app/core/common/enum/reference-source-type
import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeField } from '@app/core/model/reference-type/reference-type'; import { ReferenceType, ReferenceTypeDefinition, ReferenceTypeField } from '@app/core/model/reference-type/reference-type';
import { DefinitionPersist, FieldPersist, ReferencePersist } from '@app/core/model/reference/reference'; import { DefinitionPersist, FieldPersist, ReferencePersist } from '@app/core/model/reference/reference';
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service'; import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.service';
import { ReferenceService } from '@app/core/services/reference/reference.service';
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { FormService } from '@common/forms/form-service'; import { FormService } from '@common/forms/form-service';
import { takeUntil } from 'rxjs/operators'; import { debounceTime, takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof'; import { nameof } from 'ts-simple-nameof';
@Component({ @Component({
@ -19,16 +20,11 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
referenceType: ReferenceType; referenceType: ReferenceType;
systemFields: string[]; systemFields: string[];
label: string = null label: string = null
private existingReferences: string[] = []; referenceExists: Boolean;
get referenceExists(){
const reference = this.formGroup.get(this.systemFields[0]).value;
return this.existingReferences.find((r)=>r === reference)
}
constructor( constructor(
private referenceTypeService: ReferenceTypeService, private referenceTypeService: ReferenceTypeService,
private referenceService: ReferenceService,
private fb: UntypedFormBuilder, private fb: UntypedFormBuilder,
public dialogRef: MatDialogRef<ReferenceDialogEditorComponent>, public dialogRef: MatDialogRef<ReferenceDialogEditorComponent>,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any,
@ -36,7 +32,6 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
) { ) {
super(); super();
this.label = data.label; this.label = data.label;
this.existingReferences = data.existingReferences;
this.formGroup = this.fb.group({}); this.formGroup = this.fb.group({});
} }
@ -49,6 +44,21 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
referenceType => { referenceType => {
this.referenceType = referenceType; this.referenceType = referenceType;
this.buildForm(referenceType.definition?.fields); this.buildForm(referenceType.definition?.fields);
this.formGroup.get(this.systemFields[0]).valueChanges
.pipe(takeUntil(this._destroyed), debounceTime(500))
.subscribe(x => this.findReferenceIfExist());
}
);
}
findReferenceIfExist(): void {
this.referenceExists = null;
this.referenceService.findReference(this.formGroup.get(this.systemFields[0]).value, this.data.referenceTypeId)
.pipe(takeUntil(this._destroyed))
.subscribe(
result => {
this.referenceExists = result;
} }
); );
} }
@ -68,7 +78,7 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
} }
isFormValid() { isFormValid() {
return this.formGroup.valid && !this.referenceExists; return this.formGroup.valid && this.referenceExists != null && !this.referenceExists;
} }
send() { send() {

View File

@ -132,47 +132,26 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
addReference() { addReference() {
this.referenceService.searchWithDefinition(this.buildAutocompleteSearchLookup(this.referenceType.id)) const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, {
.pipe(takeUntil(this._destroyed)) width: '500px',
.subscribe( restoreFocus: false,
references => { data: {
const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, { referenceTypeId: this.referenceType.id,
width: '500px', label: this.label ?? this.referenceType.name,
restoreFocus: false, },
data: { });
referenceTypeId: this.referenceType.id, dialogRef.afterClosed()
label: this.label ?? this.referenceType.name, .pipe(takeUntil(this._destroyed))
existingReferences: references.map(x => x.reference) .subscribe(newResult => {
}, if (!newResult) { return; }
if (this.multiple) {
let results = this.form.value as ReferencePersist[];
if (results == undefined) results = [];
results.push(newResult);
this.form.setValue(results);
} else {
this.form.setValue(newResult);
}
}); });
dialogRef.afterClosed()
.pipe(takeUntil(this._destroyed))
.subscribe(newResult => {
if (!newResult) { return; }
if (this.multiple) {
let results = this.form.value as ReferencePersist[];
if (results == undefined) results = [];
results.push(newResult);
this.form.setValue(results);
} else {
this.form.setValue(newResult);
}
});
}
);
}
private buildAutocompleteSearchLookup(typeId: Guid): ReferenceSearchLookup {
const lookup: ReferenceSearchLookup = new ReferenceSearchLookup();
lookup.page = { size: 100, offset: 0 };
lookup.project = {
fields: [
nameof<Reference>(x => x.reference),
]
};
lookup.typeId = typeId;
lookup.order = { items: [nameof<Reference>(x => x.label)] };
return lookup;
} }
} }