mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
chore: accommodate new changes to the specs (#2254)
* chore: accommodate new changes to the specs * chore: fix error * chore: fix error
This commit is contained in:
committed by
Aiden McClelland
parent
6fed6c8d30
commit
833c1f22a3
@@ -4,7 +4,15 @@
|
|||||||
*ngIf="spec.description"
|
*ngIf="spec.description"
|
||||||
[content]="spec.description"
|
[content]="spec.description"
|
||||||
></tui-tooltip>
|
></tui-tooltip>
|
||||||
<button tuiLink type="button" class="add" (click)="add()">+ Add</button>
|
<button
|
||||||
|
tuiLink
|
||||||
|
type="button"
|
||||||
|
class="add"
|
||||||
|
[disabled]="!canAdd"
|
||||||
|
(click)="add()"
|
||||||
|
>
|
||||||
|
+ Add
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<tui-error [error]="order | tuiFieldError | async"></tui-error>
|
<tui-error [error]="order | tuiFieldError | async"></tui-error>
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ export class FormArrayComponent {
|
|||||||
private readonly dialogs = inject(TuiDialogService)
|
private readonly dialogs = inject(TuiDialogService)
|
||||||
private readonly destroy$ = inject(TuiDestroyService)
|
private readonly destroy$ = inject(TuiDestroyService)
|
||||||
|
|
||||||
|
get canAdd(): boolean {
|
||||||
|
return (
|
||||||
|
!this.spec.maxLength ||
|
||||||
|
this.spec.maxLength >= this.array.control.controls.length
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
if (!this.warned && this.spec.warning) {
|
if (!this.warned && this.spec.warning) {
|
||||||
this.dialogs
|
this.dialogs
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<ng-container [ngSwitch]="spec.type">
|
<ng-container [ngSwitch]="spec.type">
|
||||||
<form-text *ngSwitchCase="'text'"></form-text>
|
<form-text *ngSwitchCase="'text'"></form-text>
|
||||||
<form-number *ngSwitchCase="'number'"></form-number>
|
<form-number *ngSwitchCase="'number'"></form-number>
|
||||||
<form-text *ngSwitchCase="'textarea'"></form-text>
|
<form-textarea *ngSwitchCase="'textarea'"></form-textarea>
|
||||||
<form-toggle *ngSwitchCase="'toggle'"></form-toggle>
|
<form-toggle *ngSwitchCase="'toggle'"></form-toggle>
|
||||||
<form-select *ngSwitchCase="'select'"></form-select>
|
<form-select *ngSwitchCase="'select'"></form-select>
|
||||||
<form-multiselect *ngSwitchCase="'multiselect'"></form-multiselect>
|
<form-multiselect *ngSwitchCase="'multiselect'"></form-multiselect>
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import {
|
|||||||
TemplateRef,
|
TemplateRef,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
} from '@angular/core'
|
} from '@angular/core'
|
||||||
import { AbstractTuiNullableControl } from '@taiga-ui/cdk'
|
import {
|
||||||
|
AbstractTuiNullableControl,
|
||||||
|
TuiContextWithImplicit,
|
||||||
|
} from '@taiga-ui/cdk'
|
||||||
import {
|
import {
|
||||||
TuiAlertService,
|
TuiAlertService,
|
||||||
TuiDialogContext,
|
TuiDialogContext,
|
||||||
@@ -17,6 +20,11 @@ import { filter, takeUntil } from 'rxjs'
|
|||||||
import { ValueSpec, ValueSpecText } from 'start-sdk/lib/config/configTypes'
|
import { ValueSpec, ValueSpecText } from 'start-sdk/lib/config/configTypes'
|
||||||
import { ERRORS } from '../form-group/form-group.component'
|
import { ERRORS } from '../form-group/form-group.component'
|
||||||
|
|
||||||
|
interface ValidatorsPatternError {
|
||||||
|
actualValue: string
|
||||||
|
requiredPattern: string | RegExp
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'form-control',
|
selector: 'form-control',
|
||||||
templateUrl: './form-control.component.html',
|
templateUrl: './form-control.component.html',
|
||||||
@@ -28,7 +36,10 @@ import { ERRORS } from '../form-group/form-group.component'
|
|||||||
deps: [FormControlComponent],
|
deps: [FormControlComponent],
|
||||||
useFactory: (control: FormControlComponent<ValueSpecText, string>) => ({
|
useFactory: (control: FormControlComponent<ValueSpecText, string>) => ({
|
||||||
required: 'Required',
|
required: 'Required',
|
||||||
patterns: () => control.spec.patterns.map(p => p.regex), // @TODO Alex
|
pattern: ({ requiredPattern }: ValidatorsPatternError) =>
|
||||||
|
control.spec.patterns.find(
|
||||||
|
({ regex }) => String(regex) === String(requiredPattern),
|
||||||
|
)?.description || 'Invalid pattern',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
<tui-multi-select
|
<tui-multi-select
|
||||||
[tuiHintContent]="spec.description"
|
[tuiHintContent]="spec.description"
|
||||||
[editable]="false"
|
[editable]="false"
|
||||||
|
[disabledItemHandler]="disabledItemHandler"
|
||||||
[(ngModel)]="selected"
|
[(ngModel)]="selected"
|
||||||
(focusedChange)="onFocus($event)"
|
(focusedChange)="onFocus($event)"
|
||||||
>
|
>
|
||||||
{{ spec.name }}
|
{{ spec.name }}
|
||||||
<select tuiSelect multiple [items]="items"></select>
|
<select
|
||||||
|
tuiSelect
|
||||||
|
multiple
|
||||||
|
[items]="items"
|
||||||
|
[disabledItemHandler]="disabledItemHandler"
|
||||||
|
></select>
|
||||||
</tui-multi-select>
|
</tui-multi-select>
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ export class FormMultiselectComponent extends Control<
|
|||||||
> {
|
> {
|
||||||
readonly items = Object.values(this.spec.values)
|
readonly items = Object.values(this.spec.values)
|
||||||
|
|
||||||
|
readonly disabledItemHandler = (item: string): boolean =>
|
||||||
|
!!this.spec.maxLength &&
|
||||||
|
this.selected.length >= this.spec.maxLength &&
|
||||||
|
!this.selected.includes(item)
|
||||||
|
|
||||||
get selected(): string[] {
|
get selected(): string[] {
|
||||||
return this.memoize(this.value)
|
return this.memoize(this.value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<!-- @TODO Alex look at "attr.step", is this correct? -->
|
<!-- @TODO Implement InputNumber step once it is added in Taiga UI -->
|
||||||
<tui-input-number
|
<tui-input-number
|
||||||
[tuiHintContent]="spec.description"
|
[tuiHintContent]="spec.description"
|
||||||
[tuiTextfieldPostfix]="spec.units || ''"
|
[tuiTextfieldPostfix]="spec.units || ''"
|
||||||
[precision]="Infinity"
|
[precision]="Infinity"
|
||||||
[decimal]="spec.integer ? 'never' : 'not-zero'"
|
[decimal]="spec.integer ? 'never' : 'not-zero'"
|
||||||
[min]="min"
|
[min]="spec.min ?? -Infinity"
|
||||||
[max]="max"
|
[max]="spec.max ?? Infinity"
|
||||||
[attr.step]="spec.step"
|
|
||||||
[(ngModel)]="value"
|
[(ngModel)]="value"
|
||||||
(focusedChange)="onFocus($event)"
|
(focusedChange)="onFocus($event)"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -8,14 +8,4 @@ import { Control } from '../control'
|
|||||||
})
|
})
|
||||||
export class FormNumberComponent extends Control<ValueSpecNumber, number> {
|
export class FormNumberComponent extends Control<ValueSpecNumber, number> {
|
||||||
protected readonly Infinity = Infinity
|
protected readonly Infinity = Infinity
|
||||||
|
|
||||||
get min(): number {
|
|
||||||
if (typeof this.spec.min !== 'number') return -Infinity
|
|
||||||
return this.spec.min
|
|
||||||
}
|
|
||||||
|
|
||||||
get max(): number {
|
|
||||||
if (typeof this.spec.max !== 'number') return Infinity
|
|
||||||
return this.spec.max
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
tuiTextfield
|
tuiTextfield
|
||||||
[class.masked]="spec.masked && masked"
|
[class.masked]="spec.masked && masked"
|
||||||
[placeholder]="spec.placeholder || ''"
|
[placeholder]="spec.placeholder || ''"
|
||||||
[minLength]="spec.minLength"
|
[attr.minLength]="spec.minLength"
|
||||||
[maxLength]="spec.maxLength"
|
[attr.maxLength]="spec.maxLength"
|
||||||
[attr.inputmode]="spec.inputmode"
|
[attr.inputmode]="spec.inputmode"
|
||||||
/>
|
/>
|
||||||
</tui-input>
|
</tui-input>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
[tuiHintContent]="spec.description"
|
[tuiHintContent]="spec.description"
|
||||||
[expandable]="true"
|
[expandable]="true"
|
||||||
[rows]="6"
|
[rows]="6"
|
||||||
|
[maxLength]="spec.maxLength"
|
||||||
[(ngModel)]="value"
|
[(ngModel)]="value"
|
||||||
(focusedChange)="onFocus($event)"
|
(focusedChange)="onFocus($event)"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user