Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995297
index.page.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
index.page.ts
View Options
import
{
CRUD
}
from
"@sealcode/crud-ui"
;
import
type
{
Context
}
from
"koa"
;
import
type
{
CollectionItem
}
from
"sealious"
;
import
type
{
ListFilterRender
}
from
"@sealcode/sealgen"
;
import
{
Controls
,
DefaultListFilters
,
Fields
}
from
"@sealcode/sealgen"
;
import
{
Rules
}
from
"src/back/collections/collections.js"
;
import
html
from
"src/back/html.js"
;
import
{
getProxy
}
from
"src/back/proxy.js"
;
export
const
actionName
=
"RulesCRUD"
;
const
edit_fields
=
<
const
>
{
name
:
new
Fields
.
CollectionField
(
Rules
.
fields
.
name
.
required
,
Rules
.
fields
.
name
),
code
:
new
Fields
.
CollectionField
(
Rules
.
fields
.
code
.
required
,
Rules
.
fields
.
code
),
active
:
new
Fields
.
Boolean
(
Rules
.
fields
.
active
.
required
),
};
const
edit_controls
=
[
new
Controls
.
SimpleInput
(
edit_fields
.
name
,
{
label
:
"name"
}),
new
Controls
.
Checkbox
(
edit_fields
.
active
,
{
label
:
"active"
}),
new
Controls
.
Textarea
(
edit_fields
.
code
,
{
label
:
"code"
,
cols
:
80
,
rows
:
15
,
autogrow
:
true
,
placeholder
:
``
,
}),
new
Controls
.
HTML
(
"decoration"
,
/* HTML */
`<div>
Examples:
<h3>Change contents of all paragraphs to "p"</h3>
<pre><code>
rewriter.on("p", {
element(element) {
element.setInnerContent("new");
},
});
</code></pre>
<h3>Add an attribute to all links within a div with a class 'footer'</h3>
<pre><code>
rewriter.on(".footer a", {
element(element) {
element.setAttribute("rel", "nofollow")
},
});
</code></pre>
</div>`
),
];
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const
fields_for_display
=
[
{
field
:
"name"
,
label
:
"name"
},
{
field
:
"code"
,
label
:
"code"
},
{
field
:
"active"
,
label
:
"active"
,
format
:
(
v
:
boolean
)
=>
(
v
?
"YES"
:
"NO"
),
},
]
as
{
field
:
keyof
(
typeof
Rules
)[
"fields"
];
label
:
string
;
format
?:
(
value
:
unknown
,
item
:
CollectionItem
<
typeof
Rules
>
)
=>
string
|
Promise
<
string
>
;
}[];
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const
fields_for_filters
=
[
{
field
:
"name"
,
...
DefaultListFilters
[
"text"
]
},
{
field
:
"code"
,
...
DefaultListFilters
[
"text"
]
},
{
field
:
"active"
,
...
DefaultListFilters
[
"boolean"
]
},
]
as
{
field
:
keyof
(
typeof
Rules
)[
"fields"
];
render
?:
ListFilterRender
;
prepareValue
?:
(
filter_value
:
unknown
)
=>
unknown
;
// set this function to change what filter value is passed to Sealious
}[];
async
function
restart_proxy
(
ctx
:
Context
)
{
console
.
log
(
"RESTARTING PROXY"
);
const
proxy
=
getProxy
(
ctx
.
$app
);
await
proxy
.
stop
();
await
proxy
.
start
();
}
export
default
new
CRUD
({
collection
:
Rules
,
nice_collection_name
:
"Rules"
,
fields_for_display
,
fields_for_filters
,
html
,
list_title
:
"Rules list"
,
edit_title
:
"Edit"
,
edit_button_text
:
"Edit"
,
delete_button_text
:
"Delete"
,
back_to_list_button_text
:
"← Back to Rules list"
,
edit_fields
,
edit_controls
,
form_value_to_sealious_value
:
{},
sealious_value_to_form_value
:
{},
post_edit
:
restart_proxy
,
post_create
:
restart_proxy
,
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Dec 23, 00:57 (4 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556677
Default Alt Text
index.page.ts (2 KB)
Attached To
Mode
rREWRITE Configurable rewriter
Attached
Detach File
Event Timeline
Log In to Comment