From 5e1b5860964d767a5bf0b82b54e0e370081f21f5 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Thu, 27 Nov 2025 14:04:40 +0200 Subject: [PATCH 1/7] implement default licence selection for front end --- .../registries-license.component.ts | 33 ++++++++++++++++--- .../registration/registration.mapper.ts | 1 + .../registration/draft-registration.model.ts | 1 + .../registration-json-api.model.ts | 1 + 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts index fdfaac181..9101f3143 100644 --- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts +++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts @@ -70,13 +70,36 @@ export class RegistriesLicenseComponent { return; } + console.log('this.draftRegistration()'); + console.log(this.draftRegistration()); if (!licenses.find((license) => license.id === selectedLicense.id)) { - this.control().patchValue({ - id: null, - }); - this.control().markAsTouched(); - this.control().updateValueAndValidity(); + const defaultLicense = licenses.find((license) => license.name === 'GNU General Public License (GPL) 2.0'); + + if (defaultLicense) { + const defaultLicenseId = defaultLicense.id; + alert(defaultLicenseId); + this.control().patchValue({ + id: defaultLicenseId, + }); + alert(JSON.stringify(this.control().value)); + this.control().markAsTouched(); + this.control().updateValueAndValidity(); + if (!defaultLicense.requiredFields.length) { + this.actions.saveLicense(this.draftId, defaultLicenseId); + } + } } + + // const registry = this.draftRegistration(); + // if (!licenses.find((license) => license.id === selectedLicense.id) && registry) { + // const defaultLicenseId = registry?.defaultLicenseId; + // alert(defaultLicenseId); + // this.control().patchValue({ + // id: '6787c3d713a6530063d0ce93', + // }); + // this.control().markAsTouched(); + // this.control().updateValueAndValidity(); + // } }); } diff --git a/src/app/shared/mappers/registration/registration.mapper.ts b/src/app/shared/mappers/registration/registration.mapper.ts index 43040ec85..41fbe6ef4 100644 --- a/src/app/shared/mappers/registration/registration.mapper.ts +++ b/src/app/shared/mappers/registration/registration.mapper.ts @@ -47,6 +47,7 @@ export class RegistrationMapper { }, providerId: response.relationships.provider?.data?.id || '', hasProject: !!response.attributes.has_project, + defaultLicenseId: response.attributes?.default_license_id, components: [], currentUserPermissions: response.attributes.current_user_permissions, }; diff --git a/src/app/shared/models/registration/draft-registration.model.ts b/src/app/shared/models/registration/draft-registration.model.ts index 4d0230e0d..4a18222ac 100644 --- a/src/app/shared/models/registration/draft-registration.model.ts +++ b/src/app/shared/models/registration/draft-registration.model.ts @@ -18,6 +18,7 @@ export interface DraftRegistrationModel { branchedFrom?: Partial; providerId: string; hasProject: boolean; + defaultLicenseId?: string; components: Partial[]; currentUserPermissions: UserPermissions[]; } diff --git a/src/app/shared/models/registration/registration-json-api.model.ts b/src/app/shared/models/registration/registration-json-api.model.ts index 1a6d64e12..1e38892af 100644 --- a/src/app/shared/models/registration/registration-json-api.model.ts +++ b/src/app/shared/models/registration/registration-json-api.model.ts @@ -39,6 +39,7 @@ export interface DraftRegistrationAttributesJsonApi { datetime_updated: string; description: string; has_project: boolean; + default_license_id?: string; node_license: LicenseRecordJsonApi; registration_metadata: Record; registration_responses: Record; From 40525f36f283e0b442c309efee0e9123d5fdb602 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Thu, 27 Nov 2025 17:13:40 +0200 Subject: [PATCH 2/7] update code --- .../registries-license.component.ts | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts index 9101f3143..06d8f915c 100644 --- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts +++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts @@ -70,36 +70,23 @@ export class RegistriesLicenseComponent { return; } - console.log('this.draftRegistration()'); - console.log(this.draftRegistration()); - if (!licenses.find((license) => license.id === selectedLicense.id)) { - const defaultLicense = licenses.find((license) => license.name === 'GNU General Public License (GPL) 2.0'); - + const defaultLicenseId = this.draftRegistration()?.defaultLicenseId; + if (!licenses.find((license) => license.id === selectedLicense.id) && defaultLicenseId) { + const defaultLicense = licenses.find((license) => license.id === defaultLicenseId); + console.log('defaultLicense', defaultLicense); + console.log('registry.defaultLicenseId', defaultLicenseId); if (defaultLicense) { - const defaultLicenseId = defaultLicense.id; - alert(defaultLicenseId); this.control().patchValue({ - id: defaultLicenseId, + id: defaultLicense.id, }); - alert(JSON.stringify(this.control().value)); this.control().markAsTouched(); this.control().updateValueAndValidity(); + if (!defaultLicense.requiredFields.length) { - this.actions.saveLicense(this.draftId, defaultLicenseId); + this.actions.saveLicense(this.draftId, defaultLicense.id); } } } - - // const registry = this.draftRegistration(); - // if (!licenses.find((license) => license.id === selectedLicense.id) && registry) { - // const defaultLicenseId = registry?.defaultLicenseId; - // alert(defaultLicenseId); - // this.control().patchValue({ - // id: '6787c3d713a6530063d0ce93', - // }); - // this.control().markAsTouched(); - // this.control().updateValueAndValidity(); - // } }); } From a3dd1d983504490eb36d5867684f4fdb827c7d41 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Fri, 28 Nov 2025 17:00:32 +0200 Subject: [PATCH 3/7] update registration licance set logic --- .../registries-license/registries-license.component.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts index 06d8f915c..4e2598ad8 100644 --- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts +++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts @@ -71,10 +71,8 @@ export class RegistriesLicenseComponent { } const defaultLicenseId = this.draftRegistration()?.defaultLicenseId; - if (!licenses.find((license) => license.id === selectedLicense.id) && defaultLicenseId) { + if (defaultLicenseId && !licenses.find((license) => license.id === selectedLicense.id)) { const defaultLicense = licenses.find((license) => license.id === defaultLicenseId); - console.log('defaultLicense', defaultLicense); - console.log('registry.defaultLicenseId', defaultLicenseId); if (defaultLicense) { this.control().patchValue({ id: defaultLicense.id, @@ -101,6 +99,7 @@ export class RegistriesLicenseComponent { this.control().patchValue({ id: license.id, }); + console.log('license.id', license.id); this.control().markAsTouched(); this.control().updateValueAndValidity(); this.actions.saveLicense(this.draftId, license.id); From f0944a8fb2174434865cc83c6fb6f092cd387648 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Fri, 28 Nov 2025 18:35:53 +0200 Subject: [PATCH 4/7] update preprint licance set logic --- .../preprints-metadata-step.component.ts | 6 ++++++ src/app/features/preprints/mappers/preprints.mapper.ts | 4 ++++ .../features/preprints/models/preprint-json-api.models.ts | 1 + src/app/features/preprints/models/preprint.models.ts | 2 ++ .../features/preprints/store/preprint/preprint.selectors.ts | 5 +++++ 5 files changed, 18 insertions(+) diff --git a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts index 716bcdfa9..a35f36b3b 100644 --- a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts +++ b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts @@ -14,6 +14,7 @@ import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angula import { formInputLimits } from '@osf/features/preprints/constants'; import { MetadataForm, PreprintModel, PreprintProviderDetails } from '@osf/features/preprints/models'; +import { PreprintSelectors } from '@osf/features/preprints/store/preprint'; import { CreatePreprint, FetchLicenses, @@ -77,6 +78,7 @@ export class PreprintsMetadataStepComponent implements OnInit { licenses = select(PreprintStepperSelectors.getLicenses); createdPreprint = select(PreprintStepperSelectors.getPreprint); isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting); + isLicenseSet = select(PreprintSelectors.isLicenseSet); provider = input.required(); nextClicked = output(); @@ -85,6 +87,9 @@ export class PreprintsMetadataStepComponent implements OnInit { ngOnInit() { this.actions.fetchLicenses(); this.initForm(); + console.log('this.createdPreprint ' + this.createdPreprint()); + // console.log('selectedLicense ' + this.selectedLicense()); + alert('this.createdPreprint ' + this.isLicenseSet()); } initForm() { @@ -135,6 +140,7 @@ export class PreprintsMetadataStepComponent implements OnInit { } selectLicense(license: LicenseModel) { + alert('selectLicense'); if (license.requiredFields.length) { return; } diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts index 51ead14da..3c792ad18 100644 --- a/src/app/features/preprints/mappers/preprints.mapper.ts +++ b/src/app/features/preprints/mappers/preprints.mapper.ts @@ -38,6 +38,7 @@ export class PreprintsMapper { static fromPreprintJsonApi( response: ApiData ): PreprintModel { + console.log(' response ', response); return { id: response.id, dateCreated: response.attributes.date_created, @@ -82,6 +83,9 @@ export class PreprintsMapper { articleDoiLink: response.links.doi, embeddedLicense: null, providerId: response.relationships?.provider?.data?.id, + defaultLicenseId: response.attributes.default_license_id, + // license: response.attributes.license_record, + isLicenseSet: !!response.attributes.license_record, }; } diff --git a/src/app/features/preprints/models/preprint-json-api.models.ts b/src/app/features/preprints/models/preprint-json-api.models.ts index 9761ef0fa..3fa417f48 100644 --- a/src/app/features/preprints/models/preprint-json-api.models.ts +++ b/src/app/features/preprints/models/preprint-json-api.models.ts @@ -37,6 +37,7 @@ export interface PreprintAttributesJsonApi { why_no_prereg: StringOrNull; prereg_links: string[]; prereg_link_info: PreregLinkInfo | null; + default_license_id: string; } export interface PreprintRelationshipsJsonApi { diff --git a/src/app/features/preprints/models/preprint.models.ts b/src/app/features/preprints/models/preprint.models.ts index f4ad604b4..0dd5da44b 100644 --- a/src/app/features/preprints/models/preprint.models.ts +++ b/src/app/features/preprints/models/preprint.models.ts @@ -47,6 +47,8 @@ export interface PreprintModel { articleDoiLink?: string; identifiers?: IdentifierModel[]; providerId: string; + defaultLicenseId?: string; + isLicenseSet?: boolean; } export interface PreprintFilesLinks { diff --git a/src/app/features/preprints/store/preprint/preprint.selectors.ts b/src/app/features/preprints/store/preprint/preprint.selectors.ts index 4f67a2572..274ed6a82 100644 --- a/src/app/features/preprints/store/preprint/preprint.selectors.ts +++ b/src/app/features/preprints/store/preprint/preprint.selectors.ts @@ -11,6 +11,11 @@ export class PreprintSelectors { return state.preprint.data; } + @Selector([PreprintState]) + static isLicenseSet(state: PreprintStateModel) { + return state.preprint.data?.isLicenseSet || null; + } + @Selector([PreprintState]) static isPreprintSubmitting(state: PreprintStateModel) { return state.preprint.isSubmitting; From 121121d63f8b61d56d3977cde0471ff47a924351 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Mon, 1 Dec 2025 16:31:19 +0200 Subject: [PATCH 5/7] update preprint licance set logic --- .../preprints-metadata-step.component.ts | 23 +++++++++++++------ .../preprints/mappers/preprints.mapper.ts | 3 --- .../preprints/models/preprint.models.ts | 1 - .../preprint-stepper.state.ts | 1 - .../store/preprint/preprint.selectors.ts | 5 ---- .../registries-license.component.ts | 1 - 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts index a35f36b3b..fe0efbf24 100644 --- a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts +++ b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts @@ -9,12 +9,11 @@ import { InputText } from 'primeng/inputtext'; import { Message } from 'primeng/message'; import { Tooltip } from 'primeng/tooltip'; -import { ChangeDetectionStrategy, Component, inject, input, OnInit, output } from '@angular/core'; +import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output, untracked } from '@angular/core'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { formInputLimits } from '@osf/features/preprints/constants'; import { MetadataForm, PreprintModel, PreprintProviderDetails } from '@osf/features/preprints/models'; -import { PreprintSelectors } from '@osf/features/preprints/store/preprint'; import { CreatePreprint, FetchLicenses, @@ -78,18 +77,29 @@ export class PreprintsMetadataStepComponent implements OnInit { licenses = select(PreprintStepperSelectors.getLicenses); createdPreprint = select(PreprintStepperSelectors.getPreprint); isUpdatingPreprint = select(PreprintStepperSelectors.isPreprintSubmitting); - isLicenseSet = select(PreprintSelectors.isLicenseSet); provider = input.required(); nextClicked = output(); backClicked = output(); + constructor() { + effect(() => { + const licenses = this.licenses(); + const preprint = this.createdPreprint(); + + if (licenses.length && preprint && !preprint.licenseId && preprint.defaultLicenseId) { + const defaultLicense = licenses.find((license) => license.id === preprint?.defaultLicenseId); + + if (defaultLicense && !defaultLicense.requiredFields.length) { + this.actions.saveLicense(defaultLicense.id); + } + } + }); + } + ngOnInit() { this.actions.fetchLicenses(); this.initForm(); - console.log('this.createdPreprint ' + this.createdPreprint()); - // console.log('selectedLicense ' + this.selectedLicense()); - alert('this.createdPreprint ' + this.isLicenseSet()); } initForm() { @@ -140,7 +150,6 @@ export class PreprintsMetadataStepComponent implements OnInit { } selectLicense(license: LicenseModel) { - alert('selectLicense'); if (license.requiredFields.length) { return; } diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts index 3c792ad18..feee05b82 100644 --- a/src/app/features/preprints/mappers/preprints.mapper.ts +++ b/src/app/features/preprints/mappers/preprints.mapper.ts @@ -38,7 +38,6 @@ export class PreprintsMapper { static fromPreprintJsonApi( response: ApiData ): PreprintModel { - console.log(' response ', response); return { id: response.id, dateCreated: response.attributes.date_created, @@ -84,8 +83,6 @@ export class PreprintsMapper { embeddedLicense: null, providerId: response.relationships?.provider?.data?.id, defaultLicenseId: response.attributes.default_license_id, - // license: response.attributes.license_record, - isLicenseSet: !!response.attributes.license_record, }; } diff --git a/src/app/features/preprints/models/preprint.models.ts b/src/app/features/preprints/models/preprint.models.ts index 0dd5da44b..5a0c9a3a0 100644 --- a/src/app/features/preprints/models/preprint.models.ts +++ b/src/app/features/preprints/models/preprint.models.ts @@ -48,7 +48,6 @@ export interface PreprintModel { identifiers?: IdentifierModel[]; providerId: string; defaultLicenseId?: string; - isLicenseSet?: boolean; } export interface PreprintFilesLinks { diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index bd43281ba..aac8b9157 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -138,7 +138,6 @@ export class PreprintStepperState { if (action.payload.isPublished) { ctx.setState(patch({ hasBeenSubmitted: true })); } - ctx.setState(patch({ preprint: patch({ isSubmitting: false, data: preprint }) })); }), catchError((error) => handleSectionError(ctx, 'preprint', error)) diff --git a/src/app/features/preprints/store/preprint/preprint.selectors.ts b/src/app/features/preprints/store/preprint/preprint.selectors.ts index 274ed6a82..4f67a2572 100644 --- a/src/app/features/preprints/store/preprint/preprint.selectors.ts +++ b/src/app/features/preprints/store/preprint/preprint.selectors.ts @@ -11,11 +11,6 @@ export class PreprintSelectors { return state.preprint.data; } - @Selector([PreprintState]) - static isLicenseSet(state: PreprintStateModel) { - return state.preprint.data?.isLicenseSet || null; - } - @Selector([PreprintState]) static isPreprintSubmitting(state: PreprintStateModel) { return state.preprint.isSubmitting; diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts index 4e2598ad8..7d1f809ee 100644 --- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts +++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts @@ -99,7 +99,6 @@ export class RegistriesLicenseComponent { this.control().patchValue({ id: license.id, }); - console.log('license.id', license.id); this.control().markAsTouched(); this.control().updateValueAndValidity(); this.actions.saveLicense(this.draftId, license.id); From b4278522d821f297743040d36fa20972d69ec61a Mon Sep 17 00:00:00 2001 From: mkovalua Date: Mon, 1 Dec 2025 16:37:45 +0200 Subject: [PATCH 6/7] fix linter --- .../preprints-metadata-step.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts index fe0efbf24..1d1b07030 100644 --- a/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts +++ b/src/app/features/preprints/components/stepper/preprints-metadata-step/preprints-metadata-step.component.ts @@ -9,7 +9,7 @@ import { InputText } from 'primeng/inputtext'; import { Message } from 'primeng/message'; import { Tooltip } from 'primeng/tooltip'; -import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output, untracked } from '@angular/core'; +import { ChangeDetectionStrategy, Component, effect, inject, input, OnInit, output } from '@angular/core'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { formInputLimits } from '@osf/features/preprints/constants'; From 437750e87bde71b8eda0790817c60e83cd3f81c4 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Tue, 2 Dec 2025 02:26:58 +0200 Subject: [PATCH 7/7] handle default license with required fields set for draft preprint --- .../registries-license.component.html | 2 +- .../registries-license.component.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html index da782b1e3..df9e3b8c7 100644 --- a/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html +++ b/src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.html @@ -11,7 +11,7 @@

{{ 'shared.license.title' | translate }}

{ const licenses = this.licenses(); - const selectedLicense = untracked(() => this.selectedLicense()); + const selectedLicense = this.selectedLicense(); + const defaultLicenseId = this.draftRegistration()?.defaultLicenseId; - if (!licenses.length || !selectedLicense) { + if (!licenses.length) { return; } - const defaultLicenseId = this.draftRegistration()?.defaultLicenseId; - if (defaultLicenseId && !licenses.find((license) => license.id === selectedLicense.id)) { + if ( + defaultLicenseId && + (!selectedLicense?.id || !licenses.find((license) => license.id === selectedLicense?.id)) + ) { const defaultLicense = licenses.find((license) => license.id === defaultLicenseId); if (defaultLicense) { this.control().patchValue({