67478: Intermediate commit - Basic components

This commit is contained in:
Kristof De Langhe
2019-11-29 17:51:27 +01:00
parent 0048a97181
commit de4b32dcad
15 changed files with 326 additions and 5 deletions

View File

@@ -0,0 +1,33 @@
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
import { NormalizedObject } from './normalized-object.model';
import { ExternalSourceEntry } from '../../shared/external-source-entry.model';
import { mapsTo } from '../builders/build-decorators';
import { MetadataMap, MetadataMapSerializer } from '../../shared/metadata.models';
@mapsTo(ExternalSourceEntry)
@inheritSerialization(NormalizedObject)
export class NormalizedExternalSourceEntry extends NormalizedObject<ExternalSourceEntry> {
/**
* Unique identifier
*/
@autoserialize
id: string;
/**
* The value to display
*/
@autoserialize
display: string;
/**
* The value to store the entry with
*/
@autoserialize
value: string;
/**
* Metadata of the entry
*/
@autoserializeAs(MetadataMapSerializer)
metadata: MetadataMap;
}

View File

@@ -0,0 +1,26 @@
import { autoserialize, inheritSerialization } from 'cerialize';
import { NormalizedObject } from './normalized-object.model';
import { ExternalSource } from '../../shared/external-source.model';
import { mapsTo } from '../builders/build-decorators';
@mapsTo(ExternalSource)
@inheritSerialization(NormalizedObject)
export class NormalizedExternalSource extends NormalizedObject<ExternalSource> {
/**
* Unique identifier
*/
@autoserialize
id: string;
/**
* The name of this external source
*/
@autoserialize
name: string;
/**
* Is the source hierarchical?
*/
@autoserialize
hierarchical: boolean;
}

View File

