提交 2b7c9491 编写于 作者: Z zhoushimin
demo-widget @ 2489060e
Subproject commit 2489060e09630dff334e88b8e51e1efa1bfa1989
time="2022-11-02T16:37:36+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
time="2022-11-02T16:37:36+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
time="2022-11-02T16:37:36+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
time="2022-11-02T16:38:14+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
time="2022-11-02T16:40:07+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
time="2022-11-02T16:41:13+08:00" level=warning msg="Can't load env file. open /home/zhoushimin/workspace/github/1024opensource/demo-widget/$(pwd)/.env: no such file or directory"
.env
logs/application.log
data/.session.db
db/yao.db
.DS_Store
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# YAO Widget DEMO
![Image](docs/images/intro.png)
[中文介绍](README.zh-CN.md)
YAO Widget DEMO
Documentation: [https://yaoapps.com/en-US/doc](https://yaoapps.com/en-US/doc/Introduction/Getting%20Started)
## USAGE
### Docker
```bash
docker run -d -p 5099:5099 --restart unless-stopped \
-e YAO_INIT=reset \
-e YAO_PROCESS_RESET=flows.setmenu \
yaoapp/demo-widget:1.0.0-amd64
```
### Yao
#### Download source code
```bash
git clone https://github.com/YaoApp/demo-widget /app/path/widget
```
#### Set the environment variables
```bash
mkdir /app/path/widget/db
mkdir /app/path/widget/data
mkdir /app/path/widget/logs
cat << EOF
YAO_ENV=development # development | production
YAO_ROOT="/app/path/widget"
YAO_HOST="0.0.0.0"
YAO_PORT="5099"
YAO_SESSION="memory"
YAO_LOG="/app/path/widget/logs/application.log"
YAO_LOG_MODE="TEXT" # TEXT | JSON
YAO_JWT_SECRET="bLp@bi!oqo-2U+hoTRUG"
YAO_DB_DRIVER=sqlite3 # sqlite3 | mysql
YAO_DB_PRIMARY="/app/path/widget/db/yao.db"
EOF > /app/path/widget/.env
```
#### Initialization
```bash
cd /app/path/widget
# Create tables & set menu
yao migrate --reset
yao run flows.setmenu
```
#### Start the service
```bash
cd /app/path/widget
yao start
```
## ADMIN
Open the browser to visit the URL:
http://127.0.0.1:5099/xiang/login/admin
User Name: `xiang@iqka.com`
Password: `A123456p+`
# YAO Widget DEMO
![Image](docs/images/intro.png)
[English](README.md)
云表格 DEMO
参考文档: [https://yaoapps.com/doc](https://yaoapps.com/doc/%E6%95%99%E7%A8%8B/%E4%BD%BF%E7%94%A8%20YAO%20Widget%20%E8%87%AA%E5%BB%BA%E4%BA%91%E8%A1%A8%E6%A0%BC)
## 下载安装
### 使用 Docker 运行
```bash
docker run -d -p 5099:5099 --restart unless-stopped \
-e YAO_INIT=demo \
-e YAO_PROCESS_RESET=flows.init.menu \
-e YAO_PROCESS_DEMO=flows.demo.data \
yaoapp/demo-widget:1.0.3-amd64
```
### 在本地运行
#### 下载源码
```bash
git clone https://github.com/YaoApp/demo-widget /app/path/widget
```
#### 设置环境变量
```bash
mkdir /app/path/widget/db
mkdir /app/path/widget/data
mkdir /app/path/widget/logs
cat << EOF
YAO_ENV=development # development | production
YAO_ROOT="/app/path/widget"
YAO_HOST="0.0.0.0"
YAO_PORT="5099"
YAO_SESSION="memory"
YAO_LOG="/app/path/widget/logs/application.log"
YAO_LOG_MODE="TEXT" # TEXT | JSON
YAO_JWT_SECRET="bLp@bi!oqo-2U+hoTRUG"
YAO_DB_DRIVER=sqlite3 # sqlite3 | mysql
YAO_DB_PRIMARY="/app/path/widget/db/yao.db"
EOF > /app/path/widget/.env
```
#### 项目初始化
```bash
cd /app/path/widget
# 创建数据表 & 设置菜单
yao migrate --reset
yao run flows.setmenu
```
#### 启动服务
```bash
cd /app/path/widget
yao start
```
## 管理后台
打开浏览器输入以下网址进入:
http://127.0.0.1:5099/xiang/login/admin
用户名: `xiang@iqka.com`
密码: `A123456p+`
{
"name": "选项接口",
"version": "1.0.0",
"description": "选项接口",
"group": "page",
"guard": "-",
"paths": [
{
"path": "/form/setting/:name",
"method": "GET",
"guard": "-",
"process": "xiang.table.Setting",
"in": ["$param.name", ":query"],
"out": { "status": 200, "type": "application/json" }
}
]
}
{
"name": "Widget Demo",
"short": "Widget",
"description": "Widget demo app",
"option": {
"nav_user": "xiang.user",
"nav_menu": "xiang.menu",
"hide_user": false,
"hide_menu": false,
"login": { "entry": { "admin": "/table/template" } }
}
}
{
"name": "TEST",
"decription": "A TEST DYFORM",
"columns": [
{
"title": "First Name",
"name": "name",
"type": "input",
"search": true,
"props": {
"placeholder": "Please input your first name"
}
},
{
"title": "Amount",
"name": "amount",
"type": "input",
"search": true,
"props": {
"placeholder": "Please input amount"
}
},
{
"title": "Description",
"name": "desc",
"type": "textArea",
"props": {
"placeholder": "Please input Description"
}
}
]
}
{
"label": "System Menu",
"version": "1.0.0",
"description": "Initialize system menu",
"nodes": [
{
"name": "Clean menu data",
"engine": "xiang",
"query": {
"sql": { "stmt": "delete from xiang_menu" }
}
},
{
"name": "Add new menu",
"process": "models.xiang.menu.Insert",
"args": [
[
"id",
"name",
"path",
"icon",
"rank",
"status",
"parent",
"visible_menu",
"blocks"
],
[
[
1,
"Template",
"/table/template",
"icon-grid",
1,
"enabled",
null,
0,
0
],
[
2,
"Tables",
"/table/dyform.demo",
"icon-database",
1,
"enabled",
null,
1,
0
],
[3, "Demo", "/table/dyform.demo", null, 1, "enabled", 2, 1, 0]
]
]
}
],
"output": "done"
}
{
"Keywords": {
"__comment": "{ '@': 'f.Keywords', 'in': ['where.name.match']}",
"label": "Keywords",
"bind": "{{$in.0}}",
"input": {
"type": "input",
"props": {
"placeholder": "type Keywords..."
}
}
}
}
\ No newline at end of file
{
"name": "Template",
"table": { "name": "template", "comment": "For dyform DSL source" },
"columns": [
{ "label": "ID", "name": "id", "type": "ID", "comment": "ID" },
{
"label": "INSTANCE",
"name": "instance",
"type": "string",
"unique": true
},
{
"label": "SN",
"name": "sn",
"type": "string",
"nullable": true,
"unique": true
},
{ "label": "Name", "name": "name", "type": "string", "index": true },
{
"label": "DSL",
"name": "dsl",
"type": "text",
"comment": "DSL"
}
],
"values": [],
"option": { "timestamps": true, "soft_deletes": true }
}
/**
* AfterSave Hook: upgrade the instance shcema
*/
function AfterSave(id, payload) {
payload = payload || {};
if (!payload.dsl) {
return id;
}
var dsl = {};
try {
dsl = JSON.parse(payload.dsl);
} catch (e) {
log.Error("After Save: %s", e.message);
return id;
}
// Save schema
const instance = `instance_${id}`;
var res = Process("widgets.dyform.Save", instance, dsl);
if (!res) {
log.Error("After Save: upgrade schema error");
return id;
}
// Add Menu items
setMenu(instance, dsl.name ? dsl.name : instance);
return id;
}
/**
* AfterDelete Hook: remove the instance shcema
*/
function AfterDelete(params, id) {
// Remove schema
const instance = `instance_${id}`;
Process("widgets.dyform.Delete", instance);
removeMenu(instance);
return id;
}
/**
* AfterFind Hook: transform the DSL format to the form editor needs
* @param {*} id
* @param {*} template
*/
function AfterFind(template, id) {
let dsl = JSON.parse(template["dsl"]);
let columns = dsl.columns || [];
let types = { input: "Input", select: "Select" };
template["dsl"] = [];
columns.forEach((column) => {
// let props = column.props || {};
// let search = props.showSearch ? true : false;
template["dsl"].push({
title: column.title,
bind: column.name,
id: types[column.type],
props: column.props || {},
search: true,
width: 6,
chosen: false,
selected: false,
});
});
return template;
}
/**
* BeforSave Hook: transform the form editor data to the DSL
* @param {*} payload
*/
function BeforeSave(payload) {
payload = payload || {};
columns = payload.dsl || [];
payload["dsl"] = { columns: [], name: payload.name || "UNTITLE" };
columns.forEach((column) => {
let type = column.id || "";
payload["dsl"].columns.push({
title: column.title || "UNTITLE",
name: column.bind,
type: type.toLowerCase(),
props: column.props || {},
});
});
payload["dsl"] = JSON.stringify(payload["dsl"]);
return [payload];
}
/**
* Remove menu item
* @debug
* yao run scripts.template.removeMenu instance_1
*
* @param {*} instance
*/
function removeMenu(instance) {
const path = `/table/dyform.${instance}`;
Process("models.xiang.menu.DestroyWhere", {
wheres: [{ column: "path", value: path }],
});
}
/**
* Set Menu
*
* @debug
* yao run scripts.template.setMenu instance_1 Foo
*
* @param {*} instance
* @param {*} title
* @returns
*/
function setMenu(instance, title) {
var parentItem = new Query().Get({
select: ["id"],
from: "xiang_menu",
wheres: [{ ":name": "名称", "=": "Tables" }],
limit: 1,
});
var parent_id = parentItem.length > 0 ? parentItem[0].id : null;
if (parent_id == null) {
return;
}
const path = `/table/dyform.${instance}`;
var menu = {
name: title,
parent: parent_id,
path: path,
rank: 1,
status: "enabled",
visible_menu: 1,
blocks: 0,
};
var items = Process("models.xiang.menu.Get", {
select: ["id"],
wheres: [{ column: "path", value: path }],
limit: 1,
});
if (items.code && items.message) {
log.Error("After Save: save menu %s", items.message);
return id;
}
if (items.length > 0) {
menu["id"] = items[0].id;
}
Process("models.xiang.menu.Save", menu);
}
{
"name": "Template",
"version": "1.0.0",
"decription": "Form Templates",
"bind": { "model": "template" },
"apis": {},
"hooks": {
"after:find": "scripts.template.AfterFind",
"before:save": "scripts.template.BeforeSave",
"after:save": "scripts.template.AfterSave",
"after:delete": "scripts.template.AfterDelete"
},
"columns": {
"ID": {
"label": "ID",
"view": { "type": "label", "props": { "value": ":id" } }
},
"Form Name": {
"label": "Form Name",
"view": { "type": "label", "props": { "value": ":name" } },
"edit": { "type": "input", "props": { "value": ":name" } }
},
"Form Editor": {
"label": "Form Editor",
"edit": { "type": "FormPrinter", "props": { "value": ":dsl" } }
}
},
"filters": { "Keywords": { "@": "f.Keywords", "in": ["where.name.match"] } },
"list": {
"primary": "id",
"layout": {
"columns": [
{ "name": "ID", "width": 80 },
{ "name": "Name", "width": 200 }
],
"filters": [{ "name": "Keywords" }]
},
"actions": {
"pagination": { "props": { "showTotal": true } },
"create": {
"props": { "label": "Create" }
}
},
"option": { "operation": { "unfold": true } }
},
"edit": {
"primary": "id",
"layout": {
"fieldset": [
{
"columns": [
{ "name": "Form Name", "width": 24 },
{ "name": "Form Editor", "width": 24 }
]
}
]
},
"actions": {
"cancel": {},
"save": {},
"delete": { "type": "button", "props": { "label": "Delete" } }
},
"option": { "dev": false }
}
}
{
"columns": [
{
"title": "First Name",
"name": "name",
"type": "input",
"search": true,
"props": {
"placeholder": "Please input your first name"
}
},
{
"title": "Amount",
"name": "amount",
"type": "input",
"search": true,
"props": {
"placeholder": "Please input amount"
}
},
{
"title": "Description",
"name": "desc",
"type": "textArea",
"props": {
"placeholder": "Please input Description"
}
}
]
}
It works! <a href="https://yaoapps.com">https://yaoapps.com</a>
\ No newline at end of file
此差异已折叠。
.c-input[data-v-53e2c381]{width:300px;height:32px}.header[data-v-8b7cdf89]{font-size:1.1rem;margin-bottom:.5em}.failure[data-v-8b7cdf89]{color:red}.form-item[data-v-8b7cdf89]{display:flex;width:400px;justify-content:space-between;margin-bottom:15px}.form-item .label[data-v-8b7cdf89]{font-weight:400;text-align:right;width:80px;line-height:32px}.form-item .button[data-v-8b7cdf89]{width:100%;height:32px}@media (min-width: 1024px){header[data-v-8b7cdf89]{display:flex;place-items:center;padding-right:calc(var(--section-gap) / 2)}.logo[data-v-8b7cdf89]{margin:0 2rem 0 0}header .wrapper[data-v-8b7cdf89]{display:flex;place-items:flex-start;flex-wrap:wrap}}:root{--vt-c-white: #ffffff;--vt-c-white-soft: #f8f8f8;--vt-c-white-mute: #f2f2f2;--vt-c-black: #181818;--vt-c-black-soft: #222222;--vt-c-black-mute: #282828;--vt-c-indigo: #2c3e50;--vt-c-divider-light-1: rgba(60, 60, 60, .29);--vt-c-divider-light-2: rgba(60, 60, 60, .12);--vt-c-divider-dark-1: rgba(84, 84, 84, .65);--vt-c-divider-dark-2: rgba(84, 84, 84, .48);--vt-c-text-light-1: var(--vt-c-indigo);--vt-c-text-light-2: rgba(60, 60, 60, .66);--vt-c-text-dark-1: var(--vt-c-white);--vt-c-text-dark-2: rgba(235, 235, 235, .64)}:root{--color-background: var(--vt-c-white);--color-background-soft: var(--vt-c-white-soft);--color-background-mute: var(--vt-c-white-mute);--color-border: var(--vt-c-divider-light-2);--color-border-hover: var(--vt-c-divider-light-1);--color-heading: var(--vt-c-text-light-1);--color-text: var(--vt-c-text-light-1);--section-gap: 160px}@media (prefers-color-scheme: dark){:root{--color-background: var(--vt-c-black);--color-background-soft: var(--vt-c-black-soft);--color-background-mute: var(--vt-c-black-mute);--color-border: var(--vt-c-divider-dark-2);--color-border-hover: var(--vt-c-divider-dark-1);--color-heading: var(--vt-c-text-dark-1);--color-text: var(--vt-c-text-dark-2)}}*,*:before,*:after{box-sizing:border-box;margin:0;position:relative;font-weight:400}body{min-height:100vh;color:var(--color-text);background:var(--color-background);transition:color .5s,background-color .5s;line-height:1.6;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;font-size:15px;text-rendering:optimizeLegibility;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}#app{max-width:1280px;margin:0 auto;padding:2rem;font-weight:400}a,.green{text-decoration:none;color:#00bd7e;transition:.4s}@media (hover: hover){a:hover{background-color:#00bd7e33}}@media (min-width: 1024px){body{display:flex;place-items:center}#app{display:grid;grid-template-columns:1fr 1fr;padding:0 2rem}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/vue3/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" crossorigin src="/vue3/assets/index.0a966209.js"></script>
<link rel="stylesheet" href="/vue3/assets/index.dbbe974b.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
/**
* The DSL compiler.
* Translate the customize DSL to Models, Processes, Flows, Tables, etc.
*/
/**
* Source
* Where to get the source of DSL
*/
function Source() {
var sources = {};
tpls = Process("models.template.Get", { select: ["id", "dsl"], limit: 2000 });
if (tpls.code && tpls.message) {
log.Error("Load dyform sources: %s", tpls.message);
return sources;
}
tpls.forEach((tpl) => {
tpl = tpl || {};
try {
instance = `instance_${tpl.id}`;
dsl = JSON.parse(tpl.dsl);
sources[instance] = dsl;
} catch (e) {
log.Error("Source %v DSL: %s", tpl.id, e.message);
return;
}
});
return sources;
}
/**
* Compile
* Translate or extend the customize DSL
* @param {*} dsl
*/
function Compile(name, dsl) {
return dsl;
}
/**
* OnLoad
* When the widget instance are loaded, the function will be called.
* For preparing the sources the widget need.
* @param {DSL} dsl
*/
function OnLoad(name, dsl) {
log.Info("[Widget] dyform %s loaded", name);
}
/**
* Migrate
* When the migrate command executes, the function will be called
* @param {DSL} dsl
* @param {bool} force
*/
function Migrate(dsl, force) {}
/**
* Export Models, APIs, Tables, Tasks, Schedules, etc.
*/
/**
* Export API
*/
function APIs() {}
/**
* Export Models
* @param {*} name
* @param {*} dsl
*/
function Models(name, dsl) {
var exportModels = {};
const models = Process("widgets.dyform.Model", name, dsl);
models.forEach((model) => {
exportModels[model.name] = model.dsl;
});
return exportModels;
}
/**
* Export Tables
* @param {*} name
* @param {*} dsl
*/
function Tables(name, dsl) {
var exportTables = {};
const tables = Process("widgets.dyform.Table", name, dsl);
tables.forEach((table) => {
exportTables[table.name] = table.dsl;
});
return exportTables;
}
/**
* Export the widget processes
* Export() defined witch function in this file will be registered as YAO PROCESS
* The process name is widgets.<WIDGET NAME>.<FUNCTION NAME>
* The process args are [<INSTANCE NAME>, <COMPILED DSL>]
*
* @todo:
* The processes can be used in compile.js and export.js DIRECTLY
*/
/**
* Model
* Convert DSL to yao model
*
* @debug
* yao run widgets.dyform.Model test '::{"name":"TEST", "decription":"A TEST DYFORM", "columns":[{"title":"First Name","name":"name","type":"input","search":true,"props":{"placeholder":"Please input your first name"}},{"title":"Amount","name":"amount","type":"input","search":true,"props":{"placeholder":"Please input amount"}},{"title":"Description","name":"desc","type":"textArea","props":{"placeholder":"Please input Description"}}]}'
*
* @name: widgets.dyform.Model
* @param {String} instance the instance name
* @param {*} payload
*/
function Model(instance, dsl) {
const name = `dyform.${instance}`;
return [{ name: name, dsl: toModel(instance, dsl) }];
}
/**
* Table
* Convert DSL to yao table
*
* @debug
* yao run widgets.dyform.Table test '::{"name":"TEST", "decription":"A TEST DYFORM", "columns":[{"title":"First Name","name":"name","type":"input","search":true,"props":{"placeholder":"Please input your first name"}},{"title":"Amount","name":"amount","type":"input","search":true,"props":{"placeholder":"Please input amount"}},{"title":"Description","name":"desc","type":"textArea","props":{"placeholder":"Please input Description"}}]}'
*
* @name: widgets.dyform.Model
* @param {String} instance the instance name
* @param {*} payload
*/
function Table(instance, dsl) {
const name = `dyform.${instance}`;
return [{ name: name, dsl: toTable(instance, dsl) }];
}
/**
* Save
* MIGRATE the given instance shcema, and (re)load the instance
*
* @debug
* yao run widgets.dyform.Save test '::{"name":"TEST", "decription":"A TEST DYFORM", "columns":[{"title":"First Name","name":"name","type":"input","search":true,"props":{"placeholder":"Please input your first name"}},{"title":"Amount","name":"amount","type":"input","search":true,"props":{"placeholder":"Please input amount"}},{"title":"Description","name":"desc","type":"textArea","props":{"placeholder":"Please input Description"}}]}'
*
* @param {*} instance
* @param {*} dsl
*/
function Save(instance, dsl) {
if (migrateModel(instance, dsl) === false) {
return false;
}
// Reload Instance
log.Info("[Widget] dyform reload %s", instance);
var res = Process("widgets.dyform.Reload", instance, JSON.stringify(dsl));
if (res && res.code != 200 && res.message) {
log.Error("widgets.dyform.Save: %s", res.message);
return false;
}
return true;
}
/**
* Delete
* REMOVE the given instance schema
*
* @debug
* yao run widgets.dyform.Delete test
*
* @param {*} instance
*/
function Delete(instance) {
var res = Process("schemas.default.TableDrop", `dyform_${instance}`);
if (res && res.code != 200 && res.message) {
log.Error("widgets.dyform.Delete: %s", res.message);
return false;
}
return true;
}
/**
* migrateModel
* @param {*} instance
* @param {*} dsl
*/
function migrateModel(instance, dsl) {
if (!instance) {
log.Error("widgets.dyform.Save: missing instance");
return false;
}
dsl = dsl || {};
var schNew = toModel(instance, dsl);
// Customize the table creation logic
// var schOld = Process("schemas.default.TableGet", `dyform_${instance}`);
// if (schOld.code != 200 && schOld.message) {
// if (!schOld.message.includes("not exists")) {
// log.Error("widgets.dyform.Save: %s", schOld.message);
// return false;
// }
// // Create schema
// var res = Process(
// "schemas.default.TableCreate",
// `dyform_${instance}`,
// schNew
// );
// if (res && res.code != 200 && res.message) {
// log.Error("widgets.dyform.Save: %s", res.message);
// return false;
// }
// return true;
// }
// Upgrade schema
var res = Process("schemas.default.TableSave", `dyform_${instance}`, schNew);
if (res && res.code != 200 && res.message) {
log.Error("widgets.dyform.Save: %s", res.message);
return false;
}
return true;
}
/**
* Generate a model
* @param {*} instance
* @param {*} payload
* @returns
*/
function toModel(instance, payload) {
payload = payload || {};
const tableName = `dyform_${instance}`; // the shcema table name
const columns = payload.columns || [];
var modelTemplate = {
name: `AUTO GENERATE BY DYFORM ${instance}`,
table: { name: tableName, comment: "dyform data store" },
columns: [{ label: "ID", name: "id", type: "ID", comment: "ID" }],
indexes: [],
};
columns.forEach((column) => {
var col = castModelColumn(column);
if (col) {
modelTemplate.columns.push(col);
}
});
return modelTemplate;
}
/**
* Generate a table
* @param {*} instance
* @param {*} payload
*/
function toTable(instance, payload) {
payload = payload || {};
const columns = payload.columns || [];
const modelName = `dyform.${instance}`; // the model name
var tableTemplate = {
name: payload.name || instance,
version: "1.0.0",
decription: payload.decription || "a dyform instance",
bind: { model: modelName },
columns: {},
filters: {},
list: {
primary: "id",
layout: { columns: [], filters: [] },
actions: {
pagination: { props: { showTotal: true } },
create: { props: { label: "Create" } },
},
option: { operation: { unfold: true } },
},
edit: {
primary: "id",
layout: {
fieldset: [{ columns: [] }],
},
actions: {
cancel: {},
save: {},
delete: { type: "button", props: { label: "Delete" } },
},
option: { dev: true },
},
};
columns.forEach((column) => {
var col = castTableColumn(column);
if (col) {
col.columns.forEach((c) => (tableTemplate.columns[c.name] = c.component));
col.filters.forEach((f) => (tableTemplate.filters[f.name] = f.filter));
col.edit.forEach((c) =>
tableTemplate.edit.layout.fieldset[0].columns.push(c)
);
col.list.columns.forEach((c) =>
tableTemplate.list.layout.columns.push(c)
);
col.list.filters.forEach((f) =>
tableTemplate.list.layout.filters.push(f)
);
}
});
return tableTemplate;
}
function castTableColumn(column) {
column = column || {};
const props = column.props || {};
const title = column.title;
const name = column.name;
const bind = `:${name}`;
if (!name) {
log.Error("castTableColumn: missing name");
return false;
}
if (!title) {
log.Error("castTableColumn: missing title");
return false;
}
var res = {
columns: [],
filters: [],
list: { columns: [], filters: [] },
edit: [],
};
// Converted to custom component, here converted to Yao table widget
var component = {
label: title,
view: { type: "label", props: { value: `:${name}` } },
edit: {},
};
switch (column.type) {
case "input":
component.edit = { type: "input", props: { value: bind } };
res.list.columns.push({ name: title });
res.edit.push({ name: title, width: 24 });
break;
case "textArea":
component.edit = { type: "textArea", props: { value: bind } };
res.list.columns.push({ name: title });
res.edit.push({ name: title, width: 24 });
break;
default:
log.Error("castTableColumn: Type %s does not support", column.type);
return false;
}
res.columns.push({ name: title, component: component });
// Convert to filter based on DSL description
if (column.search) {
var filter = {
label: title,
bind: `where.${name}.match`,
input: {
type: "input",
props: { placeholder: props.placeholder || `type ${title}...` },
},
};
res.filters.push({ name: title, filter: filter });
res.list.filters.push({ name: title });
}
return res;
}
function castModelColumn(column) {
column = column || {};
if (!column.name) {
log.Error("castModelColumn: missing name");
return false;
}
var col = {
name: column.name,
label: column.title,
comment: column.title,
index: column.search ? true : false,
};
// Convert to data model based on custom component type for storing data
switch (column.type) {
case "input":
col.type = "string";
col.length = 200;
return col;
case "textArea":
col.type = "text";
return col;
}
log.Error("castModelColumn: Type %s does not support", column.type);
return false;
}
/**
* Export processes
*/
function Export() {
return { Model: "Model", Table: "Table", Save: "Save", Delete: "Delete" };
}
{
"label": "Dynamic Form",
"description": "A form widget. users can design forms online",
"version": "0.1.0",
"root": "dyforms",
"extension": ".form.json",
"modules": ["Models", "Tables"]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册