mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 03:23:07 +00:00
creating relationship type service
This commit is contained in:
@@ -99,6 +99,7 @@ import { SearchSidebarService } from './shared/search/search-sidebar.service';
|
|||||||
import { SearchFilterService } from './shared/search/search-filter.service';
|
import { SearchFilterService } from './shared/search/search-filter.service';
|
||||||
import { SearchConfigurationService } from './shared/search/search-configuration.service';
|
import { SearchConfigurationService } from './shared/search/search-configuration.service';
|
||||||
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
|
||||||
|
import { RelationshipTypeService } from './data/relationship-type.service';
|
||||||
|
|
||||||
export const restServiceFactory = (cfg: GlobalConfig, mocks: MockResponseMap, http: HttpClient) => {
|
export const restServiceFactory = (cfg: GlobalConfig, mocks: MockResponseMap, http: HttpClient) => {
|
||||||
// if (ENV_CONFIG.production) {
|
// if (ENV_CONFIG.production) {
|
||||||
@@ -204,6 +205,7 @@ const PROVIDERS = [
|
|||||||
SearchFilterService,
|
SearchFilterService,
|
||||||
SearchConfigurationService,
|
SearchConfigurationService,
|
||||||
SelectableListService,
|
SelectableListService,
|
||||||
|
RelationshipTypeService,
|
||||||
// register AuthInterceptor as HttpInterceptor
|
// register AuthInterceptor as HttpInterceptor
|
||||||
{
|
{
|
||||||
provide: HTTP_INTERCEPTORS,
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
69
src/app/core/data/relationship-type.service.ts
Normal file
69
src/app/core/data/relationship-type.service.ts
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { RequestService } from './request.service';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util';
|
||||||
|
import { distinctUntilChanged, filter, flatMap, map, switchMap, take, tap } from 'rxjs/operators';
|
||||||
|
import {
|
||||||
|
configureRequest,
|
||||||
|
filterSuccessfulResponses,
|
||||||
|
getRemoteDataPayload, getResponseFromEntry,
|
||||||
|
getSucceededRemoteData
|
||||||
|
} from '../shared/operators';
|
||||||
|
import { DeleteRequest, FindAllOptions, GetRequest, PostRequest, RestRequest } from './request.models';
|
||||||
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
import { RestResponse } from '../cache/response.models';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
|
import { Relationship } from '../shared/item-relationships/relationship.model';
|
||||||
|
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
|
||||||
|
import { RemoteData } from './remote-data';
|
||||||
|
import { combineLatest as observableCombineLatest } from 'rxjs/internal/observable/combineLatest';
|
||||||
|
import { zip as observableZip } from 'rxjs';
|
||||||
|
import { PaginatedList } from './paginated-list';
|
||||||
|
import { ItemDataService } from './item-data.service';
|
||||||
|
import {
|
||||||
|
compareArraysUsingIds, filterRelationsByTypeLabel,
|
||||||
|
relationsToItems
|
||||||
|
} from '../../+item-page/simple/item-types/shared/item-relationships-utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The service handling all relationship requests
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class RelationshipTypeService {
|
||||||
|
protected linkPath = 'relationshiptypes';
|
||||||
|
|
||||||
|
constructor(protected requestService: RequestService,
|
||||||
|
protected halService: HALEndpointService,
|
||||||
|
protected rdbService: RemoteDataBuildService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the endpoint for a relationship type by ID
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
getRelationshipTypeEndpoint(id: number) {
|
||||||
|
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||||
|
map((href: string) => `${href}/${id}`)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllRelationshipTypes(options: FindAllOptions): Observable<RemoteData<PaginatedList<RelationshipType>>> {
|
||||||
|
const link$ = this.halService.getEndpoint(this.linkPath);
|
||||||
|
link$
|
||||||
|
.pipe(
|
||||||
|
// map((url) => )
|
||||||
|
map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||||
|
configureRequest(this.requestService),
|
||||||
|
).subscribe();
|
||||||
|
return this.rdbService.buildList(link$);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the RelationshipType for a relationship type by label
|
||||||
|
* @param label
|
||||||
|
*/
|
||||||
|
getRelationshipTypeByLabel(label: string) {
|
||||||
|
this.getAllRelationshipTypes
|
||||||
|
}
|
||||||
|
}
|
@@ -53,13 +53,15 @@
|
|||||||
|
|
||||||
<div *ngIf="hasRelationLookup" class="mt-3">
|
<div *ngIf="hasRelationLookup" class="mt-3">
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
<li *ngFor="let result of ( model.value | async)">
|
<li *ngFor="let result of ( model.value | async); let i = index">
|
||||||
<ng-container *ngVar="result.indexableObject as v">
|
<ng-container *ngVar="result.indexableObject as v">
|
||||||
<button type="button" class="close float-left" aria-label="Close button"
|
<button type="button" class="close float-left" aria-label="Close button"
|
||||||
(click)="removeSelection(result)">
|
(click)="removeSelection(result)">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
<span class="d-inline-block align-middle ml-1"><ds-item-type-switcher [object]="result" [viewMode]="itemViewMode.Summary"></ds-item-type-switcher></span>
|
<span class="d-inline-block align-middle ml-1">
|
||||||
|
<ds-item-type-switcher [object]="(modelValueMDRepresentation | async)[i]" [viewMode]="itemViewMode.Metadata"></ds-item-type-switcher>
|
||||||
|
</span>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -79,8 +79,12 @@ import { RelationshipService } from '../../../../core/data/relationship.service'
|
|||||||
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
|
import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service';
|
||||||
import { DsDynamicDisabledComponent } from './models/disabled/dynamic-disabled.component';
|
import { DsDynamicDisabledComponent } from './models/disabled/dynamic-disabled.component';
|
||||||
import { DYNAMIC_FORM_CONTROL_TYPE_DISABLED } from './models/disabled/dynamic-disabled.model';
|
import { DYNAMIC_FORM_CONTROL_TYPE_DISABLED } from './models/disabled/dynamic-disabled.model';
|
||||||
import { DsDynamicLookupRelationModalComponent } from './lookup-modal/dynamic-lookup-relation-modal.component';
|
import { DsDynamicLookupRelationModalComponent } from './relation-lookup-modal/dynamic-lookup-relation-modal.component';
|
||||||
import { ItemViewMode } from '../../../items/item-type-decorator';
|
import { ItemViewMode } from '../../../items/item-type-decorator';
|
||||||
|
import { MetadataRepresentationType } from '../../../../core/shared/metadata-representation/metadata-representation.model';
|
||||||
|
import { MetadatumRepresentation } from '../../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
|
||||||
|
import { relationship } from '../../../../core/cache/builders/build-decorators';
|
||||||
|
import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||||
|
|
||||||
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type<DynamicFormControl> | null {
|
||||||
switch (model.type) {
|
switch (model.type) {
|
||||||
@@ -168,7 +172,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
|
|
||||||
hasRelationLookup: boolean;
|
hasRelationLookup: boolean;
|
||||||
modalRef: NgbModalRef;
|
modalRef: NgbModalRef;
|
||||||
modalValuesString = '';
|
modelValueMDRepresentation;
|
||||||
listId: string;
|
listId: string;
|
||||||
filter: string;
|
filter: string;
|
||||||
searchConfig: string;
|
searchConfig: string;
|
||||||
@@ -207,8 +211,8 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
|
|||||||
this.listId = 'list-' + this.model.relationship.relationshipType;
|
this.listId = 'list-' + this.model.relationship.relationshipType;
|
||||||
this.model.value = this.selectableListService.getSelectableList(this.listId).pipe(
|
this.model.value = this.selectableListService.getSelectableList(this.listId).pipe(
|
||||||
map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []),
|
map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []),
|
||||||
tap((t) => console.log(t))
|
|
||||||
);
|
);
|
||||||
|
this.modelValueMDRepresentation = this.model.value.pipe(map((result: SearchResult<DSpaceObject>[]) => result.map((element: SearchResult<DSpaceObject>) => Object.assign(new ItemMetadataRepresentation(), element.indexableObject))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
<div class="col">
|
<div class="col">
|
||||||
<input class="form-control"
|
<input class="form-control"
|
||||||
[class.is-invalid]="showErrorMessages"
|
[class.is-invalid]="showErrorMessages"
|
||||||
[value]="model.value"
|
[value]="modelValuesString"
|
||||||
[disabled]="model.disabled"
|
[disabled]="model.disabled"
|
||||||
[type]="model.inputType"
|
[type]="model.inputType"
|
||||||
[placeholder]="model.placeholder | translate"
|
[placeholder]="model.placeholder | translate"
|
||||||
|
@@ -3,6 +3,7 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|||||||
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
import { DynamicFormControlComponent, DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
|
||||||
import { FormGroup } from '@angular/forms';
|
import { FormGroup } from '@angular/forms';
|
||||||
import { DynamicDisabledModel } from './dynamic-disabled.model';
|
import { DynamicDisabledModel } from './dynamic-disabled.model';
|
||||||
|
import { RelationshipTypeService } from '../../../../../../core/data/relationship-type.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-dynamic-disabled',
|
selector: 'ds-dynamic-disabled',
|
||||||
@@ -13,15 +14,17 @@ export class DsDynamicDisabledComponent extends DynamicFormControlComponent {
|
|||||||
@Input() formId: string;
|
@Input() formId: string;
|
||||||
@Input() group: FormGroup;
|
@Input() group: FormGroup;
|
||||||
@Input() model: DynamicDisabledModel;
|
@Input() model: DynamicDisabledModel;
|
||||||
|
modelValuesString = '';
|
||||||
|
|
||||||
@Output() blur: EventEmitter<any> = new EventEmitter<any>();
|
@Output() blur: EventEmitter<any> = new EventEmitter<any>();
|
||||||
@Output() change: EventEmitter<any> = new EventEmitter<any>();
|
@Output() change: EventEmitter<any> = new EventEmitter<any>();
|
||||||
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
@Output() focus: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
|
|
||||||
constructor(protected layoutService: DynamicFormLayoutService,
|
constructor(protected layoutService: DynamicFormLayoutService,
|
||||||
protected validationService: DynamicFormValidationService
|
protected validationService: DynamicFormValidationService,
|
||||||
|
protected relationshipTypeService: RelationshipTypeService
|
||||||
) {
|
) {
|
||||||
super(layoutService, validationService);
|
super(layoutService, validationService);
|
||||||
|
relationshipTypeService.getRelationshipTypeByLabel('test').subscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,8 @@ import { SearchResult } from '../../search/search-result.model';
|
|||||||
import { Item } from '../../../core/shared/item.model';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { hasValue } from '../../empty.util';
|
import { hasValue } from '../../empty.util';
|
||||||
import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model';
|
import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model';
|
||||||
import { getComponentByItemType } from '../item-type-decorator';
|
import { getComponentByItemType, ItemViewMode } from '../item-type-decorator';
|
||||||
import { MetadataRepresentation } from '../../../core/shared/metadata-representation/metadata-representation.model';
|
import { MetadataRepresentation, MetadataRepresentationType } from '../../../core/shared/metadata-representation/metadata-representation.model';
|
||||||
|
|
||||||
export const ITEM: InjectionToken<string> = new InjectionToken<string>('item');
|
export const ITEM: InjectionToken<string> = new InjectionToken<string>('item');
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export class ItemTypeSwitcherComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* The preferred view-mode to display
|
* The preferred view-mode to display
|
||||||
*/
|
*/
|
||||||
@Input() viewMode: string;
|
@Input() viewMode: ItemViewMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object injector used to inject the item into the child component
|
* The object injector used to inject the item into the child component
|
||||||
|
@@ -138,7 +138,7 @@ import { RoleDirective } from './roles/role.directive';
|
|||||||
import { UserMenuComponent } from './auth-nav-menu/user-menu/user-menu.component';
|
import { UserMenuComponent } from './auth-nav-menu/user-menu/user-menu.component';
|
||||||
import { ClaimedTaskActionsReturnToPoolComponent } from './mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component';
|
import { ClaimedTaskActionsReturnToPoolComponent } from './mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component';
|
||||||
import { ItemDetailPreviewFieldComponent } from './object-detail/my-dspace-result-detail-element/item-detail-preview/item-detail-preview-field/item-detail-preview-field.component';
|
import { ItemDetailPreviewFieldComponent } from './object-detail/my-dspace-result-detail-element/item-detail-preview/item-detail-preview-field/item-detail-preview-field.component';
|
||||||
import { DsDynamicLookupRelationModalComponent } from './form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component';
|
import { DsDynamicLookupRelationModalComponent } from './form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component';
|
||||||
import { SearchResultsComponent } from './search/search-results/search-results.component';
|
import { SearchResultsComponent } from './search/search-results/search-results.component';
|
||||||
import { SearchSidebarComponent } from './search/search-sidebar/search-sidebar.component';
|
import { SearchSidebarComponent } from './search/search-sidebar/search-sidebar.component';
|
||||||
import { SearchSettingsComponent } from './search/search-settings/search-settings.component';
|
import { SearchSettingsComponent } from './search/search-settings/search-settings.component';
|
||||||
|
Reference in New Issue
Block a user