Skip to content

Commit d3b4d40

Browse files
author
Huaqiao Zhang
committed
fix: all datagrid and pagination not working as expected
Signed-off-by: Huaqiao Zhang <huaqiaoz@vmware.com>
1 parent d5cc884 commit d3b4d40

File tree

10 files changed

+129
-74
lines changed

10 files changed

+129
-74
lines changed

web/src/app/metadata/device/device-list/device-list.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ export class DeviceListComponent implements OnInit {
180180

181181
isCheckedAll(): boolean {
182182
let checkedAll = true;
183+
if (this.deviceList && this.deviceList.length === 0) {
184+
checkedAll = false
185+
}
183186
this.deviceList.forEach(device => {
184187
if (this.selectedDevice.findIndex(d => d.name === device.name) === -1) {
185188
checkedAll = false

web/src/app/metadata/profile/device-profile-list/device-profile-list.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ export class DeviceProfileListComponent implements OnInit {
175175

176176
isCheckedAll(): boolean {
177177
let checkall = true;
178+
if (this.profileList && this.profileList.length === 0) {
179+
checkall = false
180+
}
178181
this.profileList.forEach((p) => {
179182
if (this.multiProfilesSelected.indexOf(p.name) === -1) {
180183
checkall = false

web/src/app/notifications/notification/notification-list/notification-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<table class="table table-hover text-truncate ">
144144
<thead class="thead-light">
145145
<tr>
146-
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
146+
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll()" (click)="selectAll($event)"></th>
147147
<th scope="col">ID</th>
148148
<th scope="col">Category</th>
149149
<th scope="col">Labels</th>

web/src/app/notifications/notification/notification-list/notification-list.component.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class NotificationListComponent implements OnInit {
3030

3131
notificationList: Notification[] = [];
3232
notificationSelected: Notification[] = [];
33-
isCheckedAll: boolean = false;
3433
pagination: number = 1;
3534
pageLimit: number = 5;
3635
pageOffset: number = (this.pagination - 1) * this.pageLimit;
@@ -241,40 +240,53 @@ export class NotificationListComponent implements OnInit {
241240
$("#deleteConfirmDialog").modal('hide');
242241
}
243242

243+
isCheckedAll(): boolean {
244+
let checkedAll = true;
245+
if (this.notificationList && this.notificationList.length === 0) {
246+
checkedAll = false
247+
}
248+
this.notificationList.forEach(notification => {
249+
if (this.notificationSelected.findIndex(notificationSelected => notificationSelected.id === notification.id) === -1) {
250+
checkedAll = false
251+
}
252+
});
253+
return checkedAll
254+
}
255+
244256
selectAll(event: any) {
245257
const checkbox = event.target;
246258
if (checkbox.checked) {
247-
this.notificationSelected = [];
248259
this.notificationList.forEach(notification => {
260+
if (this.notificationSelected.findIndex(notiSelected => notiSelected.id === notification.id) !== -1) {
261+
return
262+
}
249263
this.notificationSelected.push(notification);
250-
this.isChecked(notification.id);
251264
});
252-
this.isCheckedAll = true;
253265
return
254266
}
255-
this.isCheckedAll = false;
256-
this.notificationSelected = [];
257267
this.notificationList.forEach(notification => {
258-
this.isChecked(notification.id);
268+
let found = this.notificationSelected.findIndex(notiSelected => notiSelected.id === notification.id)
269+
if (found !== -1) {
270+
this.notificationSelected.splice(found,1)
271+
}
259272
});
260273
}
261274

262275
isChecked(id: string): boolean {
263-
return this.notificationSelected.findIndex(v => v.id === id) >= 0;
276+
return this.notificationSelected.findIndex(notification => notification.id === id) >= 0;
264277
}
265278

266279
selectOne(event: any, notification: Notification) {
267280
const checkbox = event.target;
268281
if (checkbox.checked) {
269-
this.notificationSelected.push(notification);
270-
if (this.notificationSelected.length === this.notificationList.length) {
271-
this.isCheckedAll = true;
272-
}
282+
this.notificationSelected.push(notification)
273283
return
274284
}
275-
this.isCheckedAll = false;
276-
this.isChecked(notification.id);
277-
this.notificationSelected.splice(this.notificationSelected.indexOf(notification), 1)
285+
286+
let found = this.notificationSelected.findIndex(notiSelected => notiSelected.id === notification.id)
287+
if (found !== -1) {
288+
this.notificationSelected.splice(found,1)
289+
}
278290
}
279291

280292
paginationBySearchMode() {

web/src/app/notifications/subscription/subscription-list/subscription-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<table class="table table-hover text-truncate ">
4242
<thead class="thead-light">
4343
<tr>
44-
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
44+
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll()" (click)="selectAll($event)"></th>
4545
<th scope="col">ID</th>
4646
<th scope="col">Name</th>
4747
<th scope="col">Description</th>

web/src/app/notifications/subscription/subscription-list/subscription-list.component.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class SubscriptionListComponent implements OnInit {
3535
subscriptionList: Subscription[] = [];
3636
subscriptionSelected: Subscription[] = [];
3737
// checkedSubscription?: Subscription;
38-
isCheckedAll: boolean = false;
3938
pagination: number = 1;
4039
pageLimit: number = 5;
4140
pageOffset: number = (this.pagination - 1) * this.pageLimit;
@@ -75,40 +74,52 @@ export class SubscriptionListComponent implements OnInit {
7574
})
7675
}
7776

77+
isCheckedAll(): boolean {
78+
let checkedAll = true;
79+
if (this.subscriptionList && this.subscriptionList.length === 0) {
80+
checkedAll = false
81+
}
82+
this.subscriptionList.forEach(subscription => {
83+
if (this.subscriptionSelected.findIndex(subscriptionSelected => subscriptionSelected.id === subscription.id) === -1) {
84+
checkedAll = false
85+
}
86+
});
87+
return checkedAll
88+
}
89+
7890
selectAll(event: any) {
7991
const checkbox = event.target;
8092
if (checkbox.checked) {
81-
this.subscriptionSelected = [];
82-
this.subscriptionList.forEach(interval => {
83-
this.subscriptionSelected.push(interval);
84-
this.isChecked(interval.name);
93+
this.subscriptionList.forEach(subscription => {
94+
if (this.subscriptionSelected.findIndex(sub => sub.name === subscription.name) !== -1) {
95+
return
96+
}
97+
this.subscriptionSelected.push(subscription);
8598
});
86-
this.isCheckedAll = true;
8799
return
88100
}
89-
this.isCheckedAll = false;
90-
this.subscriptionSelected = [];
91-
this.subscriptionList.forEach(interval => {
92-
this.isChecked(interval.name);
101+
this.subscriptionList.forEach(subscription => {
102+
let found = this.subscriptionSelected.findIndex(sub => sub.name === subscription.name);
103+
if (found !== -1) {
104+
this.subscriptionSelected.splice(found,1)
105+
}
93106
});
94107
}
95108

96109
isChecked(name: string): boolean {
97-
return this.subscriptionSelected.findIndex(v => v.name === name) >= 0;
110+
return this.subscriptionSelected.findIndex(subscription => subscription.name === name) >= 0;
98111
}
99112

100-
selectOne(event: any, sub: Subscription) {
113+
selectOne(event: any, subscription: Subscription) {
101114
const checkbox = event.target;
102115
if (checkbox.checked) {
103-
this.subscriptionSelected.push(sub);
104-
if (this.subscriptionSelected.length === this.subscriptionList.length) {
105-
this.isCheckedAll = true;
106-
}
116+
this.subscriptionSelected.push(subscription);
107117
return
108118
}
109-
this.isCheckedAll = false;
110-
this.isChecked(sub.name);
111-
this.subscriptionSelected.splice(this.subscriptionSelected.indexOf(sub), 1)
119+
let found = this.subscriptionSelected.findIndex(sub => sub.name === subscription.name);
120+
if (found !== -1) {
121+
this.subscriptionSelected.splice(found,1)
122+
}
112123
}
113124

114125
edit() {

web/src/app/scheduler/interval/interval-list/interval-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<table class="table table-hover text-truncate ">
4242
<thead class="thead-light">
4343
<tr>
44-
<th scope="col"><input *ngIf="enableSelectAll" type="checkbox" role="button" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
44+
<th scope="col"><input *ngIf="enableSelectAll" type="checkbox" role="button" [checked]="isCheckedAll()" (click)="selectAll($event)"></th>
4545
<th scope="col">ID</th>
4646
<th scope="col">Name</th>
4747
<th scope="col">Start</th>

web/src/app/scheduler/interval/interval-list/interval-list.component.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class IntervalListComponent implements OnInit {
3737
intervalList: Interval[] = [];
3838
intervalSelected: Interval[] = [];
3939
@Input() singleIntervalSelected?: Interval;
40-
isCheckedAll: boolean = false;
40+
// isCheckedAll: boolean = false;
4141
pagination: number = 1;
4242
pageLimit: number = 5;
4343
pageOffset: number = (this.pagination - 1) * this.pageLimit;
@@ -104,47 +104,61 @@ export class IntervalListComponent implements OnInit {
104104
this.onSingleIntervalSelectedEmitter();
105105
}
106106

107+
isCheckedAll(): boolean {
108+
let checkedAll = true;
109+
if (this.intervalList && this.intervalList.length === 0) {
110+
checkedAll = false
111+
}
112+
this.intervalList.forEach(interval => {
113+
if (this.intervalSelected.findIndex(intervalSelected => intervalSelected.name === interval.name) === -1) {
114+
checkedAll = false
115+
}
116+
});
117+
return checkedAll
118+
}
119+
107120
selectAll(event: any) {
108121
const checkbox = event.target;
109122
if (checkbox.checked) {
110-
this.intervalSelected = [];
111123
this.intervalList.forEach(interval => {
124+
if (this.intervalSelected.findIndex((intervalSelected) => intervalSelected.name === interval.name) !== -1) {
125+
return
126+
}
112127
this.intervalSelected.push(interval);
113-
this.isChecked(interval.name);
114128
});
115-
this.isCheckedAll = true;
116-
return
117-
}
118-
this.isCheckedAll = false;
119-
this.intervalSelected = [];
120-
this.intervalList.forEach(interval => {
121-
this.isChecked(interval.name);
122-
});
129+
} else {
130+
this.intervalList.forEach(interval => {
131+
let found = this.intervalSelected.findIndex((intervalSelected) => intervalSelected.name === interval.name);
132+
if (found !== -1) {
133+
this.intervalSelected.splice(found,1)
134+
}
135+
});
136+
}
123137
}
124138

125139
isChecked(name: string): boolean {
126140
if (!this.enableSelectAll) {
127141
return this.isSingleChecked(name)
128142
}
129-
return this.intervalSelected.findIndex(v => v.name === name) >= 0;
143+
return this.intervalSelected.findIndex(interval => interval.name === name) >= 0;
130144
}
131145

132146
selectOne(event: any, interval: Interval) {
133147
if (!this.enableSelectAll) {
134148
this.selectSingleInterval(event, interval.name);
135149
return
136150
}
151+
137152
const checkbox = event.target;
138153
if (checkbox.checked) {
139-
this.intervalSelected.push(interval);
140-
if (this.intervalSelected.length === this.intervalList.length) {
141-
this.isCheckedAll = true;
142-
}
154+
this.intervalSelected.push(interval)
143155
return
144156
}
145-
this.isCheckedAll = false;
146-
this.isChecked(interval.name);
147-
this.intervalSelected.splice(this.intervalSelected.indexOf(interval), 1)
157+
158+
let found = this.intervalSelected.findIndex(intervalSelected => intervalSelected.name === interval.name);
159+
if (found !== -1) {
160+
this.intervalSelected.splice(found, 1)
161+
}
148162
}
149163

150164
edit() {

web/src/app/scheduler/intervalaction/interval-action-list/interval-action-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<table class="table table-hover text-truncate ">
4242
<thead class="thead-light">
4343
<tr>
44-
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll" (click)="selectAll($event)"></th>
44+
<th scope="col"><input type="checkbox" role="button" [checked]="isCheckedAll()" (click)="selectAll($event)"></th>
4545
<th scope="col">ID</th>
4646
<th scope="col">Name</th>
4747
<th scope="col">AssociatedInterval</th>

web/src/app/scheduler/intervalaction/interval-action-list/interval-action-list.component.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class IntervalActionListComponent implements OnInit {
3131

3232
intervalActionList: IntervalAction[] = [];
3333
intervalActionSelected: IntervalAction[] = [];
34-
isCheckedAll: boolean = false;
34+
// isCheckedAll: boolean = false;
3535
pagination: number = 1;
3636
pageLimit: number = 5;
3737
pageOffset: number = (this.pagination - 1) * this.pageLimit;
@@ -65,40 +65,52 @@ export class IntervalActionListComponent implements OnInit {
6565
});
6666
}
6767

68+
isCheckedAll(): boolean {
69+
let checkedAll = true;
70+
if (this.intervalActionList && this.intervalActionList.length === 0) {
71+
checkedAll = false
72+
}
73+
this.intervalActionList.forEach(action => {
74+
if (this.intervalActionSelected.findIndex(actionSelected => actionSelected.name === action.name) === -1) {
75+
checkedAll = false
76+
}
77+
});
78+
return checkedAll
79+
}
80+
6881
selectAll(event: any) {
6982
const checkbox = event.target;
7083
if (checkbox.checked) {
71-
this.intervalActionSelected = [];
7284
this.intervalActionList.forEach(intervalAction => {
85+
if (this.intervalActionSelected.findIndex(actionSelected => actionSelected.name === intervalAction.name) !== -1) {
86+
return
87+
}
7388
this.intervalActionSelected.push(intervalAction);
74-
this.isChecked(intervalAction.name);
7589
});
76-
this.isCheckedAll = true;
77-
return
90+
} else {
91+
this.intervalActionList.forEach(intervalAction => {
92+
let found = this.intervalActionSelected.findIndex(actionSelected => actionSelected.name === intervalAction.name);
93+
if (found !== -1) {
94+
this.intervalActionSelected.splice(found,1)
95+
}
96+
});
7897
}
79-
this.isCheckedAll = false;
80-
this.intervalActionSelected = [];
81-
this.intervalActionList.forEach(intervalAction => {
82-
this.isChecked(intervalAction.name);
83-
});
8498
}
8599

86100
isChecked(name: string): boolean {
87-
return this.intervalActionSelected.findIndex(v => v.name === name) >= 0;
101+
return this.intervalActionSelected.findIndex(intervalAction => intervalAction.name === name) >= 0;
88102
}
89103

90104
selectOne(event: any, intervalAction: IntervalAction) {
91105
const checkbox = event.target;
92106
if (checkbox.checked) {
93107
this.intervalActionSelected.push(intervalAction);
94-
if (this.intervalActionSelected.length === this.intervalActionList.length) {
95-
this.isCheckedAll = true;
96-
}
97108
return
98109
}
99-
this.isCheckedAll = false;
100-
this.isChecked(intervalAction.name);
101-
this.intervalActionSelected.splice(this.intervalActionSelected.indexOf(intervalAction), 1)
110+
let found = this.intervalActionSelected.findIndex(actionSelected => actionSelected.name === intervalAction.name);
111+
if (found !== -1) {
112+
this.intervalActionSelected.splice(found,1)
113+
}
102114
}
103115

104116
edit() {

0 commit comments

Comments
 (0)