mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-03-17 13:22:53 +01:00
fix: Show custom values in dropdown if set (#578)
* fix: Show custom values in dropdown if set * fix: Memory leak & checkDevTools binding
This commit is contained in:
parent
32b74c6911
commit
82029eb5ac
@ -67,70 +67,18 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1366">
|
||||
|
||||
<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]="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"
|
||||
<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]="BM1368CoreVoltage" optionLabel="name"
|
||||
optionValue="value" formControlName="coreVoltage"></p-dropdown>
|
||||
</div>
|
||||
</ng-container>
|
||||
<ng-container *ngIf="!devToolsOpen && ASICModel == eASICModel.BM1370">
|
||||
|
||||
<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"
|
||||
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>
|
||||
|
@ -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';
|
||||
@ -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;
|
||||
|
||||
@ -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({
|
||||
@ -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();
|
||||
@ -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
|
||||
@ -190,7 +199,7 @@ export class EditComponent implements OnInit {
|
||||
} else {
|
||||
this.devToolsOpen = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public updateSystem() {
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user