mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
opt some
This commit is contained in:
parent
89024c6f30
commit
07f530721f
@ -199,7 +199,8 @@ func LocalCGI(m *Message, c *Context) *template.FuncMap {
|
|||||||
func(k string, v *Command) {
|
func(k string, v *Command) {
|
||||||
cgi[k] = func(arg ...interface{}) (res interface{}) {
|
cgi[k] = func(arg ...interface{}) (res interface{}) {
|
||||||
m.TryCatch(m.Spawn(), true, func(msg *Message) {
|
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{})
|
buffer := bytes.NewBuffer([]byte{})
|
||||||
m.Assert(m.Optionv("tmpl").(*template.Template).ExecuteTemplate(buffer,
|
m.Assert(m.Optionv("tmpl").(*template.Template).ExecuteTemplate(buffer,
|
||||||
|
@ -3,6 +3,7 @@ package chat
|
|||||||
import (
|
import (
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"contexts/web"
|
"contexts/web"
|
||||||
|
mis "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -502,10 +503,14 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
m.Confm("share", []string{"hash", h}, func(value map[string]interface{}) {
|
m.Confm("share", []string{"hash", h}, func(value map[string]interface{}) {
|
||||||
switch kit.Format(value["type"]) {
|
switch kit.Format(value["type"]) {
|
||||||
case "file":
|
case "file":
|
||||||
|
// 下载文件
|
||||||
m.Cmdy("/download/" + h)
|
m.Cmdy("/download/" + h)
|
||||||
|
|
||||||
case "wiki":
|
case "wiki":
|
||||||
|
// 查看文档
|
||||||
p := path.Join(path.Join("var/share", h))
|
p := path.Join(path.Join("var/share", h))
|
||||||
if _, e := os.Stat(p); e == nil {
|
if _, e := os.Stat(p); e == nil {
|
||||||
|
// 读取缓存
|
||||||
m.Log("info", "read cache %v", p)
|
m.Log("info", "read cache %v", p)
|
||||||
r := m.Optionv("request").(*http.Request)
|
r := m.Optionv("request").(*http.Request)
|
||||||
w := m.Optionv("response").(http.ResponseWriter)
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
@ -513,9 +518,11 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成模板
|
||||||
if b, e := ioutil.ReadFile("usr/template/share.tmpl"); e == nil {
|
if b, e := ioutil.ReadFile("usr/template/share.tmpl"); e == nil {
|
||||||
m.Echo(string(b))
|
m.Echo(string(b))
|
||||||
}
|
}
|
||||||
|
// 生成文档
|
||||||
m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"])
|
m.Cmdy("ssh._route", value["dream"], "web.wiki.note", value["code"])
|
||||||
if f, _, e := kit.Create(p); e == nil {
|
if f, _, e := kit.Create(p); e == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@ -525,6 +532,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 访问记录
|
||||||
m.Grow("share", nil, map[string]interface{}{
|
m.Grow("share", nil, map[string]interface{}{
|
||||||
"time": m.Time(),
|
"time": m.Time(),
|
||||||
"share": h,
|
"share": h,
|
||||||
@ -540,17 +548,34 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"share": &ctx.Command{Name: "share type code", Help: "共享链接", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
|
"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 {
|
if len(arg) < 2 {
|
||||||
|
// 共享列表
|
||||||
m.Confm("share", "hash", func(key string, value map[string]interface{}) {
|
m.Confm("share", "hash", func(key string, value map[string]interface{}) {
|
||||||
m.Push("key", key)
|
m.Push("key", key)
|
||||||
|
m.Push("time", value["time"])
|
||||||
m.Push("type", value["type"])
|
m.Push("type", value["type"])
|
||||||
m.Push("code", value["code"])
|
m.Push("code", value["code"])
|
||||||
m.Push("dream", value["dream"])
|
m.Push("dream", value["dream"])
|
||||||
m.Push("link", fmt.Sprintf("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), key))
|
m.Push("link", fmt.Sprintf("%s/chat/share/%s", m.Cmdx(".spide", "self", "client", "url"), key))
|
||||||
})
|
})
|
||||||
m.Table()
|
m.Sort("time", "time_r")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 共享链接
|
||||||
h := kit.ShortKey(m.Confm(cmd, "hash"), 6)
|
h := kit.ShortKey(m.Confm(cmd, "hash"), 6)
|
||||||
m.Confv(cmd, []string{"hash", h}, map[string]interface{}{
|
m.Confv(cmd, []string{"hash", h}, map[string]interface{}{
|
||||||
"from": m.Option("username"),
|
"from": m.Option("username"),
|
||||||
|
@ -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) {
|
"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] {
|
switch arg[0] {
|
||||||
case "progress":
|
case "progress":
|
||||||
if len(arg) > 2 && arg[1] != "" {
|
if len(arg) > 3 && arg[1] != "" {
|
||||||
switch arg[2] {
|
switch arg[3] {
|
||||||
case "prepare", "action", "cancel", "finish":
|
case "prepare", "action", "cancel", "finish":
|
||||||
prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "update"}
|
|
||||||
time := "close_time"
|
time := "close_time"
|
||||||
switch arg[2] {
|
switch arg[3] {
|
||||||
case "prepare", "action":
|
case "prepare", "action":
|
||||||
time = "begin_time"
|
time = "begin_time"
|
||||||
case "cancel", "finish":
|
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")}
|
arg = []string{arg[0], m.Option("table")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ type Chart interface {
|
|||||||
type Block struct {
|
type Block struct {
|
||||||
Text string
|
Text string
|
||||||
FontColor string
|
FontColor string
|
||||||
|
FontFamily string
|
||||||
BackGround string
|
BackGround string
|
||||||
|
|
||||||
FontSize int
|
FontSize int
|
||||||
@ -33,11 +34,38 @@ type Block struct {
|
|||||||
RectData string
|
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 {
|
func (b *Block) GetWidth(str ...string) int {
|
||||||
if b.Width != 0 {
|
if b.Width != 0 {
|
||||||
return b.Width
|
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 {
|
func (b *Block) GetHeight(str ...string) int {
|
||||||
if b.Height != 0 {
|
if b.Height != 0 {
|
||||||
@ -51,32 +79,8 @@ func (b *Block) GetWidths(str ...string) int {
|
|||||||
func (b *Block) GetHeights(str ...string) int {
|
func (b *Block) GetHeights(str ...string) int {
|
||||||
return b.GetHeight() + b.Margin
|
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 {
|
type Chain struct {
|
||||||
data map[string]interface{}
|
data map[string]interface{}
|
||||||
max map[int]int
|
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.LineSize = kit.Int(kit.Select("12", arg, 4))
|
||||||
b.Padding = kit.Int(kit.Select("8", arg, 5))
|
b.Padding = kit.Int(kit.Select("8", arg, 5))
|
||||||
b.Margin = kit.Int(kit.Select("8", arg, 6))
|
b.Margin = kit.Int(kit.Select("8", arg, 6))
|
||||||
|
m.Log("info", "data %v", kit.Formats(b.data))
|
||||||
|
|
||||||
// 计算尺寸
|
// 计算尺寸
|
||||||
b.max = map[int]int{}
|
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))
|
m.Log("info", "data %v", kit.Formats(b.data))
|
||||||
return b
|
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) {
|
func (b *Chain) show(m *ctx.Message, str string) (res []string) {
|
||||||
miss := []int{}
|
miss := []int{}
|
||||||
list := mis.Split(str, "\n")
|
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
|
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 {
|
type Table struct {
|
||||||
data [][]string
|
data [][]string
|
||||||
max map[int]int
|
max map[int]int
|
||||||
|
@ -380,13 +380,13 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
|||||||
}
|
}
|
||||||
return
|
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.Option("render", "code")
|
||||||
m.Echo("$ %v\n", strings.Join(arg[1:], " "))
|
m.Echo("$ %v\n", strings.Join(arg[1:], " "))
|
||||||
m.Cmdy("cli.system", "cmd_dir", arg[0], "bash", "-c", strings.Join(arg[1:], " "))
|
m.Cmdy("cli.system", "cmd_dir", arg[0], "bash", "-c", strings.Join(arg[1:], " "))
|
||||||
return
|
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")
|
m.Option("render", "raw")
|
||||||
var chart Chart
|
var chart Chart
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
@ -400,10 +400,12 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
|||||||
arg[1] = strings.TrimSpace(arg[1])
|
arg[1] = strings.TrimSpace(arg[1])
|
||||||
|
|
||||||
chart.Init(m, arg[1:]...)
|
chart.Init(m, arg[1:]...)
|
||||||
m.Echo(`<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%d", height="%d">`,
|
m.Echo(`<svg vertion="1.1" xmlns="http://www.w3.org/2000/svg" width="%d", height="%d" style="%s">`,
|
||||||
chart.GetWidth(), chart.GetHeight())
|
chart.GetWidth(), chart.GetHeight(), m.Option("style"))
|
||||||
|
m.Echo("\n")
|
||||||
chart.Draw(m, 0, 0)
|
chart.Draw(m, 0, 0)
|
||||||
m.Echo(`</svg>`)
|
m.Echo(`</svg>`)
|
||||||
|
m.Echo("\n")
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
@ -14,16 +14,14 @@ fun date "每一天" "index.js" "index.css" protected \
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
kit progress "任务进度" public "_:web.team.task" progress \
|
kit progress "任务进度" public "_:web.team.task" "@you" progress \
|
||||||
text "" name dream imports plugin_you \
|
|
||||||
text "task" name table \
|
text "task" name table \
|
||||||
text "30" name limit \
|
text "30" name limit \
|
||||||
text "0" name offset \
|
text "0" name offset \
|
||||||
feature detail action finish cancel prepare \
|
feature detail action finish cancel prepare \
|
||||||
button "查看" action auto
|
button "查看" action auto
|
||||||
|
|
||||||
kit create "创建任务" public "_:web.team.task" create \
|
kit create "创建任务" public "_:web.team.task" "@you" create \
|
||||||
text "" name dream imports plugin_you \
|
|
||||||
text "task" name table \
|
text "task" name table \
|
||||||
select "3" name level values 1 values 2 values 3 values 4 values 5 \
|
select "3" name level values 1 values 2 values 3 values 4 values 5 \
|
||||||
select "" name class values add values opt values fix \
|
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" \
|
textarea "" name detail half "4" \
|
||||||
button "添加" before br
|
button "添加" before br
|
||||||
|
|
||||||
kit select "查看任务" public "_:web.team.task" \
|
kit select "查看任务" public "_:web.team.task" "@you" \
|
||||||
text "" name dream imports plugin_you \
|
|
||||||
text "task" name table imports pluing_table \
|
text "task" name table imports pluing_table \
|
||||||
text "" name index imports plugin_task_id action auto \
|
text "" name index imports plugin_task_id action auto \
|
||||||
button "查看" action auto \
|
button "查看" action auto \
|
||||||
|
@ -18,5 +18,5 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "code"}}
|
{{define "code"}}
|
||||||
<div class="story code">{{results .}}</div>
|
<div class="story code" style='{{options . "style"}}'>{{results .}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user