Skip to content

Commit 4a3c937

Browse files
feat(registries): update lisecse
1 parent b9ddad0 commit 4a3c937

15 files changed

+130
-112
lines changed
Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,7 @@
11
<osf-license
22
[licenses]="licenses()"
3-
[selectedLicenseId]="selectedLicense?.id"
4-
[selectedLicenseOptions]=""
3+
[selectedLicenseId]="selectedLicense()?.id"
4+
[selectedLicenseOptions]="selectedLicense()?.options"
55
(createLicense)="createLicense($event)"
66
(selectLicense)="selectLicense($event)"
77
/>
8-
9-
<p-card class="w-full">
10-
<h2 class="mb-2">{{ 'shared.license.title' | translate }}</h2>
11-
<p class="mb-1">
12-
{{ 'shared.license.description' | translate }}
13-
</p>
14-
<p>
15-
{{ 'shared.license.helpText' | translate }}
16-
<a href="https://help.osf.io/article/148-licensing">{{ 'common.links.helpGuide' | translate }}</a
17-
>.
18-
</p>
19-
<p-select
20-
[options]="licenses()"
21-
[(ngModel)]="selectedLicense"
22-
optionLabel="name"
23-
(onChange)="onSelectLicense($event.value)"
24-
class="w-6 mt-4"
25-
/>
26-
@if (selectedLicense) {
27-
<p-divider styleClass="mt-3 mb-3" />
28-
@if (selectedLicense.requiredFields.length) {
29-
<form [formGroup]="licenseForm" class="flex gap-3 mb-3 w-full">
30-
<div class="w-6">
31-
<label for="licenseYear"> {{ 'common.labels.year' | translate }} </label>
32-
<p-datepicker
33-
id="licenseYear"
34-
formControlName="year"
35-
[maxDate]="currentYear"
36-
dataType="string"
37-
view="year"
38-
dateFormat="yy"
39-
/>
40-
</div>
41-
<osf-text-input
42-
class="w-6"
43-
label="shared.license.copyrightHolders"
44-
[control]="licenseForm.controls['copyrightHolders']"
45-
[maxLength]="inputLimits.fullName.maxLength"
46-
>
47-
</osf-text-input>
48-
</form>
49-
}
50-
51-
<p class="highlight-block">
52-
<osf-truncated-text [text]="selectedLicense.text | interpolate: licenseForm.value" />
53-
</p>
54-
}
55-
</p-card>
Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
11
import { createDispatchMap, select } from '@ngxs/store';
22

3-
import { TranslatePipe } from '@ngx-translate/core';
4-
5-
import { Card } from 'primeng/card';
6-
import { DatePicker } from 'primeng/datepicker';
7-
import { Divider } from 'primeng/divider';
8-
import { Select } from 'primeng/select';
9-
103
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
114
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
125
import { ActivatedRoute } from '@angular/router';
136

14-
import { License } from '@osf/features/registries/models';
15-
import { FetchLicenses, RegistriesSelectors } from '@osf/features/registries/store';
16-
import { LicenseComponent, TextInputComponent, TruncatedTextComponent } from '@osf/shared/components';
7+
import { FetchLicenses, RegistriesSelectors, SaveLicense } from '@osf/features/registries/store';
8+
import { LicenseComponent } from '@osf/shared/components';
179
import { InputLimits } from '@osf/shared/constants';
18-
import { LicenseOptions } from '@osf/shared/models';
19-
import { InterpolatePipe } from '@osf/shared/pipes';
10+
import { License, LicenseOptions } from '@osf/shared/models';
2011
import { CustomValidators } from '@osf/shared/utils';
2112

