feat: add chain select cmp

This commit is contained in:
2026-02-11 21:19:55 -03:00
parent 5d4c0c5d36
commit 6babbea1c4
7 changed files with 144 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { Component, inject, OnInit, Optional, Self } from '@angular/core';
import { ChainDAO } from '../../dao/ChainDAO';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { AsyncPipe } from '@angular/common';
import { ControlValueAccessor, FormControl, NgControl, ReactiveFormsModule } from '@angular/forms';
import { Chain } from '../../models/Chain';
import { TranslatePipe } from '@ngx-translate/core';
import { UpperfirstPipe } from "../../pipes/upperfirst-pipe";
@Component({
selector: 'app-chain-select',
imports: [
AsyncPipe,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
ReactiveFormsModule,
TranslatePipe,
UpperfirstPipe
],
templateUrl: './chain-select.html',
styleUrl: './chain-select.scss',
})
export class ChainSelect implements ControlValueAccessor, OnInit {
private readonly chainDAO = inject(ChainDAO);
protected chains$ = this.chainDAO.findAll();
protected control = new FormControl();
constructor(@Self() @Optional() public controlDir: NgControl) {
if (this.controlDir) {
this.controlDir.valueAccessor = this;
}
}
ngOnInit() {
this.control = <FormControl>this.controlDir.control;
}
writeValue(obj: any): void {}
registerOnChange(onChange: any) {}
registerOnTouched(fn: any): void {}
setDisabledState?(isDisabled: boolean): void {}
compareFn(c1: Chain, c2: Chain) {
if (!c1 || !c2) return false;
return c1.id === c2.id;
}
}