Merge branch 'dmp-refactoring' of code-repo.d4science.org:MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Efstratios Giannopoulos 2024-04-30 12:54:39 +03:00
commit 7ed9a59595
21 changed files with 112 additions and 93 deletions

View File

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

View File

@ -23,4 +23,6 @@ public interface ReferenceService {
void deleteAndSave(UUID id) throws MyForbiddenException, 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));
}
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
public List<Reference> searchReferenceData(ReferenceSearchLookup lookup) throws MyNotFoundException, InvalidApplicationException {
int initialOffset = 0;

View File

@ -105,6 +105,19 @@ public class ReferenceController {
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}")
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));

View File

@ -46,6 +46,14 @@ export class ReferenceService {
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> {
const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } };

View File

@ -8,7 +8,7 @@
<mat-progress-bar color="primary" mode="indeterminate"></mat-progress-bar>
</div>
<div mat-dialog-content class="definition-content">
<app-description-form *ngIf="formGroup && formGroup.get('properties')" [propertiesFormGroup]="previewPropertiesFormGroup" [descriptionId]="descriptionId" [descriptionTemplate]="descriptionTemplate" [visibilityRulesService]="visibilityRulesService"></app-description-form>
<app-description-form *ngIf="formGroup && formGroup.get('properties')" [propertiesFormGroup]="previewPropertiesFormGroup" [descriptionId]="descriptionId" [descriptionTemplate]="descriptionTemplate" [visibilityRulesService]="visibilityRulesService" [isNew]="true"></app-description-form>
</div>
<div mat-mat-dialog-actions *ngIf="formGroup">
<div class="col-auto d-flex pb-4 pt-2">

View File

@ -104,7 +104,7 @@
</div>
<div [id]="'preview_container'+ form.get('id').value" class="row">
<div *ngIf="previewFieldSet && showPreview && firstField?.get('data')?.get('fieldType')?.value" class="col-12" [@fade-in-fast]>
<app-description-form-field-set class="w-100" [propertiesFormGroup]="previewPropertiesFormGroup" [fieldSet]="previewFieldSet" [visibilityRulesService]="visibilityRulesService"></app-description-form-field-set>
<app-description-form-field-set class="w-100" [propertiesFormGroup]="previewPropertiesFormGroup" [fieldSet]="previewFieldSet" [visibilityRulesService]="visibilityRulesService" [hideAnnotations]="true"></app-description-form-field-set>
</div>
</div>
</div>

View File

@ -1 +1 @@
<app-description-form *ngIf="previewPropertiesFormGroup" [propertiesFormGroup]="previewPropertiesFormGroup" [descriptionTemplate]="descriptionTemplate" [visibilityRulesService]="visibilityRulesService"></app-description-form>
<app-description-form *ngIf="previewPropertiesFormGroup" [propertiesFormGroup]="previewPropertiesFormGroup" [descriptionTemplate]="descriptionTemplate" [visibilityRulesService]="visibilityRulesService" [isNew]="true"></app-description-form>

View File

@ -65,7 +65,8 @@
[hasFocus]="fieldset.get('id').value === selectedFieldSetId"
[datasetProfileId]="datasetProfileId"
[validationErrorModel]="validationErrorModel"
[validationRootPath]="validationRootPath + '.fieldSets[' + i + ']'">
[validationRootPath]="validationRootPath + '.fieldSets[' + i + ']'"
>
</app-description-template-editor-composite-field-component>
</mat-card-content>
</mat-card>

View File

