Skip to content

Commit 5e1b586

Browse files
committed
implement default licence selection for front end
1 parent 1434ee6 commit 5e1b586

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

src/app/features/registries/components/registries-metadata-step/registries-license/registries-license.component.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,36 @@ export class RegistriesLicenseComponent {
7070
return;
7171
}
7272

73+
console.log('this.draftRegistration()');
74+
console.log(this.draftRegistration());
7375
if (!licenses.find((license) => license.id === selectedLicense.id)) {
74-
this.control().patchValue({
75-
id: null,
76-
});
77-
this.control().markAsTouched();
78-
this.control().updateValueAndValidity();
76+
const defaultLicense = licenses.find((license) => license.name === 'GNU General Public License (GPL) 2.0');
77+
78+
if (defaultLicense) {
79+
const defaultLicenseId = defaultLicense.id;
80+
alert(defaultLicenseId);
81+
this.control().patchValue({
82+
id: defaultLicenseId,
83+
});
84+
alert(JSON.stringify(this.control().value));
85+
this.control().markAsTouched();
86+
this.control().updateValueAndValidity();
87+
if (!defaultLicense.requiredFields.length) {
88+
this.actions.saveLicense(this.draftId, defaultLicenseId);
89+
}
90+
}
7991
}
92+
93+
// const registry = this.draftRegistration();
94+
// if (!licenses.find((license) => license.id === selectedLicense.id) && registry) {
95+
// const defaultLicenseId = registry?.defaultLicenseId;
96+
// alert(defaultLicenseId);
97+
// this.control().patchValue({
98+
// id: '6787c3d713a6530063d0ce93',
99+
// });
100+
// this.control().markAsTouched();
101+
// this.control().updateValueAndValidity();
102+
// }
80103
});
81104
}
82105

src/app/shared/mappers/registration/registration.mapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class RegistrationMapper {
4747
},
4848
providerId: response.relationships.provider?.data?.id || '',
4949
hasProject: !!response.attributes.has_project,
50+
defaultLicenseId: response.attributes?.default_license_id,
5051
components: [],
5152
currentUserPermissions: response.attributes.current_user_permissions,
5253
};

src/app/shared/models/registration/draft-registration.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface DraftRegistrationModel {
1818
branchedFrom?: Partial<ProjectModel>;
1919
providerId: string;
2020
hasProject: boolean;
21+
defaultLicenseId?: string;
2122
components: Partial<ProjectModel>[];
2223
currentUserPermissions: UserPermissions[];
2324
}

src/app/shared/models/registration/registration-json-api.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface DraftRegistrationAttributesJsonApi {
3939
datetime_updated: string;
4040
description: string;
4141
has_project: boolean;
42+
default_license_id?: string;
4243
node_license: LicenseRecordJsonApi;
4344
registration_metadata: Record<string, unknown>;
4445
registration_responses: Record<string, unknown>;

0 commit comments

Comments
 (0)