mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
remove subtype from list spec
This commit is contained in:
committed by
Aiden McClelland
parent
e4cd4d64d7
commit
bb50beb7ab
8
frontend/package-lock.json
generated
8
frontend/package-lock.json
generated
@@ -49,7 +49,7 @@
|
||||
"patch-db-client": "file: ../../../patch-db/client",
|
||||
"pbkdf2": "^3.1.2",
|
||||
"rxjs": "^7.5.6",
|
||||
"start-sdk": "^0.4.0-lib0.beta6",
|
||||
"start-sdk": "^0.4.0-lib0.beta9",
|
||||
"swiper": "^8.2.4",
|
||||
"ts-matches": "^5.2.1",
|
||||
"tslib": "^2.3.0",
|
||||
@@ -13771,9 +13771,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/start-sdk": {
|
||||
"version": "0.4.0-lib0.beta6",
|
||||
"resolved": "https://registry.npmjs.org/start-sdk/-/start-sdk-0.4.0-lib0.beta6.tgz",
|
||||
"integrity": "sha512-9dR2noD/rJ4u/Xuhs5S0+lv95nqpERWzxbXlpXDbtjXzMKzX8v1zmKKMNfTir1oxaZC820llLlaCeuPG2VGNpg==",
|
||||
"version": "0.4.0-lib0.beta9",
|
||||
"resolved": "https://registry.npmjs.org/start-sdk/-/start-sdk-0.4.0-lib0.beta9.tgz",
|
||||
"integrity": "sha512-gTpvFG9HARW1XlljA3It+L1NdNEp8OZrTJjc9vTJpgKn14U9HCYI/+XZC+UzGvP2AJpfR+1bBKSv2UAfElfw9A==",
|
||||
"dependencies": {
|
||||
"@iarna/toml": "^2.2.5",
|
||||
"lodash": "^4.17.21",
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
"patch-db-client": "file: ../../../patch-db/client",
|
||||
"pbkdf2": "^3.1.2",
|
||||
"rxjs": "^7.5.6",
|
||||
"start-sdk": "^0.4.0-lib0.beta6",
|
||||
"start-sdk": "^0.4.0-lib0.beta9",
|
||||
"swiper": "^8.2.4",
|
||||
"ts-matches": "^5.2.1",
|
||||
"tslib": "^2.3.0",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
[class.input_redacted]="
|
||||
spec.type === 'string' && control.value && spec.masked && !unmasked
|
||||
"
|
||||
[inputmode]="spec.type === 'number' ? 'tel' : 'text'"
|
||||
[inputmode]="spec.type === 'string' ? spec.inputmode : 'tel'"
|
||||
[placeholder]="spec.placeholder"
|
||||
[formControl]="control"
|
||||
(ionFocus)="warning.onChange(name, spec)"
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
"
|
||||
>
|
||||
<!-- object -->
|
||||
<ng-container *ngIf="spec.subtype === 'object'">
|
||||
<ng-container *ngIf="spec.spec.type === 'object'">
|
||||
<!-- object label -->
|
||||
<ion-item
|
||||
button
|
||||
@@ -130,7 +130,7 @@
|
||||
[id]="objectId | toElementId : entry.key : i"
|
||||
>
|
||||
<form-object
|
||||
*ngIf="spec.subtype === 'object'"
|
||||
*ngIf="spec.spec.type === 'object'"
|
||||
[objectSpec]="$any(spec.spec).spec"
|
||||
[formGroup]="abstractControl"
|
||||
[current]="current?.[entry.key]?.[i]"
|
||||
@@ -153,7 +153,9 @@
|
||||
</ng-container>
|
||||
<!-- string or number -->
|
||||
<div
|
||||
*ngIf="spec.subtype === 'string' || spec.subtype === 'number'"
|
||||
*ngIf="
|
||||
spec.spec.type === 'string' || spec.spec.type === 'number'
|
||||
"
|
||||
[id]="objectId | toElementId : entry.key : i"
|
||||
>
|
||||
<ion-item
|
||||
@@ -161,7 +163,9 @@
|
||||
>
|
||||
<ion-input
|
||||
type="text"
|
||||
[inputmode]="spec.subtype === 'number' ? 'tel' : 'text'"
|
||||
[inputmode]="
|
||||
spec.spec.type === 'string' ? spec.spec.inputmode : 'tel'
|
||||
"
|
||||
[placeholder]="
|
||||
$any(spec.spec).placeholder || 'Enter ' + spec.name
|
||||
"
|
||||
|
||||
@@ -82,7 +82,7 @@ export class FormObjectComponent {
|
||||
Object.keys(this.objectSpec).forEach(key => {
|
||||
const spec = this.objectSpec[key]
|
||||
|
||||
if (spec.type === 'list' && ['object', 'union'].includes(spec.subtype)) {
|
||||
if (spec.type === 'list' && spec.spec.type === 'object') {
|
||||
this.objectListDisplay[key] = []
|
||||
this.formGroup.get(key)?.value.forEach((obj: any, index: number) => {
|
||||
const displayAs = (spec.spec as ListValueSpecOf<'object'>).displayAs
|
||||
@@ -209,8 +209,8 @@ export class FormObjectComponent {
|
||||
const index = arr.length
|
||||
arr.insert(index, newItem)
|
||||
|
||||
if (['object', 'union'].includes(listSpec.subtype)) {
|
||||
const displayAs = (listSpec.spec as ListValueSpecOf<'object'>).displayAs
|
||||
if (listSpec.spec.type === 'object') {
|
||||
const displayAs = listSpec.spec.displayAs
|
||||
this.objectListDisplay[key].push({
|
||||
expanded: false,
|
||||
displayAs: displayAs ? Mustache.render(displayAs, newItem.value) : '',
|
||||
@@ -223,7 +223,7 @@ export class FormObjectComponent {
|
||||
)
|
||||
element?.parentElement?.scrollIntoView({ behavior: 'smooth' })
|
||||
|
||||
if (['object', 'union'].includes(listSpec.subtype)) {
|
||||
if (listSpec.spec.type === 'object') {
|
||||
pauseFor(250).then(() => this.toggleExpandListObject(key, index))
|
||||
}
|
||||
}, 100)
|
||||
|
||||
@@ -235,7 +235,6 @@ const SAMPLE_CONFIG: InputSpec = {
|
||||
'sample-number': {
|
||||
type: 'number',
|
||||
name: 'Example Number Input',
|
||||
inputmode: 'decimal',
|
||||
required: true,
|
||||
range: '[5,1000000]',
|
||||
integral: true,
|
||||
|
||||
@@ -746,7 +746,6 @@ export module Mock {
|
||||
},
|
||||
'p2p-port': {
|
||||
type: 'number',
|
||||
inputmode: 'numeric',
|
||||
name: 'P2P Port',
|
||||
description:
|
||||
'The port that your Bitcoin Core P2P server is bound to',
|
||||
@@ -866,7 +865,6 @@ export module Mock {
|
||||
'object-list': {
|
||||
name: 'Object List',
|
||||
type: 'list',
|
||||
subtype: 'object',
|
||||
description: 'This is a list of objects, like users or something',
|
||||
warning: null,
|
||||
range: '[0,4]',
|
||||
@@ -885,6 +883,7 @@ export module Mock {
|
||||
// the outer spec here, at the list level, says that what's inside (the inner spec) pertains to its inner elements.
|
||||
// it just so happens that ValueSpecObject's have the field { spec: InputSpec }
|
||||
spec: {
|
||||
type: 'object',
|
||||
uniqueBy: 'last-name',
|
||||
displayAs: `I'm {{last-name}}, {{first-name}} {{last-name}}`,
|
||||
spec: {
|
||||
@@ -919,7 +918,6 @@ export module Mock {
|
||||
},
|
||||
age: {
|
||||
name: 'Age',
|
||||
inputmode: 'numeric',
|
||||
type: 'number',
|
||||
description: 'The age of the user',
|
||||
required: false,
|
||||
@@ -963,7 +961,6 @@ export module Mock {
|
||||
},
|
||||
'favorite-number': {
|
||||
name: 'Favorite Number',
|
||||
inputmode: 'decimal',
|
||||
type: 'number',
|
||||
integral: false,
|
||||
description: 'Your favorite number of all time',
|
||||
@@ -978,11 +975,10 @@ export module Mock {
|
||||
'unlucky-numbers': {
|
||||
name: 'Unlucky Numbers',
|
||||
type: 'list',
|
||||
subtype: 'number',
|
||||
description: 'Numbers that you like but are not your top favorite.',
|
||||
warning: null,
|
||||
spec: {
|
||||
inputmode: 'decimal',
|
||||
type: 'number',
|
||||
integral: false,
|
||||
range: '[-100,200)',
|
||||
units: null,
|
||||
@@ -1034,12 +1030,12 @@ export module Mock {
|
||||
rulemakers: {
|
||||
name: 'Rule Makers',
|
||||
type: 'list',
|
||||
subtype: 'object',
|
||||
description: 'the people who make the rules',
|
||||
warning: null,
|
||||
range: '[0,2]',
|
||||
default: [],
|
||||
spec: {
|
||||
type: 'object',
|
||||
uniqueBy: null,
|
||||
displayAs: null,
|
||||
spec: {
|
||||
@@ -1185,7 +1181,6 @@ export module Mock {
|
||||
},
|
||||
port: {
|
||||
name: 'Port',
|
||||
inputmode: 'numeric',
|
||||
type: 'number',
|
||||
integral: true,
|
||||
description:
|
||||
@@ -1214,7 +1209,6 @@ export module Mock {
|
||||
rpcallowip: {
|
||||
name: 'RPC Allowed IPs',
|
||||
type: 'list',
|
||||
subtype: 'string',
|
||||
description:
|
||||
'external ip addresses that are authorized to access your Bitcoin node',
|
||||
warning:
|
||||
@@ -1222,6 +1216,7 @@ export module Mock {
|
||||
range: '[1,10]',
|
||||
default: ['192.168.1.1'],
|
||||
spec: {
|
||||
type: 'string',
|
||||
inputmode: 'text',
|
||||
masked: false,
|
||||
placeholder: null,
|
||||
@@ -1233,12 +1228,12 @@ export module Mock {
|
||||
rpcauth: {
|
||||
name: 'RPC Auth',
|
||||
type: 'list',
|
||||
subtype: 'string',
|
||||
description: 'api keys that are authorized to access your Bitcoin node.',
|
||||
warning: null,
|
||||
range: '[0,*)',
|
||||
default: [],
|
||||
spec: {
|
||||
type: 'string',
|
||||
inputmode: 'text',
|
||||
masked: false,
|
||||
placeholder: null,
|
||||
@@ -1307,12 +1302,12 @@ export module Mock {
|
||||
law3: {
|
||||
name: 'Third Law',
|
||||
type: 'list',
|
||||
subtype: 'object',
|
||||
description: 'the third law',
|
||||
warning: null,
|
||||
range: '[0,2]',
|
||||
default: [],
|
||||
spec: {
|
||||
type: 'object',
|
||||
uniqueBy: null,
|
||||
displayAs: null,
|
||||
spec: {
|
||||
@@ -1368,12 +1363,12 @@ export module Mock {
|
||||
rulemakers: {
|
||||
name: 'Rule Makers',
|
||||
type: 'list',
|
||||
subtype: 'object',
|
||||
description: 'the people who make the rules',
|
||||
warning: null,
|
||||
range: '[0,2]',
|
||||
default: [],
|
||||
spec: {
|
||||
type: 'object',
|
||||
uniqueBy: null,
|
||||
displayAs: null,
|
||||
spec: {
|
||||
|
||||
@@ -337,13 +337,12 @@ export function listUnique(spec: ValueSpecList): ValidatorFn {
|
||||
|
||||
function listItemEquals(spec: ValueSpecList, val1: any, val2: any): boolean {
|
||||
// TODO: fix types
|
||||
switch (spec.subtype) {
|
||||
switch (spec.spec.type) {
|
||||
case 'string':
|
||||
case 'number':
|
||||
return val1 == val2
|
||||
case 'object':
|
||||
const obj: ListValueSpecObject = spec.spec as any
|
||||
|
||||
const obj = spec.spec
|
||||
return listObjEquals(obj.uniqueBy, obj, val1, val2)
|
||||
default:
|
||||
return false
|
||||
@@ -553,15 +552,15 @@ export function convertValuesRecursive(
|
||||
const formArr = group.get(key) as UntypedFormArray
|
||||
const { controls } = formArr
|
||||
|
||||
if (valueSpec.subtype === 'number') {
|
||||
if (valueSpec.spec.type === 'number') {
|
||||
controls.forEach(control => {
|
||||
control.setValue(control.value ? Number(control.value) : null)
|
||||
})
|
||||
} else if (valueSpec.subtype === 'string') {
|
||||
} else if (valueSpec.spec.type === 'string') {
|
||||
controls.forEach(control => {
|
||||
if (!control.value) control.setValue(null)
|
||||
})
|
||||
} else if (valueSpec.subtype === 'object') {
|
||||
} else if (valueSpec.spec.type === 'object') {
|
||||
controls.forEach(formGroup => {
|
||||
const objectSpec = valueSpec.spec as ListValueSpecObject
|
||||
convertValuesRecursive(objectSpec.spec, formGroup as UntypedFormGroup)
|
||||
|
||||
Reference in New Issue
Block a user