62849: existing selected objects are already selected and disabled

This commit is contained in:
lotte
2019-07-09 14:59:23 +02:00
parent 1a30744f5b
commit 7f3dab9fc0
4 changed files with 25 additions and 15 deletions

View File

@@ -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": [

View File

@@ -7,7 +7,8 @@
</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">
<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"

View File

@@ -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]
}
@@ -123,7 +130,9 @@ export class DsDynamicLookupRelationModalComponent implements OnInit {
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)))
);
}

View File

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