From 494295cd97ce81bbb45b73d515b9656528326833 Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Tue, 24 Oct 2023 15:26:11 +0200 Subject: [PATCH] CST-11045 added sections parts --- ...eitem-section-form-notify-service.model.ts | 16 ++- .../ldn-service/ldn-service.component.html | 0 .../ldn-service/ldn-service.component.scss | 0 .../ldn-service/ldn-service.component.spec.ts | 23 ++++ .../ldn-service/ldn-service.component.ts | 129 ++++++++++++++++++ .../sections/ldn-service/ldn-service.model.ts | 27 ++++ src/app/submission/sections/sections-type.ts | 1 + src/app/submission/submission.module.ts | 3 + 8 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 src/app/submission/sections/ldn-service/ldn-service.component.html create mode 100644 src/app/submission/sections/ldn-service/ldn-service.component.scss create mode 100644 src/app/submission/sections/ldn-service/ldn-service.component.spec.ts create mode 100644 src/app/submission/sections/ldn-service/ldn-service.component.ts create mode 100644 src/app/submission/sections/ldn-service/ldn-service.model.ts diff --git a/src/app/core/submission/models/workspaceitem-section-form-notify-service.model.ts b/src/app/core/submission/models/workspaceitem-section-form-notify-service.model.ts index b614eb9140..c952dc6100 100644 --- a/src/app/core/submission/models/workspaceitem-section-form-notify-service.model.ts +++ b/src/app/core/submission/models/workspaceitem-section-form-notify-service.model.ts @@ -1,17 +1,21 @@ import {NotifyServiceObject} from './notify-service-submission.model' +import { LdnService } from '../../../admin/admin-ldn-services/ldn-services-model/ldn-services.model'; /** - * An interface to represent the submission's item accesses condition. + * An interface to represent the submission's item ldn-services condition. */ export interface WorkspaceitemSectionNotifyServiceRequestItemDissemination extends NotifyServiceObject { /** - * The access condition id + * The ldn-review service */ - id: string; + reviewService: LdnService; /** - * Boolean that indicates whether the current item must be findable via search or browse. + * The ldn-endorse service */ - discoverable: boolean; - + endorseService: LdnService; + /** + * The ldn-ingest service + */ + ingestService: LdnService; } diff --git a/src/app/submission/sections/ldn-service/ldn-service.component.html b/src/app/submission/sections/ldn-service/ldn-service.component.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/submission/sections/ldn-service/ldn-service.component.scss b/src/app/submission/sections/ldn-service/ldn-service.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/submission/sections/ldn-service/ldn-service.component.spec.ts b/src/app/submission/sections/ldn-service/ldn-service.component.spec.ts new file mode 100644 index 0000000000..ec36f1f010 --- /dev/null +++ b/src/app/submission/sections/ldn-service/ldn-service.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LdnServiceComponent } from './ldn-service.component'; + +describe('LdnServiceComponent', () => { + let component: LdnServiceComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ LdnServiceComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(LdnServiceComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/submission/sections/ldn-service/ldn-service.component.ts b/src/app/submission/sections/ldn-service/ldn-service.component.ts new file mode 100644 index 0000000000..6690395e72 --- /dev/null +++ b/src/app/submission/sections/ldn-service/ldn-service.component.ts @@ -0,0 +1,129 @@ +import { ChangeDetectorRef, Component, Inject, ViewChild } from '@angular/core'; +import { DynamicFormControlEvent } from '@ng-dynamic-forms/core'; +import { Observable, Subscription } from 'rxjs'; +import { SectionModelComponent } from '../models/section.model'; +import { renderSectionFor } from '../sections-decorator'; +import { SectionsType } from '../sections-type'; +import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner'; +import { FormComponent } from '../../../shared/form/form.component'; +import { CollectionDataService } from '../../../core/data/collection-data.service'; +import { FormBuilderService } from '../../../shared/form/builder/form-builder.service'; +import { SectionFormOperationsService } from '../form/section-form-operations.service'; +import { FormService } from '../../../shared/form/form.service'; +import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; +import { SectionsService } from '../sections.service'; +import { SubmissionService } from '../../submission.service'; +import { TranslateService } from '@ngx-translate/core'; +import { SectionDataObject } from '../models/section-data.model'; +import { + WorkspaceitemSectionNotifyServiceRequestItemDissemination +} from '../../../core/submission/models/workspaceitem-section-form-notify-service.model'; +import { hasValue } from '../../../shared/empty.util'; +/** + * This component represents a section that contains the submission ldn-service form. + */ +@Component({ + selector: 'ds-ldn-service', + templateUrl: './ldn-service.component.html', + styleUrls: ['./ldn-service.component.scss'] +}) +@renderSectionFor(SectionsType.LdnService) +export class LdnServiceComponent extends SectionModelComponent { + + /** + * The [[JsonPatchOperationPathCombiner]] object + * @type {JsonPatchOperationPathCombiner} + */ + protected pathCombiner: JsonPatchOperationPathCombiner; + + /** + * Array to track all subscriptions and unsubscribe them onDestroy + * @type {Array} + */ + protected subs: Subscription[] = []; + + /** + * A boolean representing if div should start collapsed + */ + public isCollapsed = false; + + /** + * The FormComponent reference + */ + @ViewChild('formRef') private formRef: FormComponent; + + /** + * Initialize instance variables + * + * @param {ChangeDetectorRef} changeDetectorRef + * @param {CollectionDataService} collectionDataService + * @param {FormBuilderService} formBuilderService + * @param {SectionFormOperationsService} formOperationsService + * @param {FormService} formService + * @param {JsonPatchOperationsBuilder} operationsBuilder + * @param {SectionsService} sectionService + * @param {SubmissionService} submissionService + * @param {TranslateService} translateService + * @param {string} injectedCollectionId + * @param {SectionDataObject} injectedSectionData + * @param {string} injectedSubmissionId + */ + constructor(protected changeDetectorRef: ChangeDetectorRef, + protected collectionDataService: CollectionDataService, + protected formBuilderService: FormBuilderService, + protected formOperationsService: SectionFormOperationsService, + protected formService: FormService, + protected operationsBuilder: JsonPatchOperationsBuilder, + protected sectionService: SectionsService, + protected submissionService: SubmissionService, + protected translateService: TranslateService, + @Inject('collectionIdProvider') public injectedCollectionId: string, + @Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, + @Inject('submissionIdProvider') public injectedSubmissionId: string) { + super(injectedCollectionId, injectedSectionData, injectedSubmissionId); + } + + /** + * Initialize all instance variables + */ + onSectionInit() { + this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionData.id); + this.subs.push( + this.sectionService.getSectionData(this.submissionId, this.sectionData.id, this.sectionData.sectionType) + .subscribe((ldnServicesSection: WorkspaceitemSectionNotifyServiceRequestItemDissemination) => { + console.log(ldnServicesSection); + }) + ); + } + + + + /** + * Method called when a form dfChange event is fired. + * Dispatch form operations based on changes. + */ + onChange(event: DynamicFormControlEvent) { + const path = this.formOperationsService.getFieldPathSegmentedFromChangeEvent(event); + const value = this.formOperationsService.getFieldValueFromChangeEvent(event); + if (value) { + this.operationsBuilder.add(this.pathCombiner.getPath(path), value.value.toString(), false, true); + this.sectionService.dispatchRemoveSectionErrors(this.submissionId, this.sectionData.id); + } else { + this.operationsBuilder.remove(this.pathCombiner.getPath(path)); + } + } + + /** + * Unsubscribe from all subscriptions + */ + onSectionDestroy() { + this.subs + .filter((subscription) => hasValue(subscription)) + .forEach((subscription) => subscription.unsubscribe()); + } + + protected getSectionStatus(): Observable { + return undefined; + } + +} diff --git a/src/app/submission/sections/ldn-service/ldn-service.model.ts b/src/app/submission/sections/ldn-service/ldn-service.model.ts new file mode 100644 index 0000000000..fb441dd362 --- /dev/null +++ b/src/app/submission/sections/ldn-service/ldn-service.model.ts @@ -0,0 +1,27 @@ +export const SECTION_LDN_SERVICE_FORM_LAYOUT = { + + granted: { + element: { + container: 'custom-control custom-checkbox pl-1', + control: 'custom-control-input', + label: 'custom-control-label pt-1' + } + } +}; + +export const SECTION_LDN_SERVICE_FORM_MODEL = [ + { + id: 'granted', + label: 'submission.sections.license.granted-label', + required: true, + value: false, + validators: { + required: null + }, + errorMessages: { + required: 'submission.sections.license.required', + notgranted: 'submission.sections.license.notgranted' + }, + type: 'CHECKBOX', + } +]; diff --git a/src/app/submission/sections/sections-type.ts b/src/app/submission/sections/sections-type.ts index 6bca8a7252..40f6f85e0e 100644 --- a/src/app/submission/sections/sections-type.ts +++ b/src/app/submission/sections/sections-type.ts @@ -9,4 +9,5 @@ export enum SectionsType { SherpaPolicies = 'sherpaPolicy', Identifiers = 'identifiers', Collection = 'collection', + LdnService = 'ldn-service' } diff --git a/src/app/submission/submission.module.ts b/src/app/submission/submission.module.ts index cf0ab2b369..8f35bb4420 100644 --- a/src/app/submission/submission.module.ts +++ b/src/app/submission/submission.module.ts @@ -67,6 +67,7 @@ import { } from './sections/sherpa-policies/metadata-information/metadata-information.component'; import { SectionFormOperationsService } from './sections/form/section-form-operations.service'; import {SubmissionSectionIdentifiersComponent} from './sections/identifiers/section-identifiers.component'; +import { LdnServiceComponent } from './sections/ldn-service/ldn-service.component'; const ENTRY_COMPONENTS = [ // put only entry components that use custom decorator @@ -76,6 +77,7 @@ const ENTRY_COMPONENTS = [ SubmissionSectionCcLicensesComponent, SubmissionSectionAccessesComponent, SubmissionSectionSherpaPoliciesComponent, + LdnServiceComponent ]; const DECLARATIONS = [ @@ -114,6 +116,7 @@ const DECLARATIONS = [ CoreModule.forRoot(), SharedModule, StoreModule.forFeature('submission', submissionReducers, storeModuleConfig as StoreConfig), + EffectsModule.forFeature(), EffectsModule.forFeature(submissionEffects), JournalEntitiesModule.withEntryComponents(), ResearchEntitiesModule.withEntryComponents(),