-
Notifications
You must be signed in to change notification settings - Fork 4
Development: Redesign the rating card
#2574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
f07a317
feat/rating-redesign: adding names to ratings and ratings to comments
SultanTheHL 4bd731c
feat/rating-redesign: change button name
SultanTheHL 9204bf2
feat/rating-redesign: add rating count
SultanTheHL 62ae8ec
Revert "feat/rating-redesign: add rating count"
SultanTheHL 222e394
Merge branch 'main' into feat/rating-redesign
SultanTheHL d03e40b
feat/rating-redesign: updating tests
SultanTheHL d8e1d89
feat/rating-redesign: fix lint issues
SultanTheHL 658bf53
feat/rating-redesign: security fix
SultanTheHL 7ce408f
Merge branch 'main' into feat/rating-redesign
SultanTheHL f14e469
feat/rating-redesign: security fix
SultanTheHL a889cb6
feat/rating-redesign: color borders, wrap components and hover effect
SultanTheHL 265f101
feat/rating-redesign: pr comments
SultanTheHL 822afe9
feat/rating-redesign: fix
SultanTheHL 55bc511
feat/rating-redesign: prettier
SultanTheHL 1cb9e09
feat/rating-redesign: renaming tests
SultanTheHL 370a9e5
Merge branch 'main' into feat/rating-redesign
SultanTheHL 11f2b34
feat/rating-redesign: pr comments
SultanTheHL ad7142b
feat/rating-redesign: security fix
SultanTheHL b82bf9b
feat/rating-redesign: fix
SultanTheHL 5dc9ebc
feat/rating-redesign: fix
SultanTheHL 0fea177
feat/rating-redesign: changing translations
SultanTheHL 5d3f028
feat/rating-redesign: translation change
SultanTheHL e0610af
feat/rating-redesign: PR fix
SultanTheHL c767b62
feat/rating-redesign: test fix and text
SultanTheHL eec9893
feat/rating-redesign:design adjustments
SultanTheHL d9e5405
feat/rating-redesign: fixing text and tests
SultanTheHL 26f053f
Merge branch 'main' into feat/rating-redesign
SultanTheHL 02cd411
feat/rating-redesign: border change
SultanTheHL 69e76f4
Merge remote-tracking branch 'origin/feat/rating-redesign' into feat/…
SultanTheHL 6e21813
feat/rating-redesign: changing preset colors in dark mode
SultanTheHL cfe4391
feat/rating-redesign: wrap rating pills on mobile and drop dead toolt…
az108 80154df
Merge remote-tracking branch 'origin/main' into feat/rating-redesign
Cathy0123456789 b10cab1
Merge branch 'main' into feat/rating-redesign
Cathy0123456789 4cea5d2
`Bugfix`: Make selected rating chips readable in both colour schemes
az108 95c9100
`Bugfix`: Give the rating chips one label colour on a lighter scale
az108 86960d4
`Bugfix`: Lighten the poor rating chip
az108 213b591
`Bugfix`: Respace the green rating chips so excellent can be lighter
az108 a5b7440
`Development`: Replace the rating pills with a star scale
az108 4711455
`Development`: Colour the rating stars by step and preview on hover
az108 5cd17e8
`Development`: Use one star scale for the rating input and the card a…
az108 b94f046
`Test`: Cover the star rating display and register its half-star icon
az108 57bb491
`Development`: Load the application ratings once on the review page
az108 d9331db
`Development`: Match comment ratings to their author by id
az108 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 22 additions & 15 deletions
37
src/main/webapp/app/shared/components/atoms/rating/rating.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,22 @@ | ||
| <div class="flex gap-[2%] w-full max-w-[21rem] h-4 rounded-pill overflow-hidden"> | ||
| @for (item of likertValues; track $index) { | ||
| <div | ||
| class="flex-1 transition-colors" | ||
| [class]="selectable() ? 'cursor-pointer hover:brightness-75' : ''" | ||
| [style.background-color]="getSectionColor($index)" | ||
| [pTooltip]="tooltipTexts()[$index]" | ||
| tooltipPosition="top" | ||
| tabindex="0" | ||
| role="button" | ||
| (click)="onSectionClick($index)" | ||
| (keydown.enter)="onSectionClick($index)" | ||
| ></div> | ||
| } | ||
| </div> | ||
| @if (selectable()) { | ||
| <div class="flex flex-wrap gap-2"> | ||
| @for (item of likertValues; track $index) { | ||
| <button | ||
| type="button" | ||
| class="px-3 py-1.5 rounded-full text-sm font-medium transition-colors duration-150 border border-border-default focus:outline-none" | ||
| [style.background-color]="getButtonBg($index)" | ||
| [style.color]="getButtonTextColor($index)" | ||
| (click)="onSectionClick($index)" | ||
| (keydown.enter)="onSectionClick($index)" | ||
| > | ||
| {{ tooltipTexts()[$index] }} | ||
| </button> | ||
| } | ||
| </div> | ||
| } @else if (rating() !== undefined) { | ||
| <span | ||
| class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium text-white" | ||
| [style.background-color]="getColorForValue(rating()!)" | ||
|
SultanTheHL marked this conversation as resolved.
Outdated
|
||
| >{{ getSelectedLabel() }}</span | ||
| > | ||
| } | ||
94 changes: 54 additions & 40 deletions
94
src/main/webapp/app/shared/components/atoms/rating/rating.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,85 @@ | ||
| import { Component, computed, inject, input, model } from '@angular/core'; | ||
| import { toSignal } from '@angular/core/rxjs-interop'; | ||
| import { TranslateService } from '@ngx-translate/core'; | ||
| import { TooltipModule } from 'primeng/tooltip'; | ||
|
|
||
| type LikertValue = -2 | -1 | 0 | 1 | 2; | ||
|
|
||
| interface LikertEntry { | ||
| value: LikertValue; | ||
| key: string; | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'jhi-rating', | ||
| imports: [TooltipModule], | ||
| templateUrl: './rating.component.html', | ||
| }) | ||
| export class RatingComponent { | ||
| rating = model<number | undefined>(undefined); | ||
| selectable = input<boolean>(false); | ||
|
|
||
| // Likert scale values from -2 to +2 | ||
| readonly likertValues = [-2, -1, 0, 1, 2]; | ||
| readonly likertScale: LikertEntry[] = [ | ||
| { value: -2, key: 'very_bad' }, | ||
| { value: -1, key: 'bad' }, | ||
| { value: 0, key: 'neutral' }, | ||
| { value: 1, key: 'good' }, | ||
| { value: 2, key: 'very_good' }, | ||
| ]; | ||
|
|
||
| readonly likertValues: LikertValue[] = this.likertScale.map(s => s.value); | ||
|
|
||
| readonly tooltipTexts = computed(() => { | ||
| this.langChange(); | ||
| return this.tooltipKeys.map(suffix => this.translateService.instant(`evaluation.ratings.${suffix}`)); | ||
| return this.likertScale.map(s => this.translateService.instant(`evaluation.ratings.${s.key}`) as string); | ||
|
SultanTheHL marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| protected readonly Array = Array; | ||
|
|
||
| private readonly tooltipKeys = ['very_bad', 'bad', 'neutral', 'good', 'very_good']; | ||
| private translateService = inject(TranslateService); | ||
| private langChange = toSignal(this.translateService.onLangChange, { initialValue: undefined }); | ||
|
|
||
| onSectionClick(index: number): void { | ||
| if (!this.selectable()) { | ||
| return; | ||
| } | ||
| if (!this.selectable()) return; | ||
| const entry = this.entryAt(index); | ||
| if (entry === undefined) return; | ||
| this.rating.set(this.rating() === entry.value ? undefined : entry.value); | ||
| } | ||
|
|
||
| const newRating = this.likertValues[index]; | ||
| // If clicking the same rating, unselect it | ||
| if (this.rating() === newRating) { | ||
| this.rating.set(undefined); | ||
| } else { | ||
| this.rating.set(newRating); | ||
| getColorForValue(value: number): string { | ||
| switch (value) { | ||
| case -2: | ||
| return 'var(--color-negative-active)'; | ||
| case -1: | ||
| return 'var(--color-negative-hover)'; | ||
| case 0: | ||
| return 'var(--color-warning-default)'; | ||
| case 1: | ||
| return 'var(--color-positive-hover)'; | ||
| case 2: | ||
| return 'var(--color-positive-active)'; | ||
| default: | ||
| return 'var(--p-background-surface-alt)'; | ||
| } | ||
| } | ||
|
|
||
| getSectionColor(index: number): string { | ||
| const currentRating = this.rating(); | ||
| const sectionValue = this.likertValues[index]; | ||
| getButtonBg(index: number): string { | ||
| const entry = this.entryAt(index); | ||
| if (entry === undefined) return 'var(--p-background-surface-alt)'; | ||
| return this.rating() === entry.value ? this.getColorForValue(entry.value) : 'var(--p-background-surface-alt)'; | ||
| } | ||
|
|
||
| if (currentRating === undefined) { | ||
| return 'var(--p-background-surface-alt)'; | ||
| } | ||
| getButtonTextColor(index: number): string { | ||
| const entry = this.entryAt(index); | ||
| if (entry === undefined) return 'var(--p-text-color)'; | ||
| return this.rating() === entry.value ? 'white' : 'var(--p-text-color)'; | ||
| } | ||
|
|
||
| if (sectionValue === currentRating) { | ||
| switch (sectionValue) { | ||
| case -2: | ||
| return 'var(--color-negative-active)'; | ||
| case -1: | ||
| return 'var(--color-negative-hover)'; | ||
| case 0: | ||
| return 'var(--color-warning-default)'; | ||
| case 1: | ||
| return 'var(--color-positive-hover)'; | ||
| case 2: | ||
| return 'var(--color-positive-active)'; | ||
| } | ||
| } | ||
| return 'var(--p-background-surface-alt)'; | ||
| getSelectedLabel(): string { | ||
| const r = this.rating(); | ||
| if (r === undefined) return ''; | ||
| const entry = this.likertScale.find(s => s.value === r); | ||
| if (entry === undefined) return ''; | ||
| return this.translateService.instant(`evaluation.ratings.${entry.key}`) as string; | ||
| } | ||
|
|
||
| getCursor(): string { | ||
| return this.selectable() ? 'pointer' : 'default'; | ||
| private entryAt(index: number): LikertEntry | undefined { | ||
| return this.likertScale.find((_, i) => i === index); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
SultanTheHL marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.