1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
shaoying 2019-12-06 20:35:41 +08:00
parent 89024c6f30
commit 07f530721f
7 changed files with 77 additions and 47 deletions

View File

@ -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,

View File

@ -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"),

View File

@ -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")}
}
}

View File

@ -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(`<rect x="%d" y="%d" width="%d" height="%d" fill="%s" %v/>`,
x+b.Margin/2, y+b.Margin/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData)
m.Echo("\n")
m.Echo(`<text x="%d" y="%d" font-size="%d" style="dominant-baseline:middle;text-anchor:middle;" fill="%s" %v>%v</text>`,
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(`<rect x="%d" y="%d" width="%d" height="%d" fill="%s" %v/>`,
x+b.Margin/2, y+b.Margin/2, b.GetWidth(), b.GetHeight(), b.BackGround, b.RectData)
m.Echo(`<text x="%d" y="%d" font-size="%d" style="dominant-baseline:middle;text-anchor:middle;" fill="%s" %v>%v</text>`,
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

View File

@ -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(`<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%d", height="%d">`,
chart.GetWidth(), chart.GetHeight())
m.Echo(`<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%d", height="%d" style="%s">`,
chart.GetWidth(), chart.GetHeight(), m.Option("style"))
m.Echo("\n")
chart.Draw(m, 0, 0)
m.Echo(`</svg>`)
m.Echo("\n")
return
}},

View File

@ -14,16 +14,14 @@ fun date "每一天" "index.js" "index.css" protected \
end
end
kit progress "任务进度" public "_:web.team.task" progress \
text "" name dream imports plugin_you \
kit progress "任务进度" public "_:web.team.task" "@you" progress \
text "task" name table \
text "30" name limit \
text "0" name offset \
feature detail action finish cancel prepare \
button "查看" action auto
kit create "创建任务" public "_:web.team.task" create \
text "" name dream imports plugin_you \
kit create "创建任务" public "_:web.team.task" "@you" create \
text "task" name table \
select "3" name level values 1 values 2 values 3 values 4 values 5 \
select "" name class values add values opt values fix \
@ -34,8 +32,7 @@ kit create "创建任务" public "_:web.team.task" create \
textarea "" name detail half "4" \
button "添加" before br
kit select "查看任务" public "_:web.team.task" \
text "" name dream imports plugin_you \
kit select "查看任务" public "_:web.team.task" "@you" \
text "task" name table imports pluing_table \
text "" name index imports plugin_task_id action auto \
button "查看" action auto \

View File

@ -18,5 +18,5 @@
{{end}}
{{define "code"}}
<div class="story code">{{results .}}</div>
<div class="story code" style='{{options . "style"}}'>{{results .}}</div>
{{end}}