Skip to content

Commit

Permalink
feat(list-view): multi-select items
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed May 29, 2020
1 parent 39c2c87 commit c6efb4e
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/app/pages/manager/fileMode/listView/listView.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import { API, APIDefinition } from 'ngx-easy-table';
selector: 'manager-listView',
template: `
<ng-template #secAll>
<nb-checkbox> </nb-checkbox>
<nb-checkbox
[(indeterminate)]="checAllInteral"
[(checked)]="checkAll"
(checkedChange)="onToggleAll($event)"
>
</nb-checkbox>
</ng-template>
<ngx-table
#table
Expand All @@ -29,7 +34,7 @@ import { API, APIDefinition } from 'ngx-easy-table';
>
<ng-template let-row let-index="index">
<td>
<nb-checkbox> </nb-checkbox>
<nb-checkbox [(checked)]="check[index]" (checkedChange)="onToggle()"> </nb-checkbox>
<!-- todo: disable double click event here-->
</td>
<td>
Expand Down Expand Up @@ -69,9 +74,14 @@ export class ListViewComponent implements OnInit, OnDestroy {
];

public data: OperationsListFlowOutItemNode[];
public check: boolean[];
public checkAll = false;
public checAllInteral = false;

@ViewChild('table') table: APIDefinition;
resetCurrentPage() {
this.check = [];
this.checkAll = false;
this.table.apiEvent({
type: API.setPaginationCurrentPage,
value: 1,
Expand All @@ -94,14 +104,37 @@ export class ListViewComponent implements OnInit, OnDestroy {
}
}

onToggleAll(val: boolean) {
this.check = this.check.map(() => val);
this.checAllInteral = false;
}
onToggle() {
let sum = 0;
this.check.forEach((x) => (sum += x ? 1 : 0));
if (sum === this.check.length) {
this.checkAll = true;
this.checAllInteral = false;
} else if (sum === 0) {
this.checkAll = false;
this.checAllInteral = false;
} else {
this.checkAll = false;
this.checAllInteral = true;
}
}

@Input() list$: OperationsListFlow;

ngOnInit() {
this.listScrb = this.list$.getSupersetOutput().subscribe((x) => {
if (x[1].length !== 0) {
this.data = undefined;
this.check = [];
this.checkAll = false;
}
this.data = x[0].list;
this.check = x[0].list.map(() => false);
this.checkAll = false;
this.remote = x[0].remote;
});

Expand Down

0 comments on commit c6efb4e

Please sign in to comment.