dmp editor add dmp associated user and placeholders

This commit is contained in:
amentis 2024-02-01 14:42:23 +02:00
parent 20ffacad0d
commit da62f79a73
8 changed files with 47 additions and 31 deletions

View File

@ -3,11 +3,10 @@ package eu.eudat.model.builder.dmpproperties;
import eu.eudat.authorization.AuthorizationFlags; import eu.eudat.authorization.AuthorizationFlags;
import eu.eudat.commons.types.dmp.DmpContactEntity; import eu.eudat.commons.types.dmp.DmpContactEntity;
import eu.eudat.convention.ConventionService; import eu.eudat.convention.ConventionService;
import eu.eudat.data.DmpUserEntity; import eu.eudat.model.DmpAssociatedUser;
import eu.eudat.model.DmpUser;
import eu.eudat.model.User; import eu.eudat.model.User;
import eu.eudat.model.builder.BaseBuilder; import eu.eudat.model.builder.BaseBuilder;
import eu.eudat.model.builder.UserBuilder; import eu.eudat.model.builder.DmpAssociatedUserBuilder;
import eu.eudat.model.dmpproperties.DmpContact; import eu.eudat.model.dmpproperties.DmpContact;
import eu.eudat.query.UserQuery; import eu.eudat.query.UserQuery;
import gr.cite.tools.data.builder.BuilderFactory; import gr.cite.tools.data.builder.BuilderFactory;
@ -57,7 +56,7 @@ public class DmpContactBuilder extends BaseBuilder<DmpContact, DmpContactEntity>
//Not Bulk Build because is XML no interaction with db //Not Bulk Build because is XML no interaction with db
FieldSet userFields = fields.extractPrefixed(this.asPrefix(DmpContact._user)); FieldSet userFields = fields.extractPrefixed(this.asPrefix(DmpContact._user));
Map<UUID, User> userItemsMap = this.collectUsers(userFields, data); Map<UUID, DmpAssociatedUser> userItemsMap = this.collectUsers(userFields, data);
List<DmpContact> models = new ArrayList<>(); List<DmpContact> models = new ArrayList<>();
for (DmpContactEntity d : data) { for (DmpContactEntity d : data) {
@ -72,25 +71,25 @@ public class DmpContactBuilder extends BaseBuilder<DmpContact, DmpContactEntity>
return models; return models;
} }
private Map<UUID, User> collectUsers(FieldSet fields, List<DmpContactEntity> data) throws MyApplicationException { private Map<UUID, DmpAssociatedUser> collectUsers(FieldSet fields, List<DmpContactEntity> data) throws MyApplicationException {
if (fields.isEmpty() || data.isEmpty()) if (fields.isEmpty() || data.isEmpty())
return null; return null;
this.logger.debug("checking related - {}", User.class.getSimpleName()); this.logger.debug("checking related - {}", User.class.getSimpleName());
Map<UUID, User> itemMap; Map<UUID, DmpAssociatedUser> itemMap;
if (!fields.hasOtherField(this.asIndexer(User._id))) { if (!fields.hasOtherField(this.asIndexer(DmpAssociatedUser._id))) {
itemMap = this.asEmpty( itemMap = this.asEmpty(
data.stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().collect(Collectors.toList()), data.stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().collect(Collectors.toList()),
x -> { x -> {
User item = new User(); DmpAssociatedUser item = new DmpAssociatedUser();
item.setId(x); item.setId(x);
return item; return item;
}, },
User::getId); DmpAssociatedUser::getId);
} else { } else {
FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id); FieldSet clone = new BaseFieldSet(fields.getFields()).ensure(User._id);
UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().collect(Collectors.toList())); UserQuery q = this.queryFactory.query(UserQuery.class).authorize(this.authorize).ids(data.stream().filter(x-> x.getUserId() != null).map(DmpContactEntity::getUserId).distinct().collect(Collectors.toList()));
itemMap = this.builderFactory.builder(UserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, User::getId); itemMap = this.builderFactory.builder(DmpAssociatedUserBuilder.class).authorize(this.authorize).asForeignKey(q, clone, DmpAssociatedUser::getId);
} }
if (!fields.hasField(User._id)) { if (!fields.hasField(User._id)) {
itemMap.forEach((id, item) -> { itemMap.forEach((id, item) -> {

View File

@ -1,10 +1,10 @@
package eu.eudat.model.dmpproperties; package eu.eudat.model.dmpproperties;
import eu.eudat.model.User; import eu.eudat.model.DmpAssociatedUser;
public class DmpContact { public class DmpContact {
private User user; private DmpAssociatedUser user;
public static final String _user = "user"; public static final String _user = "user";
private String firstName; private String firstName;
@ -39,11 +39,11 @@ public class DmpContact {
this.email = email; this.email = email;
} }
public User getUser() { public DmpAssociatedUser getUser() {
return user; return user;
} }
public void setUser(User user) { public void setUser(DmpAssociatedUser user) {
this.user = user; this.user = user;
} }
} }

View File

@ -9,7 +9,7 @@ import { Description } from '../description/description';
import { DmpBlueprint } from '../dmp-blueprint/dmp-blueprint'; import { DmpBlueprint } from '../dmp-blueprint/dmp-blueprint';
import { EntityDoi } from '../entity-doi/entity-doi'; import { EntityDoi } from '../entity-doi/entity-doi';
import { ReferencePersist } from '../reference/reference'; import { ReferencePersist } from '../reference/reference';
import { User } from "../user/user"; import { DmpAssociatedUser, User } from "../user/user";
import { DmpReference } from './dmp-reference'; import { DmpReference } from './dmp-reference';
export interface Dmp extends BaseEntity { export interface Dmp extends BaseEntity {
@ -45,7 +45,7 @@ export interface DmpBlueprintValue {
} }
export interface DmpContact { export interface DmpContact {
user?: User; user?: DmpAssociatedUser;
firstName: string; firstName: string;
lastName: string; lastName: string;
email: string; email: string;

View File

@ -122,6 +122,16 @@ export class UserService {
valueAssign: (item: User) => item.id, valueAssign: (item: User) => item.id,
}; };
singleAutoCompleteDmpAssociatedUserConfiguration: SingleAutoCompleteConfiguration = {
initialItems: (data?: any) => this.queryDmpAssociated(this.buildAutocompleteLookup()).pipe(map(x => x.items)),
filterFn: (searchQuery: string, data?: any) => this.queryDmpAssociated(this.buildAutocompleteLookup(searchQuery)).pipe(map(x => x.items)),
getSelectedItem: (selectedItem: any) => this.queryDmpAssociated(this.buildAutocompleteLookup(null, null, [selectedItem])).pipe(map(x => x.items[0])),
displayFn: (item: DmpAssociatedUser) => item.name,
subtitleFn: (item: DmpAssociatedUser) => item.email,
titleFn: (item: DmpAssociatedUser) => item.name,
valueAssign: (item: DmpAssociatedUser) => item.id,
};
private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): UserLookup { private buildAutocompleteLookup(like?: string, excludedIds?: Guid[], ids?: Guid[]): UserLookup {
const lookup: UserLookup = new UserLookup(); const lookup: UserLookup = new UserLookup();
lookup.page = { size: 100, offset: 0 }; lookup.page = { size: 100, offset: 0 };

View File

@ -147,30 +147,30 @@
</mat-form-field> </mat-form-field>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.HTML_TEXT"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.HTML_TEXT">
<rich-text-editor-component [form]="formGroup.get('description')" [placeholder]="'DMP-EDITOR.PLACEHOLDER.DESCRIPTION'" [required]="field.required"> <rich-text-editor-component [form]="formGroup.get('description')" [placeholder]="field.placeholder ?? 'DMP-EDITOR.PLACEHOLDER.DESCRIPTION'" [required]="field.required">
</rich-text-editor-component> </rich-text-editor-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.RESEARCHERS"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.RESEARCHERS">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Researcher"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Researcher"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.ORGANIZATIONS"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.ORGANIZATIONS">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Organizations"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Organizations"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.FUNDER"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.FUNDER">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Funder"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Funder"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.GRANT"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.GRANT">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Grants"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Grants"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.PROJECT"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.PROJECT">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Project"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Project"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.LICENSE"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.LICENSE">
<app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [referenceType]="referenceTypeEnum.Licenses"></app-reference-field-component> <app-reference-field-component [form]="formGroup.get('properties').get('dmpBlueprintValues').get(field.id).get('references')" [label]= "field.label" [placeholder]="field.placeholder ?? field.label" [referenceType]="referenceTypeEnum.Licenses"></app-reference-field-component>
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.LANGUAGE"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.LANGUAGE">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-select [formControl]="formGroup.get('language')" placeholder="{{'DMP-EDITOR.FIELDS.LANGUAGE' | translate}}" required> <mat-select [formControl]="formGroup.get('language')" placeholder="{{field.placeholder ?? 'DMP-EDITOR.FIELDS.LANGUAGE' | translate}}" required>
<mat-option *ngFor="let lang of getLanguageInfos()" [value]="lang.code"> <mat-option *ngFor="let lang of getLanguageInfos()" [value]="lang.code">
{{ lang.name }} {{ lang.name }}
</mat-option> </mat-option>
@ -198,7 +198,7 @@
<div class="col d-flex" *ngIf="contact.get('contactType').value == dmpContactTypeEnum.Internal"> <div class="col d-flex" *ngIf="contact.get('contactType').value == dmpContactTypeEnum.Internal">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-label>{{'DMP-EDITOR.FIELDS1.USER' | translate}}</mat-label> <mat-label>{{'DMP-EDITOR.FIELDS1.USER' | translate}}</mat-label>
<app-single-auto-complete [formControl]="contact.get('userId')" [hidePlaceholder]="true" [configuration]="userService.singleAutocompleteConfiguration"></app-single-auto-complete> <app-single-auto-complete [formControl]="contact.get('userId')" [hidePlaceholder]="true" [configuration]="userService.singleAutoCompleteDmpAssociatedUserConfiguration"></app-single-auto-complete>
<mat-error *ngIf="contact.get('userId').hasError('backendError')">{{contact.get('userId').getError('backendError').message}}</mat-error> <mat-error *ngIf="contact.get('userId').hasError('backendError')">{{contact.get('userId').getError('backendError').message}}</mat-error>
<mat-error *ngIf="contact.get('userId').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="contact.get('userId').hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>
</mat-form-field> </mat-form-field>
@ -250,7 +250,7 @@
</div> </div>
<div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.ACCESS_RIGHTS"> <div *ngIf="field.systemFieldType == dmpBlueprintSystemFieldTypeEnum.ACCESS_RIGHTS">
<mat-form-field class="w-100"> <mat-form-field class="w-100">
<mat-select [formControl]="formGroup.get('accessType')" placeholder="{{'DMP-EDITOR.FIELDS.ACCESS-TYPE' | translate}}"> <mat-select [formControl]="formGroup.get('accessType')" placeholder="{{field.placeholder ?? 'DMP-EDITOR.FIELDS.ACCESS-TYPE' | translate}}">
<mat-option *ngFor="let dmpAccessType of dmpAccessTypeEnumValues" [value]="dmpAccessType"> <mat-option *ngFor="let dmpAccessType of dmpAccessTypeEnumValues" [value]="dmpAccessType">
{{enumUtils.toDmpAccessTypeString(dmpAccessType)}} {{enumUtils.toDmpAccessTypeString(dmpAccessType)}}
</mat-option> </mat-option>
@ -322,4 +322,4 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,7 +5,7 @@ import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, Dm
import { Dmp, DmpBlueprintValue, DmpContact, DmpDescriptionTemplate, DmpProperties } from '@app/core/model/dmp/dmp'; import { Dmp, DmpBlueprintValue, DmpContact, DmpDescriptionTemplate, DmpProperties } from '@app/core/model/dmp/dmp';
import { DmpReference, DmpReferenceData } from '@app/core/model/dmp/dmp-reference'; import { DmpReference, DmpReferenceData } from '@app/core/model/dmp/dmp-reference';
import { Reference } from '@app/core/model/reference/reference'; import { Reference } from '@app/core/model/reference/reference';
import { User } from '@app/core/model/user/user'; import { DmpAssociatedUser, User } from '@app/core/model/user/user';
import { DmpService } from '@app/core/services/dmp/dmp.service'; import { DmpService } from '@app/core/services/dmp/dmp.service';
import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service'; import { BreadcrumbService } from '@app/ui/misc/breadcrumb/breadcrumb.service';
import { BaseEditorResolver } from '@common/base/base-editor.resolver'; import { BaseEditorResolver } from '@common/base/base-editor.resolver';
@ -38,7 +38,7 @@ export class DmpEditorResolver extends BaseEditorResolver {
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldId)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldId)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldValue)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.dmpBlueprintValues), nameof<DmpBlueprintValue>(x => x.fieldValue)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.user), nameof<User>(x => x.id)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.user), nameof<DmpAssociatedUser>(x => x.id)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.firstName)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.firstName)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.lastName)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.lastName)].join('.'),
[nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.email)].join('.'), [nameof<Dmp>(x => x.properties), nameof<DmpProperties>(x => x.contacts), nameof<DmpContact>(x => x.email)].join('.'),

