@@ -10,6 +10,9 @@ import {
1010} from '@angular/core' ;
1111import { AuthService } from '@dspace/core/auth/auth.service' ;
1212import { ObjectCacheService } from '@dspace/core/cache/object-cache.service' ;
13+ import { ConfigObject } from '@dspace/core/config/models/config.model' ;
14+ import { SubmissionDefinitionModel } from '@dspace/core/config/models/config-submission-definition.model' ;
15+ import { SubmissionDefinitionsConfigDataService } from '@dspace/core/config/submission-definitions-config-data.service' ;
1316import { CollectionDataService } from '@dspace/core/data/collection-data.service' ;
1417import { EntityTypeDataService } from '@dspace/core/data/entity-type-data.service' ;
1518import { RequestService } from '@dspace/core/data/request.service' ;
@@ -25,6 +28,7 @@ import {
2528} from '@dspace/shared/utils/empty.util' ;
2629import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
2730import {
31+ DynamicCheckboxModel ,
2832 DynamicFormControlModel ,
2933 DynamicFormOptionConfig ,
3034 DynamicFormService ,
@@ -34,16 +38,24 @@ import {
3438 TranslateModule ,
3539 TranslateService ,
3640} from '@ngx-translate/core' ;
37- import { Observable } from 'rxjs' ;
41+ import {
42+ catchError ,
43+ combineLatest ,
44+ Observable ,
45+ of ,
46+ } from 'rxjs' ;
3847
3948import { ComColFormComponent } from '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component' ;
4049import { ComcolPageLogoComponent } from '../../shared/comcol/comcol-page-logo/comcol-page-logo.component' ;
4150import { FormComponent } from '../../shared/form/form.component' ;
4251import { UploaderComponent } from '../../shared/upload/uploader/uploader.component' ;
4352import { VarDirective } from '../../shared/utils/var.directive' ;
4453import {
54+ collectionFormCorrectionSubmissionDefinitionSelectionConfig ,
4555 collectionFormEntityTypeSelectionConfig ,
4656 collectionFormModels ,
57+ collectionFormSharedWorkspaceCheckboxConfig ,
58+ collectionFormSubmissionDefinitionSelectionConfig ,
4759} from './collection-form.models' ;
4860
4961/**
@@ -79,6 +91,20 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
7991 */
8092 entityTypeSelection : DynamicSelectModel < string > = new DynamicSelectModel ( collectionFormEntityTypeSelectionConfig ) ;
8193
94+ /**
95+ * The dynamic form field used for submission definition selection
96+ * @type {DynamicSelectModel<string> }
97+ */
98+ submissionDefinitionSelection : DynamicSelectModel < string > = new DynamicSelectModel ( collectionFormSubmissionDefinitionSelectionConfig ) ;
99+
100+ /**
101+ * The dynamic form field used for correction submission definition selection
102+ * @type {DynamicSelectModel<string> }
103+ */
104+ correctionSubmissionDefinitionSelection : DynamicSelectModel < string > = new DynamicSelectModel ( collectionFormCorrectionSubmissionDefinitionSelectionConfig ) ;
105+
106+ sharedWorkspaceChekbox : DynamicCheckboxModel = new DynamicCheckboxModel ( collectionFormSharedWorkspaceCheckboxConfig ) ;
107+
82108 /**
83109 * The dynamic form fields used for creating/editing a collection
84110 * @type {DynamicFormControlModel[] }
@@ -94,6 +120,7 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
94120 protected objectCache : ObjectCacheService ,
95121 protected entityTypeService : EntityTypeDataService ,
96122 protected chd : ChangeDetectorRef ,
123+ protected submissionDefinitionService : SubmissionDefinitionsConfigDataService ,
97124 protected modalService : NgbModal ) {
98125 super ( formService , translate , notificationsService , authService , requestService , objectCache , modalService ) ;
99126 }
@@ -117,35 +144,76 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
117144
118145 initializeForm ( ) {
119146 let currentRelationshipValue : MetadataValue [ ] ;
147+ let currentDefinitionValue : MetadataValue [ ] ;
148+ let currentCorrectionDefinitionValue : MetadataValue [ ] ;
149+ let currentSharedWorkspaceValue : MetadataValue [ ] ;
120150 if ( this . dso && this . dso . metadata ) {
121151 currentRelationshipValue = this . dso . metadata [ 'dspace.entity.type' ] ;
152+ currentDefinitionValue = this . dso . metadata [ 'cris.submission.definition' ] ;
153+ currentCorrectionDefinitionValue = this . dso . metadata [ 'cris.submission.definition-correction' ] ;
154+ currentSharedWorkspaceValue = this . dso . metadata [ 'cris.workspace.shared' ] ;
122155 }
123156
124157 const entities$ : Observable < ItemType [ ] > = this . entityTypeService . findAll ( { elementsPerPage : 100 , currentPage : 1 } ) . pipe (
125158 getFirstSucceededRemoteListPayload ( ) ,
126159 ) ;
127160
128- // retrieve all entity types to populate the dropdowns selection
129- entities$ . subscribe ( ( entityTypes : ItemType [ ] ) => {
130-
131- entityTypes = entityTypes . filter ( ( type : ItemType ) => type . label !== NONE_ENTITY_TYPE ) ;
132- entityTypes . forEach ( ( type : ItemType , index : number ) => {
133- this . entityTypeSelection . add ( {
134- disabled : false ,
135- label : type . label ,
136- value : type . label ,
137- } as DynamicFormOptionConfig < string > ) ;
138- if ( currentRelationshipValue && currentRelationshipValue . length > 0 && currentRelationshipValue [ 0 ] . value === type . label ) {
139- this . entityTypeSelection . select ( index ) ;
140- this . entityTypeSelection . disabled = true ;
141- }
142- } ) ;
161+ const definitions$ : Observable < ConfigObject [ ] > = this . submissionDefinitionService
162+ . findAll ( { elementsPerPage : 100 , currentPage : 1 } ) . pipe (
163+ getFirstSucceededRemoteListPayload ( ) ,
164+ catchError ( ( ) => of ( [ ] ) ) ,
165+ ) ;
166+
167+ // retrieve all entity types and submission definitions to populate the dropdowns selection
168+ combineLatest ( [ entities$ , definitions$ ] )
169+ . subscribe ( ( [ entityTypes , definitions ] : [ ItemType [ ] , SubmissionDefinitionModel [ ] ] ) => {
170+
171+ const sortedEntityTypes = entityTypes
172+ . filter ( ( type : ItemType ) => type . label !== NONE_ENTITY_TYPE )
173+ . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ;
174+
175+ sortedEntityTypes . forEach ( ( type : ItemType , index : number ) => {
176+ this . entityTypeSelection . add ( {
177+ disabled : false ,
178+ label : type . label ,
179+ value : type . label ,
180+ } as DynamicFormOptionConfig < string > ) ;
181+ if ( currentRelationshipValue && currentRelationshipValue . length > 0 && currentRelationshipValue [ 0 ] . value === type . label ) {
182+ this . entityTypeSelection . select ( index ) ;
183+ this . entityTypeSelection . disabled = true ;
184+ }
185+ } ) ;
143186
144- this . formModel = entityTypes . length === 0 ? collectionFormModels : [ ...collectionFormModels , this . entityTypeSelection ] ;
187+ definitions . forEach ( ( definition : SubmissionDefinitionModel , index : number ) => {
188+ this . submissionDefinitionSelection . add ( {
189+ disabled : false ,
190+ label : definition . name ,
191+ value : definition . name ,
192+ } as DynamicFormOptionConfig < string > ) ;
193+ this . correctionSubmissionDefinitionSelection . add ( {
194+ disabled : false ,
195+ label : definition . name ,
196+ value : definition . name ,
197+ } as DynamicFormOptionConfig < string > ) ;
198+ if ( currentDefinitionValue && currentDefinitionValue . length > 0 && currentDefinitionValue [ 0 ] . value === definition . name ) {
199+ this . submissionDefinitionSelection . select ( index ) ;
200+ }
201+ if ( currentCorrectionDefinitionValue && currentCorrectionDefinitionValue . length > 0 && currentCorrectionDefinitionValue [ 0 ] . value === definition . name ) {
202+ this . correctionSubmissionDefinitionSelection . select ( index ) ;
203+ }
204+ } ) ;
145205
146- super . ngOnInit ( ) ;
147- this . chd . detectChanges ( ) ;
148- } ) ;
206+ this . formModel = entityTypes . length === 0 ?
207+ [ ...collectionFormModels , this . submissionDefinitionSelection , this . correctionSubmissionDefinitionSelection , this . sharedWorkspaceChekbox ] :
208+ [ ...collectionFormModels , this . entityTypeSelection , this . submissionDefinitionSelection , this . correctionSubmissionDefinitionSelection , this . sharedWorkspaceChekbox ] ;
209+
210+ super . ngOnInit ( ) ;
211+
212+ if ( currentSharedWorkspaceValue && currentSharedWorkspaceValue . length > 0 ) {
213+ this . sharedWorkspaceChekbox . value = currentSharedWorkspaceValue [ 0 ] . value === 'true' ;
214+ }
215+ this . chd . detectChanges ( ) ;
216+ } ) ;
149217
150218 }
151219}
0 commit comments