From cfe149e4a39a8e0a6478d72a83085624e516c8b1 Mon Sep 17 00:00:00 2001
From: Guilhem CARRON <gcarron@grandlyon.com>
Date: Mon, 7 Nov 2022 09:42:27 +0000
Subject: [PATCH] feat(personnalOffer): Add-multi-checkbox

---
 .../training-type-picker.component.html       | 14 ++++++++++++-
 .../training-type-picker.component.scss       |  4 ++++
 .../training-type-picker.component.ts         | 21 +++++++++++++++++++
 .../modal-filter/modal-filter.component.scss  | 14 -------------
 src/styles.scss                               | 20 +++++++++++++++---
 5 files changed, 55 insertions(+), 18 deletions(-)

diff --git a/src/app/shared/components/training-type-picker/training-type-picker.component.html b/src/app/shared/components/training-type-picker/training-type-picker.component.html
index c32862de6..1ca460408 100644
--- a/src/app/shared/components/training-type-picker/training-type-picker.component.html
+++ b/src/app/shared/components/training-type-picker/training-type-picker.component.html
@@ -6,8 +6,20 @@
           class="collapseHeader"
           fxLayoutAlign="flex-start center"
           fxLayout="row"
-          (click)="toggleCollapse(categorie.id)"
+          (click)="toggleCollapse(categorie.id); $event.stopPropagation()"
         >
+          <label class="checkbox">
+            <input
+              type="checkbox"
+              [checked]="getCategoryCheckboxStatus(categorie) === 'checked'"
+              (change)="pickAllCategory(categorie, $event.target.checked); $event.stopPropagation()"
+            />
+            <span
+              class="customCheck customCheckPrimary"
+              [ngClass]="{ halfCheck: getCategoryCheckboxStatus(categorie) === 'halfChecked' }"
+            ></span>
+          </label>
+
           <div class="titleCollapse">
             {{ categorie.name }}
           </div>
diff --git a/src/app/shared/components/training-type-picker/training-type-picker.component.scss b/src/app/shared/components/training-type-picker/training-type-picker.component.scss
index e394db9f9..4cf4a1660 100644
--- a/src/app/shared/components/training-type-picker/training-type-picker.component.scss
+++ b/src/app/shared/components/training-type-picker/training-type-picker.component.scss
@@ -47,6 +47,10 @@ button {
     @include lato-bold-14;
     margin-bottom: 12px;
   }
+  .checkbox {
+    width: 2.25rem;
+    margin-top: 0.2rem;
+  }
 
   button {
     background: none;
diff --git a/src/app/shared/components/training-type-picker/training-type-picker.component.ts b/src/app/shared/components/training-type-picker/training-type-picker.component.ts
index 751387b08..77f4c990e 100644
--- a/src/app/shared/components/training-type-picker/training-type-picker.component.ts
+++ b/src/app/shared/components/training-type-picker/training-type-picker.component.ts
@@ -74,4 +74,25 @@ export class TrainingTypePickerComponent implements OnInit {
     }
     this.selectedType.emit(this.selectedChoices);
   }
+  public pickAllCategory(categorie: Category): void {
+    const index = this.selectedChoices.findIndex((_categorie) => _categorie.id === categorie.id);
+    if (this.getCategoryCheckboxStatus(categorie) === 'checked') {
+      this.selectedChoices[index].modules = [];
+    } else {
+      for (let module of categorie.modules) {
+        if (!this.isModulePicked(categorie, module)) this.selectedChoices[index].modules.push(module);
+      }
+    }
+  }
+
+  public getCategoryCheckboxStatus(c: Category): string {
+    const index = this.selectedChoices.findIndex((_categorie) => _categorie.id === c.id);
+    if (this.selectedChoices[index].modules.length === c.modules.length) {
+      return 'checked';
+    } else if (this.selectedChoices[index].modules.length === 0) {
+      return 'unchecked';
+    } else if (this.selectedChoices[index].modules.length && this.selectedChoices[index].modules.length > 0) {
+      return 'halfChecked';
+    }
+  }
 }
diff --git a/src/app/structure-list/components/modal-filter/modal-filter.component.scss b/src/app/structure-list/components/modal-filter/modal-filter.component.scss
index c443be97c..6f72e78f8 100644
--- a/src/app/structure-list/components/modal-filter/modal-filter.component.scss
+++ b/src/app/structure-list/components/modal-filter/modal-filter.component.scss
@@ -96,20 +96,6 @@
         min-width: 0;
       }
       .categoryCheckBox {
-        .halfCheck {
-          position: relative;
-          &:before {
-            content: '';
-            position: absolute;
-            display: block;
-            width: 10px;
-            left: 4px;
-            top: 8px;
-            transform: rotate(0deg);
-            border-bottom: solid 2px $grey-2;
-            border-radius: 0;
-          }
-        }
         ul {
           display: none;
         }
diff --git a/src/styles.scss b/src/styles.scss
index 0155bc7df..b3e3f2cba 100644
--- a/src/styles.scss
+++ b/src/styles.scss
@@ -209,11 +209,11 @@ button {
     opacity: 0;
     display: none;
     &:checked ~ .customCheck {
-      background-color: $grey-1;
+      background-color: $grey-3;
       border-color: transparent;
     }
     &:checked ~ .customCheckPrimary {
-      background-color: $primary-color;
+      background-color: $grey-1;
       border-color: transparent;
     }
     &:checked ~ .customCheck:after {
@@ -240,7 +240,7 @@ button {
     min-width: 18px;
     min-height: 18px;
     background-color: $white;
-    border: 1px solid $grey;
+    border: 1px solid $grey-3;
     cursor: pointer;
     position: relative;
     border-radius: 4px;
@@ -268,6 +268,20 @@ button {
     width: unset;
   }
 }
+.halfCheck {
+  position: relative;
+  &:before {
+    content: '';
+    position: absolute;
+    display: block;
+    width: 10px;
+    left: 4px;
+    top: 8px;
+    transform: rotate(0deg);
+    border-bottom: solid 2px $grey-2;
+    border-radius: 0;
+  }
+}
 
 // Layout
 .w-100 {
-- 
GitLab