|
|
|
@ -8,7 +8,7 @@ |
|
|
|
import { computed, inject, Service } from '@angular/core'; |
|
|
|
import { EMPTY, Observable, throwError } from 'rxjs'; |
|
|
|
import { catchError, finalize, tap } from 'rxjs/operators'; |
|
|
|
import { AssignContributorDto, ContributorDto, ContributorsDto, debug, DialogService, ErrorDto, getPagingInfo, ListState, shareMapSubscribed, shareSubscribed, State, StringHelper, TeamsState, Types, VersionTag } from '@app/shared'; |
|
|
|
import { AssignContributorDto, ContributorDto, ContributorsDto, debug, DialogService, ErrorDto, ListState, PagingInfo, shareMapSubscribed, shareSubscribed, State, StringHelper, TeamsState, Types, VersionTag } from '@app/shared'; |
|
|
|
import { TeamContributorsService } from '../internal'; |
|
|
|
|
|
|
|
interface Snapshot extends ListState<string> { |
|
|
|
@ -27,6 +27,7 @@ interface Snapshot extends ListState<string> { |
|
|
|
|
|
|
|
@Service({ autoProvided: false }) |
|
|
|
export class TeamContributorsState extends State<Snapshot> { |
|
|
|
private readonly contributorsPage = this.project(getContributorsPage); |
|
|
|
private readonly contributorsService = inject(TeamContributorsService); |
|
|
|
private readonly dialogs = inject(DialogService); |
|
|
|
private readonly teamsState = inject(TeamsState); |
|
|
|
@ -35,7 +36,7 @@ export class TeamContributorsState extends State<Snapshot> { |
|
|
|
this.project(x => x.contributors); |
|
|
|
|
|
|
|
public readonly paging = |
|
|
|
this.project(x => getPagingInfo(x, x.contributors.length)); |
|
|
|
computed(() => this.contributorsPage().paging); |
|
|
|
|
|
|
|
public readonly query = |
|
|
|
this.project(x => x.query); |
|
|
|
@ -56,7 +57,7 @@ export class TeamContributorsState extends State<Snapshot> { |
|
|
|
this.project(x => x.canCreate === true); |
|
|
|
|
|
|
|
public readonly contributorsFiltered = |
|
|
|
this.project(getFilteredContributors); |
|
|
|
computed(() => this.contributorsPage().items); |
|
|
|
|
|
|
|
public get teamId() { |
|
|
|
return this.teamsState.teamId; |
|
|
|
@ -113,7 +114,8 @@ export class TeamContributorsState extends State<Snapshot> { |
|
|
|
} |
|
|
|
|
|
|
|
public search(query: string) { |
|
|
|
this.next({ query }, 'Results Filtered'); |
|
|
|
// The current page may not exist anymore for the filtered results.
|
|
|
|
this.next({ query, page: 0 }, 'Results Filtered'); |
|
|
|
} |
|
|
|
|
|
|
|
public revoke(contributor: ContributorDto): Observable<any> { |
|
|
|
@ -162,7 +164,7 @@ function getRegex(query?: string): RegExp | undefined { |
|
|
|
return query ? StringHelper.searchRegex(query) : undefined; |
|
|
|
} |
|
|
|
|
|
|
|
function getFilteredContributors(snapshot: Snapshot) { |
|
|
|
function getContributorsPage(snapshot: Snapshot): { items: ReadonlyArray<ContributorDto>; paging: PagingInfo } { |
|
|
|
const { contributors, query, page, pageSize } = snapshot; |
|
|
|
|
|
|
|
let filtered = contributors; |
|
|
|
@ -173,5 +175,8 @@ function getFilteredContributors(snapshot: Snapshot) { |
|
|
|
filtered = filtered.filter(x => regex.test(x.contributorName)); |
|
|
|
} |
|
|
|
|
|
|
|
return filtered.slice(page * pageSize, (page + 1) * pageSize); |
|
|
|
const items = filtered.slice(page * pageSize, (page + 1) * pageSize); |
|
|
|
|
|
|
|
// The paging must be calculated from the filtered contributors, not from all contributors.
|
|
|
|
return { items, paging: { page, pageSize, total: filtered.length, count: items.length } }; |
|
|
|
} |
|
|
|
|