-
Notifications
You must be signed in to change notification settings - Fork 109
feat(metadata): add possibility to fill af form from query params #3781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/add-additional-data-fields-for-metadata
Are you sure you want to change the base?
feat(metadata): add possibility to fill af form from query params #3781
Conversation
0e2666a to
454b302
Compare
454b302 to
ed4f489
Compare
| combineLatest([ | ||
| this.acquisition_framework.asObservable().pipe( | ||
| tap(() => this.reset()), | ||
| tap(() => { | ||
| this.additionalFieldsForm = []; | ||
| }), | ||
| switchMap((af) => | ||
| af !== null ? this.acquisition_framework.asObservable() : this.initialValues | ||
| ), | ||
| map((value) => { | ||
| if (value.cor_af_actor) { | ||
| if (this.actorFormS.nbMainContact(value.cor_af_actor) == 0) { | ||
| value.cor_af_actor.push({ | ||
| id_nomenclature_actor_role: this.actorFormS.getIDRoleTypeByCdNomenclature('1'), | ||
| }); | ||
| } | ||
| value.cor_af_actor.forEach((actor) => { | ||
| this.addActor(this.actors, actor); | ||
| }); | ||
| } | ||
| if (value.bibliographical_references) { | ||
| value.bibliographical_references.forEach((e) => { | ||
| this.addBibliographicalReferences(); | ||
| }); | ||
| } | ||
| return value; | ||
| }), | ||
| // Get additional fields from acquisition framework | ||
| switchMap((acquisition_framework) => { | ||
| let additionnalFieldsObservable: Observable<any>; | ||
| additionnalFieldsObservable = this.getAdditionalFields(['METADATA_CADRE_ACQUISITION']); | ||
| return forkJoin([of(acquisition_framework), additionnalFieldsObservable]); | ||
| }), | ||
| map(([acquisition_framework, additional_data]) => { | ||
| additional_data.forEach((field) => { | ||
| // Set value of field | ||
| if (acquisition_framework.additional_data[field.attribut_name] !== undefined) { | ||
| field.value = acquisition_framework.additional_data[field.attribut_name]; | ||
| } | ||
| }); | ||
|
|
||
| return [acquisition_framework, additional_data]; | ||
| }), | ||
| // Set the additional fields form | ||
| tap(([acquisition_framework, additional_data]) => { | ||
| this.additionalFieldsForm = additional_data; | ||
| }), | ||
| // Map to return acquisition framework data only | ||
| map(([acquisition_framework, additional_data]) => acquisition_framework) | ||
| ) | ||
| .subscribe((value: any) => this.form.patchValue(value)); | ||
| ), | ||
| this.queryParamsSource, | ||
| ]).subscribe(([value, params]) => { | ||
| setTimeout(() => this.form.patchValue(value), 0); | ||
| this.setFromParams(params); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pas idéal, il faudrait faire en sorte que this.form.patchValue(value) ne s'exécute que quand c'est nécessaire, et notamment pas quand il s'agit d'une émission de this.queryParamsSource seulement.
| this.acquisition_framework.asObservable().pipe( | ||
| tap(() => this.reset()), | ||
| tap(() => { | ||
| this.additionalFieldsForm = []; | ||
| }), | ||
| switchMap((af) => | ||
| af !== null ? this.acquisition_framework.asObservable() : this.initialValues | ||
| ), | ||
| map((value) => { | ||
| if (value.cor_af_actor) { | ||
| if (this.actorFormS.nbMainContact(value.cor_af_actor) == 0) { | ||
| value.cor_af_actor.push({ | ||
| id_nomenclature_actor_role: this.actorFormS.getIDRoleTypeByCdNomenclature('1'), | ||
| }); | ||
| } | ||
| value.cor_af_actor.forEach((actor) => { | ||
| this.addActor(this.actors, actor); | ||
| }); | ||
| } | ||
| if (value.bibliographical_references) { | ||
| value.bibliographical_references.forEach((e) => { | ||
| this.addBibliographicalReferences(); | ||
| }); | ||
| } | ||
| return value; | ||
| }), | ||
| // Get additional fields from acquisition framework | ||
| switchMap((acquisition_framework) => { | ||
| let additionnalFieldsObservable: Observable<any>; | ||
| additionnalFieldsObservable = this.getAdditionalFields(['METADATA_CADRE_ACQUISITION']); | ||
| return forkJoin([of(acquisition_framework), additionnalFieldsObservable]); | ||
| }), | ||
| map(([acquisition_framework, additional_data]) => { | ||
| additional_data.forEach((field) => { | ||
| // Set value of field | ||
| if (acquisition_framework.additional_data[field.attribut_name] !== undefined) { | ||
| field.value = acquisition_framework.additional_data[field.attribut_name]; | ||
| } | ||
| }); | ||
|
|
||
| return [acquisition_framework, additional_data]; | ||
| }), | ||
| // Set the additional fields form | ||
| tap(([acquisition_framework, additional_data]) => { | ||
| this.additionalFieldsForm = additional_data; | ||
| }), | ||
| // Map to return acquisition framework data only | ||
| map(([acquisition_framework, additional_data]) => acquisition_framework) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voulu factoriser cette 1ʳᵉ observable longue dans une variable const afSource = [...], mais le lint ES vient ensuite me casser la définition de cette observable en ajoutant un ; non désiré à un endroit.
feat/additional-fields-for-metadata- // PR #3744 - plutôt quedeveloppour pouvoir tester le pré-remplissage de champs additionnel