Skip to content

Commit

Permalink
Merged in bugfix/SHIBUI-908 (pull request #205)
Browse files Browse the repository at this point in the history
SHIBUI-908 Fixed issue with check-all & check-none in attribute release datalist
  • Loading branch information
rmathis committed Sep 27, 2018
2 parents b5fb56e + 2df1e8c commit b5f9854
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ui/src/app/schema-form/widget/check/checklist.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Component, AfterViewInit } from '@angular/core';
import { Component, AfterViewInit, OnDestroy } from '@angular/core';

import { ArrayWidget } from 'ngx-schema-form';
import { AttributesService } from '../../../metadata/domain/service/attributes.service';
import { Observable, of } from 'rxjs';
import { Observable, of, Subscription } from 'rxjs';

/* istanbul ignore next */
@Component({
selector: 'checklist-component',
templateUrl: `./checklist.component.html`
})
export class ChecklistComponent extends ArrayWidget implements AfterViewInit {
export class ChecklistComponent extends ArrayWidget implements AfterViewInit, OnDestroy {
checked: any = {};
currentData: { key: string, label: string }[];
sub: Subscription;

constructor(
private attributes: AttributesService
Expand All @@ -21,6 +23,12 @@ export class ChecklistComponent extends ArrayWidget implements AfterViewInit {
ngAfterViewInit(): void {
super.ngAfterViewInit();
this.formProperty.value.forEach(val => this.checked[val] = true);

this.sub = this.data.subscribe(d => this.currentData = d);
}

ngOnDestroy(): void {
this.sub.unsubscribe();
}

private commitValue(): void {
Expand All @@ -41,11 +49,11 @@ export class ChecklistComponent extends ArrayWidget implements AfterViewInit {
}

onCheckAll(): void {
this.schema.widget.data.forEach(attr => this.checked[attr.key] = true);
this.currentData.forEach(attr => this.checked[attr.key] = true);
this.commitValue();
}
onCheckNone(event: Event | null = null): void {
this.schema.widget.data.forEach(attr => {
this.currentData.forEach(attr => {
delete this.checked[attr.key];
});
this.commitValue();
Expand Down

0 comments on commit b5f9854

Please sign in to comment.