-
Notifications
You must be signed in to change notification settings - Fork 273
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
Ca 178 add score notion to compliance assessment #267
Closed
Mohamed-Hacene
wants to merge
13
commits into
main
from
CA-178-Add-score-notion-to-ComplianceAssessment
Closed
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
937cc9a
feat: add scoring notion
Mohamed-Hacene a10a773
feat: improve score notion update
Mohamed-Hacene 197628a
locale: add scoring help text
Mohamed-Hacene 42e1fc8
feat: use null instead of -1
Mohamed-Hacene 6432bb9
feat: add min and max score choice
Mohamed-Hacene 5c91b6c
locale: add min_score and max_score translations
Mohamed-Hacene 4ff080c
feat: display scoring in tree view
Mohamed-Hacene 521969c
feat: calculate global score
Mohamed-Hacene 821af86
feat: add migration
Mohamed-Hacene 429c8e9
Merge branch 'main' into CA-178-Add-score-notion-to-ComplianceAssessment
Mohamed-Hacene db0d6d3
feat: add colors for score displaying
Mohamed-Hacene 8590464
ci: fix compliance assessment api test
Mohamed-Hacene a20a6f5
chore: rename preventNull by formatValue
Mohamed-Hacene 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
This file contains 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 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
28 changes: 28 additions & 0 deletions
28
backend/core/migrations/0009_framework_max_score_framework_min_score_and_more.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.0.4 on 2024-04-16 14:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0008_alter_complianceassessment_status_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='framework', | ||
name='max_score', | ||
field=models.IntegerField(default=100, verbose_name='Maximum score'), | ||
), | ||
migrations.AddField( | ||
model_name='framework', | ||
name='min_score', | ||
field=models.IntegerField(default=0, verbose_name='Minimum score'), | ||
), | ||
migrations.AddField( | ||
model_name='requirementassessment', | ||
name='score', | ||
field=models.IntegerField(blank=True, null=True, verbose_name='Score'), | ||
), | ||
] |
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script lang="ts"> | ||
import { formFieldProxy, type SuperForm } from 'sveltekit-superforms/client'; | ||
import { ProgressRadial } from '@skeletonlabs/skeleton'; | ||
import { RangeSlider } from '@skeletonlabs/skeleton'; | ||
import * as m from '$paraglide/messages'; | ||
import type { AnyZodObject } from 'zod'; | ||
import { displayScoreColor } from '$lib/utils/helpers'; | ||
|
||
export let label: string | undefined = undefined; | ||
export let field: string; | ||
|
||
export let min_score: number; | ||
export let max_score: number; | ||
|
||
export let form: SuperForm<AnyZodObject>; | ||
const { value, errors, constraints } = formFieldProxy(form, field); | ||
|
||
$: scoringEnabled = $value === null ? false : true | ||
|
||
function preventNull(value: number){ | ||
if(value === null){ | ||
return 0 | ||
} | ||
return value * 100 / max_score | ||
|
||
} | ||
Mohamed-Hacene marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function displayNoValue(value: number){ | ||
if(value === null){ | ||
return '--' | ||
} | ||
return value | ||
} | ||
</script> | ||
|
||
<div> | ||
{#if label !== undefined} | ||
{#if $constraints?.required} | ||
<label class="text-sm font-semibold" for={field} | ||
>{label} <span class="text-red-500">*</span></label | ||
> | ||
{:else} | ||
<label class="text-sm font-semibold" for={field}>{label}</label> | ||
{/if} | ||
{/if} | ||
{#if $errors && $errors.length > 0} | ||
<div> | ||
{#each $errors as error} | ||
<p class="text-error-500 text-xs font-medium">{error}</p> | ||
{/each} | ||
</div> | ||
{/if} | ||
<div class="flex flex-row w-full items-center space-x-4 ml-2"> | ||
<input | ||
name={field} | ||
type="checkbox" | ||
class="checkbox" | ||
data-testid="form-input-{field.replaceAll('_', '-')}" | ||
bind:checked={scoringEnabled} | ||
on:change={() => $value = null} | ||
{...$constraints} | ||
{...$$restProps} | ||
{...$constraints} | ||
{...$$restProps} | ||
/> | ||
<div class="flex w-1/2 items-center justify-center"> | ||
<RangeSlider disabled={!scoringEnabled} class="w-full" name="range-slider" bind:value={$value} min={min_score} max={max_score} step={1} ticked></RangeSlider> | ||
</div> | ||
<div class="flex w-1/2 items-center justify-center"> | ||
{#if scoringEnabled} | ||
<ProgressRadial stroke={100} meter={displayScoreColor($value, max_score)} value={preventNull($value)} font={100} width={'w-32'}>{displayNoValue($value)}</ProgressRadial> | ||
{:else} | ||
<ProgressRadial stroke={100} value={0} font={100} width={'w-32'}>--</ProgressRadial> | ||
{/if} | ||
</div> | ||
</div> | ||
<p class="text-sm text-gray-500">{m.scoringHelpText()}</p> | ||
</div> |
This file contains 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 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of getting score choices if they are just a range of integers between min_score and max_score?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It permits to be consistent on the API, to be sure we can only add a score in the range of min_score and max_score.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be done at the validation stage. This way you would only have to check the boundaries instead of iterating over every single integer contained between min_score and max_score.