Skip to content

Commit 1a0957d

Browse files
Saby-BishopsMutugiiidogi
authored
all: smoother utils sharing (fixes #9287) (#9249)
Co-authored-by: mutugiii <mutugimutuma@gmail.com> Co-authored-by: dogi <dogi@users.noreply.github.com>
1 parent 9ffae30 commit 1a0957d

7 files changed

Lines changed: 13 additions & 19 deletions

File tree

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "planet",
33
"license": "AGPL-3.0",
4-
"version": "0.20.66",
4+
"version": "0.20.67",
55
"myplanet": {
6-
"latest": "v0.36.44",
7-
"min": "v0.35.44"
6+
"latest": "v0.36.54",
7+
"min": "v0.35.54"
88
},
99
"scripts": {
1010
"ng": "ng",

src/app/courses/courses.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { CouchService } from '../shared/couchdb.service';
2525
import { PlanetMessageService } from '../shared/planet-message.service';
2626
import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.component';
2727
import { CoursesService } from './courses.service';
28-
import { dedupeShelfReduce, findByIdInArray, calculateMdAdjustedLimit } from '../shared/utils';
28+
import { dedupeShelfReduce, findByIdInArray, calculateMdAdjustedLimit, itemsShown } from '../shared/utils';
2929
import { StateService } from '../shared/state.service';
3030
import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service';
3131
import { TagsService } from '../shared/forms/tags.service';
@@ -307,8 +307,7 @@ export class CoursesComponent implements OnInit, OnChanges, AfterViewInit, OnDes
307307

308308
/** Whether the number of selected elements matches the total number of rows. */
309309
isAllSelected() {
310-
const itemsShown = Math.min(this.paginator.length - (this.paginator.pageIndex * this.paginator.pageSize), this.paginator.pageSize);
311-
return this.selection.selected.length === itemsShown;
310+
return this.selection.selected.length === itemsShown(this.paginator);
312311
}
313312

314313
/** Selects all rows if they are not all selected; otherwise clear selection. */

src/app/manager-dashboard/manager-fetch.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SelectionModel } from '@angular/cdk/collections';
99
import { MatLegacyPaginator as MatPaginator, LegacyPageEvent as PageEvent } from '@angular/material/legacy-paginator';
1010
import { MatSort } from '@angular/material/sort';
1111
import { MatLegacyTableDataSource as MatTableDataSource } from '@angular/material/legacy-table';
12-
import { findByIdInArray } from '../shared/utils';
12+
import { findByIdInArray, itemsShown } from '../shared/utils';
1313
import { SyncService } from '../shared/sync.service';
1414
import { PlanetMessageService } from '../shared/planet-message.service';
1515

@@ -62,8 +62,7 @@ export class ManagerFetchComponent implements OnInit, AfterViewInit {
6262

6363
/** Whether the number of selected elements matches the total number of rows. */
6464
isAllSelected() {
65-
const itemsShown = Math.min(this.paginator.length - (this.paginator.pageIndex * this.paginator.pageSize), this.paginator.pageSize);
66-
return this.selection.selected.length === itemsShown;
65+
return this.selection.selected.length === itemsShown(this.paginator);
6766
}
6867

6968
/** Selects all rows if they are not all selected; otherwise clear selection. */

src/app/meetups/meetups.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { takeUntil } from 'rxjs/operators';
1313
import { MeetupService } from './meetups.service';
1414
import { StateService } from '../shared/state.service';
1515
import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service';
16-
import { findByIdInArray } from '../shared/utils';
16+
import { findByIdInArray, itemsShown } from '../shared/utils';
1717

1818
@Component({
1919
templateUrl: './meetups.component.html',
@@ -88,8 +88,7 @@ export class MeetupsComponent implements OnInit, AfterViewInit, OnDestroy {
8888
}
8989

9090
isAllSelected() {
91-
const itemsShown = Math.min(this.paginator.length - (this.paginator.pageIndex * this.paginator.pageSize), this.paginator.pageSize);
92-
return this.selection.selected.length === itemsShown;
91+
return this.selection.selected.length === itemsShown(this.paginator);
9392
}
9493
onPaginateChange(e: PageEvent) {
9594
this.selection.clear();

src/app/resources/resources.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { FormControl } from '../../../node_modules/@angular/forms';
2424
import { PlanetTagInputComponent } from '../shared/forms/planet-tag-input.component';
2525
import { DialogsListService } from '../shared/dialogs/dialogs-list.service';
2626
import { DialogsListComponent } from '../shared/dialogs/dialogs-list.component';
27-
import { findByIdInArray, calculateMdAdjustedLimit } from '../shared/utils';
27+
import { findByIdInArray, calculateMdAdjustedLimit, itemsShown } from '../shared/utils';
2828
import { StateService } from '../shared/state.service';
2929
import { DialogsLoadingService } from '../shared/dialogs/dialogs-loading.service';
3030
import { ResourcesSearchComponent } from './search-resources/resources-search.component';
@@ -202,8 +202,7 @@ export class ResourcesComponent implements OnInit, AfterViewInit, OnDestroy {
202202

203203
/** Whether the number of selected elements matches the total number of rows. */
204204
isAllSelected() {
205-
const itemsShown = Math.min(this.paginator.length - (this.paginator.pageIndex * this.paginator.pageSize), this.paginator.pageSize);
206-
return this.selection.selected.length === itemsShown;
205+
return this.selection.selected.length === itemsShown(this.paginator);
207206
}
208207

209208
applyResFilter(filterResValue: string) {

src/app/shared/utils.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export const styleVariables: any = {
4949

5050
export const filterById = (array = [], id: string) => array.filter(item => item._id !== id);
5151

52-
export const arraySubField = (array: any[], field: string) => array.map(item => item[field]);
53-
5452
export const itemsShown = (paginator: any) => Math.min(paginator.length - (paginator.pageIndex * paginator.pageSize), paginator.pageSize);
5553

5654
export const isInMap = (tag: string, map: Map<string, boolean>) => map.get(tag);

src/app/users/users-table.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { DialogsPromptComponent } from '../shared/dialogs/dialogs-prompt.compone
1919
import { UsersService } from './users.service';
2020
import { PlanetMessageService } from '../shared/planet-message.service';
2121
import { UserProfileDialogComponent } from './users-profile/users-profile-dialog.component';
22+
import { itemsShown } from '../shared/utils';
2223

2324
export class TableState {
2425
isOnlyManagerSelected = false;
@@ -157,8 +158,7 @@ export class UsersTableComponent implements OnInit, OnDestroy, AfterViewInit, On
157158
}
158159

159160
isAllSelected() {
160-
const itemsShown = Math.min(this.paginator.length - (this.paginator.pageIndex * this.paginator.pageSize), this.paginator.pageSize);
161-
return this.selection.selected.length === itemsShown;
161+
return this.selection.selected.length === itemsShown(this.paginator);
162162
}
163163

164164
onlyManagerSelected() {

0 commit comments

Comments
 (0)