Added policy path dropdown.

This commit is contained in:
Tom
2025-03-18 14:39:02 +00:00
parent 9201f9b6c5
commit d0556dce9c
11 changed files with 54 additions and 51 deletions

View File

@@ -0,0 +1,19 @@
<mat-form-field>
<mat-label>Path</mat-label>
<input name="path"
matInput
type="text"
placeholder="Pick a policy..."
[formControl]="policyControl"
[matAutocomplete]="auto" />
<mat-autocomplete #auto="matAutocomplete">
@for (option of filteredPolicies | async; track option) {
<mat-option [value]="option">{{option}}</mat-option>
}
</mat-autocomplete>
@if (policyControl.invalid && (policyControl.dirty || policyControl.touched)) {
@if (policyControl.hasError('required')) {
<small class="error">This field is required.</small>
}
}
</mat-form-field>

View File

@@ -0,0 +1,3 @@
.error {
color: #ba1a1a;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PolicyDropdownComponent } from './policy-dropdown.component';
describe('PolicyAddFormComponent', () => {
let component: PolicyDropdownComponent;
let fixture: ComponentFixture<PolicyDropdownComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PolicyDropdownComponent]
})
.compileComponents();
fixture = TestBed.createComponent(PolicyDropdownComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,72 @@
import { AsyncPipe } from '@angular/common';
import { Component, Input } from '@angular/core';
import { FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatInputModule } from '@angular/material/input';
import { map, Observable, startWith } from 'rxjs';
const Policies = [
{ path: "tts", description: "Anything to do with TTS" },
{ path: "tts.chat", description: "Anything to do with chat" },
{ path: "tts.chat.bits.read", description: "To read chat messages with bits via TTS" },
{ path: "tts.chat.messages.read", description: "To read chat messages via TTS" },
{ path: "tts.chat.redemptions.read", description: "To read channel point redemption messages via TTS" },
{ path: "tts.chat.subscriptions.read", description: "To read chat messages from subscriptions via TTS" },
{ path: "tts.commands", description: "To execute commands for TTS" },
{ path: "tts.commands.nightbot", description: "To use !nightbot command" },
{ path: "tts.commands.obs", description: "To use !obs command" },
{ path: "tts.commands.refresh", description: "To use !refresh command" },
{ path: "tts.commands.skip", description: "To use !skip command" },
{ path: "tts.commands.skipall", description: "To use !skipall command" },
{ path: "tts.commands.tts", description: "To use !tts command" },
{ path: "tts.commands.tts.join", description: "To use !tts join command" },
{ path: "tts.commands.tts.leave", description: "To use !tts leave command" },
{ path: "tts.commands.version", description: "To use !version command" },
{ path: "tts.commands.voice", description: "To use !voice command" },
{ path: "tts.commands.voice.admin", description: "To use !voice command on others" },
]
@Component({
selector: 'policy-dropdown',
imports: [
AsyncPipe,
FormsModule,
MatAutocompleteModule,
MatButtonModule,
MatInputModule,
ReactiveFormsModule,
],
templateUrl: './policy-dropdown.component.html',
styleUrl: './policy-dropdown.component.scss'
})
export class PolicyDropdownComponent {
@Input() policy: string | null = '';
policyControl = new FormControl('', [Validators.required]);
filteredPolicies: Observable<string[]>;
constructor() {
this.filteredPolicies = this.policyControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value || '')),
);
}
ngOnInit() {
this.policyControl.setValue(this.policy);
this.filteredPolicies = this.policyControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value || '')),
);
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
const names = Policies.map(p => p.path);
if (names.includes(filterValue)) {
return names;
}
return names.filter(option => option.toLowerCase().includes(filterValue));
}
}