✨ first working version (bugs with missing codes)
This commit is contained in:
1
src/app/compos/logo/logo.component.html
Normal file
1
src/app/compos/logo/logo.component.html
Normal file
@@ -0,0 +1 @@
|
||||
<div class="logo">help<span class="contra">Contra</span></div>
|
||||
17
src/app/compos/logo/logo.component.scss
Normal file
17
src/app/compos/logo/logo.component.scss
Normal file
@@ -0,0 +1,17 @@
|
||||
@import "../../../styles/variables.scss";
|
||||
|
||||
.logo {
|
||||
margin-top: 32px;
|
||||
font-weight: 500;
|
||||
color: $color-A;
|
||||
font-size: 32px;
|
||||
|
||||
& .contra {
|
||||
background-color: $color-E;
|
||||
color: #FFF;
|
||||
border-radius: 8px;
|
||||
text-transform: uppercase;
|
||||
padding: 4px 8px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
15
src/app/compos/logo/logo.component.ts
Normal file
15
src/app/compos/logo/logo.component.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-logo',
|
||||
templateUrl: './logo.component.html',
|
||||
styleUrls: ['./logo.component.scss']
|
||||
})
|
||||
export class LogoComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
||||
3
src/app/compos/progress/progress.component.html
Normal file
3
src/app/compos/progress/progress.component.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="container">
|
||||
<div class="progress" [style.width]="progress + '%'"></div>
|
||||
</div>
|
||||
14
src/app/compos/progress/progress.component.scss
Normal file
14
src/app/compos/progress/progress.component.scss
Normal file
@@ -0,0 +1,14 @@
|
||||
@import "../../../styles/variables.scss";
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
height: 12px;
|
||||
background-color: #FFF;
|
||||
overflow: hidden;
|
||||
|
||||
& .progress {
|
||||
background-color: $color-A;
|
||||
height: 100%;
|
||||
transition: width 0.2s;
|
||||
}
|
||||
}
|
||||
17
src/app/compos/progress/progress.component.ts
Normal file
17
src/app/compos/progress/progress.component.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {Component, Input, OnInit} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-progress',
|
||||
templateUrl: './progress.component.html',
|
||||
styleUrls: ['./progress.component.scss']
|
||||
})
|
||||
export class ProgressComponent implements OnInit {
|
||||
|
||||
@Input() progress = 0;
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
||||
31
src/app/compos/question/question.component.html
Normal file
31
src/app/compos/question/question.component.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<app-progress [progress]="computeProgress()"></app-progress>
|
||||
|
||||
|
||||
<div class="container" *ngIf="question">
|
||||
<app-logo></app-logo>
|
||||
|
||||
<div class="hasTaken block">
|
||||
<h2>Question {{question.id}}</h2>
|
||||
<div class="question"><h3>{{question.question.split('*')[0]}}<span class="highlight">{{question.question.split('*')[1]}}</span> ?</h3></div>
|
||||
<div class="answer">
|
||||
<div class="answers">
|
||||
<span (click)="setHasTaken(true)" [ngClass]="{'active': hasTaken}">Oui</span>
|
||||
<span (click)="setHasTaken(false)" [ngClass]="{'active': hasTaken === false}">Non</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="symptoms block" *ngIf="hasTaken">
|
||||
<div class="question">
|
||||
<h3 class="question">A-t-elle présenté un ou plusieurs effet(s) indésirable(s) suivant(s) ?</h3>
|
||||
<span class="how">Plusieurs choix possibles. Sélectionnez si applicable.</span>
|
||||
</div>
|
||||
<app-radio (onAddSymptom)="addAnswer($event)" (onRemoveSymptom)="removeAnswer($event)" [choices]="question.symptoms"></app-radio>
|
||||
</div>
|
||||
|
||||
<div class="buttons">
|
||||
<button *ngIf="!isFirstQuestion" class="btn secondary">Question précédente</button>
|
||||
<button *ngIf="!isLastQuestion" [disabled]="hasTaken === undefined" class="btn" (click)="next()">Question suivante</button>
|
||||
<button *ngIf="isLastQuestion" [disabled]="hasTaken === undefined" class="btn" (click)="validate()">Valider</button>
|
||||
</div>
|
||||
</div>
|
||||
82
src/app/compos/question/question.component.scss
Normal file
82
src/app/compos/question/question.component.scss
Normal file
@@ -0,0 +1,82 @@
|
||||
@import "../../../styles/variables.scss";
|
||||
|
||||
h2 {
|
||||
font-weight: 500;
|
||||
color: #FFF;
|
||||
font-size: 64px;
|
||||
}
|
||||
|
||||
.question h3 {
|
||||
font-size: 32px;
|
||||
line-height: 48px;
|
||||
font-weight: 200;
|
||||
|
||||
& .highlight {
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
|
||||
width: 60%;
|
||||
margin: 0 auto;
|
||||
|
||||
.block {
|
||||
display: flex;
|
||||
gap: 32px;
|
||||
flex-direction: column;
|
||||
border-radius: 32px;
|
||||
margin-top: 32px;
|
||||
}
|
||||
|
||||
& .hasTaken {
|
||||
|
||||
background: rgb(126,197,187);
|
||||
background: linear-gradient(142deg, rgba(126,197,187,1) 0%, rgb(61, 141, 141) 100%);
|
||||
position: relative;
|
||||
box-shadow: #00000022 0px 0px 10px;
|
||||
padding: 64px 32px;
|
||||
|
||||
.answers {
|
||||
background-color: #FFF;
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
display: inline-block;
|
||||
|
||||
& span {
|
||||
font-size: 20px;
|
||||
cursor: pointer;
|
||||
color: $color-A;
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
font-weight: 500;
|
||||
padding: 8px 16px;
|
||||
display: inline-block;
|
||||
|
||||
&.active {
|
||||
background-color: $color-A;
|
||||
color: #FFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
& .symptoms {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
padding-top: 0;
|
||||
border-left: 4px solid $color-A;
|
||||
border-radius: 0;
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.buttons {
|
||||
margin-top: 64px;
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: flex-end;
|
||||
& .btn {
|
||||
width: 300px;
|
||||
}
|
||||
}
|
||||
69
src/app/compos/question/question.component.ts
Normal file
69
src/app/compos/question/question.component.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
import {Question, QUESTIONS, Symptom} from "../../questions.constants";
|
||||
import {AnswersService} from "../../services/answers.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-question',
|
||||
templateUrl: './question.component.html',
|
||||
styleUrls: ['./question.component.scss']
|
||||
})
|
||||
export class QuestionComponent {
|
||||
|
||||
_question: Question = QUESTIONS[0];
|
||||
get question(): Question {
|
||||
return this._question;
|
||||
}
|
||||
@Input() set question(question: Question) {
|
||||
this._question = question;
|
||||
this.isFirstOrLast();
|
||||
}
|
||||
|
||||
@Output() onValidate: EventEmitter<void> = new EventEmitter<void>();
|
||||
@Output() onNext: EventEmitter<void> = new EventEmitter<void>();
|
||||
@Output() onPrevious: EventEmitter<void> = new EventEmitter<void>();
|
||||
|
||||
hasTaken: boolean | undefined = undefined;
|
||||
isFirstQuestion: boolean = false;
|
||||
isLastQuestion: boolean = false;
|
||||
|
||||
constructor(private answerService: AnswersService) { }
|
||||
|
||||
setHasTaken = (hasTaken: boolean) => {
|
||||
this.hasTaken = hasTaken;
|
||||
}
|
||||
|
||||
isFirstOrLast = () => {
|
||||
this.isFirstQuestion = this.question.id === 1;
|
||||
this.isLastQuestion = this.question.id === QUESTIONS.length;
|
||||
}
|
||||
|
||||
next = () => {
|
||||
this.onNext.emit();
|
||||
this.hasTaken = undefined;
|
||||
this.isFirstOrLast();
|
||||
}
|
||||
|
||||
previous = () => {
|
||||
this.onPrevious.emit();
|
||||
this.hasTaken = undefined;
|
||||
this.isFirstOrLast();
|
||||
}
|
||||
|
||||
computeProgress() {
|
||||
return (this.question.id - 1) * 100 / (QUESTIONS.length - 1);
|
||||
}
|
||||
|
||||
addAnswer = (symptom: Symptom) => {
|
||||
const code = `Q${this._question.id}${symptom.key}`;
|
||||
this.answerService.addAnswer(code);
|
||||
}
|
||||
|
||||
removeAnswer = (symptom: Symptom) => {
|
||||
const code = `Q${this._question.id}${symptom.key}`;
|
||||
this.answerService.removeAnswer(code);
|
||||
}
|
||||
|
||||
validate = () => {
|
||||
this.onValidate.emit();
|
||||
}
|
||||
}
|
||||
6
src/app/compos/radio/radio.component.html
Normal file
6
src/app/compos/radio/radio.component.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<div class="choices">
|
||||
<div class="choice" (click)="onClick(c)" *ngFor="let c of choices">
|
||||
<span class="token-choice" [ngClass]="{'active': isActive(c)}">{{c.label}}</span>
|
||||
<span class="token-choice-description" *ngIf="c.description">{{c.description}}</span>
|
||||
</div>
|
||||
</div>
|
||||
14
src/app/compos/radio/radio.component.scss
Normal file
14
src/app/compos/radio/radio.component.scss
Normal file
@@ -0,0 +1,14 @@
|
||||
.choices {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-direction: column;
|
||||
|
||||
.choice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
& .token-choice-description {
|
||||
margin-left: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/app/compos/radio/radio.component.ts
Normal file
34
src/app/compos/radio/radio.component.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
import {Symptom} from "../../questions.constants";
|
||||
|
||||
@Component({
|
||||
selector: 'app-radio',
|
||||
templateUrl: './radio.component.html',
|
||||
styleUrls: ['./radio.component.scss']
|
||||
})
|
||||
export class RadioComponent {
|
||||
|
||||
@Input() choices: Symptom[] = [];
|
||||
|
||||
@Output() onAddSymptom: EventEmitter<Symptom> = new EventEmitter<Symptom>();
|
||||
@Output() onRemoveSymptom: EventEmitter<Symptom> = new EventEmitter<Symptom>();
|
||||
|
||||
active: Symptom[] = [];
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
onClick = (c: Symptom) => {
|
||||
if (this.isActive(c)) {
|
||||
this.onRemoveSymptom.emit(c);
|
||||
this.active.splice(this.active.indexOf(c), 1);
|
||||
} else {
|
||||
this.active.push(c);
|
||||
this.onAddSymptom.emit(c);
|
||||
}
|
||||
}
|
||||
|
||||
isActive = (c: Symptom): boolean => {
|
||||
return this.active.includes(c);
|
||||
}
|
||||
}
|
||||
19
src/app/compos/results/results.component.html
Normal file
19
src/app/compos/results/results.component.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<app-progress [progress]="100"></app-progress>
|
||||
<div class="container">
|
||||
<app-logo></app-logo>
|
||||
<h2>Résultats</h2>
|
||||
<div class="explanation">
|
||||
<p>Les résultats sont classés du plus recommandé au moins recommandé.</p>
|
||||
<p>Cliquez sur un traitement pour plus d'information.</p>
|
||||
</div>
|
||||
<h3>Recommandé</h3>
|
||||
<div class="recommendation" *ngFor="let r of recommendations">
|
||||
<div class="treatment">{{r.treatment.label}} ({{r.score}})</div>
|
||||
</div>
|
||||
<h3 class="discouragement">Non-recommandé</h3>
|
||||
<div class="recommendation" *ngFor="let r of discouragements">
|
||||
<div class="treatment">{{r.treatment.label}} ({{r.score}})</div>
|
||||
</div>
|
||||
|
||||
<button class="btn" (click)="onReset.emit()">Relancer le formulaire</button>
|
||||
</div>
|
||||
43
src/app/compos/results/results.component.scss
Normal file
43
src/app/compos/results/results.component.scss
Normal file
@@ -0,0 +1,43 @@
|
||||
@import "../../../styles/variables.scss";
|
||||
|
||||
.container {
|
||||
width: 60%;
|
||||
margin: 0 auto;
|
||||
|
||||
h2 {
|
||||
font-weight: 500;
|
||||
color: $color-E;
|
||||
font-size: 64px;
|
||||
margin: 96px 0 16px 0;
|
||||
}
|
||||
|
||||
.explanation {
|
||||
margin-bottom: 32px;
|
||||
|
||||
& p {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-weight: 500;
|
||||
color: $color-B;
|
||||
font-size: 32px;
|
||||
margin-top: 32px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
&.discouragement {
|
||||
color: #c18c9d;
|
||||
}
|
||||
}
|
||||
|
||||
.recommendation {
|
||||
display: flex;
|
||||
|
||||
& .treatment {
|
||||
font-size: 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
src/app/compos/results/results.component.ts
Normal file
24
src/app/compos/results/results.component.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
|
||||
import {EngineService, RecommendationModel} from "../../services/engine.service";
|
||||
import {AnswersService} from "../../services/answers.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-results',
|
||||
templateUrl: './results.component.html',
|
||||
styleUrls: ['./results.component.scss']
|
||||
})
|
||||
export class ResultsComponent implements OnInit {
|
||||
|
||||
recommendations: RecommendationModel[] = [];
|
||||
discouragements: RecommendationModel[] = [];
|
||||
|
||||
@Output() onReset: EventEmitter<void> = new EventEmitter<void>();
|
||||
|
||||
constructor(private engine: EngineService, private answers: AnswersService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
const recommendations = this.engine.getRecommendations(this.answers.answersIndexes);
|
||||
this.recommendations = recommendations.filter((r) => r.score >= 0).sort((r1, r2) => r2.score - r1.score);
|
||||
this.discouragements = recommendations.filter((r) => r.score < 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user