From addc6618ba1b9361a613ea6878e813f80da519a0 Mon Sep 17 00:00:00 2001 From: lotte Date: Thu, 29 Aug 2019 16:29:55 +0200 Subject: [PATCH] solved issues with radiobuttons --- src/app/core/core.module.ts | 11 ++++++-- .../core/data/relationship-type.service.ts | 3 ++- .../dspace-rest-v2/mocks/mock-response-map.ts | 2 ++ .../mocks/mock-submission-response.json | 5 +++- .../relationship.actions.ts | 2 +- .../object-list/object-list.component.html | 10 +++++--- .../object-list/object-list.component.ts | 25 +++++++++++++------ .../selectable-list.actions.ts | 5 ++-- .../selectable-list.reducer.ts | 8 ++---- .../selectable-list.service.ts | 5 ++-- src/app/shared/search/search-result.model.ts | 5 ---- 11 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 10a2fdc9f6..9c4620d72e 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -132,7 +132,13 @@ 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'; - +export const restServiceFactory = (cfg: GlobalConfig, mocks: MockResponseMap, http: HttpClient) => { + if (ENV_CONFIG.production) { + return new DSpaceRESTv2Service(http); + } else { + return new EndpointMockingRestService(cfg, mocks, http); + } +}; const IMPORTS = [ CommonModule, @@ -152,7 +158,8 @@ const PROVIDERS = [ CommunityDataService, CollectionDataService, DSOResponseParsingService, - DSpaceRESTv2Service, + { provide: MOCK_RESPONSE_MAP, useValue: mockResponseMap }, + { provide: DSpaceRESTv2Service, useFactory: restServiceFactory, deps: [GLOBAL_CONFIG, MOCK_RESPONSE_MAP, HttpClient]}, DynamicFormLayoutService, DynamicFormService, DynamicFormValidationService, diff --git a/src/app/core/data/relationship-type.service.ts b/src/app/core/data/relationship-type.service.ts index a3ce8cc33e..04ce49c3c4 100644 --- a/src/app/core/data/relationship-type.service.ts +++ b/src/app/core/data/relationship-type.service.ts @@ -2,7 +2,7 @@ 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 { filter, find, map, switchMap } from 'rxjs/operators'; +import { filter, find, map, switchMap, tap } from 'rxjs/operators'; import { configureRequest, getSucceededRemoteData } from '../shared/operators'; import { FindAllOptions, FindAllRequest } from './request.models'; import { Observable } from 'rxjs/internal/Observable'; @@ -60,6 +60,7 @@ export class RelationshipTypeService { else if (type.rightLabel === label) return this.checkType(type, secondType, firstType); else return []; }), + tap((t) => console.log(t)) ); } diff --git a/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts b/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts index 15ec504bc8..573a724c5a 100644 --- a/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts +++ b/src/app/core/dspace-rest-v2/mocks/mock-response-map.ts @@ -1,8 +1,10 @@ import { InjectionToken } from '@angular/core'; +import mockSubmissionResponse from '../mocks/mock-submission-response.json'; export class MockResponseMap extends Map {}; export const MOCK_RESPONSE_MAP: InjectionToken = new InjectionToken('mockResponseMap'); export const mockResponseMap: MockResponseMap = new Map([ + [ '/config/submissionforms/traditionalpageone', mockSubmissionResponse ] ]); diff --git a/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json b/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json index eca33c9587..3c7860102f 100644 --- a/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json +++ b/src/app/core/dspace-rest-v2/mocks/mock-submission-response.json @@ -38,7 +38,10 @@ "closed": null } ], - "languageCodes": ["en", "nl"] + "languageCodes": [ + "en", + "nl" + ] } ] }, diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.actions.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.actions.ts index e458151f0d..1030dc9754 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.actions.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.actions.ts @@ -6,7 +6,7 @@ import { Action } from '@ngrx/store'; import { Item } from '../../../../../core/shared/item.model'; export const RelationshipActionTypes = { - ADD_RELATIONSHIP: type('dspace/ relationship/ADD_RELATIONSHIP'), + ADD_RELATIONSHIP: type('dspace/relationship/ADD_RELATIONSHIP'), REMOVE_RELATIONSHIP: type('dspace/relationship/REMOVE_RELATIONSHIP'), }; diff --git a/src/app/shared/object-list/object-list.component.html b/src/app/shared/object-list/object-list.component.html index 4e1eb62aa9..b233298061 100644 --- a/src/app/shared/object-list/object-list.component.html +++ b/src/app/shared/object-list/object-list.component.html @@ -12,16 +12,18 @@ (paginationChange)="onPaginationChange($event)">
  • + + [checked]="checked" + (change)="selectCheckbox(!checked, object)"> + [checked]="checked" + (click)="selectRadio(!checked, object)"> +
