mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5404] Started working on new feature,added services and started working on selection
This commit is contained in:
@@ -15,7 +15,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { ItemType } from '../shared/item-relationships/item-type.model';
|
||||
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||
import { RELATIONSHIP_TYPE } from '../shared/item-relationships/relationship-type.resource-type';
|
||||
import { getFirstSucceededRemoteData, getFirstCompletedRemoteData } from '../shared/operators';
|
||||
import { getFirstSucceededRemoteData, getFirstCompletedRemoteData, getRemoteDataPayload } from '../shared/operators';
|
||||
import { DataService } from './data.service';
|
||||
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
|
||||
import { ItemDataService } from './item-data.service';
|
||||
@@ -120,4 +120,33 @@ export class RelationshipTypeService extends DataService<RelationshipType> {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given RelationshipType has the given itemTypes on its left and right sides.
|
||||
* Returns an observable of the given RelationshipType if it matches, null if it doesn't
|
||||
*
|
||||
* @param type The RelationshipType to check
|
||||
* @param leftItemType The item type that should be on the left side
|
||||
* @param rightItemType The item type that should be on the right side
|
||||
* @private
|
||||
*/
|
||||
searchByEntityType(type: string): Observable<RelationshipType[]> {
|
||||
|
||||
|
||||
return this.searchBy(
|
||||
'byEntityType',
|
||||
{
|
||||
searchParams: [
|
||||
{
|
||||
fieldName: 'type',
|
||||
fieldValue: type
|
||||
}
|
||||
]
|
||||
}).pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
) as Observable<RelationshipType[]>;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -469,4 +469,48 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
update(object: Relationship): Observable<RemoteData<Relationship>> {
|
||||
return this.put(object);
|
||||
}
|
||||
|
||||
searchByItemsAndType(typeId: string,itemUuid: string,focusSide: string, arrayOfItemIds: string[] ): Observable<Relationship> {
|
||||
|
||||
let searchParams = [
|
||||
{
|
||||
fieldName: 'typeId',
|
||||
fieldValue: typeId
|
||||
},
|
||||
{
|
||||
fieldName: 'focusItem',
|
||||
fieldValue: itemUuid
|
||||
},
|
||||
{
|
||||
fieldName: 'relationshipLabel',
|
||||
fieldValue: 'isPublicationOfAuthor'
|
||||
},
|
||||
// {
|
||||
// fieldName: 'page',
|
||||
// fieldValue: 1
|
||||
// },
|
||||
];
|
||||
|
||||
arrayOfItemIds.forEach((itemId)=>{
|
||||
searchParams.push(
|
||||
{
|
||||
fieldName: 'relatedItem',
|
||||
fieldValue: itemId
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
return this.getSearchByHref(
|
||||
'byItemsAndType',
|
||||
{
|
||||
searchParams : searchParams
|
||||
}).pipe(
|
||||
switchMap((href) => this.findByHref(href)),
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -49,6 +49,8 @@ import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||
import { Subscription } from 'rxjs/internal/Subscription';
|
||||
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
|
||||
import { PaginationService } from '../../../../core/pagination/pagination.service';
|
||||
import { RelationshipTypeService } from '../../../../core/data/relationship-type.service';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'ds-edit-relationship-list',
|
||||
@@ -142,6 +144,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
protected objectUpdatesService: ObjectUpdatesService,
|
||||
protected linkService: LinkService,
|
||||
protected relationshipService: RelationshipService,
|
||||
protected relationshipTypeService: RelationshipTypeService,
|
||||
protected modalService: NgbModal,
|
||||
protected paginationService: PaginationService,
|
||||
protected selectableListService: SelectableListService,
|
||||
@@ -209,6 +212,9 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
modalComp.repeatable = true;
|
||||
modalComp.listId = this.listId;
|
||||
modalComp.item = this.item;
|
||||
modalComp.relationshipType = this.relationshipType;
|
||||
modalComp.currentItemIsLeftItem$ = this.currentItemIsLeftItem$;
|
||||
|
||||
this.item.owningCollection.pipe(
|
||||
getFirstSucceededRemoteDataPayload()
|
||||
).subscribe((collection: Collection) => {
|
||||
@@ -297,6 +303,8 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
).subscribe((items) => {
|
||||
this.selectableListService.select(this.listId, items);
|
||||
});
|
||||
|
||||
console.log(modalComp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,6 +345,7 @@ export class EditRelationshipListComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
// store the left and right type of the relationship in a single observable
|
||||
this.relationshipLeftAndRightType$ = observableCombineLatest([
|
||||
this.relationshipType.leftType,
|
||||
|
@@ -7,7 +7,7 @@ import {
|
||||
RelationshipIdentifiable,
|
||||
} from '../../../core/data/object-updates/object-updates.reducer';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { map, startWith, switchMap, take } from 'rxjs/operators';
|
||||
import { map, startWith, switchMap, take, tap } from 'rxjs/operators';
|
||||
import {
|
||||
combineLatest as observableCombineLatest,
|
||||
of as observableOf,
|
||||
@@ -32,6 +32,8 @@ import { FieldChangeType } from '../../../core/data/object-updates/object-update
|
||||
import { Relationship } from '../../../core/shared/item-relationships/relationship.model';
|
||||
import { NoContent } from '../../../core/shared/NoContent.model';
|
||||
import { hasValue } from '../../../shared/empty.util';
|
||||
import { RelationshipTypeService } from '../../../core/data/relationship-type.service';
|
||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-item-relationships',
|
||||
@@ -65,6 +67,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
public objectCache: ObjectCacheService,
|
||||
public requestService: RequestService,
|
||||
public entityTypeService: EntityTypeService,
|
||||
protected relationshipTypeService: RelationshipTypeService,
|
||||
public cdr: ChangeDetectorRef,
|
||||
) {
|
||||
super(itemService, objectUpdatesService, router, notificationsService, translateService, route);
|
||||
@@ -78,6 +81,12 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
const label = this.item.firstMetadataValue('dspace.entity.type');
|
||||
if (label !== undefined) {
|
||||
|
||||
// this.relationshipTypes$ = this.relationshipTypeService.searchByEntityType(label)
|
||||
// .pipe(
|
||||
// map((relationship:any) => relationship.page),
|
||||
// tap(res => console.log(res))
|
||||
// );
|
||||
|
||||
this.entityType$ = this.entityTypeService.getEntityTypeByLabel(label).pipe(
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
@@ -95,6 +104,7 @@ export class ItemRelationshipsComponent extends AbstractItemUpdateComponent {
|
||||
getFirstSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
map((relationshipTypes) => relationshipTypes.page),
|
||||
tap((res)=> console.log(res))
|
||||
)
|
||||
),
|
||||
);
|
||||
|
@@ -17,6 +17,8 @@
|
||||
[repeatable]="repeatable"
|
||||
[context]="context"
|
||||
[query]="query"
|
||||
[relationshipType]="relationshipType"
|
||||
[item]="item"
|
||||
(selectObject)="select($event)"
|
||||
(deselectObject)="deselect($event)"
|
||||
class="d-block pt-3">
|
||||
|
@@ -114,6 +114,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
*/
|
||||
totalExternal$: Observable<number[]>;
|
||||
|
||||
relationshipType;
|
||||
|
||||
currentItemIsLeftItem$ : Observable<boolean>;
|
||||
|
||||
constructor(
|
||||
public modal: NgbActiveModal,
|
||||
@@ -132,6 +135,16 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
// this.currentItemIsLeftItem$.subscribe((isLeft) => {
|
||||
// if(isLeft){
|
||||
// console.log(this.relationshipType.leftwardType);
|
||||
// }else{
|
||||
// console.log(this.relationshipType.rightwardType);
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
this.selection$ = this.selectableListService
|
||||
.getSelectableList(this.listId)
|
||||
.pipe(map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []));
|
||||
|
@@ -20,6 +20,9 @@ import { CollectionElementLinkType } from '../../../../../object-collection/coll
|
||||
import { Context } from '../../../../../../core/shared/context.model';
|
||||
import { LookupRelationService } from '../../../../../../core/data/lookup-relation.service';
|
||||
import { PaginationService } from '../../../../../../core/pagination/pagination.service';
|
||||
import { RelationshipService } from '../../../../../../core/data/relationship.service';
|
||||
import { RelationshipType } from '../../../../../../core/shared/item-relationships/relationship-type.model';
|
||||
import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-dynamic-lookup-relation-search-tab',
|
||||
@@ -63,6 +66,16 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
*/
|
||||
@Input() context: Context;
|
||||
|
||||
/**
|
||||
* The type of relationship
|
||||
*/
|
||||
@Input() relationshipType: RelationshipType;
|
||||
|
||||
/**
|
||||
* The item being viewed
|
||||
*/
|
||||
@Input() item: Item;
|
||||
|
||||
/**
|
||||
* Send an event to deselect an object from the list
|
||||
*/
|
||||
@@ -119,6 +132,8 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
public searchConfigService: SearchConfigurationService,
|
||||
private routeService: RouteService,
|
||||
public lookupRelationService: LookupRelationService,
|
||||
private relationshipService: RelationshipService,
|
||||
private relationshipTypeService: RelationshipTypeService,
|
||||
private paginationService: PaginationService
|
||||
) {
|
||||
}
|
||||
@@ -127,11 +142,23 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
* Sets up the pagination and fixed query parameters
|
||||
*/
|
||||
ngOnInit(): void {
|
||||
console.log(this.item);
|
||||
this.resetRoute();
|
||||
this.routeService.setParameter('fixedFilterQuery', this.relationship.filter);
|
||||
this.routeService.setParameter('configuration', this.relationship.searchConfiguration);
|
||||
this.resultsRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
|
||||
switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(startWith(undefined)))
|
||||
switchMap((options) => this.lookupRelationService.getLocalResults(this.relationship, options).pipe(
|
||||
startWith(undefined),
|
||||
tap(res=> {
|
||||
if(!!res && res.state == 'Success'){
|
||||
const idOfItems = res.payload.page.map(itemSearchResult => {
|
||||
return itemSearchResult.indexableObject.uuid;
|
||||
});
|
||||
this.setSelectedIds(idOfItems);
|
||||
}
|
||||
|
||||
})
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,6 +226,13 @@ export class DsDynamicLookupRelationSearchTabComponent implements OnInit, OnDest
|
||||
);
|
||||
}
|
||||
|
||||
setSelectedIds(idOfItems){
|
||||
console.log(this.relationshipType)
|
||||
this.relationshipService.searchByItemsAndType(this.relationshipType.id, this.item.uuid, this.relationship.relationshipType ,idOfItems).subscribe((res)=>{
|
||||
console.log(res);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deselect all items
|
||||
*/
|
||||
|
@@ -4,7 +4,7 @@ import { SearchConfigurationService } from '../../../../../../core/shared/search
|
||||
import { Observable } from 'rxjs';
|
||||
import { ListableObject } from '../../../../../object-collection/shared/listable-object.model';
|
||||
import { RemoteData } from '../../../../../../core/data/remote-data';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { map, switchMap, take, tap } from 'rxjs/operators';
|
||||
import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model';
|
||||
import {
|
||||
PaginatedList,
|
||||
@@ -115,7 +115,8 @@ export class DsDynamicLookupRelationSelectionTabComponent {
|
||||
totalPages: Math.ceil(selected.length / pagination.pageSize)
|
||||
});
|
||||
return createSuccessfulRemoteDataObject(buildPaginatedList(pageInfo, selection));
|
||||
})
|
||||
}),
|
||||
tap((res)=> console.log(res))
|
||||
);
|
||||
})
|
||||
);
|
||||
|
Reference in New Issue
Block a user