@ -88,20 +88,22 @@
</div>
<div class="row stepper-title"> <div class="col-auto"><span>{{'DESCRIPTION-EDITOR.TOC.TITLE' | translate}}</span></div></div>
<div class="row stepper-options" id="stepper-options">
<div class="col-12 stepper-list">
<div class="row" *ngIf="!descriptionInfoValid()">
<div (click)="table0fContents.onToCentrySelected()" class="col-12 main-info" [ngClass]="{'active': this.step === 0, 'text-danger': countErrorsOfBaseInfoPage > 0}">{{'DESCRIPTION-EDITOR.TOC.MAIN-INFO' | translate}} <span *ngIf="countErrorsOfBaseInfoPage > 0">({{ countErrorsOfBaseInfoPage }})</span></div>
</div>
<div class="row" *ngIf="descriptionInfoValid()">
<div (click)="table0fContents.onToCentrySelected()" class="col-12 main-info" [ngClass]="{'active': this.step === 0}">{{'DESCRIPTION-EDITOR.TOC.MAIN-INFO' | translate}} (<mat-icon class="done-icon">done</mat-icon>)</div>
</div>
<div class="row toc-pane-container" #boundary>
<div #spacer></div>
<div class="col-12">
<app-table-of-contents [visibilityRulesService]="visibilityRulesService" [selectedFieldsetId]="fieldsetIdWithFocus" #table0fContents [showErrors]="showtocentriesErrors" [TOCENTRY_ID_PREFIX]="TOCENTRY_ID_PREFIX" [hasFocus]="step > 0" [formGroup]="formGroup.get('properties')" [descriptionTemplate]="item.descriptionTemplate" *ngIf="formGroup" [links]="links" [boundary]="boundary" [spacer]="spacer" [isActive]="step !== 0" stickyThing (stepFound)="onStepFound($event)" (currentLinks)="getLinks($event)" (entrySelected)="changeStep($event.entry, $event.execute)" [pageToFieldSetMap]="pageToFieldSetMap"></app-table-of-contents>
<div class="col-12">
<div class="container stepper-list">
<div class="row" *ngIf="!descriptionInfoValid()">
<div (click)="table0fContents.onToCentrySelected()" class="col-12 main-info" [ngClass]="{'active': this.step === 0, 'text-danger': countErrorsOfBaseInfoPage > 0}">{{'DESCRIPTION-EDITOR.TOC.MAIN-INFO' | translate}} <span *ngIf="countErrorsOfBaseInfoPage > 0">({{ countErrorsOfBaseInfoPage }})</span></div>
</div>
<div class="row" *ngIf="descriptionInfoValid()">
<div (click)="table0fContents.onToCentrySelected()" class="col-12 main-info" [ngClass]="{'active': this.step === 0}">{{'DESCRIPTION-EDITOR.TOC.MAIN-INFO' | translate}} (<mat-icon class="done-icon">done</mat-icon>)</div>
</div>
<div class="row toc-pane-container" #boundary>
<div #spacer></div>
<div class="col-12">
<app-table-of-contents [visibilityRulesService]="visibilityRulesService" [selectedFieldsetId]="fieldsetIdWithFocus" #table0fContents [showErrors]="showtocentriesErrors" [TOCENTRY_ID_PREFIX]="TOCENTRY_ID_PREFIX" [hasFocus]="step > 0" [formGroup]="formGroup.get('properties')" [descriptionTemplate]="item.descriptionTemplate" *ngIf="formGroup" [links]="links" [boundary]="boundary" [spacer]="spacer" [isActive]="step !== 0" stickyThing (stepFound)="onStepFound($event)" (currentLinks)="getLinks($event)" (entrySelected)="changeStep($event.entry, $event.execute)" [pageToFieldSetMap]="pageToFieldSetMap"></app-table-of-contents>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-3 stepper-actions justify-content-around">
<div class="col-auto mb-1">
@ -147,7 +149,9 @@
[hidden]="this.step === 0"
[linkToScroll]="linkToScroll"
[validationErrorModel]="editorModel.validationErrorModel"
(fieldsetFocusChange)="fieldsetIdWithFocus = $event"></app-description-form>
[isNew]="isNew || isCopy"
(fieldsetFocusChange)="fieldsetIdWithFocus = $event"
></app-description-form>
</div>
</div>
</form>

View File

@ -5,7 +5,7 @@
<div class="col">
<app-description-form-field-set-title class="row" [fieldSet]="fieldSet" [path]="path" [isChild]="isChild"></app-description-form-field-set-title>
</div>
<div class="col-auto">
<div *ngIf="!hideAnnotations" class="col-auto">
<button mat-icon-button class="col-auto annotation-icon" (click)="showAnnotations(fieldSet.id)" [disabled]="propertiesFormGroup.disabled">
<mat-icon matTooltip="{{'DATASET-EDITOR.QUESTION.EXTENDED-DESCRIPTION.ANNOTATIONS' | translate}}" [matBadge]="annotationsCount" [matBadgeHidden]="annotationsCount <= 0" matBadgeColor="warn">comment</mat-icon>
</button>

View File

