Skip to content

Commit d57c60a

Browse files
authored
ADD boolean chars as checkboxes on price simulator (#134)
* ADD boolean chars as checkboxes on price simulator * Disable select when char is disabled
1 parent 34d080e commit d57c60a

6 files changed

Lines changed: 77 additions & 19 deletions

File tree

src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,11 +1115,11 @@ export class CreateProductSpecComponent implements OnInit {
11151115
if(this.booleanCharSelected){
11161116
this.creatingChars=[
11171117
{
1118-
isDefault:true,
1118+
isDefault:false,
11191119
value: true as any
11201120
},
11211121
{
1122-
isDefault:false,
1122+
isDefault:true,
11231123
value:false as any
11241124
}
11251125
]

src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,11 +1329,11 @@ export class UpdateProductSpecComponent implements OnInit {
13291329
if(this.booleanCharSelected){
13301330
this.creatingChars=[
13311331
{
1332-
isDefault:true,
1332+
isDefault:false,
13331333
value: true as any
13341334
},
13351335
{
1336-
isDefault:false,
1336+
isDefault:true,
13371337
value:false as any
13381338
}
13391339
]

src/app/shared/characteristic/characteristic.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h4 class="text-lg font-semibold text-primary-100 dark:text-gray-300">{{ characteristic.name }}</h4>
55
<markdown class="text-gray-500 dark:text-gray-400 text-wrap break-all" [data]="characteristic.description"></markdown>
66
</div>
7-
7+
@if(!isDisabled){
88
<!-- Slider -->
99
@if (isSlider()){
1010
<div class="flex items-center space-x-2">
@@ -32,6 +32,7 @@ <h4 class="text-lg font-semibold text-primary-100 dark:text-gray-300">{{ charact
3232
</select>
3333
</div>
3434
}
35+
}
3536

3637
} @else {
3738
<div class="grid grid-cols-2 items-center">

src/app/shared/characteristic/characteristic.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ interface Characteristic {
3535
export class CharacteristicComponent implements OnInit {
3636
@Input() characteristic!: ProductSpecificationCharacteristic;
3737
@Input() readOnly: boolean = false;
38+
@Input() isDisabled: boolean = false;
39+
@Input() canBeDisabled: boolean = false;
3840
@Output() valueChange = new EventEmitter<any>();
3941

4042
control = new FormControl();

src/app/shared/price-plan-drawer/price-plan-drawer.component.html

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,33 @@ <h5 id="drawer-right-label" class="inline-flex items-center text-wrap break-all
6161
<p class="mt-6 text-sm text-gray-500 dark:text-gray-400">This price plan has an associate profile. That means that the following characteristics are already set for you.</p>
6262
<div class="rounded-lg border border-dashed border-primary-100 bg-white p-2 m-2 dark:bg-gray-800">
6363
@for (ch of filteredCharacteristics ; track ch.id) {
64+
@if(!ch.name?.endsWith('- enabled')){
6465
<app-characteristic [characteristic]="ch" [readOnly]="true" (valueChange)="onValueChange($event)"></app-characteristic>
66+
}
6567
}
6668
</div>
6769
} @else if(filteredCharacteristics.length > 0) {
6870
<p class="mt-6 text-sm text-gray-500 dark:text-gray-400">Please select the characteristics you need to suit this offer to you.</p>
6971
<div class="rounded-lg border border-dashed border-primary-100 bg-white p-2 m-2 dark:bg-gray-800">
70-
@for (ch of filteredCharacteristics ; track ch.id) {
71-
@if (!disabledCharacteristics.includes(ch.id)) {
72-
<app-characteristic [characteristic]="ch" [readOnly]="false" (valueChange)="onValueChange($event)"></app-characteristic>
72+
@for (ch of filteredCharacteristics ; track ch.id; let i = $index) {
73+
@if(!ch.name?.endsWith('- enabled')){
74+
<div class="flex flex-row w-full items-start">
75+
@if(canBeDisabledChars.includes(ch.id)){
76+
<label class="inline-flex items-center cursor-pointer w-fit justify-start items-start my-4 mr-2">
77+
<input type="checkbox" (change)="onToggleChange($event, ch.name)" class="sr-only peer">
78+
<div class="relative w-9 h-5 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600 dark:peer-checked:bg-blue-600"></div>
79+
</label>
80+
}
81+
<div class="flex w-full">
82+
<app-characteristic
83+
[characteristic]="ch"
84+
[readOnly]="false"
85+
[isDisabled]="disabledCharacteristics.includes(ch.id)"
86+
[canBeDisabled]="canBeDisabledChars.includes(ch.id)"
87+
(valueChange)="onValueChange($event)">
88+
</app-characteristic>
89+
</div>
90+
</div>
7391
}
7492
}
7593
</div>

src/app/shared/price-plan-drawer/price-plan-drawer.component.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy {
6565
characteristics: ProductSpecificationCharacteristic[] = []; // Características dinámicas
6666
filteredCharacteristics: ProductSpecificationCharacteristic[] = [];
6767
disabledCharacteristics: any[] = [];
68+
canBeDisabledChars: any[]=[];
6869

6970
@HostListener('document:keydown.escape', ['$event'])
7071
handleEscape(event: KeyboardEvent): void {
@@ -231,15 +232,46 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy {
231232

232233
characteristicsGroup.addControl(
233234
characteristic.id,
234-
this.fb.control(defaultValue || null, Validators.required)
235+
this.fb.control(defaultValue ?? null, Validators.required)
235236
);
237+
if(!characteristic.name?.endsWith('- enabled') && this.filteredCharacteristics.some((char => char.name === characteristic.name+' - enabled'))){
238+
this.canBeDisabledChars.push(characteristic.id)
239+
this.disabledCharacteristics.push(characteristic.id)
240+
}
236241
}
237242
});
238243

239244
this.form.setControl('characteristics', characteristicsGroup);
240245
}
241-
242-
246+
247+
onToggleChange(event: Event, charName: any): void {
248+
const inputElement = event.target as HTMLInputElement;
249+
const isChecked = inputElement.checked;
250+
let char = this.filteredCharacteristics.find(char => char.name == charName+' - enabled')
251+
const characteristicsGroup = this.form.get('characteristics') as FormGroup;
252+
if(char && char.id)
253+
characteristicsGroup.get(char.id)?.setValue(isChecked)
254+
255+
const cleanName = char?.name?.replace(/- enabled$/, '').trim();
256+
const disabledChar = this.filteredCharacteristics.find(
257+
item => item.name === cleanName
258+
);
259+
//const isSelected = event.selectedValue === true || event.selectedValue === 'true';
260+
if (disabledChar) {
261+
if (!isChecked) {
262+
// Add it if it's not already in the array
263+
if (!this.disabledCharacteristics.includes(disabledChar.id)) {
264+
this.disabledCharacteristics.push(disabledChar.id);
265+
}
266+
} else {
267+
// Remove it if it exists
268+
this.disabledCharacteristics = this.disabledCharacteristics.filter(
269+
id => id !== disabledChar.id
270+
);
271+
}
272+
}
273+
this.calculatePrice();
274+
}
243275

244276
// Handle price plan selection
245277
async onPricePlanSelected(pricePlan: any) {
@@ -326,7 +358,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy {
326358
const characteristicsGroup = this.form.get('characteristics') as FormGroup;
327359
characteristicsGroup.get(event.characteristicId)?.setValue(event.selectedValue);
328360

329-
let char = this.filteredCharacteristics.find(item => item.id === event.characteristicId);
361+
/*let char = this.filteredCharacteristics.find(item => item.id === event.characteristicId);
330362
if (char?.name?.endsWith('- enabled')) {
331363
const cleanName = char.name.replace(/- enabled$/, '').trim();
332364
const disabledChar = this.filteredCharacteristics.find(
@@ -348,7 +380,7 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy {
348380
}
349381
}
350382
}
351-
console.log(char)
383+
console.log(char)*/
352384
this.calculatePrice();
353385
}
354386

@@ -407,14 +439,19 @@ export class PricePlanDrawerComponent implements OnInit, OnDestroy {
407439
if(value==null && valueType=='number'){
408440
value=0
409441
}
410-
411-
this.orderChars.push({
412-
"name": this.filteredCharacteristics[idx].name,
413-
"value": value,
414-
"valueType": valueType,
415-
})
442+
443+
if(!this.filteredCharacteristics[idx].name?.endsWith('- enabled')){
444+
this.orderChars.push({
445+
"name": this.filteredCharacteristics[idx].name,
446+
"value": value,
447+
"valueType": valueType,
448+
})
449+
}
450+
416451
}
417452
}
453+
console.log('Calculating the price with...')
454+
console.log(this.orderChars)
418455
}
419456

420457
// Método para calcular el precio usando el servicio

0 commit comments

Comments
 (0)