Skip to content

Commit

Permalink
fix: Show custom values in dropdown if set
Browse files Browse the repository at this point in the history
  • Loading branch information
mrv777 committed Dec 12, 2024
1 parent ba6be3c commit 26951ee
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,70 +67,18 @@
</div>
</div>

<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1366">

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="frequency">Frequency</label>
<div class="col-12 md:col-10">
<p-dropdown [options]="BM1366DropdownFrequency" optionLabel="name" optionValue="value"
formControlName="frequency"></p-dropdown>
</div>
</div>


<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="coreVoltage">Core Voltage</label>
<p-dropdown class="col-12 md:col-10" [options]="BM1366CoreVoltage" optionLabel="name"
optionValue="value" formControlName="coreVoltage"></p-dropdown>
</div>

</ng-container>

<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1368">

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="frequency">Frequency</label>
<div class="col-12 md:col-10">
<p-dropdown [options]="BM1368DropdownFrequency" optionLabel="name" optionValue="value"
formControlName="frequency"></p-dropdown>
</div>
</div>

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="coreVoltage">Core Voltage</label>
<p-dropdown class="col-12 md:col-10" [options]="BM1368CoreVoltage" optionLabel="name"
optionValue="value" formControlName="coreVoltage"></p-dropdown>
</div>
</ng-container>
<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1370">

<ng-container *ngIf="!devToolsOpen && [eASICModel.BM1366, eASICModel.BM1368, eASICModel.BM1370, eASICModel.BM1397].includes(ASICModel)">
<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="frequency">Frequency</label>
<div class="col-12 md:col-10">
<p-dropdown [options]="BM1370DropdownFrequency" optionLabel="name" optionValue="value"
<p-dropdown [options]="getDropdownFrequency()" optionLabel="name" optionValue="value"
formControlName="frequency"></p-dropdown>
</div>
</div>

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="coreVoltage">Core Voltage</label>
<p-dropdown class="col-12 md:col-10" [options]="BM1370CoreVoltage" optionLabel="name"
optionValue="value" formControlName="coreVoltage"></p-dropdown>
</div>
</ng-container>
<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1397">

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="frequency">Frequency</label>

<p-dropdown class="col-12 md:col-10" [options]="BM1397DropdownFrequency" optionLabel="name"
optionValue="value" formControlName="frequency"></p-dropdown>

</div>

<div class="field grid p-fluid">
<label class="col-12 mb-2 md:col-2 md:mb-0" htmlFor="coreVoltage">Core Voltage</label>
<p-dropdown class="col-12 md:col-10" [options]="BM1397CoreVoltage" optionLabel="name"
<p-dropdown class="col-12 md:col-10" [options]="getCoreVoltage()" optionLabel="name"
optionValue="value" formControlName="coreVoltage"></p-dropdown>
</div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export class EditComponent implements OnInit {
private fb: FormBuilder,
private systemService: SystemService,
private toastr: ToastrService,
private toastrService: ToastrService,
private loadingService: LoadingService
) {

Expand Down Expand Up @@ -247,4 +246,58 @@ export class EditComponent implements OnInit {
});
}

getDropdownFrequency() {
// Get base frequency options based on ASIC model
let options = [];
switch(this.ASICModel) {
case this.eASICModel.BM1366: options = [...this.BM1366DropdownFrequency]; break;
case this.eASICModel.BM1368: options = [...this.BM1368DropdownFrequency]; break;
case this.eASICModel.BM1370: options = [...this.BM1370DropdownFrequency]; break;
case this.eASICModel.BM1397: options = [...this.BM1397DropdownFrequency]; break;
default: return [];
}

// Get current frequency value from form
const currentFreq = this.form?.get('frequency')?.value;

// If current frequency exists and isn't in the options
if (currentFreq && !options.some(opt => opt.value === currentFreq)) {
options.push({
name: `${currentFreq} (Custom)`,
value: currentFreq
});
// Sort options by frequency value
options.sort((a, b) => a.value - b.value);
}

return options;
}

getCoreVoltage() {
// Get base voltage options based on ASIC model
let options = [];
switch(this.ASICModel) {
case this.eASICModel.BM1366: options = [...this.BM1366CoreVoltage]; break;
case this.eASICModel.BM1368: options = [...this.BM1368CoreVoltage]; break;
case this.eASICModel.BM1370: options = [...this.BM1370CoreVoltage]; break;
case this.eASICModel.BM1397: options = [...this.BM1397CoreVoltage]; break;
default: return [];
}

// Get current voltage value from form
const currentVoltage = this.form?.get('coreVoltage')?.value;

// If current voltage exists and isn't in the options
if (currentVoltage && !options.some(opt => opt.value === currentVoltage)) {
options.push({
name: `${currentVoltage} (Custom)`,
value: currentVoltage
});
// Sort options by voltage value
options.sort((a, b) => a.value - b.value);
}

return options;
}

}

0 comments on commit 26951ee

Please sign in to comment.