@ -27,6 +27,7 @@ export class DescriptionFormFieldSetComponent extends BaseComponent {
@Input() fieldSet: DescriptionTemplateFieldSet;
@Input() propertiesFormGroup: UntypedFormGroup;
@Input() descriptionId: Guid;
@Input() hideAnnotations: boolean = false;
get isMultiplicityEnabled() {
return this.fieldSet.hasMultiplicity && this.fieldSet.multiplicity != null;

View File

@ -21,7 +21,9 @@
[path]="path + '.' + (i+1)"
[visibilityRulesService]="visibilityRulesService"
[validationErrorModel]="validationErrorModel"
[isChild]="false"></app-description-form-field-set>
[isChild]="false"
[hideAnnotations]="isNew"
></app-description-form-field-set>
</div>
</div>
</div>

View File

@ -1,14 +1,4 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges
} from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateSection } from '@app/core/model/description-template/description-template';
import { BaseComponent } from '@common/base/base.component';
@ -28,6 +18,7 @@ import { Guid } from '@common/types/guid';
})
export class DescriptionFormSectionComponent extends BaseComponent implements OnInit, OnChanges {
@Input() isNew: boolean = false;
@Input() section: DescriptionTemplateSection;
@Input() propertiesFormGroup: UntypedFormGroup;
@Input() visibilityRulesService: VisibilityRulesService;

View File

@ -15,7 +15,7 @@
</mat-expansion-panel-header>
<ng-container *ngFor="let section of page.sections; let i = index;">
<div class="row" *ngIf="visibilityRulesService.isVisibleMap[section.id]">
<app-description-form-section class="col-12" [section]="section" [path]="(z+1)+'.'+(i+1)" [pathName]="'pages.'+z+'.sections.'+i" [propertiesFormGroup]="propertiesFormGroup" [descriptionId]="descriptionId" [visibilityRulesService]="visibilityRulesService" (askedToScroll)="onAskedToScroll(expansionPanel, $event)" [linkToScroll]="linkToScroll" [validationErrorModel]="validationErrorModel"></app-description-form-section>
<app-description-form-section class="col-12" [section]="section" [path]="(z+1)+'.'+(i+1)" [pathName]="'pages.'+z+'.sections.'+i" [propertiesFormGroup]="propertiesFormGroup" [descriptionId]="descriptionId" [visibilityRulesService]="visibilityRulesService" (askedToScroll)="onAskedToScroll(expansionPanel, $event)" [linkToScroll]="linkToScroll" [validationErrorModel]="validationErrorModel" [isNew]="isNew"></app-description-form-section>
</div>
</ng-container>
</mat-expansion-panel>

View File

@ -20,8 +20,7 @@ export class DescriptionFormComponent extends BaseComponent implements OnInit, A
@Input() descriptionTemplate: DescriptionTemplate;
@Input() visibilityRulesService: VisibilityRulesService;
@Input() descriptionId: Guid;
@Input() isNew: boolean = false;
// @ViewChild('stepper', { static: false }) stepper: MatStepper;
@Input() path: string;

View File

@ -1,12 +1,12 @@
<div *ngIf="links?.length" class="docs-toc-container">
<div class="scroll-container">
<div *ngIf="links?.length" class="row docs-toc-container">
<div class="col-12 scroll-container">
<span *ngFor="let link of links; let i = index" (click)="toggle(link); goToStep(link)" class="docs-level-{{link.type}} docs-link mt-0" [class.docs-active]="link.active">
<span *ngIf="link.show" class="link-name"><span [class.selected]="link.selected && isActive">{{link.name}}</span></span>
</span>
</div>
</div>
<div *ngIf="tocentries" class="docs-toc-container">
<div *ngIf="tocentries" class="row docs-toc-container">
<div class="scroll-container col-12 internal-table">
<table-of-contents-internal #internalTable [TOCENTRY_ID_PREFIX]="TOCENTRY_ID_PREFIX" [tocentries]="tocentries"

View File

@ -43,9 +43,9 @@ span {
overflow: hidden;
color: #21212194;
font-weight: 400;
max-width: 290px;
min-width: 290px;
padding: 0rem .4rem;
// max-width: 290px;
// min-width: 290px;
// padding: 0rem .4rem;
span {
white-space: nowrap;
overflow: hidden;

View File

@ -11,12 +11,12 @@
<div mat-dialog-content class="row">
<div *ngFor="let field of systemFields;">
<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>
<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>
<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>
<mat-error *ngIf="formGroup.get(field).hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field>
@ -37,7 +37,7 @@
</div>
<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="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>
</form>
</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 { DefinitionPersist, FieldPersist, ReferencePersist } from '@app/core/model/reference/reference';
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 { FormService } from '@common/forms/form-service';
import { takeUntil } from 'rxjs/operators';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
@Component({
@ -19,16 +20,11 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
referenceType: ReferenceType;
systemFields: string[];
label: string = null
private existingReferences: string[] = [];
get referenceExists(){
const reference = this.formGroup.get(this.systemFields[0]).value;
return this.existingReferences.find((r)=>r === reference)
}
referenceExists: Boolean;
constructor(
private referenceTypeService: ReferenceTypeService,
private referenceService: ReferenceService,
private fb: UntypedFormBuilder,
public dialogRef: MatDialogRef<ReferenceDialogEditorComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
@ -36,7 +32,6 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
) {
super();
this.label = data.label;
this.existingReferences = data.existingReferences;
this.formGroup = this.fb.group({});
}
@ -49,6 +44,21 @@ export class ReferenceDialogEditorComponent extends BaseComponent implements OnI
referenceType => {
this.referenceType = referenceType;
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() {
return this.formGroup.valid && !this.referenceExists;
return this.formGroup.valid && this.referenceExists != null && !this.referenceExists;
}
send() {

View File

@ -132,47 +132,26 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit, On
addReference() {
this.referenceService.searchWithDefinition(this.buildAutocompleteSearchLookup(this.referenceType.id))
.pipe(takeUntil(this._destroyed))
.subscribe(
references => {
const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, {
width: '500px',
restoreFocus: false,
data: {
referenceTypeId: this.referenceType.id,
label: this.label ?? this.referenceType.name,
existingReferences: references.map(x => x.reference)
},
const dialogRef = this.dialog.open(ReferenceDialogEditorComponent, {
width: '500px',
restoreFocus: false,
data: {
referenceTypeId: this.referenceType.id,
label: this.label ?? this.referenceType.name,
},
});
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);
}
});
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;
}
}