Commits
Kristof De Langhe authored a3b6917abac
200 200 | /** |
201 201 | * Subscription to update the current form |
202 202 | */ |
203 203 | updateSub: Subscription; |
204 204 | |
205 205 | /** |
206 206 | * The content harvesting type used when harvesting is disabled |
207 207 | */ |
208 208 | harvestTypeNone = ContentSourceHarvestType.None; |
209 209 | |
210 + | /** |
211 + | * The previously selected harvesting type |
212 + | * Used for switching between ContentSourceHarvestType.None and the previously selected value when enabling / disabling harvesting |
213 + | * Defaults to ContentSourceHarvestType.Metadata |
214 + | */ |
215 + | previouslySelectedHarvestType = ContentSourceHarvestType.Metadata; |
216 + | |
210 217 | public constructor(public objectUpdatesService: ObjectUpdatesService, |
211 218 | public notificationsService: NotificationsService, |
212 219 | protected location: Location, |
213 220 | protected formService: DynamicFormService, |
214 221 | protected translate: TranslateService, |
215 222 | protected route: ActivatedRoute, |
216 223 | protected router: Router, |
217 224 | @Inject(GLOBAL_CONFIG) protected EnvConfig: GlobalConfig, |
218 225 | protected collectionService: CollectionDataService) { |
219 226 | super(objectUpdatesService, notificationsService, translate); |
279 286 | }); |
280 287 | } |
281 288 | |
282 289 | /** |
283 290 | * Fill the metadataConfigIdModel's options using the contentSource's metadataConfigs property |
284 291 | */ |
285 292 | initializeMetadataConfigs() { |
286 293 | this.metadataConfigIdModel.options = this.contentSource.metadataConfigs |
287 294 | .map((metadataConfig: MetadataConfig) => Object.assign({ value: metadataConfig.id, label: metadataConfig.label })); |
288 295 | if (this.metadataConfigIdModel.options.length > 0) { |
289 - | this.metadataConfigIdModel.value = this.metadataConfigIdModel.options[0].value; |
296 + | this.formGroup.patchValue({ |
297 + | oaiSetContainer: { |
298 + | metadataConfigId: this.metadataConfigIdModel.options[0].value |
299 + | } |
300 + | }); |
290 301 | } |
291 302 | } |
292 303 | |
293 304 | /** |
294 305 | * Used the update translations of errors and labels on init and on language change |
295 306 | */ |
296 307 | private updateFieldTranslations() { |
297 308 | this.inputModels.forEach( |
298 309 | (fieldModel: DynamicFormControlModel) => { |
299 310 | this.updateFieldTranslation(fieldModel); |
360 371 | */ |
361 372 | isValid(): boolean { |
362 373 | return (this.contentSource.harvestType === ContentSourceHarvestType.None) || this.formGroup.valid; |
363 374 | } |
364 375 | |
365 376 | /** |
366 377 | * Switch the external source on or off and fire a field update |
367 378 | */ |
368 379 | changeExternalSource() { |
369 380 | if (this.contentSource.harvestType === ContentSourceHarvestType.None) { |
370 - | this.contentSource.harvestType = ContentSourceHarvestType.Metadata; |
381 + | this.contentSource.harvestType = this.previouslySelectedHarvestType; |
371 382 | } else { |
383 + | this.previouslySelectedHarvestType = this.contentSource.harvestType; |
372 384 | this.contentSource.harvestType = ContentSourceHarvestType.None; |
373 385 | } |
374 386 | this.updateContentSource(false); |
375 387 | } |
376 388 | |
377 389 | /** |
378 390 | * Loop over all inputs and update the Content Source with their value |
379 391 | * @param updateHarvestType When set to false, the harvestType of the contentSource will be ignored in the update |
380 392 | */ |
381 393 | updateContentSource(updateHarvestType: boolean) { |