mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
62849: existing selected objects are already selected and disabled
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"label": "Journal Issue",
|
||||
"mandatory": true,
|
||||
"repeatable": false,
|
||||
"repeatable": true,
|
||||
"mandatoryMessage": "Required field!",
|
||||
"hints": "Select a journal issue for this publication.",
|
||||
"selectableMetadata": [
|
||||
|
@@ -6,8 +6,9 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body" *ngVar="(resultsRD$ | async) as resultsRD">
|
||||
<form class="input-group mb-3" #queryForm="ngForm" (ngSubmit)="search(queryForm.value.query)" >
|
||||
<input type="text" class="form-control" name="query" placeholder="Search query" [ngModel]="searchQuery">
|
||||
<form class="input-group mb-3" #queryForm="ngForm" (ngSubmit)="search(queryForm.value.query)">
|
||||
<input type="text" class="form-control" name="query" placeholder="Search query"
|
||||
[ngModel]="searchQuery">
|
||||
<div class="input-group-append">
|
||||
<button class="btn btn-outline-secondary" type="submit">Go</button>
|
||||
</div>
|
||||
@@ -25,16 +26,13 @@
|
||||
-->
|
||||
<input *ngIf="!isAllSelected() && !isSomeSelected()" type="checkbox"
|
||||
[indeterminate]="false"
|
||||
(change)="selectAll()"
|
||||
>
|
||||
(change)="selectAll()">
|
||||
<input *ngIf="!isAllSelected() && isSomeSelected()" type="checkbox"
|
||||
[indeterminate]="true"
|
||||
(change)="deselectAll()"
|
||||
>
|
||||
(change)="deselectAll()">
|
||||
<input *ngIf="isAllSelected()" type="checkbox"
|
||||
[checked]="true"
|
||||
(change)="deselectAll()"
|
||||
>
|
||||
(change)="deselectAll()">
|
||||
</div>
|
||||
</div>
|
||||
<div ngbDropdown class="input-group-append">
|
||||
@@ -69,6 +67,7 @@
|
||||
[name]="'checkbox' + i"
|
||||
[id]="'object'+i"
|
||||
[checked]="isSelected(result.indexableObject)"
|
||||
[disabled]="isDisabled(result.indexableObject)"
|
||||
(change)="selectCheckbox($event.currentTarget.checked, result.indexableObject)">
|
||||
<input *ngIf="!repeatable" class="form-check-input" type="radio"
|
||||
[name]="'radio' + i"
|
||||
|
@@ -29,6 +29,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
||||
searchConfig: PaginatedSearchOptions;
|
||||
repeatable: boolean;
|
||||
selection: DSpaceObject[] = [];
|
||||
previousSelection: DSpaceObject[] = [];
|
||||
allSelected = false;
|
||||
searchQuery;
|
||||
initialPagination = Object.assign(new PaginationComponentOptions(), {
|
||||
@@ -75,7 +76,12 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
||||
}
|
||||
|
||||
isSelected(dso: DSpaceObject): boolean {
|
||||
return hasValue(this.selection.find((selected) => selected.uuid === dso.uuid));
|
||||
const completeSelection = [...this.selection, ...this.previousSelection];
|
||||
return hasValue(completeSelection.find((selected) => selected.uuid === dso.uuid));
|
||||
}
|
||||
|
||||
isDisabled(dso: DSpaceObject): boolean {
|
||||
return hasValue(this.previousSelection.find((selected) => selected.uuid === dso.uuid));
|
||||
}
|
||||
|
||||
selectCheckbox(value: boolean, dso: DSpaceObject) {
|
||||
@@ -98,7 +104,8 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
||||
selectPage(page: SearchResult<DSpaceObject>[]) {
|
||||
const newObjects: DSpaceObject[] = page
|
||||
.map((searchResult) => searchResult.indexableObject)
|
||||
.filter((dso) => hasNoValue(this.selection.find((selected) => selected.uuid === dso.uuid)));
|
||||
.filter((dso) => hasNoValue(this.selection.find((selected) => selected.uuid === dso.uuid)))
|
||||
.filter((dso) => hasNoValue(this.previousSelection.find((object) => object.uuid === dso.uuid)));
|
||||
this.selection = [...this.selection, ...newObjects]
|
||||
}
|
||||
|
||||
@@ -119,11 +126,13 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
|
||||
const fullSearchConfig = Object.assign(this.searchConfig, { pagination: fullPagination });
|
||||
const results = this.searchService.search(fullSearchConfig);
|
||||
results.pipe(
|
||||
getSucceededRemoteData(),
|
||||
map((resultsRD) => resultsRD.payload.page)
|
||||
)
|
||||
getSucceededRemoteData(),
|
||||
map((resultsRD) => resultsRD.payload.page)
|
||||
)
|
||||
.subscribe((results) =>
|
||||
this.selection = [...this.selection, ...results.map((searchResult) => searchResult.indexableObject)]
|
||||
this.selection = results
|
||||
.map((searchResult) => searchResult.indexableObject)
|
||||
.filter((dso) => hasNoValue(this.previousSelection.find((object) => object.uuid === dso.uuid)))
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -47,6 +47,8 @@ export class DsDynamicLookupRelationComponent extends DynamicFormControlComponen
|
||||
openLookup() {
|
||||
this.modalRef = this.modalService.open(DsDynamicLookupRelationModalComponent);
|
||||
this.modalRef.componentInstance.repeatable = this.model.repeatable;
|
||||
this.modalRef.componentInstance.selection = this.selectedResults || [];
|
||||
this.modalRef.componentInstance.previousSelection = this.model.value || [];
|
||||
this.modalRef.componentInstance.relationKey = this.model.name;
|
||||
this.modalRef.result.then((resultList) => {
|
||||
this.selectedResults = resultList;
|
||||
|
Reference in New Issue
Block a user