mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
67611: Import external entry as new entity pt1
This commit is contained in:
@@ -1533,6 +1533,8 @@
|
||||
|
||||
"submission.sections.describe.relationship-lookup.external-source.import-modal.cancel": "Cancel",
|
||||
|
||||
"submission.sections.describe.relationship-lookup.external-source.import-modal.collection": "Select a collection to import new entries to",
|
||||
|
||||
"submission.sections.describe.relationship-lookup.external-source.import-modal.entities": "Entities",
|
||||
|
||||
"submission.sections.describe.relationship-lookup.external-source.import-modal.entities.new": "Import as a new local entity",
|
||||
|
@@ -37,6 +37,7 @@ import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { Collection } from '../shared/collection.model';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
||||
|
||||
@Injectable()
|
||||
export class ItemDataService extends DataService<Item> {
|
||||
@@ -247,4 +248,32 @@ export class ItemDataService extends DataService<Item> {
|
||||
map((request: RequestEntry) => request.response)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Import an external source entry into a collection
|
||||
* @param externalSourceEntry
|
||||
* @param collectionId
|
||||
*/
|
||||
public importExternalSourceEntry(externalSourceEntry: ExternalSourceEntry, collectionId: string): Observable<RestResponse> {
|
||||
const options: HttpOptions = Object.create({});
|
||||
let headers = new HttpHeaders();
|
||||
headers = headers.append('Content-Type', 'text/uri-list');
|
||||
options.headers = headers;
|
||||
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
const href$ = this.halService.getEndpoint(this.linkPath).pipe(map((href) => `${href}?owningCollection=${collectionId}`));
|
||||
|
||||
href$.pipe(
|
||||
find((href: string) => hasValue(href)),
|
||||
map((href: string) => {
|
||||
const request = new PostRequest(requestId, href, externalSourceEntry.self, options);
|
||||
this.requestService.configure(request);
|
||||
})
|
||||
).subscribe();
|
||||
|
||||
return this.requestService.getByUUID(requestId).pipe(
|
||||
find((request: RequestEntry) => request.completed),
|
||||
map((request: RequestEntry) => request.response)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -101,6 +101,7 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search-
|
||||
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||
import { MetadataValue } from '../../../../core/shared/metadata.models';
|
||||
import * as uuidv4 from 'uuid/v4';
|
||||
import { Collection } from '../../../../core/shared/collection.model';
|
||||
|
||||
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
||||
switch (model.type) {
|
||||
@@ -188,6 +189,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
hasRelationLookup: boolean;
|
||||
modalRef: NgbModalRef;
|
||||
item: Item;
|
||||
collection: Collection;
|
||||
listId: string;
|
||||
searchConfig: string;
|
||||
selectedValues$: Observable<Array<{
|
||||
@@ -234,13 +236,18 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
this.hasRelationLookup = hasValue(this.model.relationship);
|
||||
if (this.hasRelationLookup) {
|
||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||
const item$ = this.submissionObjectService
|
||||
|
||||
const submissionObject$ = this.submissionObjectService
|
||||
.findById(this.model.submissionId).pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
|
||||
getRemoteDataPayload()
|
||||
);
|
||||
|
||||
const item$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable<RemoteData<Item>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
|
||||
const collection$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.collection as Observable<RemoteData<Collection>>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload())));
|
||||
|
||||
this.subs.push(item$.subscribe((item) => this.item = item));
|
||||
this.subs.push(collection$.subscribe((collection) => this.collection = collection));
|
||||
|
||||
this.relationService.getRelatedItemsByLabel(this.item, this.model.relationship.relationshipType).pipe(
|
||||
map((items: RemoteData<PaginatedList<Item>>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))),
|
||||
@@ -325,6 +332,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
||||
modalComp.label = this.model.label;
|
||||
modalComp.metadataFields = this.model.metadataFields;
|
||||
modalComp.item = this.item;
|
||||
modalComp.collection = this.collection;
|
||||
}
|
||||
|
||||
removeSelection(object: SearchResult<Item>) {
|
||||
|
@@ -26,6 +26,8 @@
|
||||
<ng-template ngbTabContent>
|
||||
<ds-dynamic-lookup-relation-external-source-tab
|
||||
[listId]="listId"
|
||||
[item]="item"
|
||||
[collection]="collection"
|
||||
[relationship]="relationshipOptions"
|
||||
[repeatable]="repeatable"
|
||||
[context]="context"
|
||||
|
@@ -47,6 +47,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
relationshipOptions: RelationshipOptions;
|
||||
listId: string;
|
||||
item;
|
||||
collection;
|
||||
repeatable: boolean;
|
||||
selection$: Observable<ListableObject[]>;
|
||||
context: Context;
|
||||
|
@@ -20,6 +20,8 @@ import { ExternalSourceEntryImportModalComponent } from './external-source-entry
|
||||
import { Subscription } from 'rxjs/internal/Subscription';
|
||||
import { hasValue } from '../../../../../empty.util';
|
||||
import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service';
|
||||
import { Item } from '../../../../../../core/shared/item.model';
|
||||
import { Collection } from '../../../../../../core/shared/collection.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dynamic-lookup-relation-external-source-tab',
|
||||
@@ -40,6 +42,8 @@ import { SelectableListService } from '../../../../../object-list/selectable-lis
|
||||
export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit, OnDestroy {
|
||||
@Input() label: string;
|
||||
@Input() listId: string;
|
||||
@Input() item: Item;
|
||||
@Input() collection: Collection;
|
||||
@Input() relationship: RelationshipOptions;
|
||||
@Input() repeatable: boolean;
|
||||
@Input() context: Context;
|
||||
@@ -103,6 +107,8 @@ export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit
|
||||
});
|
||||
const modalComp = this.modalRef.componentInstance;
|
||||
modalComp.externalSourceEntry = entry;
|
||||
modalComp.item = this.item;
|
||||
modalComp.collection = this.collection;
|
||||
modalComp.relationship = this.relationship;
|
||||
this.importObjectSub = modalComp.importedObject.subscribe((object) => {
|
||||
this.selectableListService.selectSingle(this.listId, object);
|
||||
|
@@ -13,7 +13,13 @@
|
||||
</div>
|
||||
|
||||
<h4>{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.select' | translate) }}</h4>
|
||||
<div id="external-source-entry-entities" class="mb-2">
|
||||
<div id="external-source-entry-collection" class="mb-3">
|
||||
<div class="form-group">
|
||||
<label for="collection">{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.collection' | translate) }}</label>
|
||||
<input type="text" class="form-control" id="collection" placeholder="Enter collection ID" [value]="collectionId">
|
||||
</div>
|
||||
</div>
|
||||
<div id="external-source-entry-entities" class="mb-3">
|
||||
<h5 class="font-weight-bold">{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.entities' | translate) }}</h5>
|
||||
|
||||
<ds-search-results *ngIf="(localEntitiesRD$ | async)?.payload?.page?.length > 0"
|
||||
@@ -29,7 +35,7 @@
|
||||
(deselectObject)="deselectEntity()"
|
||||
(selectObject)="selectEntity($event)">
|
||||
</ds-search-results>
|
||||
<div class="form-check">
|
||||
<div class="ml-4">
|
||||
<input class="form-check-input" type="radio" name="new-entity" id="new-entity" value="new-entity" (click)="selectNewEntity()" [checked]="selectedImportType === importType.NewEntity" />
|
||||
<label class="form-check-label" for="new-entity">{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.entities.new' | translate) }}</label>
|
||||
</div>
|
||||
@@ -37,7 +43,7 @@
|
||||
<div id="external-source-entry-authority">
|
||||
<h5 class="font-weight-bold">{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.authority' | translate) }}</h5>
|
||||
|
||||
<div class="form-check">
|
||||
<div class="ml-4">
|
||||
<input class="form-check-input" type="radio" name="new-authority" id="new-authority" value="new-authority" (click)="selectNewAuthority()" [checked]="selectedImportType === importType.NewAuthority" />
|
||||
<label class="form-check-label" for="new-authority">{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.authority.new' | translate) }}</label>
|
||||
</div>
|
||||
|
@@ -15,7 +15,8 @@ import { CollectionElementLinkType } from '../../../../../../object-collection/c
|
||||
import { Context } from '../../../../../../../core/shared/context.model';
|
||||
import { SelectableListService } from '../../../../../../object-list/selectable-list/selectable-list.service';
|
||||
import { ListableObject } from '../../../../../../object-collection/shared/listable-object.model';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { Collection } from '../../../../../../../core/shared/collection.model';
|
||||
import { ItemDataService } from '../../../../../../../core/data/item-data.service';
|
||||
|
||||
/**
|
||||
* The possible types of import for the external entry
|
||||
@@ -39,6 +40,21 @@ export class ExternalSourceEntryImportModalComponent implements OnInit {
|
||||
*/
|
||||
externalSourceEntry: ExternalSourceEntry;
|
||||
|
||||
/**
|
||||
* The item in submission
|
||||
*/
|
||||
item: Item;
|
||||
|
||||
/**
|
||||
* The collection the user is submitting in
|
||||
*/
|
||||
collection: Collection;
|
||||
|
||||
/**
|
||||
* The ID of the collection to import entries to
|
||||
*/
|
||||
collectionId: string;
|
||||
|
||||
/**
|
||||
* The current relationship-options used for filtering results
|
||||
*/
|
||||
@@ -106,13 +122,15 @@ export class ExternalSourceEntryImportModalComponent implements OnInit {
|
||||
|
||||
constructor(public modal: NgbActiveModal,
|
||||
public lookupRelationService: LookupRelationService,
|
||||
private selectService: SelectableListService) {
|
||||
private selectService: SelectableListService,
|
||||
private itemService: ItemDataService) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.uri = Metadata.first(this.externalSourceEntry.metadata, 'dc.identifier.uri');
|
||||
this.searchOptions = Object.assign(new PaginatedSearchOptions({ query: 'sarah' }));
|
||||
this.localEntitiesRD$ = this.lookupRelationService.getLocalResults(this.relationship, this.searchOptions);
|
||||
this.collectionId = this.collection.id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +180,10 @@ export class ExternalSourceEntryImportModalComponent implements OnInit {
|
||||
* Create and import a new entity from the external entry
|
||||
*/
|
||||
importNewEntity() {
|
||||
this.importedObject.emit(this.externalSourceEntry);
|
||||
console.log(this.collection);
|
||||
this.itemService.importExternalSourceEntry(this.externalSourceEntry, this.collectionId).subscribe((response) => {
|
||||
console.log(response);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user