Skip to content

Commit

Permalink
feat: add is_scored in db to store score value anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Apr 25, 2024
1 parent 09348cc commit 0a5808b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions backend/core/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def get_sorted_requirement_nodes_rec(
"name": node.name,
"ra_id": str(req_as.id) if requirements_assessed else None,
"status": req_as.status if requirements_assessed else None,
"is_scored": req_as.is_scored if requirements_assessed else None,
"score": req_as.score if requirements_assessed else None,
"max_score": req_as.compliance_assessment.framework.max_score
if requirements_assessed
Expand Down Expand Up @@ -278,6 +279,7 @@ def get_sorted_requirement_nodes_rec(
"description": req.description,
"ra_id": str(req_as.id),
"status": req_as.status,
"is_scored": req_as.is_scored,
"score": req_as.score,
"max_score": req_as.compliance_assessment.framework.max_score,
"status_display": req_as.get_status_display(),
Expand Down
5 changes: 5 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ def get_global_score(self):
RequirementAssessment.objects.filter(compliance_assessment=self)
.exclude(score=None)
.exclude(status=RequirementAssessment.Status.NOT_APPLICABLE)
.exclude(is_scored=False)
)
score = requirement_assessments_scored.aggregate(models.Avg("score"))
if score["score__avg"]:
Expand Down Expand Up @@ -1495,6 +1496,10 @@ class Status(models.TextChoices):
null=True,
verbose_name=_("Score"),
)
is_scored = models.BooleanField(
default=False,
verbose_name=_("Is scored"),
)
evidences = models.ManyToManyField(
Evidence,
blank=True,
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/lib/components/Forms/Score.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
export let form: SuperForm<AnyZodObject>;
const { value, errors, constraints } = formFieldProxy(form, field);
$: scoringEnabled = $value === null ? false : true;
$value = $value ?? min_score;
const isScored = formFieldProxy(form, 'is_scored')['value'];
$: if (max_score === 100) score_step = 5;
const status = formFieldProxy(form, 'status')['value'];
Expand All @@ -45,7 +48,7 @@
<div class="flex flex-row w-full items-center justify-evenly space-x-4">
{#if isApplicable}
<div class="flex w-full items-center justify-center">
{#if scoringEnabled}
{#if $isScored}
<RangeSlider
class="w-full"
name="range-slider"
Expand All @@ -57,9 +60,8 @@
>
<div class="flex justify-between items-center">
<SlideToggle
bind:checked={scoringEnabled}
bind:checked={$isScored}
active="bg-primary-500"
on:click={() => ($value = null)}
name="score-slider"
>
<p class="text-sm text-gray-500">{m.scoringHelpText()}</p></SlideToggle
Expand All @@ -85,17 +87,16 @@
disabled
class="w-full"
name="range-slider"
value={min_score}
value={$value}
min={min_score}
max={max_score}
step={score_step}
ticked
>
<div class="flex justify-between items-center">
<SlideToggle
bind:checked={scoringEnabled}
bind:checked={$isScored}
active="bg-primary-500"
on:click={() => ($value = min_score)}
name="score-slider"
>
<p class="text-sm text-gray-500">{m.scoringHelpText()}</p></SlideToggle
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const AssetSchema = baseNamedObject({
export const RequirementAssessmentSchema = z.object({
status: z.string(),
score: z.number().optional().nullable(),
is_scored: z.boolean().optional(),
comment: z.string().optional().nullable(),
folder: z.string(),
requirement: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
statusDisplay: node.status_display,
statusColor: complianceColorMap[node.status],
score: node.score,
isScored: node.is_scored,
max_score: node.max_score
},
children: node.children ? transformToTreeView(Object.entries(node.children)) : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let statusColor: string;
export let assessable: boolean;
export let score: number;
export let isScored: boolean;
export let max_score: number;
const lead = localItems(languageTag())[statusI18n] ?? statusDisplay ?? '';
Expand All @@ -21,7 +22,7 @@
<span class="badge {classesText} h-fit" style="background-color: {statusColor};">
{lead}
</span>
{#if score !== null && statusI18n !== 'notApplicable'}
{#if score !== null && statusI18n !== 'notApplicable' && isScored}
<span>
<ProgressRadial
stroke={100}
Expand Down

0 comments on commit 0a5808b

Please sign in to comment.