diff --git a/src/app/shared/object-list/object-list.component.ts b/src/app/shared/object-list/object-list.component.ts index 6070cad37d..0b7dc6bf85 100644 --- a/src/app/shared/object-list/object-list.component.ts +++ b/src/app/shared/object-list/object-list.component.ts @@ -15,6 +15,7 @@ import { PaginationComponentOptions } from '../pagination/pagination-component-o import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { SearchResult } from '../search/search-result.model'; import { SelectableListService } from './selectable-list/selectable-list.service'; +import { map, take, tap } from 'rxjs/operators'; @Component({ changeDetection: ChangeDetectionStrategy.Default, @@ -123,12 +124,22 @@ export class ObjectListComponent { } selectRadio(value: boolean, object: ListableObject) { - if (value) { - this.selectionService.selectSingle(this.selectionConfig.listId, object, false); - this.selectObject.emit(object); - } else { - this.selectionService.deselectSingle(this.selectionConfig.listId, object); - this.deselectObject.emit(object); - } + const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId); + selected$.pipe( + take(1), + map((selected) => selected ? selected.selection : []) + ).subscribe((selection) => { + // First deselect any existing selections, this is a radio button + selection.forEach((selectedObject) => { + this.selectionService.deselectSingle(this.selectionConfig.listId, selectedObject); + this.deselectObject.emit(selectedObject); + }); + if (value) { + this.selectionService.selectSingle(this.selectionConfig.listId, object); + this.selectObject.emit(object); + } + }); + + } } diff --git a/src/app/shared/object-list/selectable-list/selectable-list.actions.ts b/src/app/shared/object-list/selectable-list/selectable-list.actions.ts index 89f8682c33..28ba79867d 100644 --- a/src/app/shared/object-list/selectable-list/selectable-list.actions.ts +++ b/src/app/shared/object-list/selectable-list/selectable-list.actions.ts @@ -40,12 +40,11 @@ export class SelectableListSelectAction extends SelectableListAction { export class SelectableListSelectSingleAction extends SelectableListAction { payload: { object: ListableObject, - multipleSelectionsAllowed: boolean }; - constructor(id: string, object: ListableObject, multipleSelectionsAllowed: boolean = true) { + constructor(id: string, object: ListableObject) { super(SelectableListActionTypes.SELECT_SINGLE, id); - this.payload = { object, multipleSelectionsAllowed }; + this.payload = { object }; } } diff --git a/src/app/shared/object-list/selectable-list/selectable-list.reducer.ts b/src/app/shared/object-list/selectable-list/selectable-list.reducer.ts index e3f0479d7b..b42f9efef8 100644 --- a/src/app/shared/object-list/selectable-list/selectable-list.reducer.ts +++ b/src/app/shared/object-list/selectable-list/selectable-list.reducer.ts @@ -70,13 +70,9 @@ function select(state: SelectableListState, action: SelectableListSelectAction) } function selectSingle(state: SelectableListState, action: SelectableListSelectSingleAction) { - let newSelection; + let newSelection = state.selection; if (!isObjectInSelection(state.selection, action.payload.object)) { - if (action.payload.multipleSelectionsAllowed) { - newSelection = [...state.selection, action.payload.object]; - } else { - newSelection = [action.payload.object]; - } + newSelection = [...state.selection, action.payload.object]; } return Object.assign({}, state, { selection: newSelection }); } diff --git a/src/app/shared/object-list/selectable-list/selectable-list.service.ts b/src/app/shared/object-list/selectable-list/selectable-list.service.ts index 2ea495691f..84483df3e8 100644 --- a/src/app/shared/object-list/selectable-list/selectable-list.service.ts +++ b/src/app/shared/object-list/selectable-list/selectable-list.service.ts @@ -37,10 +37,9 @@ export class SelectableListService { * Select an object in a specific list in the store * @param {string} id The id of the list on which the object should be selected * @param {ListableObject} object The object to select - * @param {boolean} multipleSelectionsAllowed Defines if the multiple selections are allowed for this selectable list */ - selectSingle(id: string, object: ListableObject, multipleSelectionsAllowed?: boolean) { - this.store.dispatch(new SelectableListSelectSingleAction(id, object, multipleSelectionsAllowed)); + selectSingle(id: string, object: ListableObject) { + this.store.dispatch(new SelectableListSelectSingleAction(id, object)); } /** diff --git a/src/app/shared/search/search-result.model.ts b/src/app/shared/search/search-result.model.ts index d12a7a4eef..c8325d7bb2 100644 --- a/src/app/shared/search/search-result.model.ts +++ b/src/app/shared/search/search-result.model.ts @@ -18,9 +18,4 @@ export class SearchResult extends ListableObject { */ @excludeFromEquals hitHighlights: MetadataMap; - - @excludeFromEquals - _links: {}; - - }