mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 18:44:14 +00:00
[CST-4591] Add entity selection field to collection create/edit form
This commit is contained in:
@@ -1,18 +1,28 @@
|
|||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import {
|
import {
|
||||||
DynamicFormControlModel,
|
DynamicFormControlModel,
|
||||||
|
DynamicFormOptionConfig,
|
||||||
DynamicFormService,
|
DynamicFormService,
|
||||||
DynamicInputModel,
|
DynamicInputModel,
|
||||||
|
DynamicSelectModel,
|
||||||
DynamicTextAreaModel
|
DynamicTextAreaModel
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
import { Collection } from '../../core/shared/collection.model';
|
import { Collection } from '../../core/shared/collection.model';
|
||||||
import { ComColFormComponent } from '../../shared/comcol-forms/comcol-form/comcol-form.component';
|
import { ComColFormComponent } from '../../shared/comcol-forms/comcol-form/comcol-form.component';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
import { RequestService } from '../../core/data/request.service';
|
||||||
import { ObjectCacheService } from '../../core/cache/object-cache.service';
|
import { ObjectCacheService } from '../../core/cache/object-cache.service';
|
||||||
|
import { EntityTypeService } from '../../core/data/entity-type.service';
|
||||||
|
import { ItemType } from '../../core/shared/item-relationships/item-type.model';
|
||||||
|
import { MetadataValue } from '../../core/shared/metadata.models';
|
||||||
|
import { getFirstSucceededRemoteListPayload } from '../../core/shared/operators';
|
||||||
|
import { collectionFormEntityTypeSelectionConfig, collectionFormModels, } from './collection-form.models';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form used for creating and editing collections
|
* Form used for creating and editing collections
|
||||||
@@ -22,7 +32,7 @@ import { ObjectCacheService } from '../../core/cache/object-cache.service';
|
|||||||
styleUrls: ['../../shared/comcol-forms/comcol-form/comcol-form.component.scss'],
|
styleUrls: ['../../shared/comcol-forms/comcol-form/comcol-form.component.scss'],
|
||||||
templateUrl: '../../shared/comcol-forms/comcol-form/comcol-form.component.html'
|
templateUrl: '../../shared/comcol-forms/comcol-form/comcol-form.component.html'
|
||||||
})
|
})
|
||||||
export class CollectionFormComponent extends ComColFormComponent<Collection> {
|
export class CollectionFormComponent extends ComColFormComponent<Collection> implements OnInit {
|
||||||
/**
|
/**
|
||||||
* @type {Collection} A new collection when a collection is being created, an existing Input collection when a collection is being edited
|
* @type {Collection} A new collection when a collection is being created, an existing Input collection when a collection is being edited
|
||||||
*/
|
*/
|
||||||
@@ -33,47 +43,17 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> {
|
|||||||
*/
|
*/
|
||||||
type = Collection.type;
|
type = Collection.type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dynamic form field used for entity type selection
|
||||||
|
* @type {DynamicSelectModel<string>}
|
||||||
|
*/
|
||||||
|
entityTypeSelection: DynamicSelectModel<string> = new DynamicSelectModel(collectionFormEntityTypeSelectionConfig);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The dynamic form fields used for creating/editing a collection
|
* The dynamic form fields used for creating/editing a collection
|
||||||
* @type {(DynamicInputModel | DynamicTextAreaModel)[]}
|
* @type {(DynamicInputModel | DynamicTextAreaModel)[]}
|
||||||
*/
|
*/
|
||||||
formModel: DynamicFormControlModel[] = [
|
formModel: DynamicFormControlModel[];
|
||||||
new DynamicInputModel({
|
|
||||||
id: 'title',
|
|
||||||
name: 'dc.title',
|
|
||||||
required: true,
|
|
||||||
validators: {
|
|
||||||
required: null
|
|
||||||
},
|
|
||||||
errorMessages: {
|
|
||||||
required: 'Please enter a name for this title'
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'description',
|
|
||||||
name: 'dc.description',
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'abstract',
|
|
||||||
name: 'dc.description.abstract',
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'rights',
|
|
||||||
name: 'dc.rights',
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'tableofcontents',
|
|
||||||
name: 'dc.description.tableofcontents',
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'license',
|
|
||||||
name: 'dc.rights.license',
|
|
||||||
}),
|
|
||||||
new DynamicTextAreaModel({
|
|
||||||
id: 'provenance',
|
|
||||||
name: 'dc.description.provenance',
|
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
public constructor(protected formService: DynamicFormService,
|
public constructor(protected formService: DynamicFormService,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
@@ -81,7 +61,41 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> {
|
|||||||
protected authService: AuthService,
|
protected authService: AuthService,
|
||||||
protected dsoService: CommunityDataService,
|
protected dsoService: CommunityDataService,
|
||||||
protected requestService: RequestService,
|
protected requestService: RequestService,
|
||||||
protected objectCache: ObjectCacheService) {
|
protected objectCache: ObjectCacheService,
|
||||||
|
protected entityTypeService: EntityTypeService) {
|
||||||
super(formService, translate, notificationsService, authService, requestService, objectCache);
|
super(formService, translate, notificationsService, authService, requestService, objectCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
|
||||||
|
let currentRelationshipValue: MetadataValue[];
|
||||||
|
if (this.dso && this.dso.metadata) {
|
||||||
|
currentRelationshipValue = this.dso.metadata['dspace.entity.type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
const entities$: Observable<ItemType[]> = this.entityTypeService.findAll({ elementsPerPage: 100, currentPage: 1 }).pipe(
|
||||||
|
getFirstSucceededRemoteListPayload()
|
||||||
|
);
|
||||||
|
|
||||||
|
// retrieve all entity types to populate the dropdowns selection
|
||||||
|
entities$.subscribe((entityTypes: ItemType[]) => {
|
||||||
|
|
||||||
|
entityTypes.forEach((type: ItemType, index: number) => {
|
||||||
|
this.entityTypeSelection.add({
|
||||||
|
disabled: false,
|
||||||
|
label: type.label,
|
||||||
|
value: type.label
|
||||||
|
} as DynamicFormOptionConfig<string>);
|
||||||
|
if (currentRelationshipValue && currentRelationshipValue.length > 0 && currentRelationshipValue[0].value === type.label) {
|
||||||
|
this.entityTypeSelection.select(index);
|
||||||
|
this.entityTypeSelection.disabled = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.formModel = [...collectionFormModels, this.entityTypeSelection];
|
||||||
|
|
||||||
|
super.ngOnInit();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
import { DynamicFormControlModel, DynamicInputModel, DynamicTextAreaModel } from '@ng-dynamic-forms/core';
|
||||||
|
import { DynamicSelectModelConfig } from '@ng-dynamic-forms/core/lib/model/select/dynamic-select.model';
|
||||||
|
|
||||||
|
export const collectionFormEntityTypeSelectionConfig: DynamicSelectModelConfig<string> = {
|
||||||
|
id: 'entityType',
|
||||||
|
name: 'dspace.entity.type',
|
||||||
|
required: true,
|
||||||
|
disabled: false,
|
||||||
|
validators: {
|
||||||
|
required: null
|
||||||
|
},
|
||||||
|
errorMessages: {
|
||||||
|
required: 'collection.form.errors.entityType.required'
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The dynamic form fields used for creating/editing a collection
|
||||||
|
* @type {(DynamicInputModel | DynamicTextAreaModel)[]}
|
||||||
|
*/
|
||||||
|
export const collectionFormModels: DynamicFormControlModel[] = [
|
||||||
|
new DynamicInputModel({
|
||||||
|
id: 'title',
|
||||||
|
name: 'dc.title',
|
||||||
|
required: true,
|
||||||
|
validators: {
|
||||||
|
required: null
|
||||||
|
},
|
||||||
|
errorMessages: {
|
||||||
|
required: 'Please enter a name for this title'
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new DynamicTextAreaModel({
|
||||||
|
id: 'description',
|
||||||
|
name: 'dc.description',
|
||||||
|
}),
|
||||||
|
new DynamicTextAreaModel({
|
||||||
|
id: 'abstract',
|
||||||
|
name: 'dc.description.abstract',
|
||||||
|
}),
|
||||||
|
new DynamicTextAreaModel({
|
||||||
|
id: 'rights',
|
||||||
|
name: 'dc.rights',
|
||||||
|
}),
|
||||||
|
new DynamicTextAreaModel({
|
||||||
|
id: 'tableofcontents',
|
||||||
|
name: 'dc.description.tableofcontents',
|
||||||
|
}),
|
||||||
|
new DynamicTextAreaModel({
|
||||||
|
id: 'license',
|
||||||
|
name: 'dc.rights.license',
|
||||||
|
})
|
||||||
|
];
|
@@ -854,6 +854,10 @@
|
|||||||
|
|
||||||
"collection.form.title": "Name",
|
"collection.form.title": "Name",
|
||||||
|
|
||||||
|
"collection.form.entityType": "Entity Type",
|
||||||
|
|
||||||
|
"collection.form.errors.entityType.required": "Please choose an entity type for this collection",
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"collection.listelement.badge": "Collection",
|
"collection.listelement.badge": "Collection",
|
||||||
|
Reference in New Issue
Block a user