mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
solved issues with radiobuttons
This commit is contained in:
@@ -132,7 +132,13 @@ import { SearchConfigurationService } from './shared/search/search-configuration
|
|||||||
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';
|
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 = [
|
const IMPORTS = [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@@ -152,7 +158,8 @@ const PROVIDERS = [
|
|||||||
CommunityDataService,
|
CommunityDataService,
|
||||||
CollectionDataService,
|
CollectionDataService,
|
||||||
DSOResponseParsingService,
|
DSOResponseParsingService,
|
||||||
DSpaceRESTv2Service,
|
{ provide: MOCK_RESPONSE_MAP, useValue: mockResponseMap },
|
||||||
|
{ provide: DSpaceRESTv2Service, useFactory: restServiceFactory, deps: [GLOBAL_CONFIG, MOCK_RESPONSE_MAP, HttpClient]},
|
||||||
DynamicFormLayoutService,
|
DynamicFormLayoutService,
|
||||||
DynamicFormService,
|
DynamicFormService,
|
||||||
DynamicFormValidationService,
|
DynamicFormValidationService,
|
||||||
|
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.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 { configureRequest, getSucceededRemoteData } from '../shared/operators';
|
||||||
import { FindAllOptions, FindAllRequest } from './request.models';
|
import { FindAllOptions, FindAllRequest } from './request.models';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
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 if (type.rightLabel === label) return this.checkType(type, secondType, firstType);
|
||||||
else return [];
|
else return [];
|
||||||
}),
|
}),
|
||||||
|
tap((t) => console.log(t))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
import { InjectionToken } from '@angular/core';
|
import { InjectionToken } from '@angular/core';
|
||||||
|
import mockSubmissionResponse from '../mocks/mock-submission-response.json';
|
||||||
|
|
||||||
export class MockResponseMap extends Map<string, any> {};
|
export class MockResponseMap extends Map<string, any> {};
|
||||||
|
|
||||||
export const MOCK_RESPONSE_MAP: InjectionToken<MockResponseMap> = new InjectionToken<MockResponseMap>('mockResponseMap');
|
export const MOCK_RESPONSE_MAP: InjectionToken<MockResponseMap> = new InjectionToken<MockResponseMap>('mockResponseMap');
|
||||||
|
|
||||||
export const mockResponseMap: MockResponseMap = new Map([
|
export const mockResponseMap: MockResponseMap = new Map([
|
||||||
|
[ '/config/submissionforms/traditionalpageone', mockSubmissionResponse ]
|
||||||
]);
|
]);
|
||||||
|
@@ -38,7 +38,10 @@
|
|||||||
"closed": null
|
"closed": null
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"languageCodes": ["en", "nl"]
|
"languageCodes": [
|
||||||
|
"en",
|
||||||
|
"nl"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@@ -6,7 +6,7 @@ import { Action } from '@ngrx/store';
|
|||||||
import { Item } from '../../../../../core/shared/item.model';
|
import { Item } from '../../../../../core/shared/item.model';
|
||||||
|
|
||||||
export const RelationshipActionTypes = {
|
export const RelationshipActionTypes = {
|
||||||
ADD_RELATIONSHIP: type('dspace/ relationship/ADD_RELATIONSHIP'),
|
ADD_RELATIONSHIP: type('dspace/relationship/ADD_RELATIONSHIP'),
|
||||||
REMOVE_RELATIONSHIP: type('dspace/relationship/REMOVE_RELATIONSHIP'),
|
REMOVE_RELATIONSHIP: type('dspace/relationship/REMOVE_RELATIONSHIP'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -12,16 +12,18 @@
|
|||||||
(paginationChange)="onPaginationChange($event)">
|
(paginationChange)="onPaginationChange($event)">
|
||||||
<ul *ngIf="objects?.hasSucceeded" class="list-unstyled">
|
<ul *ngIf="objects?.hasSucceeded" class="list-unstyled">
|
||||||
<li *ngFor="let object of objects?.payload?.page; let i = index; let last = last" class="mt-4 mb-4" [class.border-bottom]="hasBorder && !last">
|
<li *ngFor="let object of objects?.payload?.page; let i = index; let last = last" class="mt-4 mb-4" [class.border-bottom]="hasBorder && !last">
|
||||||
|
<ng-container *ngVar="selectionService.isObjectSelected(selectionConfig.listId, object) | async as checked">
|
||||||
<input *ngIf="selectable && selectionConfig.repeatable" class="form-check-input" type="checkbox"
|
<input *ngIf="selectable && selectionConfig.repeatable" class="form-check-input" type="checkbox"
|
||||||
[name]="'checkbox' + i"
|
[name]="'checkbox' + i"
|
||||||
[id]="'object'+i"
|
[id]="'object'+i"
|
||||||
[checked]="selectionService.isObjectSelected(selectionConfig.listId, object) | async"
|
[checked]="checked"
|
||||||
(change)="selectCheckbox($event.currentTarget.checked, object)">
|
(change)="selectCheckbox(!checked, object)">
|
||||||
<input *ngIf="selectable && !selectionConfig.repeatable" class="form-check-input" type="radio"
|
<input *ngIf="selectable && !selectionConfig.repeatable" class="form-check-input" type="radio"
|
||||||
[name]="'radio' + i"
|
[name]="'radio' + i"
|
||||||
[id]="'object'+i"
|
[id]="'object'+i"
|
||||||
[checked]="selectionService.isObjectSelected(selectionConfig.listId, object) | async"
|
[checked]="checked"
|
||||||
(change)="selectRadio($event.currentTarget.checked, object)">
|
(click)="selectRadio(!checked, object)">
|
||||||
|
</ng-container>
|
||||||
<ds-wrapper-list-element [object]="object" [index]="i"></ds-wrapper-list-element>
|
<ds-wrapper-list-element [object]="object" [index]="i"></ds-wrapper-list-element>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -15,6 +15,7 @@ import { PaginationComponentOptions } from '../pagination/pagination-component-o
|
|||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
import { SearchResult } from '../search/search-result.model';
|
import { SearchResult } from '../search/search-result.model';
|
||||||
import { SelectableListService } from './selectable-list/selectable-list.service';
|
import { SelectableListService } from './selectable-list/selectable-list.service';
|
||||||
|
import { map, take, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
changeDetection: ChangeDetectionStrategy.Default,
|
changeDetection: ChangeDetectionStrategy.Default,
|
||||||
@@ -123,12 +124,22 @@ export class ObjectListComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
selectRadio(value: boolean, object: ListableObject) {
|
selectRadio(value: boolean, object: ListableObject) {
|
||||||
if (value) {
|
const selected$ = this.selectionService.getSelectableList(this.selectionConfig.listId);
|
||||||
this.selectionService.selectSingle(this.selectionConfig.listId, object, false);
|
selected$.pipe(
|
||||||
this.selectObject.emit(object);
|
take(1),
|
||||||
} else {
|
map((selected) => selected ? selected.selection : [])
|
||||||
this.selectionService.deselectSingle(this.selectionConfig.listId, object);
|
).subscribe((selection) => {
|
||||||
this.deselectObject.emit(object);
|
// 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,12 +40,11 @@ export class SelectableListSelectAction extends SelectableListAction {
|
|||||||
export class SelectableListSelectSingleAction extends SelectableListAction {
|
export class SelectableListSelectSingleAction extends SelectableListAction {
|
||||||
payload: {
|
payload: {
|
||||||
object: ListableObject,
|
object: ListableObject,
|
||||||
multipleSelectionsAllowed: boolean
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(id: string, object: ListableObject, multipleSelectionsAllowed: boolean = true) {
|
constructor(id: string, object: ListableObject) {
|
||||||
super(SelectableListActionTypes.SELECT_SINGLE, id);
|
super(SelectableListActionTypes.SELECT_SINGLE, id);
|
||||||
this.payload = { object, multipleSelectionsAllowed };
|
this.payload = { object };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -70,13 +70,9 @@ function select(state: SelectableListState, action: SelectableListSelectAction)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectSingle(state: SelectableListState, action: SelectableListSelectSingleAction) {
|
function selectSingle(state: SelectableListState, action: SelectableListSelectSingleAction) {
|
||||||
let newSelection;
|
let newSelection = state.selection;
|
||||||
if (!isObjectInSelection(state.selection, action.payload.object)) {
|
if (!isObjectInSelection(state.selection, action.payload.object)) {
|
||||||
if (action.payload.multipleSelectionsAllowed) {
|
newSelection = [...state.selection, action.payload.object];
|
||||||
newSelection = [...state.selection, action.payload.object];
|
|
||||||
} else {
|
|
||||||
newSelection = [action.payload.object];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Object.assign({}, state, { selection: newSelection });
|
return Object.assign({}, state, { selection: newSelection });
|
||||||
}
|
}
|
||||||
|
@@ -37,10 +37,9 @@ export class SelectableListService {
|
|||||||
* Select an object in a specific list in the store
|
* 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 {string} id The id of the list on which the object should be selected
|
||||||
* @param {ListableObject} object The object to select
|
* @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) {
|
selectSingle(id: string, object: ListableObject) {
|
||||||
this.store.dispatch(new SelectableListSelectSingleAction(id, object, multipleSelectionsAllowed));
|
this.store.dispatch(new SelectableListSelectSingleAction(id, object));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -18,9 +18,4 @@ export class SearchResult<T extends DSpaceObject> extends ListableObject {
|
|||||||
*/
|
*/
|
||||||
@excludeFromEquals
|
@excludeFromEquals
|
||||||
hitHighlights: MetadataMap;
|
hitHighlights: MetadataMap;
|
||||||
|
|
||||||
@excludeFromEquals
|
|
||||||
_links: {};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user