solved issues with radiobuttons

This commit is contained in:
lotte
2019-08-29 16:29:55 +02:00
parent 3f0e5865f9
commit addc6618ba
11 changed files with 48 additions and 33 deletions

View File

@@ -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,

View File

@@ -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))
);
}

View File

@@ -1,8 +1,10 @@
import { InjectionToken } from '@angular/core';
import mockSubmissionResponse from '../mocks/mock-submission-response.json';
export class MockResponseMap extends Map<string, any> {};
export const MOCK_RESPONSE_MAP: InjectionToken<MockResponseMap> = new InjectionToken<MockResponseMap>('mockResponseMap');
export const mockResponseMap: MockResponseMap = new Map([
[ '/config/submissionforms/traditionalpageone', mockSubmissionResponse ]
]);

View File

@@ -38,7 +38,10 @@
"closed": null
}
],
"languageCodes": ["en", "nl"]
"languageCodes": [
"en",
"nl"
]
}
]
},

View File

@@ -12,16 +12,18 @@
(paginationChange)="onPaginationChange($event)">
<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">
<ng-container *ngVar="selectionService.isObjectSelected(selectionConfig.listId, object) | async as checked">
<input *ngIf="selectable && selectionConfig.repeatable" class="form-check-input" type="checkbox"
[name]="'checkbox' + i"
[id]="'object'+i"
[checked]="selectionService.isObjectSelected(selectionConfig.listId, object) | async"
(change)="selectCheckbox($event.currentTarget.checked, object)">
[checked]="checked"
(change)="selectCheckbox(!checked, object)">
<input *ngIf="selectable && !selectionConfig.repeatable" class="form-check-input" type="radio"
[name]="'radio' + i"
[id]="'object'+i"
[checked]="selectionService.isObjectSelected(selectionConfig.listId, object) | async"
(change)="selectRadio($event.currentTarget.checked, object)">
[checked]="checked"
(click)="selectRadio(!checked, object)">
</ng-container>
<ds-wrapper-list-element [object]="object" [index]="i"></ds-wrapper-list-element>
</li>
</ul>

View File

@@ -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) {
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, false);
this.selectionService.selectSingle(this.selectionConfig.listId, object);
this.selectObject.emit(object);
} else {
this.selectionService.deselectSingle(this.selectionConfig.listId, object);
this.deselectObject.emit(object);
}
}
});
}
}

View File

@@ -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 };
}
}

View File

@@ -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];
}
}
return Object.assign({}, state, { selection: newSelection });
}

View File

@@ -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));
}
/**

View File

@@ -18,9 +18,4 @@ export class SearchResult<T extends DSpaceObject> extends ListableObject {
*/
@excludeFromEquals
hitHighlights: MetadataMap;
@excludeFromEquals
_links: {};
}