From b3160d45f583146d378da2065de3e008460f4f8d Mon Sep 17 00:00:00 2001 From: Daniel Palafox Date: Wed, 4 Oct 2023 12:53:30 -0500 Subject: [PATCH 1/2] feature: Add `SOURCE_SORTING` togglz --- .../affiliation-stacks-groups.component.html | 2 +- .../affiliation-stacks-groups.component.ts | 11 ++++++++++- .../funding-stacks-groups.component.html | 2 +- .../funding-stacks-groups.component.ts | 17 ++++++++++++++--- .../work-stack-group.component.html | 2 +- .../work-stack-group.component.ts | 17 ++++++++++++++--- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.html b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.html index 167ff9144d..4b8b51ebda 100644 --- a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.html +++ b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.html @@ -21,7 +21,7 @@ [(expandedContent)]="expandedContent['EMPLOYMENT']" (expandedContentChange)="expandedContentChange.emit(expandedContent)" [isPublicRecord]="isPublicRecord" - [sortTypes]="['title', 'start', 'end', 'source']" + [sortTypes]="sortTypes" [sortType]="'end'" (sort)="sortEvent($event, 'EMPLOYMENT')" id="cy-affiliation-employment" diff --git a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts index 98969f2c02..1e4c6e13c5 100644 --- a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts +++ b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts @@ -15,7 +15,7 @@ import { UserRecord, UserRecordOptions, } from 'src/app/types/record.local' -import { SortData } from 'src/app/types/sort' +import { SortData, SortOrderType } from 'src/app/types/sort' import { UserInfo } from '../../../types' import { TogglzService } from '../../../core/togglz/togglz.service' @@ -54,6 +54,8 @@ export class AffiliationStacksGroupsComponent implements OnInit { @Output() expandedContentChange: EventEmitter = new EventEmitter() professionalActivitiesTogglz = false + sourceSorting = false + sortTypes: SortOrderType[] = ['title', 'start', 'end'] constructor( private _record: RecordService, @@ -66,6 +68,10 @@ export class AffiliationStacksGroupsComponent implements OnInit { .getStateOf('PROFESSIONAL_ACTIVITIES') .pipe(take(1)) .subscribe((value) => (this.professionalActivitiesTogglz = value)) + this._togglz + .getStateOf('SOURCE_SORTING') + .pipe(take(1)) + .subscribe((value) => (this.sourceSorting = value)) this.$loading = this._recordAffiliationService.$loading this._record .getRecord({ @@ -106,6 +112,9 @@ export class AffiliationStacksGroupsComponent implements OnInit { } } }) + if (this.sourceSorting) { + this.sortTypes.push('source') + } } trackByProfileAffiliationUiGroups(index, item: AffiliationUIGroup) { diff --git a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.html b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.html index bccb353be2..b496ed01ae 100644 --- a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.html +++ b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.html @@ -15,7 +15,7 @@ [isPublicRecord]="isPublicRecord" [(expandedContent)]="expandedContent['FUNDING']" (expandedContentChange)="expandedContentChange.emit(expandedContent)" - [sortTypes]="['date', 'title', 'type', 'source']" + [sortTypes]="sortTypes" [sortType]="'date'" (sort)="sortEvent($event)" > diff --git a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts index 0ed5bc56e5..0de17ff27a 100644 --- a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts +++ b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts @@ -1,6 +1,6 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' import { Observable, Subject } from 'rxjs' -import { first, takeUntil } from 'rxjs/operators' +import { first, take, takeUntil } from 'rxjs/operators' import { UserService } from 'src/app/core' import { RecordCountriesService } from 'src/app/core/record-countries/record-countries.service' import { RecordService } from 'src/app/core/record/record.service' @@ -11,10 +11,11 @@ import { UserRecordOptions, } from 'src/app/types/record.local' import { UserSession } from 'src/app/types/session.local' -import { SortData } from 'src/app/types/sort' +import { SortData, SortOrderType } from 'src/app/types/sort' import { RecordFundingsService } from '../../../core/record-fundings/record-fundings.service' import { UserInfo } from '../../../types' +import { TogglzService } from '../../../core/togglz/togglz.service' @Component({ selector: 'app-fundings', @@ -40,16 +41,26 @@ export class FundingStacksGroupsComponent implements OnInit { ngOrcidFunding = $localize`:@@shared.funding:Funding` countryCodes: { key: string; value: string }[] loading = true + sourceSorting = false + sortTypes: SortOrderType[] = ['title', 'start', 'end'] constructor( private _userSession: UserService, private _record: RecordService, private _recordFundingsService: RecordFundingsService, - private _recordCountryService: RecordCountriesService + private _recordCountryService: RecordCountriesService, + private _togglz: TogglzService ) {} ngOnInit(): void { + this._togglz + .getStateOf('SOURCE_SORTING') + .pipe(take(1)) + .subscribe((value) => (this.sourceSorting = value)) this.getRecord() + if (this.sourceSorting) { + this.sortTypes.push('source') + } } private getRecord() { diff --git a/src/app/record/components/work-stack-group/work-stack-group.component.html b/src/app/record/components/work-stack-group/work-stack-group.component.html index a729b151c7..7f4647d858 100644 --- a/src/app/record/components/work-stack-group/work-stack-group.component.html +++ b/src/app/record/components/work-stack-group/work-stack-group.component.html @@ -15,7 +15,7 @@ [isPublicRecord]="isPublicRecord" [(expandedContent)]="expandedContent['WORK']" (expandedContentChange)="expandedContentChange.emit(expandedContent)" - [sortTypes]="['date', 'title', 'type', 'source']" + [sortTypes]="sortTypes" [sortType]="'date'" [addMenuOptions]="addMenuOptions" (sort)="sortEvent($event)" diff --git a/src/app/record/components/work-stack-group/work-stack-group.component.ts b/src/app/record/components/work-stack-group/work-stack-group.component.ts index eacfafe2ec..1bc48f040d 100644 --- a/src/app/record/components/work-stack-group/work-stack-group.component.ts +++ b/src/app/record/components/work-stack-group/work-stack-group.component.ts @@ -15,7 +15,7 @@ import { MatDialog } from '@angular/material/dialog' import { MatPaginatorIntl, PageEvent } from '@angular/material/paginator' import { isEmpty } from 'lodash' import { Observable, Subject } from 'rxjs' -import { first } from 'rxjs/operators' +import { first, take } from 'rxjs/operators' import { PlatformInfo, PlatformInfoService } from 'src/app/cdk/platform-info' import { ADD_EVENT_ACTION, @@ -34,7 +34,7 @@ import { UserRecord, UserRecordOptions, } from 'src/app/types/record.local' -import { SortData } from 'src/app/types/sort' +import { SortData, SortOrderType } from 'src/app/types/sort' import { UserInfo } from '../../../types' import { ModalDeleteItemsComponent } from '../modals/modal-delete-item/modal-delete-items.component' @@ -49,6 +49,7 @@ import { WorkBibtexModalComponent } from './modals/work-bibtex-modal/work-bibtex import { ModalCombineWorksWithSelectorComponent } from '../work/modals/modal-combine-works-with-selector/modal-combine-works-with-selector.component' import { GroupingSuggestions } from 'src/app/types/works.endpoint' import { AnnouncerService } from 'src/app/core/announcer/announcer.service' +import { TogglzService } from '../../../core/togglz/togglz.service' @Component({ selector: 'app-work-stack-group', @@ -127,6 +128,8 @@ export class WorkStackGroupComponent implements OnInit { platform: PlatformInfo selectedWorks: string[] = [] selectAll: false + sourceSorting = false + sortTypes: SortOrderType[] = ['title', 'start', 'end'] @ViewChildren('selectAllCheckbox') selectAllCheckbox: MatCheckbox @ViewChildren('appWorkStacks') appWorkStacks: QueryList @@ -138,10 +141,15 @@ export class WorkStackGroupComponent implements OnInit { private _record: RecordService, private _works: RecordWorksService, private _matPaginatorIntl: MatPaginatorIntl, - private _announce: AnnouncerService + private _announce: AnnouncerService, + private _togglz: TogglzService ) {} ngOnInit(): void { + this._togglz + .getStateOf('SOURCE_SORTING') + .pipe(take(1)) + .subscribe((value) => (this.sourceSorting = value)) this.$loading = this._works.$loading this._record .getRecord({ publicRecordId: this.isPublicRecord }) @@ -163,6 +171,9 @@ export class WorkStackGroupComponent implements OnInit { this._platform.get().subscribe((platform) => { this.platform = platform }) + if (this.sourceSorting) { + this.sortTypes.push('source') + } } private getGroupingSuggestions() { From f1c91080c9c30a7f339f7fc853160f7d0f981aff Mon Sep 17 00:00:00 2001 From: Daniel Palafox Date: Wed, 4 Oct 2023 15:51:36 -0500 Subject: [PATCH 2/2] fix: Add source sorting togglz inside togglz subscribe --- .../affiliation-stacks-groups.component.ts | 10 +++++----- .../funding-stacks-groups.component.ts | 14 +++++++------- .../work-stack-group/work-stack-group.component.ts | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts index 1e4c6e13c5..8dc07c6674 100644 --- a/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts +++ b/src/app/record/components/affiliation-stacks-groups/affiliation-stacks-groups.component.ts @@ -54,7 +54,6 @@ export class AffiliationStacksGroupsComponent implements OnInit { @Output() expandedContentChange: EventEmitter = new EventEmitter() professionalActivitiesTogglz = false - sourceSorting = false sortTypes: SortOrderType[] = ['title', 'start', 'end'] constructor( @@ -71,7 +70,11 @@ export class AffiliationStacksGroupsComponent implements OnInit { this._togglz .getStateOf('SOURCE_SORTING') .pipe(take(1)) - .subscribe((value) => (this.sourceSorting = value)) + .subscribe((sourceSortingTogglz: boolean) => { + if (sourceSortingTogglz) { + this.sortTypes.push('source') + } + }) this.$loading = this._recordAffiliationService.$loading this._record .getRecord({ @@ -112,9 +115,6 @@ export class AffiliationStacksGroupsComponent implements OnInit { } } }) - if (this.sourceSorting) { - this.sortTypes.push('source') - } } trackByProfileAffiliationUiGroups(index, item: AffiliationUIGroup) { diff --git a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts index 0de17ff27a..216a300742 100644 --- a/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts +++ b/src/app/record/components/funding-stacks-groups/funding-stacks-groups.component.ts @@ -41,7 +41,6 @@ export class FundingStacksGroupsComponent implements OnInit { ngOrcidFunding = $localize`:@@shared.funding:Funding` countryCodes: { key: string; value: string }[] loading = true - sourceSorting = false sortTypes: SortOrderType[] = ['title', 'start', 'end'] constructor( @@ -54,13 +53,14 @@ export class FundingStacksGroupsComponent implements OnInit { ngOnInit(): void { this._togglz - .getStateOf('SOURCE_SORTING') - .pipe(take(1)) - .subscribe((value) => (this.sourceSorting = value)) + .getStateOf('SOURCE_SORTING') + .pipe(take(1)) + .subscribe((sourceSortingTogglz: boolean) => { + if (sourceSortingTogglz) { + this.sortTypes.push('source') + } + }) this.getRecord() - if (this.sourceSorting) { - this.sortTypes.push('source') - } } private getRecord() { diff --git a/src/app/record/components/work-stack-group/work-stack-group.component.ts b/src/app/record/components/work-stack-group/work-stack-group.component.ts index 1bc48f040d..d6aaf6377f 100644 --- a/src/app/record/components/work-stack-group/work-stack-group.component.ts +++ b/src/app/record/components/work-stack-group/work-stack-group.component.ts @@ -128,7 +128,6 @@ export class WorkStackGroupComponent implements OnInit { platform: PlatformInfo selectedWorks: string[] = [] selectAll: false - sourceSorting = false sortTypes: SortOrderType[] = ['title', 'start', 'end'] @ViewChildren('selectAllCheckbox') selectAllCheckbox: MatCheckbox @@ -147,9 +146,13 @@ export class WorkStackGroupComponent implements OnInit { ngOnInit(): void { this._togglz - .getStateOf('SOURCE_SORTING') - .pipe(take(1)) - .subscribe((value) => (this.sourceSorting = value)) + .getStateOf('SOURCE_SORTING') + .pipe(take(1)) + .subscribe((sourceSortingTogglz: boolean) => { + if (sourceSortingTogglz) { + this.sortTypes.push('source') + } + }) this.$loading = this._works.$loading this._record .getRecord({ publicRecordId: this.isPublicRecord }) @@ -171,9 +174,6 @@ export class WorkStackGroupComponent implements OnInit { this._platform.get().subscribe((platform) => { this.platform = platform }) - if (this.sourceSorting) { - this.sortTypes.push('source') - } } private getGroupingSuggestions() {