From ad5a944f1ba896c5f84edd887a9aea537305189a Mon Sep 17 00:00:00 2001
From: Daniel Klein
Date: Wed, 25 Sep 2024 20:31:41 +0200
Subject: [PATCH 1/2] fix(rating): show percentage in rating instead of total
points
---
components/Card.vue | 4 ++--
components/Project/ProjectHeading.vue | 4 ++--
components/Project/ProjectPrivacy.vue | 2 +-
components/Project/ProjectRating.vue | 20 ++++++++++----------
composables/useData.ts | 9 ++++++++-
types/project.ts | 1 +
6 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/components/Card.vue b/components/Card.vue
index 1d18c5c..81528d6 100644
--- a/components/Card.vue
+++ b/components/Card.vue
@@ -165,7 +165,7 @@ const projectItems: { label: string | string[], type: string, rating?: ProjectRa
@@ -210,7 +210,7 @@ const projectItems: { label: string | string[], type: string, rating?: ProjectRa
diff --git a/components/Project/ProjectHeading.vue b/components/Project/ProjectHeading.vue
index 13523bd..93dd145 100644
--- a/components/Project/ProjectHeading.vue
+++ b/components/Project/ProjectHeading.vue
@@ -215,7 +215,7 @@ const logo = props.project?.logos?.at(0)?.url
- {{ project.compliance ? 'YES' : 'NO' }}
+ {{ project.compliance ? project.compliance : 'NO' }}
{
diff --git a/composables/useData.ts b/composables/useData.ts
index bd3d524..8b4344b 100644
--- a/composables/useData.ts
+++ b/composables/useData.ts
@@ -233,6 +233,7 @@ export const useData = defineStore('data', () => {
const generateProjectRating = (project: Project) => {
const projectRatings: ProjectRating[] = ranks.value?.map((rank) => {
let rankPoints = 0
+ let maxPoints = 0
const ratingStats: ProjectRatingItem[] = rank.references?.map((ref) => {
let isValid = false
@@ -240,6 +241,7 @@ export const useData = defineStore('data', () => {
let value
let positive
+ let negative
if (ref.condition.minLength !== undefined) {
value = (field as any[])?.length
@@ -252,6 +254,9 @@ export const useData = defineStore('data', () => {
value = field
if (value !== undefined)
isValid = value === ref.condition.equals
+ if (ref.field === 'compliance') {
+ negative = value
+ }
}
if (ref.condition.exists !== undefined) {
@@ -260,11 +265,12 @@ export const useData = defineStore('data', () => {
isValid = !!value
}
rankPoints += isValid ? ref.points : 0
+ maxPoints += ref.points
return {
isValid,
label: ref.label.name,
positive: positive ? positive : ref.label.positive,
- negative: ref.label.negative,
+ negative: negative ? negative : ref.label.negative,
value,
} as ProjectRatingItem
})
@@ -273,6 +279,7 @@ export const useData = defineStore('data', () => {
name: rank.name,
items: ratingStats,
points: rankPoints,
+ percentagePoints: rankPoints / maxPoints * 100,
}
})
diff --git a/types/project.ts b/types/project.ts
index d5aa58f..fabb1b7 100644
--- a/types/project.ts
+++ b/types/project.ts
@@ -165,6 +165,7 @@ export interface ProjectRating {
name: string
items: ProjectRatingItem[]
points: number
+ percentagePoints: number
}
export interface ProjectRatingItem {
From 1d06159cbd4ca4c0b76db6c0f0e7ec8bc2f5e3b8 Mon Sep 17 00:00:00 2001
From: Daniel Klein
Date: Wed, 25 Sep 2024 20:36:39 +0200
Subject: [PATCH 2/2] fix(rating): compliance condition placement
---
composables/useData.ts | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/composables/useData.ts b/composables/useData.ts
index 8b4344b..afe20af 100644
--- a/composables/useData.ts
+++ b/composables/useData.ts
@@ -254,9 +254,6 @@ export const useData = defineStore('data', () => {
value = field
if (value !== undefined)
isValid = value === ref.condition.equals
- if (ref.field === 'compliance') {
- negative = value
- }
}
if (ref.condition.exists !== undefined) {
@@ -264,6 +261,10 @@ export const useData = defineStore('data', () => {
if (value !== undefined)
isValid = !!value
}
+ if (ref.field === 'compliance') {
+ negative = value
+ }
+
rankPoints += isValid ? ref.points : 0
maxPoints += ref.points
return {