@@ -134,6 +134,9 @@ import { SearchConfigurationService } from './shared/search/search-configuration
import { SelectableListService } from '../shared/object-list/selectable-list/selectable-list.service';
import { RelationshipTypeService } from './data/relationship-type.service';
import { SidebarService } from '../shared/sidebar/sidebar.service';
import { NormalizedExternalSource } from './cache/models/normalized-external-source.model';
import { NormalizedExternalSourceEntry } from './cache/models/normalized-external-source-entry.model';
import { ExternalSourceService } from './data/external-source.service';
export const restServiceFactory = (cfg: GlobalConfig, mocks: MockResponseMap, http: HttpClient) => {
if (ENV_CONFIG.production) {
@@ -240,6 +243,7 @@ const PROVIDERS = [
SearchConfigurationService,
SelectableListService,
RelationshipTypeService,
ExternalSourceService,
// register AuthInterceptor as HttpInterceptor
{
provide: HTTP_INTERCEPTORS,
@@ -284,7 +288,9 @@ export const normalizedModels =
NormalizedPoolTask,
NormalizedRelationship,
NormalizedRelationshipType,
NormalizedItemType
NormalizedItemType,
NormalizedExternalSource,
NormalizedExternalSourceEntry
];
@NgModule({

View File

@@ -0,0 +1,77 @@
import { Injectable } from '@angular/core';
import { DataService } from './data.service';
import { ExternalSource } from '../shared/external-source.model';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { FindAllOptions, GetRequest } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
import { distinctUntilChanged, map, switchMap } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../../shared/search/paginated-search-options.model';
import { hasValue, isNotEmptyOperator } from '../../shared/empty.util';
import { configureRequest } from '../shared/operators';
import { RemoteData } from './remote-data';
import { PaginatedList } from './paginated-list';
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
@Injectable()
export class ExternalSourceService extends DataService<ExternalSource> {
protected linkPath = 'externalsources';
constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected dataBuildService: NormalizedObjectBuildService,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService,
protected http: HttpClient,
protected comparator: DefaultChangeAnalyzer<ExternalSource>) {
super();
}
getBrowseEndpoint(options: FindAllOptions = {}, linkPath: string = this.linkPath): Observable<string> {
return this.halService.getEndpoint(linkPath);
}
/**
* Get the endpoint for an external source's entries
* @param externalSourceId The id of the external source to fetch entries for
*/
getEntriesEndpoint(externalSourceId: string): Observable<string> {
return this.getBrowseEndpoint().pipe(
map((href) => this.getIDHref(href, externalSourceId)),
switchMap((href) => this.halService.getEndpoint('entries', href))
);
}
/**
* Get the entries for an external source
* @param externalSourceId The id of the external source to fetch entries for
* @param searchOptions The search options to limit results to
*/
getExternalSourceEntries(externalSourceId: string, searchOptions?: PaginatedSearchOptions): Observable<RemoteData<PaginatedList<ExternalSourceEntry>>> {
const requestUuid = this.requestService.generateRequestId();
const href$ = this.getEntriesEndpoint(externalSourceId).pipe(
isNotEmptyOperator(),
distinctUntilChanged(),
map((endpoint: string) => hasValue(searchOptions) ? searchOptions.toRestUrl(endpoint) : endpoint)
);
href$.pipe(
map((endpoint: string) => new GetRequest(requestUuid, endpoint)),
configureRequest(this.requestService)
).subscribe();
return this.rdbService.buildList(href$);
}
}

View File

@@ -0,0 +1,43 @@
import { MetadataMap } from './metadata.models';
import { ResourceType } from './resource-type';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { GenericConstructor } from './generic-constructor';
/**
* Model class for a single entry from an external source
*/
export class ExternalSourceEntry extends ListableObject {
static type = new ResourceType('externalSourceEntry');
/**
* Unique identifier
*/
id: string;
/**
* The value to display
*/
display: string;
/**
* The value to store the entry with
*/
value: string;
/**
* Metadata of the entry
*/
metadata: MetadataMap;
/**
* The link to the rest endpoint where this External Source Entry can be found
*/
self: string;
/**
* Method that returns as which type of object this object should be rendered
*/
getRenderTypes(): Array<string | GenericConstructor<ListableObject>> {
return [this.constructor as GenericConstructor<ListableObject>];
}
}

View File

@@ -0,0 +1,29 @@
import { ResourceType } from './resource-type';
import { CacheableObject } from '../cache/object-cache.reducer';
/**
* Model class for an external source
*/
export class ExternalSource extends CacheableObject {
static type = new ResourceType('externalsource');
/**
* Unique identifier
*/
id: string;
/**
* The name of this external source
*/
name: string;
/**
* Is the source hierarchical?
*/
hierarchical: boolean;
/**
* The link to the rest endpoint where this External Source can be found
*/
self: string;
}

View File

@@ -43,8 +43,8 @@ export class HALEndpointService {
);
}
public getEndpoint(linkPath: string): Observable<string> {
return this.getEndpointAt(this.getRootHref(), ...linkPath.split('/'));
public getEndpoint(linkPath: string, startHref?: string): Observable<string> {
return this.getEndpointAt(startHref || this.getRootHref(), ...linkPath.split('/'));
}
/**

View File

@@ -25,6 +25,7 @@ import { PersonInputSuggestionsComponent } from './submission/item-list-elements
import { NameVariantModalComponent } from './submission/name-variant-modal/name-variant-modal.component';
import { OrgUnitInputSuggestionsComponent } from './submission/item-list-elements/org-unit/org-unit-suggestions/org-unit-input-suggestions.component';
import { OrgUnitSearchResultListSubmissionElementComponent } from './submission/item-list-elements/org-unit/org-unit-search-result-list-submission-element.component';
import { ExternalSourceEntryListSubmissionElementComponent } from './submission/item-list-elements/external-source-entry/external-source-entry-list-submission-element.component';
const ENTRY_COMPONENTS = [
OrgUnitComponent,
@@ -48,7 +49,8 @@ const ENTRY_COMPONENTS = [
PersonInputSuggestionsComponent,
NameVariantModalComponent,
OrgUnitSearchResultListSubmissionElementComponent,
OrgUnitInputSuggestionsComponent
OrgUnitInputSuggestionsComponent,
ExternalSourceEntryListSubmissionElementComponent
];
@NgModule({

View File

@@ -0,0 +1 @@
<div>Listable external source works! Display: {{object.value}}</div>

View File

@@ -0,0 +1,16 @@
import { AbstractListableElementComponent } from '../../../../../shared/object-collection/shared/object-collection-element/abstract-listable-element.component';
import { ExternalSourceEntry } from '../../../../../core/shared/external-source-entry.model';
import { listableObjectComponent } from '../../../../../shared/object-collection/shared/listable-object/listable-object.decorator';
import { ViewMode } from '../../../../../core/shared/view-mode.model';
import { Context } from '../../../../../core/shared/context.model';
import { Component } from '@angular/core';
@listableObjectComponent(ExternalSourceEntry, ViewMode.ListElement, Context.SubmissionModal)
@Component({
selector: 'ds-external-source-entry-list-submission-element',
styleUrls: ['./external-source-entry-list-submission-element.component.scss'],
templateUrl: './external-source-entry-list-submission-element.component.html'
})
export class ExternalSourceEntryListSubmissionElementComponent extends AbstractListableElementComponent<ExternalSourceEntry> {
}

View File

@@ -0,0 +1,23 @@
<div class="row">
<div class="col-4">
<h3>{{ 'submission.sections.describe.relationship-lookup.selection-tab.settings' | translate}}</h3>
<ds-page-size-selector></ds-page-size-selector>
</div>
<div class="col-8">
<div *ngIf="(entriesRD$ | async)?.payload.page < 1">
{{'submission.sections.describe.relationship-lookup.selection-tab.no-selection' | translate}}
</div>
<div *ngIf="(entriesRD$ | async)?.payload.page.length >= 1">
<h3>{{ 'submission.sections.describe.relationship-lookup.selection-tab.title.' + label | translate}}</h3>
<ds-viewable-collection [objects]="entriesRD$ | async"
[selectable]="true"
[selectionConfig]="{ repeatable: repeatable, listId: listId }"
[config]="initialPagination"
[hideGear]="true"
[context]="context"
(deselectObject)="deselectObject.emit($event)"
(selectObject)="selectObject.emit($event)"
></ds-viewable-collection>
</div>
</div>
</div>

View File

@@ -0,0 +1,63 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { SEARCH_CONFIG_SERVICE } from '../../../../../../+my-dspace-page/my-dspace-page.component';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
import { Router } from '@angular/router';
import { ExternalSourceService } from '../../../../../../core/data/external-source.service';
import { Observable } from 'rxjs/internal/Observable';
import { RemoteData } from '../../../../../../core/data/remote-data';
import { PaginatedList } from '../../../../../../core/data/paginated-list';
import { ExternalSourceEntry } from '../../../../../../core/shared/external-source-entry.model';
import { ExternalSource } from '../../../../../../core/shared/external-source.model';
import { switchMap } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../../../../../search/paginated-search-options.model';
import { PaginationComponentOptions } from '../../../../../pagination/pagination-component-options.model';
import { Context } from '../../../../../../core/shared/context.model';
import { ListableObject } from '../../../../../object-collection/shared/listable-object.model';
@Component({
selector: 'ds-dynamic-lookup-relation-external-source-tab',
styleUrls: ['./dynamic-lookup-relation-external-source-tab.component.scss'],
templateUrl: './dynamic-lookup-relation-external-source-tab.component.html',
providers: [
{
provide: SEARCH_CONFIG_SERVICE,
useClass: SearchConfigurationService
}
]
})
export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit {
@Input() label: string;
@Input() listId: string;
@Input() repeatable: boolean;
@Input() context: Context;
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
@Output() selectObject: EventEmitter<ListableObject> = new EventEmitter<ListableObject>();
initialPagination = Object.assign(new PaginationComponentOptions(), {
id: 'submission-external-source-relation-list',
pageSize: 5
});
/**
* The external source we're selecting entries for
*/
@Input() externalSource: ExternalSource;
/**
* The displayed list of entries
*/
entriesRD$: Observable<RemoteData<PaginatedList<ExternalSourceEntry>>>;
constructor(private router: Router,
private searchConfigService: SearchConfigurationService,
private externalSourceService: ExternalSourceService) {
}
ngOnInit(): void {
this.entriesRD$ = this.searchConfigService.paginatedSearchOptions.pipe(
switchMap((searchOptions: PaginatedSearchOptions) =>
this.externalSourceService.getExternalSourceEntries(this.externalSource.id, searchOptions))
)
}
}

View File

@@ -174,6 +174,7 @@ import { SidebarFilterComponent } from './sidebar/filter/sidebar-filter.componen
import { SidebarFilterSelectedOptionComponent } from './sidebar/filter/sidebar-filter-selected-option.component';
import { MetadataRepresentationListComponent } from '../+item-page/simple/metadata-representation-list/metadata-representation-list.component';
import { SelectableListItemControlComponent } from './object-collection/shared/selectable-list-item-control/selectable-list-item-control.component';
import { DsDynamicLookupRelationExternalSourceTabComponent } from './form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component';
const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here
@@ -391,7 +392,8 @@ const ENTRY_COMPONENTS = [
SearchFacetRangeOptionComponent,
SearchAuthorityFilterComponent,
DsDynamicLookupRelationSearchTabComponent,
DsDynamicLookupRelationSelectionTabComponent
DsDynamicLookupRelationSelectionTabComponent,
DsDynamicLookupRelationExternalSourceTabComponent
];
const SHARED_ITEM_PAGE_COMPONENTS = [