diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 63d2f5c2f0..53c719997a 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -99,6 +99,7 @@ import { SearchSidebarService } from './shared/search/search-sidebar.service'; import { SearchFilterService } from './shared/search/search-filter.service'; import { SearchConfigurationService } from './shared/search/search-configuration.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) => { // if (ENV_CONFIG.production) { @@ -204,6 +205,7 @@ const PROVIDERS = [ SearchFilterService, SearchConfigurationService, SelectableListService, + RelationshipTypeService, // register AuthInterceptor as HttpInterceptor { provide: HTTP_INTERCEPTORS, diff --git a/src/app/core/data/relationship-type.service.ts b/src/app/core/data/relationship-type.service.ts new file mode 100644 index 0000000000..c017bc716b --- /dev/null +++ b/src/app/core/data/relationship-type.service.ts @@ -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>> { + 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 + } +} diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html index 18caeadf14..8118ad8ea0 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.html @@ -53,13 +53,15 @@
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts index 98268ddbaa..aabbe146c7 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts @@ -79,8 +79,12 @@ import { RelationshipService } from '../../../../core/data/relationship.service' import { SelectableListService } from '../../../object-list/selectable-list/selectable-list.service'; import { DsDynamicDisabledComponent } from './models/disabled/dynamic-disabled.component'; 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 { 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 | null { switch (model.type) { @@ -168,7 +172,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo hasRelationLookup: boolean; modalRef: NgbModalRef; - modalValuesString = ''; + modelValueMDRepresentation; listId: string; filter: string; searchConfig: string; @@ -207,8 +211,8 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo this.listId = 'list-' + this.model.relationship.relationshipType; this.model.value = this.selectableListService.getSelectableList(this.listId).pipe( map((listState: SelectableListState) => hasValue(listState) && hasValue(listState.selection) ? listState.selection : []), - tap((t) => console.log(t)) ); + this.modelValueMDRepresentation = this.model.value.pipe(map((result: SearchResult[]) => result.map((element: SearchResult) => Object.assign(new ItemMetadataRepresentation(), element.indexableObject)))) } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.html index 6681b08798..18fddd1446 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/disabled/dynamic-disabled.component.html @@ -3,7 +3,7 @@
= new EventEmitter(); @Output() change: EventEmitter = new EventEmitter(); @Output() focus: EventEmitter = new EventEmitter(); - constructor(protected layoutService: DynamicFormLayoutService, - protected validationService: DynamicFormValidationService + protected validationService: DynamicFormValidationService, + protected relationshipTypeService: RelationshipTypeService ) { super(layoutService, validationService); + relationshipTypeService.getRelationshipTypeByLabel('test').subscribe(); } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html similarity index 100% rename from src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.html rename to src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.scss b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.scss similarity index 100% rename from src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.scss rename to src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.scss diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts similarity index 100% rename from src/app/shared/form/builder/ds-dynamic-form-ui/lookup-modal/dynamic-lookup-relation-modal.component.ts rename to src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts diff --git a/src/app/shared/items/switcher/item-type-switcher.component.ts b/src/app/shared/items/switcher/item-type-switcher.component.ts index 62dc1f612b..308d3134f0 100644 --- a/src/app/shared/items/switcher/item-type-switcher.component.ts +++ b/src/app/shared/items/switcher/item-type-switcher.component.ts @@ -3,8 +3,8 @@ import { SearchResult } from '../../search/search-result.model'; import { Item } from '../../../core/shared/item.model'; import { hasValue } from '../../empty.util'; import { ItemSearchResult } from '../../object-collection/shared/item-search-result.model'; -import { getComponentByItemType } from '../item-type-decorator'; -import { MetadataRepresentation } from '../../../core/shared/metadata-representation/metadata-representation.model'; +import { getComponentByItemType, ItemViewMode } from '../item-type-decorator'; +import { MetadataRepresentation, MetadataRepresentationType } from '../../../core/shared/metadata-representation/metadata-representation.model'; export const ITEM: InjectionToken = new InjectionToken('item'); @@ -25,7 +25,7 @@ export class ItemTypeSwitcherComponent implements OnInit { /** * The preferred view-mode to display */ - @Input() viewMode: string; + @Input() viewMode: ItemViewMode; /** * The object injector used to inject the item into the child component diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index b99cab16fd..f994f19868 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -138,7 +138,7 @@ import { RoleDirective } from './roles/role.directive'; 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 { 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 { SearchSidebarComponent } from './search/search-sidebar/search-sidebar.component'; import { SearchSettingsComponent } from './search/search-settings/search-settings.component';