Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show custom values in dropdown if set #578

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
85 changes: 74 additions & 11 deletions main/http_server/axe-os/src/app/components/edit/edit.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { startWith } from 'rxjs';
import { startWith, Subject, takeUntil } from 'rxjs';
import { LoadingService } from 'src/app/services/loading.service';
import { SystemService } from 'src/app/services/system.service';
import { eASICModel } from 'src/models/enum/eASICModel';
Expand All @@ -12,7 +12,7 @@ import { eASICModel } from 'src/models/enum/eASICModel';
templateUrl: './edit.component.html',
styleUrls: ['./edit.component.scss']
})
export class EditComponent implements OnInit {
export class EditComponent implements OnInit, OnDestroy {

public form!: FormGroup;

Expand Down Expand Up @@ -116,21 +116,24 @@ export class EditComponent implements OnInit {
{ name: '1300', value: 1300 },
];

private destroy$ = new Subject<void>();

constructor(
private fb: FormBuilder,
private systemService: SystemService,
private toastr: ToastrService,
private toastrService: ToastrService,
private loadingService: LoadingService
) {

window.addEventListener('resize', this.checkDevTools);
window.addEventListener('resize', this.checkDevTools.bind(this));
this.checkDevTools();

}

ngOnInit(): void {
this.systemService.getInfo(this.uri)
.pipe(this.loadingService.lockUIUntilComplete())
.pipe(
this.loadingService.lockUIUntilComplete(),
takeUntil(this.destroy$)
)
.subscribe(info => {
this.ASICModel = info.ASICModel;
this.form = this.fb.group({
Expand Down Expand Up @@ -169,7 +172,8 @@ export class EditComponent implements OnInit {
});

this.form.controls['autofanspeed'].valueChanges.pipe(
startWith(this.form.controls['autofanspeed'].value)
startWith(this.form.controls['autofanspeed'].value),
takeUntil(this.destroy$)
).subscribe(autofanspeed => {
if (autofanspeed) {
this.form.controls['fanspeed'].disable();
Expand All @@ -180,8 +184,13 @@ export class EditComponent implements OnInit {
});
}

ngOnDestroy(): void {
window.removeEventListener('resize', this.checkDevTools.bind(this));
this.destroy$.next();
this.destroy$.complete();
}

private checkDevTools = () => {
private checkDevTools(): void {
if (
window.outerWidth - window.innerWidth > 160 ||
window.outerHeight - window.innerHeight > 160
Expand All @@ -190,7 +199,7 @@ export class EditComponent implements OnInit {
} else {
this.devToolsOpen = false;
}
};
}

public updateSystem() {

Expand Down Expand Up @@ -247,4 +256,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;
}

}
Loading