Skip to content

Commit eb0fa1f

Browse files
Merge pull request #154 from CenterForOpenScience/feat/238-draft-registrations-steps
feat(registries): code refactoring
2 parents 4e00189 + e27e3e7 commit eb0fa1f

26 files changed

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

2113
@Component({
2214
selector: 'osf-registries-license',
23-
imports: [
24-
Card,
25-
TranslatePipe,
26-
Select,
27-
FormsModule,
28-
Divider,
29-
TruncatedTextComponent,
30-
DatePicker,
31-
TextInputComponent,
32-
InterpolatePipe,
33-
ReactiveFormsModule,
34-
],
15+
imports: [FormsModule, ReactiveFormsModule, LicenseComponent],
3516
templateUrl: './registries-license.component.html',
3617
styleUrl: './registries-license.component.scss',
3718
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -41,11 +22,11 @@ export class RegistriesLicenseComponent {
4122
private readonly draftId = this.route.snapshot.params['id'];
4223
private readonly fb = inject(FormBuilder);
4324

44-
protected actions = createDispatchMap({ fetchLicenses: FetchLicenses });
25+
protected actions = createDispatchMap({ fetchLicenses: FetchLicenses, saveLicense: SaveLicense });
4526
protected licenses = select(RegistriesSelectors.getLicenses);
4627
protected inputLimits = InputLimits;
4728

48-
selectedLicense: License | null = null;
29+
selectedLicense = select(RegistriesSelectors.getSelectedLicense);
4930
currentYear = new Date();
5031
licenseYear = this.currentYear;
5132
licenseForm = this.fb.group({
@@ -57,7 +38,11 @@ export class RegistriesLicenseComponent {
5738
this.actions.fetchLicenses();
5839
}
5940

60-
onSelectLicense(license: License): void {
61-
console.log('Selected License:', license);
41+
createLicense(licenseDetails: { id: string; licenseOptions: LicenseOptions }) {
42+
this.actions.saveLicense(this.draftId, licenseDetails.id, licenseDetails.licenseOptions);
43+
}
44+
45+
selectLicense(license: License) {
46+
this.actions.saveLicense(this.draftId, license.id);
6247
}
6348
}

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/registries.routes.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ import { SUBJECTS_SERVICE } from '@osf/shared/tokens/subjects.token';
1010

1111
import { ModerationState } from '../moderation/store';
1212

13-
import { RegistrationSubjectsService } from './services';
13+
import {
14+
LicensesHandlers,
15+
ProjectsHandlers,
16+
ProvidersHandlers,
17+
RegistrationContributorsHandlers,
18+
SubjectsHandlers,
19+
} from './store/handlers';
20+
import { LicensesService, RegistrationContributorsService, RegistrationSubjectsService } from './services';
1421

1522
export const registriesRoutes: Routes = [
1623
{
1724
path: '',
1825
component: RegistriesComponent,
1926
providers: [
2027
provideStates([RegistriesState, ContributorsState, SubjectsState]),
28+
ProvidersHandlers,
29+
ProjectsHandlers,
30+
LicensesHandlers,
31+
RegistrationContributorsHandlers,
32+
SubjectsHandlers,
33+
RegistrationSubjectsService,
34+
RegistrationContributorsService,
35+
LicensesService,
2136
{
2237
provide: SUBJECTS_SERVICE,
2338
useClass: RegistrationSubjectsService,

0 commit comments

Comments
 (0)