Skip to content

Commit

Permalink
feature: Add new source sorting option for affiliations, funding and … (
Browse files Browse the repository at this point in the history
#2064)

* feature: Add new source sorting option for affiliations, funding and works

* fix: Update sort translations
  • Loading branch information
DanielPalafox authored Oct 2, 2023
1 parent dfb64e2 commit 9cda75a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/app/cdk/panel/sort-label.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SortLabelPipe implements PipeTransform {
date: $localize`:@@share.sortDate:Date`,
type: $localize`:@@share.sortType:Type`,
order: $localize`:@@share.sortOrderv2:Publication/Grant title`,
source: $localize`:@@shared.source:Source`,
}
transform(value: SortOrderType): string {
return this.SortOrderTypeLabel[value]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core'
import { first, takeUntil } from 'rxjs/operators'
import { Subject } from 'rxjs'
import { MatDialog } from '@angular/material/dialog'
import { RecordEmailsService } from 'src/app/core/record-emails/record-emails.service'
import { RecordService } from 'src/app/core/record/record.service'
import { PlatformInfoService } from '../platform-info'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
AffiliationUIGroup,
AffiliationGroup,
AffiliationType,
AffiliationTypeValue,
} from 'src/app/types/record-affiliation.endpoint'
import { UserRecordOptions } from 'src/app/types/record.local'

Expand All @@ -21,15 +20,17 @@ export class AffiliationsSortService {
value,
userRecordContext?.sortAsc,
userRecordContext?.sort,
type
type,
userRecordContext?.publicRecordId || userRecordContext?.privateRecordId
)
}

sort(
affiliationGroups: AffiliationUIGroup[],
ascending = false,
by = 'end',
type = null
type = null,
orcid: string
): AffiliationUIGroup[] {
if (type === 'PROFESSIONAL_ACTIVITIES' && by === 'type') {
const affiliations = affiliationGroups.filter(
Expand Down Expand Up @@ -85,6 +86,15 @@ export class AffiliationsSortService {
affiliationGroup.reverse()
}
}

if (by === 'source') {
affiliationGroup.sort((a, b) => {
return Number(AffiliationsSortService.isSelfAsserted(a, orcid)) - Number(AffiliationsSortService.isSelfAsserted(b, orcid))
})
if (!ascending) {
affiliationGroup.reverse()
}
}
}
})
return affiliationGroups
Expand Down Expand Up @@ -192,4 +202,8 @@ export class AffiliationsSortService {
return this.sortByDate(a, b, false, 'end')
})
}

private static isSelfAsserted(affiliationGroup: AffiliationGroup, orcid: string): boolean {
return affiliationGroup.defaultAffiliation.source === orcid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[(expandedContent)]="expandedContent['EMPLOYMENT']"
(expandedContentChange)="expandedContentChange.emit(expandedContent)"
[isPublicRecord]="isPublicRecord"
[sortTypes]="['title', 'start', 'end', 'source']"
[sortType]="'end'"
(sort)="sortEvent($event, 'EMPLOYMENT')"
id="cy-affiliation-employment"
Expand Down Expand Up @@ -85,6 +86,7 @@
[(expandedContent)]="expandedContent['EDUCATION_AND_QUALIFICATION']"
(expandedContentChange)="expandedContentChange.emit(expandedContent)"
[isPublicRecord]="isPublicRecord"
[sortTypes]="['title', 'start', 'end', 'source']"
[sortType]="'end'"
(sort)="sortEvent($event, 'EDUCATION_AND_QUALIFICATION')"
id="cy-affiliation-education-and-qualification"
Expand Down Expand Up @@ -287,7 +289,7 @@
[(expandedContent)]="expandedContent['PROFESSIONAL_ACTIVITIES']"
(expandedContentChange)="expandedContentChange.emit(expandedContent)"
[isPublicRecord]="isPublicRecord"
[sortTypes]="['title', 'type', 'start', 'end']"
[sortTypes]="['title', 'type', 'start', 'end', 'source']"
(sort)="sortEvent($event, 'PROFESSIONAL_ACTIVITIES')"
[professionalActivitiesTogglz]="professionalActivitiesTogglz"
id="cy-affiliation-professional-activities"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[isPublicRecord]="isPublicRecord"
[(expandedContent)]="expandedContent['FUNDING']"
(expandedContentChange)="expandedContentChange.emit(expandedContent)"
[sortTypes]="['date', 'title', 'type']"
[sortTypes]="['date', 'title', 'type', 'source']"
[sortType]="'date'"
(sort)="sortEvent($event)"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[isPublicRecord]="isPublicRecord"
[(expandedContent)]="expandedContent['WORK']"
(expandedContentChange)="expandedContentChange.emit(expandedContent)"
[sortTypes]="['date', 'title', 'type']"
[sortTypes]="['date', 'title', 'type', 'source']"
[sortType]="'date'"
[addMenuOptions]="addMenuOptions"
(sort)="sortEvent($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class AppPanelsSortByAriaLabelPipe implements PipeTransform {
return getDateLabelByType(type)
case 'type':
return getTypeLabelByType(type)
case 'source':
return getSourceLabelByType(type)
case 'order':
return $localize`:@@shared.peerReviewsSortOrderv2:Sort peer review by Publication/Grant title`
}
Expand Down Expand Up @@ -104,3 +106,19 @@ const getDateLabelByType = (type: string): string => {
return $localize`:@@shared.researchSortDate:Sort research resources by date`
}
}

const getSourceLabelByType = (type: string): string => {
switch (type) {
case 'employment':
return $localize`:@@shared.employmentSortSource:Sort employment by source`
case 'education':
case 'qualification':
return $localize`:@@shared.educationSortSource:Sort education and qualifications by source`
case 'professional-activities':
return $localize`:@@shared.professionalActivitiesSortSource:Sort professional activities by source`
case 'funding':
return $localize`:@@shared.fundingSortSource:Sort funding by source`
case 'works':
return $localize`:@@shared.worksSortSource:Sort works by source`
}
}
1 change: 1 addition & 0 deletions src/app/types/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type SortOrderType =
| 'date'
| 'type'
| 'order'
| 'source'

export interface SortData {
direction: SortOrderDirection
Expand Down
2 changes: 1 addition & 1 deletion src/environments/environment.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const environment = {
BASE_URL: '',
INFO_SITE: 'https://info.orcid.org/',
GOOGLE_ANALYTICS_TESTING_MODE: true,
GOOGLE_TAG_MANAGER: 'GTM-0000000',
GOOGLE_TAG_MANAGER: 'GTM-M9Z7DHS',
GOOGLE_RECAPTCHA: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
HELP_HERO_ID: 'oYFQMrzFHA',
ZENDESK: null,
Expand Down
5 changes: 5 additions & 0 deletions src/locale/properties/shared/shared.en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,8 @@ shared.researchSortDate=Sort research resources by date
shared.today=Today
share.more=more
shared.orcidHelpCenter=ORCID Help Center
shared.employmentSortSource=Sort employment by source
shared.educationSortSource=Sort education and qualifications by source
shared.fundingSortSource=Sort funding by source
shared.professionalActivitiesSortSource=Sort professional activities by source
shared.worksSortSource=Sort works by source

0 comments on commit 9cda75a

Please sign in to comment.