cleanup file names

This commit is contained in:
Joel Wetzell
2026-04-04 08:33:25 -05:00
committed by Joel Wetzell
parent 98f1549237
commit 2b2f798f00
36 changed files with 65 additions and 65 deletions
+112
View File
@@ -0,0 +1,112 @@
import { CdkDrag, CdkDragDrop, CdkDropList, moveItemInArray } from '@angular/cdk/drag-drop';
import { Component, inject, Input, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { ParamInfo } from '../../models/form';
import { ListsService } from '../../services/lists';
import { SchemaService } from '../../services/schema';
import { parseStringToArray } from '../../utils/params';
@Component({
selector: 'app-array-form',
templateUrl: './array-form.html',
styleUrl: './array-form.css',
imports: [MatIconModule, FormsModule, CdkDrag, CdkDropList],
standalone: true,
})
export class ArrayFormComponent implements OnInit {
@Input() paramFormControl?: any;
@Input() paramInfo?: ParamInfo;
minItems: number = 0;
maxItems: number = Number.MAX_SAFE_INTEGER;
arrayValue: any[] | undefined;
private schemaService = inject(SchemaService);
public listsService = inject(ListsService);
constructor() {}
ngOnInit(): void {
if (this.paramFormControl && this.paramInfo?.schema) {
if (!Array.isArray(this.paramFormControl.value)) {
this.arrayValue = parseStringToArray(
this.paramFormControl.value,
this.paramInfo.schema,
);
} else {
this.arrayValue = this.paramFormControl.value;
}
if (this.paramInfo.schema.minItems) {
this.minItems = parseInt(this.paramInfo?.schema.minItems);
}
if (this.paramInfo.schema.maxItems) {
this.maxItems = parseInt(this.paramInfo?.schema.maxItems);
}
}
this.ensureArrayMin();
}
dropItem(event: CdkDragDrop<any | undefined>) {
if (this.arrayValue !== undefined) {
moveItemInArray(this.arrayValue, event.previousIndex, event.currentIndex);
this.valueUpdated();
}
}
deleteItem(index: number) {
this.arrayValue?.splice(index, 1);
this.valueUpdated();
}
ensureArrayMin() {
if (this.arrayValue === undefined) {
this.arrayValue = [];
}
if (this.arrayValue.length < this.minItems) {
for (let i = 0; i <= this.minItems - this.arrayValue.length; i += 1) {
this.arrayValue.push(null);
}
this.valueUpdated();
}
}
arrayIsMaxed() {
if (this.arrayValue) {
return this.arrayValue?.length >= this.maxItems;
}
return false;
}
addItem() {
if (this.arrayValue === undefined) {
this.arrayValue = [];
}
if (!this.arrayIsMaxed()) {
this.arrayValue.push(null);
}
this.valueUpdated();
// this.updated.emit(true);
}
valueUpdated() {
if (this.arrayValue) {
this.paramFormControl.setValue(
this.schemaService.cleanArray(this.arrayValue, this.paramInfo?.schema?.items),
);
}
}
// NOTE(jwetzel): this is only needed for object item types
updateItem(index: number, value: any) {
if (this.arrayValue) {
this.arrayValue[index] = value;
this.valueUpdated();
}
}
}