From 6e8e27a46969522ab1ba09d32e721e701cb95df0 Mon Sep 17 00:00:00 2001 From: danielalexis Date: Mon, 15 Apr 2024 23:55:52 +0100 Subject: [PATCH] Update price-calculator component with new checkboxes and tasks --- .../price-calculator.component.html | 39 ++++++++++++++++- .../price-calculator.component.scss | 12 ++++++ .../price-calculator.component.ts | 42 ++++++++++++++++++- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/app/price-calculator/price-calculator.component.html b/src/app/price-calculator/price-calculator.component.html index aecf440..f1efba6 100644 --- a/src/app/price-calculator/price-calculator.component.html +++ b/src/app/price-calculator/price-calculator.component.html @@ -1,4 +1,4 @@ -
+ + + + +
+ Check me! + Disabled +
+ +
+ + + {{task.name}} + + + +
    + @for (subtask of task.subtasks; track subtask) { +
  • + + {{subtask.name}} + +
  • + } +
+
+
\ No newline at end of file diff --git a/src/app/price-calculator/price-calculator.component.scss b/src/app/price-calculator/price-calculator.component.scss index e69de29..405c033 100644 --- a/src/app/price-calculator/price-calculator.component.scss +++ b/src/app/price-calculator/price-calculator.component.scss @@ -0,0 +1,12 @@ +.example-section { + margin: 12px 0; +} + +.example-margin { + margin: 0 12px; +} + +ul { + list-style-type: none; + margin-top: 4px; +} \ No newline at end of file diff --git a/src/app/price-calculator/price-calculator.component.ts b/src/app/price-calculator/price-calculator.component.ts index 11d1e07..336f4ae 100644 --- a/src/app/price-calculator/price-calculator.component.ts +++ b/src/app/price-calculator/price-calculator.component.ts @@ -3,16 +3,24 @@ import { FormsModule } from "@angular/forms"; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatSelectModule } from '@angular/material/select'; import { MatInputModule } from '@angular/material/input'; - +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { ThemePalette } from '@angular/material/core'; interface CompanyType { name: string; value: number; } +export interface Task { + name: string; + completed: boolean; + color: ThemePalette; + subtasks?: Task[]; +} + @Component({ selector: 'app-price-calculator', standalone: true, - imports: [MatFormFieldModule, MatSelectModule, MatInputModule, FormsModule], + imports: [MatFormFieldModule, MatSelectModule, MatInputModule, FormsModule, MatCheckboxModule], templateUrl: './price-calculator.component.html', styleUrl: './price-calculator.component.scss' }) @@ -21,5 +29,35 @@ interface CompanyType { export class PriceCalculatorComponent { companyTypes: CompanyType[] = [{ name: "Trabalhador Independente", value: 1 }, { name: "Startup", value: 2 }, { name: "PME", value: 3 }, { name: "Grande Empresa", value: 4 }]; + task: Task = { + name: 'Indeterminate', + completed: false, + color: 'primary', + subtasks: [ + { name: 'Primary', completed: false, color: 'primary' }, + { name: 'Accent', completed: false, color: 'accent' }, + { name: 'Warn', completed: false, color: 'warn' }, + ], + }; + + allComplete: boolean = false; + + updateAllComplete() { + this.allComplete = this.task.subtasks != null && this.task.subtasks.every(t => t.completed); + } + + someComplete(): boolean { + if (this.task.subtasks == null) { + return false; + } + return this.task.subtasks.filter(t => t.completed).length > 0 && !this.allComplete; + } + setAll(completed: boolean) { + this.allComplete = completed; + if (this.task.subtasks == null) { + return; + } + this.task.subtasks.forEach(t => (t.completed = completed)); + } }