2213
@Component({
2314
selector: 'osf-registries-license',
24-
imports: [
25-
Card,
26-
TranslatePipe,
27-
Select,
28-
FormsModule,
29-
Divider,
30-
TruncatedTextComponent,
31-
DatePicker,
32-
TextInputComponent,
33-
InterpolatePipe,
34-
ReactiveFormsModule,
35-
LicenseComponent,
36-
],
15+
imports: [FormsModule, ReactiveFormsModule, LicenseComponent],
3716
templateUrl: './registries-license.component.html',
3817
styleUrl: './registries-license.component.scss',
3918
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -43,11 +22,11 @@ export class RegistriesLicenseComponent {
4322
private readonly draftId = this.route.snapshot.params['id'];
4423
private readonly fb = inject(FormBuilder);
4524

46-
protected actions = createDispatchMap({ fetchLicenses: FetchLicenses });
25+
protected actions = createDispatchMap({ fetchLicenses: FetchLicenses, saveLicense: SaveLicense });
4726
protected licenses = select(RegistriesSelectors.getLicenses);
4827
protected inputLimits = InputLimits;
4928

50-
selectedLicense: License | null = null;
29+
selectedLicense = select(RegistriesSelectors.getSelectedLicense);
5130
currentYear = new Date();
5231
licenseYear = this.currentYear;
5332
licenseForm = this.fb.group({
@@ -59,15 +38,11 @@ export class RegistriesLicenseComponent {
5938
this.actions.fetchLicenses();
6039
}
6140

62-
onSelectLicense(license: License): void {
63-
console.log('Selected License:', license);
64-
}
65-
6641
createLicense(licenseDetails: { id: string; licenseOptions: LicenseOptions }) {
67-
// this.actions.saveLicense(licenseDetails.id, licenseDetails.licenseOptions);
42+
this.actions.saveLicense(this.draftId, licenseDetails.id, licenseDetails.licenseOptions);
6843
}
6944

7045
selectLicense(license: License) {
71-
// this.actions.saveLicense(license.id);
46+
this.actions.saveLicense(this.draftId, license.id);
7247
}
7348
}

src/app/features/registries/mappers/licenses.mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { License, LicensesResponseJsonApi } from '../models';
1+
import { License, LicensesResponseJsonApi } from '@osf/shared/models';
22

33
export class LicensesMapper {
44
static fromLicensesResponse(response: LicensesResponseJsonApi): License[] {

src/app/features/registries/mappers/registration.mapper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export class RegistrationMapper {
88
title: response.attributes.title,
99
description: response.attributes.description,
1010
registrationSchemaId: response.relationships.registration_schema?.data?.id || '',
11+
license: {
12+
id: response.relationships.license?.data?.id || '',
13+
options: response.attributes.node_license,
14+
},
1115
};
1216
}
1317
}

src/app/features/registries/models/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './license.model';
21
export * from './licenses-json-api.model';
32
export * from './page-schema.model';
43
export * from './project';
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +0,0 @@
1-
export interface License {
2-
id: string;
3-
name: string;
4-
requiredFields: string[];
5-
url: string;
6-
text: string;
7-
}
Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { ApiData, MetaJsonApi, PaginationLinksJsonApi } from '@osf/core/models';
1+
import { LicenseRecordJsonApi } from '@shared/models';
22

3-
export interface LicensesResponseJsonApi {
4-
data: LicenseDataJsonApi[];
5-
meta: MetaJsonApi;
6-
links: PaginationLinksJsonApi;
3+
export interface LicenseRelationshipJsonApi {
4+
license: {
5+
data: {
6+
id: string;
7+
type: 'licenses';
8+
};
9+
};
710
}
811

9-
export type LicenseDataJsonApi = ApiData<LicenseAttributesJsonApi, null, null, null>;
10-
11-
interface LicenseAttributesJsonApi {
12-
name: string;
13-
required_fields: string[];
14-
url: string;
15-
text: string;
12+
export interface LicensePayloadJsonApi {
13+
data: {
14+
type: 'draft_registrations';
15+
id: string;
16+
relationships: LicenseRelationshipJsonApi;
17+
attributes: {
18+
node_license?: LicenseRecordJsonApi;
19+
};
20+
};
1621
}

src/app/features/registries/models/registration-json-api.model.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ApiData, MetaJsonApi, PaginationLinksJsonApi } from '@osf/core/models';
2+
import { LicenseOptions } from '@osf/shared/models';
23

34
export interface RegistrationResponseJsonApi {
45
data: RegistrationDataJsonApi;
@@ -20,7 +21,7 @@ interface RegistrationAttributesJsonApi {
2021
datetime_updated: string;
2122
description: string;
2223
has_project: boolean;
23-
node_license: string | null;
24+
node_license: LicenseOptions;
2425
registration_metadata: Record<string, unknown>;
2526
registration_responses: Record<string, unknown>;
2627
tags: string[];
@@ -30,8 +31,14 @@ interface RegistrationAttributesJsonApi {
3031
interface RegistrationRelationshipsJsonApi {
3132
registration_schema: {
3233
data: {
33-
id: '58fd62fcda3e2400012ca5c1';
34+
id: string;
3435
type: 'registration-schemas';
3536
};
3637
};
38+
license: {
39+
data: {
40+
id: string;
41+
type: 'licenses';
42+
};
43+
};
3744
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import { LicenseOptions } from '@osf/shared/models';
2+
13
export interface Registration {
24
id: string;
35
title: string;
46
description: string;
57
registrationSchemaId: string;
8+
license: {
9+
id: string;
10+
options: LicenseOptions;
11+
};
612
}

src/app/features/registries/services/licenses.service.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { map, Observable } from 'rxjs';
33
import { inject, Injectable } from '@angular/core';
44

55
import { JsonApiService } from '@osf/core/services';
6+
import { License, LicenseOptions, LicensesResponseJsonApi } from '@osf/shared/models';
67

78
import { LicensesMapper } from '../mappers';
8-
import { License, LicensesResponseJsonApi } from '../models';
9+
import { LicensePayloadJsonApi, RegistrationDataJsonApi } from '../models';
910

1011
import { environment } from 'src/environments/environment';
1112

@@ -47,4 +48,34 @@ export class LicensesService {
4748
})
4849
);
4950
}
51+
52+
updateLicense(registrationId: string, licenseId: string, licenseOptions?: LicenseOptions) {
53+
const payload: LicensePayloadJsonApi = {
54+
data: {
55+
type: 'draft_registrations',
56+
id: registrationId,
57+
relationships: {
58+
license: {
59+
data: {
60+
id: licenseId,
61+
type: 'licenses',
62+
},
63+
},
64+
},
65+
attributes: {
66+
...(licenseOptions && {
67+
node_license: {
68+
copyright_holders: [licenseOptions.copyrightHolders],
69+
year: licenseOptions.year,
70+
},
71+
}),
72+
},
73+
},
74+
};
75+
76+
return this.jsonApiService.patch<RegistrationDataJsonApi>(
77+
`${this.apiUrl}/draft_registrations/${registrationId}/`,
78+
payload
79+
);
80+
}
5081
}

0 commit comments

Comments
 (0)