Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F9582633
structured-array.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
structured-array.ts
View Options
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import
{
Context
}
from
"koa"
;
import
{
Field
as
SealiousField
,
FieldTypes
as
SealiousFieldTypes
,
FieldsetInput
,
}
from
"sealious"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
import
{
Table
as
TableControl
}
from
"../controls/table.js"
;
import
{
sealiousToFormField
,
SealiousToFormField
,
}
from
"./get-field-for-sealious.js"
;
import
{
FormControl
,
FormControlContext
}
from
"../controls/form-control.js"
;
import
{
ExtractedFieldInfo
}
from
"../../utils/extract-fields-from-collection.js"
;
import
{
Table
}
from
"./table.js"
;
export
class
StructuredArray
<
SealiousFields
extends
Record
<
string
,
SealiousField
<
unknown
>>
,
>
extends
Table
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
{
public
sealious_field
:
SealiousFieldTypes
.
StructuredArray
<
SealiousFields
>
;
constructor
(
sealious_field
:
SealiousFieldTypes
.
StructuredArray
<
SealiousFields
>
)
{
const
columns
=
Object
.
fromEntries
(
Object
.
entries
(
sealious_field
.
subfields
).
map
(
([
key
,
sealious_field
])
=>
[
key
,
sealiousToFormField
(
sealious_field
),
]
)
)
as
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
};
super
(
columns
);
this
.
sealious_field
=
sealious_field
;
}
getControl
()
:
TableControl
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
{
return
new
TableControl
<
{
[
name
in
keyof
SealiousFields
]
:
SealiousToFormField
<
SealiousFields
[
name
]
>
;
}
>
(
this
as
any
,
{
label
:
this
.
name
,
subfield_controls
:
Object
.
fromEntries
(
Object
.
entries
(
this
.
columns
).
map
(([
column_name
,
subfield
])
=>
[
column_name
as
keyof
SealiousFields
,
subfield
.
getControl
(),
])
)
as
unknown
as
Record
<
keyof
SealiousFields
,
FormControl
>
,
allow_adding
:
true
,
make_new_row
:
()
=>
({})
as
any
,
});
}
generateFieldDeclaration
(
_field_info
:
ExtractedFieldInfo
,
vars
:
{
form_field_types
:
string
;
sealious_field
:
string
}
)
:
string
{
return
`new
${
vars
.
form_field_types
}
.
${
this
.
constructor
.
name
}
(
${
vars
.
sealious_field
}
)`
;
}
async
getSealiousCreateValue
(
fctx
:
FormControlContext
)
:
Promise
<
SealiousFieldTypes
.
ArrayStorageInput
<
FieldsetInput
<
SealiousFields
>>
>
{
const
{
parsed
}
=
await
this
.
getParsedValue
(
fctx
.
ctx
,
fctx
.
data
.
raw_values
);
return
(
(
parsed
as
SealiousFieldTypes
.
ArrayStorageInput
<
FieldsetInput
<
SealiousFields
>
>
)
||
this
.
getEmptyValue
()
);
}
async
sealiousValueToForm
(
ctx
:
Context
,
sealiousValue
:
Record
<
string
,
FormDataValue
|
null
>
[]
|
null
)
:
Promise
<
FormDataValue
>
{
return
Promise
.
all
(
(
sealiousValue
||
[]).
map
(
async
(
element
)
=>
Object
.
fromEntries
(
await
Promise
.
all
(
Object
.
entries
(
element
).
map
(
async
([
key
,
value
])
=>
{
const
form_subfield
=
this
.
columns
[
key
];
if
(
!
form_subfield
)
{
return
[
key
,
""
];
}
return
[
key
,
await
form_subfield
.
sealiousValueToForm
(
ctx
,
value
,
{}
as
any
),
];
})
)
)
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Oct 11, 07:21 (17 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
983963
Default Alt Text
structured-array.ts (3 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment