2026-04-12 20:45:24 +02:00
|
|
|
import { Component } from "@angular/core";
|
|
|
|
|
import { CommonModule } from "@angular/common";
|
|
|
|
|
import { RouterOutlet } from "@angular/router";
|
|
|
|
|
import { MatInputModule } from "@angular/material/input";
|
|
|
|
|
import { MatButtonModule } from "@angular/material/button";
|
|
|
|
|
import { FormsModule } from "@angular/forms";
|
|
|
|
|
import {
|
|
|
|
|
findValidPairs,
|
|
|
|
|
findCorrespondingValue,
|
|
|
|
|
changeIndex,
|
|
|
|
|
} from "./pair-logic";
|
2025-11-30 13:42:16 +01:00
|
|
|
|
|
|
|
|
@Component({
|
2026-04-12 20:45:24 +02:00
|
|
|
selector: "app-root",
|
2025-11-30 13:42:16 +01:00
|
|
|
standalone: true,
|
2026-04-12 20:45:24 +02:00
|
|
|
imports: [
|
|
|
|
|
CommonModule,
|
|
|
|
|
RouterOutlet,
|
|
|
|
|
MatInputModule,
|
|
|
|
|
FormsModule,
|
|
|
|
|
MatButtonModule,
|
|
|
|
|
],
|
|
|
|
|
templateUrl: "./app.component.html",
|
|
|
|
|
styleUrls: ["./app.component.scss"],
|
2025-11-30 13:42:16 +01:00
|
|
|
})
|
|
|
|
|
export class AppComponent {
|
2026-04-12 20:45:24 +02:00
|
|
|
inputOne: number | null = null;
|
|
|
|
|
inputTwo: number | null = null;
|
2025-11-30 13:42:16 +01:00
|
|
|
min: number | null = 100;
|
|
|
|
|
max: number | null = 250;
|
|
|
|
|
step: number | null = 25;
|
|
|
|
|
targetValue: number | null = 325;
|
|
|
|
|
indexOne: number = 0;
|
|
|
|
|
indexTwo: number = 0;
|
|
|
|
|
possibleValues: Array<[number, number]> | null = [];
|
|
|
|
|
|
|
|
|
|
constructor() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.possibleValues = findValidPairs(
|
|
|
|
|
this.step,
|
|
|
|
|
this.min,
|
|
|
|
|
this.max,
|
|
|
|
|
this.targetValue,
|
|
|
|
|
);
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.possibleValues = findValidPairs(
|
|
|
|
|
this.step,
|
|
|
|
|
this.min,
|
|
|
|
|
this.max,
|
|
|
|
|
this.targetValue,
|
|
|
|
|
);
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateInput() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.possibleValues = findValidPairs(
|
|
|
|
|
this.step,
|
|
|
|
|
this.min,
|
|
|
|
|
this.max,
|
|
|
|
|
this.targetValue,
|
|
|
|
|
);
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 20:45:24 +02:00
|
|
|
private doChangeIndex(currentValue: number, direction: boolean) {
|
|
|
|
|
this.possibleValues = findValidPairs(
|
|
|
|
|
this.step,
|
|
|
|
|
this.min,
|
|
|
|
|
this.max,
|
|
|
|
|
this.targetValue,
|
|
|
|
|
);
|
2025-11-30 13:42:16 +01:00
|
|
|
const length = this.possibleValues?.length;
|
2026-04-12 20:45:24 +02:00
|
|
|
return changeIndex(currentValue, direction, length);
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTwoValue() {
|
2026-04-12 20:45:24 +02:00
|
|
|
if (this.possibleValues !== null) {
|
2025-11-30 13:42:16 +01:00
|
|
|
this.inputOne = this.possibleValues[this.indexOne][0];
|
2026-04-12 20:45:24 +02:00
|
|
|
if (typeof this.inputOne !== "undefined" && this.inputOne !== null) {
|
|
|
|
|
const result = findCorrespondingValue(
|
|
|
|
|
this.possibleValues,
|
|
|
|
|
this.inputOne,
|
|
|
|
|
);
|
|
|
|
|
if (result !== null) {
|
|
|
|
|
[this.inputTwo, this.indexTwo] = result;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.error("result is null!");
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
2026-04-12 20:45:24 +02:00
|
|
|
console.error(
|
|
|
|
|
"this.inputOne is null or undefined!: ",
|
|
|
|
|
this.inputOne,
|
|
|
|
|
this.possibleValues,
|
|
|
|
|
this.indexOne,
|
|
|
|
|
);
|
2025-11-30 13:42:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upOne() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.indexOne = this.doChangeIndex(this.indexOne, true);
|
2025-11-30 13:42:16 +01:00
|
|
|
this.updateTwoValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downOne() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.indexOne = this.doChangeIndex(this.indexOne, false);
|
2025-11-30 13:42:16 +01:00
|
|
|
this.updateTwoValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upTwo() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.indexTwo = this.doChangeIndex(this.indexTwo, true);
|
|
|
|
|
if (this.possibleValues !== null) {
|
2025-11-30 13:42:16 +01:00
|
|
|
this.inputTwo = this.possibleValues[this.indexTwo][1];
|
2026-04-12 20:45:24 +02:00
|
|
|
const result = findCorrespondingValue(
|
|
|
|
|
this.possibleValues,
|
|
|
|
|
this.inputTwo,
|
|
|
|
|
);
|
|
|
|
|
if (result !== null) {
|
2025-11-30 13:42:16 +01:00
|
|
|
[this.inputOne, this.indexOne] = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
downTwo() {
|
2026-04-12 20:45:24 +02:00
|
|
|
this.indexTwo = this.doChangeIndex(this.indexTwo, false);
|
|
|
|
|
if (this.possibleValues !== null) {
|
2025-11-30 13:42:16 +01:00
|
|
|
this.inputTwo = this.possibleValues[this.indexTwo][1];
|
2026-04-12 20:45:24 +02:00
|
|
|
const result = findCorrespondingValue(
|
|
|
|
|
this.possibleValues,
|
|
|
|
|
this.inputTwo,
|
|
|
|
|
);
|
|
|
|
|
if (result !== null) {
|
2025-11-30 13:42:16 +01:00
|
|
|
[this.inputOne, this.indexOne] = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|