diff --git a/src/contexts/ctx/cgi.go b/src/contexts/ctx/cgi.go
index 72f84a2f..943f4f8d 100644
--- a/src/contexts/ctx/cgi.go
+++ b/src/contexts/ctx/cgi.go
@@ -199,7 +199,8 @@ func LocalCGI(m *Message, c *Context) *template.FuncMap {
func(k string, v *Command) {
cgi[k] = func(arg ...interface{}) (res interface{}) {
m.TryCatch(m.Spawn(), true, func(msg *Message) {
- v.Hand(msg, c, k, kit.Trans(arg)...)
+
+ v.Hand(msg, c, k, msg.Form(v, kit.Trans(arg))...)
buffer := bytes.NewBuffer([]byte{})
m.Assert(m.Optionv("tmpl").(*template.Template).ExecuteTemplate(buffer,
diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go
index 2f76050f..27eff079 100644
--- a/src/examples/chat/chat.go
+++ b/src/examples/chat/chat.go
@@ -3,6 +3,7 @@ package chat
import (
"contexts/ctx"
"contexts/web"
+ mis "github.com/shylinux/toolkits"
"fmt"
"io/ioutil"
@@ -502,10 +503,14 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
m.Confm("share", []string{"hash", h}, func(value map[string]interface{}) {
switch kit.Format(value["type"]) {
case "file":
+ // 下载文件
m.Cmdy("/download/" + h)
+
case "wiki":
+ // 查看文档
p := path.Join(path.Join("var/share", h))
if _, e := os.Stat(p); e == nil {
+ // 读取缓存
m.Log("info", "read cache %v", p)
r := m.Optionv("request").(*http.Request)
w := m.Optionv("response").(http.ResponseWriter)
@@ -513,9 +518,11 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
break
}
+ // 生成模板
if b, e := ioutil.ReadFile("usr/template/share.tmpl"); e == nil {
m.Echo(string(b))
}
+ // 生成文档
m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"])
if f, _, e := kit.Create(p); e == nil {
defer f.Close()
@@ -525,6 +532,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
}
}
+ // 访问记录
m.Grow("share", nil, map[string]interface{}{
"time": m.Time(),
"share": h,
@@ -540,17 +548,34 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
return
}},
"share": &ctx.Command{Name: "share type code", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
+ if len(arg) > 2 {
+ switch arg[1] {
+ case "delete":
+ // 删除共享
+ switch arg[2] {
+ case "key":
+ m.Log("info", "delete share %v %v", arg[3], mis.Formats(m.Conf("share", "hash."+arg[3])))
+ m.Conf("share", "hash."+arg[3], "")
+ }
+ return
+ }
+ }
+
if len(arg) < 2 {
+ // 共享列表
m.Confm("share", "hash", func(key string, value map[string]interface{}) {
m.Push("key", key)
+ m.Push("time", value["time"])
m.Push("type", value["type"])
m.Push("code", value["code"])
m.Push("dream", value["dream"])
m.Push("link", fmt.Sprintf("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), key))
})
- m.Table()
+ m.Sort("time", "time_r")
return
}
+
+ // 共享链接
h := kit.ShortKey(m.Confm(cmd, "hash"), 6)
m.Confv(cmd, []string{"hash", h}, map[string]interface{}{
"from": m.Option("username"),
diff --git a/src/examples/team/team.go b/src/examples/team/team.go
index eee08308..69a23889 100644
--- a/src/examples/team/team.go
+++ b/src/examples/team/team.go
@@ -14,12 +14,11 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
"task": {Name: "task create table level class status begin_time close_time target detail arg...", Help: "任务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch arg[0] {
case "progress":
- if len(arg) > 2 && arg[1] != "" {
- switch arg[2] {
+ if len(arg) > 3 && arg[1] != "" {
+ switch arg[3] {
case "prepare", "action", "cancel", "finish":
- prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "update"}
time := "close_time"
- switch arg[2] {
+ switch arg[3] {
case "prepare", "action":
time = "begin_time"
case "cancel", "finish":
@@ -29,7 +28,7 @@ var Index = &ctx.Context{Name: "team", Help: "团队中心",
}
// 更新任务
- m.Cmd(prefix, m.Option("table"), arg[1], "status", arg[2], time, m.Time())
+ m.Cmd("ssh.data", "update", arg[1], arg[2], "status", arg[3], time, m.Time())
arg = []string{arg[0], m.Option("table")}
}
}
diff --git a/src/examples/wiki/chart.go b/src/examples/wiki/chart.go
index 61f579e2..7fe02110 100644
--- a/src/examples/wiki/chart.go
+++ b/src/examples/wiki/chart.go
@@ -20,6 +20,7 @@ type Chart interface {
type Block struct {
Text string
FontColor string
+ FontFamily string
BackGround string
FontSize int
@@ -33,11 +34,38 @@ type Block struct {
RectData string
}
+func (b *Block) Init(m *ctx.Message, arg ...string) Chart {
+ b.Text = kit.Select(b.Text, arg, 0)
+ b.FontColor = kit.Select("white", kit.Select(b.FontColor, arg, 1))
+ b.BackGround = kit.Select("red", kit.Select(b.BackGround, arg, 2))
+ b.FontSize = kit.Int(kit.Select("24", kit.Select(kit.Format(b.FontSize), arg, 3)))
+ b.LineSize = kit.Int(kit.Select("12", kit.Select(kit.Format(b.LineSize), arg, 4)))
+ return b
+}
+func (b *Block) Draw(m *ctx.Message, x, y int) Chart {
+ m.Echo(``,
+ x+b.Margin/2, y+b.Margin/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData)
+ m.Echo("\n")
+ m.Echo(`%v`,
+ x+b.GetWidths()/2, y+b.GetHeights()/2, b.FontSize, b.FontColor, b.TextData, b.Text)
+ m.Echo("\n")
+ return b
+}
+func (b *Block) Data(root interface{}) {
+ mis.Table(mis.Value(root, "data"), 0, 100, func(key string, value string) {
+ b.TextData += key + "='" + value + "' "
+ })
+ mis.Table(mis.Value(root, "rect"), 0, 100, func(key string, value string) {
+ b.RectData += key + "='" + value + "' "
+ })
+ b.FontColor = kit.Select(b.FontColor, mis.Value(root, "fg"))
+ b.BackGround = kit.Select(b.BackGround, mis.Value(root, "bg"))
+}
func (b *Block) GetWidth(str ...string) int {
if b.Width != 0 {
return b.Width
}
- return len(kit.Select(b.Text, str, 0))*b.FontSize/2 + b.Padding
+ return len(kit.Select(b.Text, str, 0))*b.FontSize*6/10 + b.Padding
}
func (b *Block) GetHeight(str ...string) int {
if b.Height != 0 {
@@ -51,32 +79,8 @@ func (b *Block) GetWidths(str ...string) int {
func (b *Block) GetHeights(str ...string) int {
return b.GetHeight() + b.Margin
}
-func (b *Block) Init(m *ctx.Message, arg ...string) Chart {
- b.Text = kit.Select(b.Text, arg, 0)
- b.FontColor = kit.Select("white", kit.Select(b.FontColor, arg, 1))
- b.BackGround = kit.Select("red", kit.Select(b.BackGround, arg, 2))
- b.FontSize = kit.Int(kit.Select("24", kit.Select(kit.Format(b.FontSize), arg, 3)))
- b.LineSize = kit.Int(kit.Select("12", kit.Select(kit.Format(b.LineSize), arg, 4)))
- return b
-}
-func (b *Block) Draw(m *ctx.Message, x, y int) Chart {
- m.Echo(``,
- x+b.Margin/2, y+b.Margin/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData)
- m.Echo(`%v`,
- x+b.GetWidths()/2, y+b.GetHeights()/2, b.FontSize, b.FontColor, b.TextData, b.Text)
- return b
-}
-func (b *Block) Data(root interface{}) {
- mis.Table(mis.Value(root, "data"), 0, 100, func(key string, value string) {
- b.TextData += key + "='" + value + "' "
- })
- mis.Table(mis.Value(root, "rect"), 0, 100, func(key string, value string) {
- b.RectData += key + "='" + value + "' "
- })
- b.FontColor = kit.Select(b.FontColor, mis.Value(root, "fg"))
- b.BackGround = kit.Select(b.BackGround, mis.Value(root, "bg"))
-}
+// 树
type Chain struct {
data map[string]interface{}
max map[int]int
@@ -92,6 +96,7 @@ func (b *Chain) Init(m *ctx.Message, arg ...string) Chart {
b.LineSize = kit.Int(kit.Select("12", arg, 4))
b.Padding = kit.Int(kit.Select("8", arg, 5))
b.Margin = kit.Int(kit.Select("8", arg, 6))
+ m.Log("info", "data %v", kit.Formats(b.data))
// 计算尺寸
b.max = map[int]int{}
@@ -104,6 +109,9 @@ func (b *Chain) Init(m *ctx.Message, arg ...string) Chart {
m.Log("info", "data %v", kit.Formats(b.data))
return b
}
+func (b *Chain) Draw(m *ctx.Message, x, y int) Chart {
+ return b.draw(m, b.data, 0, b.max, x, y)
+}
func (b *Chain) show(m *ctx.Message, str string) (res []string) {
miss := []int{}
list := mis.Split(str, "\n")
@@ -197,10 +205,8 @@ func (b *Chain) draw(m *ctx.Message, root map[string]interface{}, depth int, wid
})
return b
}
-func (b *Chain) Draw(m *ctx.Message, x, y int) Chart {
- return b.draw(m, b.data, 0, b.max, x, y)
-}
+// 表
type Table struct {
data [][]string
max map[int]int
diff --git a/src/examples/wiki/wiki.go b/src/examples/wiki/wiki.go
index d96e6dba..a95334e3 100644
--- a/src/examples/wiki/wiki.go
+++ b/src/examples/wiki/wiki.go
@@ -380,13 +380,13 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
}
return
}},
- "shell": {Name: "shell dir cmd", Help: "命令行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ "shell": {Name: "shell dir cmd", Help: "命令行", Form: map[string]int{"style": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Option("render", "code")
m.Echo("$ %v\n", strings.Join(arg[1:], " "))
m.Cmdy("cli.system", "cmd_dir", arg[0], "bash", "-c", strings.Join(arg[1:], " "))
return
}},
- "chart": {Name: "chart type text", Help: "绘图", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ "chart": {Name: "chart type text", Help: "绘图", Form: map[string]int{"style": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Option("render", "raw")
var chart Chart
switch arg[0] {
@@ -400,10 +400,12 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
arg[1] = strings.TrimSpace(arg[1])
chart.Init(m, arg[1:]...)
- m.Echo(`