View File

@ -1,6 +1,11 @@
<mat-form-field class="w-100" *ngIf="multipleAutoCompleteSearchConfiguration"> <mat-form-field class="w-100" *ngIf="multipleAutoCompleteSearchConfiguration">
<mat-label>{{'REFERENCE-FIELD.PLACEHOLDER' | translate}} {{enumUtils.toReferenceTypeString(referenceType)}}</mat-label> <ng-container *ngIf="label">
<app-multiple-auto-complete [formControl]="form" [configuration]="multipleAutoCompleteSearchConfiguration"> <mat-label>{{label}}</mat-label>
</ng-container>
<ng-container *ngIf="!label">
<mat-label>{{'REFERENCE-FIELD.PLACEHOLDER' | translate}} {{enumUtils.toReferenceTypeString(referenceType)}}</mat-label>
</ng-container>
<app-multiple-auto-complete placeholder = "{{ placeholder ?? enumUtils.toReferenceTypeString(referenceType)}}" [formControl]="form" [configuration]="multipleAutoCompleteSearchConfiguration">
</app-multiple-auto-complete> </app-multiple-auto-complete>
<mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error> <mat-error *ngIf="form.hasError('backendError')">{{form.getError('backendError').message}}</mat-error>
<mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error> <mat-error *ngIf="form.hasError('required')">{{'GENERAL.VALIDATION.REQUIRED' | translate}}</mat-error>

View File

@ -15,6 +15,8 @@ export class ReferenceFieldComponent extends BaseComponent implements OnInit {
@Input() referenceType: ReferenceType = null; @Input() referenceType: ReferenceType = null;
@Input() form: UntypedFormGroup = null; @Input() form: UntypedFormGroup = null;
@Input() label: string = null;
@Input() placeholder: string = "Enter text";
multipleAutoCompleteSearchConfiguration: MultipleAutoCompleteConfiguration; multipleAutoCompleteSearchConfiguration: MultipleAutoCompleteConfiguration;