1
0
forked from x/icebergs

opt inner

This commit is contained in:
shylinux 2020-06-08 10:16:34 +08:00
parent 8073489376
commit 8b1aac8384
11 changed files with 666 additions and 602 deletions

View File

@ -372,9 +372,9 @@ func _story_history(m *ice.Message, name string) {
} }
} }
func StoryHistory(m *ice.Message, name string) { _story_history(m, name) } func StoryHistory(m *ice.Message, name string) *ice.Message { _story_history(m, name); return m }
func StoryIndex(m *ice.Message, name string) { _story_index(m, name, true) } func StoryIndex(m *ice.Message, name string) *ice.Message { _story_index(m, name, true); return m }
func StoryWatch(m *ice.Message, index string, file string) { _story_watch(m, index, file) } func StoryWatch(m *ice.Message, index string, file string) { _story_watch(m, index, file) }
func StoryCatch(m *ice.Message, mime string, file string) { func StoryCatch(m *ice.Message, mime string, file string) {
_story_catch(m, "catch", kit.Select(mime, strings.TrimPrefix(path.Ext(file), ".")), file, "") _story_catch(m, "catch", kit.Select(mime, strings.TrimPrefix(path.Ext(file), ".")), file, "")
} }

View File

@ -81,6 +81,11 @@ func _action_order(m *ice.Message, arg ...string) {
return return
} }
if m.Option("index") == "" || !m.Right(kit.Keys(m.Option("group"), m.Option("index"))) {
m.Render("status", 403, "not auth")
return
}
cmds := kit.Simple(kit.Keys(m.Option("group"), m.Option("index")), arg[3:]) cmds := kit.Simple(kit.Keys(m.Option("group"), m.Option("index")), arg[3:])
if m.Set(ice.MSG_RESULT); !m.Right(cmds) { if m.Set(ice.MSG_RESULT); !m.Right(cmds) {
m.Render("status", 403, "not auth") m.Render("status", 403, "not auth")

View File

@ -21,6 +21,8 @@ func _river_right(m *ice.Message, action string) bool {
} }
func _river_list(m *ice.Message) { func _river_list(m *ice.Message) {
m.Set(ice.MSG_OPTION, "key")
m.Set(ice.MSG_OPTION, "name")
m.Richs(RIVER, nil, "*", func(key string, value map[string]interface{}) { m.Richs(RIVER, nil, "*", func(key string, value map[string]interface{}) {
m.Richs(RIVER, kit.Keys(kit.MDB_HASH, key, "user"), m.Option(ice.MSG_USERNAME), func(k string, val map[string]interface{}) { m.Richs(RIVER, kit.Keys(kit.MDB_HASH, key, "user"), m.Option(ice.MSG_USERNAME), func(k string, val map[string]interface{}) {
m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME}) m.Push(key, value["meta"], []string{kit.MDB_KEY, kit.MDB_NAME})

View File

@ -1,38 +0,0 @@
Volcanos("onimport", {help: "导入数据", list: [],
init: function(can, msg, cb, output, option) {output.innerHTML = "";
if (!msg.append || msg.append.length == 0) {
var code = can.page.Append(can, output, [{view: ["code", "div", msg.Result()]}]).code;
return typeof cb == "function" && cb(msg), code;
}
var table = can.page.AppendTable(can, output, msg, msg.append);
table.oncontextmenu = function(event) {var target = event.target; var data = target.dataset;
switch (event.target.tagName) {
case "SPAN":
can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {
var id = data.id;
can.run(event, [id, cmd], function(msg) {
can.onimport.init(can, msg, cb, output, option)
can.user.toast(cmd+"成功");
}, true)
}))
event.stopPropagation()
event.preventDefault()
break
case "TH":
case "TR":
case "TABLE":
}
}
return typeof cb == "function" && cb(msg), table;
},
})
Volcanos("onaction", {help: "组件交互", list: [],
})
Volcanos("onchoice", {help: "组件菜单", list: [],
})
Volcanos("ondetail", {help: "组件详情", list: [],
})
Volcanos("onexport", {help: "导出数据", list: [],
})

View File

@ -4,482 +4,104 @@ import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"encoding/csv"
"strings"
"time"
) )
func DateZero(m *ice.Message, day time.Time) time.Time { const (
_, z := day.Zone() TASK = "task"
day = day.Truncate(time.Hour * 24).Add(-time.Duration(z) * time.Second) ZONE = "zone"
return day )
}
func ShowDay(m *ice.Message, day time.Time) string { const (
if day.Day() == 1 { StatusPrepare = "prepare"
if day.Month() == 1 { StatusProcess = "process"
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d年</span>`, StatusCancel = "cancel"
day.Year(), day.Month(), day.Day(), day.Year()) StatusFinish = "finish"
} else { )
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d月</span>`,
day.Year(), day.Month(), day.Day(), day.Month()) func _task_list(m *ice.Message, zone string, id string, field ...interface{}) {
m.Richs(TASK, nil, kit.Select("*", zone), func(key string, val map[string]interface{}) {
if zone = kit.Format(kit.Value(val, "meta.zone")); id == "" {
m.Grows(TASK, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
m.Push(zone, value, []string{"time"})
m.Push("zone", zone)
m.Push(zone, value, []string{"id", "status", "name", "text"})
})
return
} }
} m.Grows(TASK, kit.Keys("hash", key), "id", id, func(index int, value map[string]interface{}) {
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d</span>`, m.Push("detail", value)
day.Year(), day.Month(), day.Day(), day.Day()) })
})
}
func _task_create(m *ice.Message, zone string) {
m.Rich(TASK, nil, kit.Data(ZONE, zone))
m.Log_CREATE("zone", zone)
}
func _task_insert(m *ice.Message, zone, kind, name, text, begin_time, close_time string, arg ...string) {
m.Richs(TASK, nil, zone, func(key string, value map[string]interface{}) {
id := m.Grow(TASK, kit.Keys("hash", key), kit.Dict(
kit.MDB_TYPE, kind, kit.MDB_NAME, name, kit.MDB_TEXT, text,
"begin_time", begin_time, "close_time", begin_time, "status", StatusPrepare,
kit.MDB_EXTRA, kit.Dict(arg),
))
m.Log_INSERT("zone", zone, "id", id, "type", kind, "name", name)
m.Echo("%d", id)
})
}
func _task_modify(m *ice.Message, zone, id, pro, set, old string) {
m.Richs(TASK, nil, kit.Select("*", zone), func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys("hash", key), "id", id, func(index int, value map[string]interface{}) {
m.Log_MODIFY("zone", zone, "id", id, "key", pro, "value", set, "old", old)
kit.Value(value, pro, set)
})
})
}
func _task_delete(m *ice.Message, zone, id string) {
m.Richs(TASK, nil, kit.Select("*", zone), func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys("hash", key), "id", id, func(index int, value map[string]interface{}) {
m.Log_DELETE("zone", zone, "id", id)
kit.Value(value, "status", "cancel")
})
})
}
func _task_remove(m *ice.Message, zone string) {
} }
var Index = &ice.Context{Name: "team", Help: "团队中心", var Index = &ice.Context{Name: "team", Help: "团队中心",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{
"task": {Name: "task", Help: "任务", Value: kit.Data(kit.MDB_SHORT, "zone")}, TASK: {Name: "task", Help: "task", Value: kit.Data(kit.MDB_SHORT, "zone")},
"plan": {Name: "plan", Help: "计划", Value: kit.Data(kit.MDB_SHORT, "zone",
"head", []interface{}{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}, "template", kit.Dict(
"day", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.status}} {{.name}}: {{.text}}</div>`,
"week", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"month", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"year", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.name}}: {{.text}}</div>`,
),
)},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
m.Load() ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("task") }},
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("task")
}},
"task": {Name: "task [zone=auto [id=auto]] auto", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { TASK: {Name: "task zone=auto id=auto auto", Help: "任务", Action: map[string]*ice.Action{
if m.Option("_action") == "保存" { "modify": {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
arg = []string{"action", "export"} _task_modify(m, m.Option("zone"), m.Option("id"), arg[0], arg[1], arg[2])
} }},
"delete": {Name: "delete key value", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 && arg[0] == "action" { _task_delete(m, m.Option("zone"), m.Option("id"))
switch arg[1] { }},
case "export": }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 导出数据 if len(arg) < 3 {
m.Option("cache.limit", -2) _task_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1))
if f, p, e := kit.Create(kit.Select("usr/local/task.csv", arg, 2)); m.Assert(e) {
defer f.Close()
w := csv.NewWriter(f)
defer w.Flush()
w.Write([]string{"begin_time", "close_time", "status", "type", "name", "text", "extra", "zone"})
m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, zone map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, task map[string]interface{}) {
w.Write([]string{
kit.Format(task["begin_time"]),
kit.Format(task["close_time"]),
kit.Format(task["status"]),
kit.Format(task["type"]),
kit.Format(task["name"]),
kit.Format(task["text"]),
kit.Format(task["extra"]),
kit.Format(kit.Value(zone, "meta.zone")),
})
})
})
m.Log(ice.LOG_EXPORT, "%s", p)
m.Cmdy(ice.WEB_STORY, "catch", "csv", p)
}
case "import":
// 导入数据
m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) {
item := kit.Dict("time", data["time"],
"type", data["type"], "name", data["name"], "text", data["text"], "extra", kit.UnMarshal(data["extra"]),
"begin_time", data["begin_time"], "close_time", data["close_time"], "status", data["status"],
)
if m.Richs(cmd, nil, data["zone"], nil) == nil {
// 添加领域
m.Log(ice.LOG_CREATE, "zone: %s", data["zone"])
m.Rich(cmd, nil, kit.Data("zone", data["zone"]))
}
m.Richs(cmd, nil, data["zone"], func(key string, value map[string]interface{}) {
// 添加任务
n := m.Grow(cmd, kit.Keys("hash", key), item)
m.Log(ice.LOG_IMPORT, "%s: %d %s: %s", data["zone"], n, data["type"], data["name"])
})
})
case "modify":
// 任务修改
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 6), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3])
kit.Value(current, arg[2], arg[3])
})
})
case "process":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
if kit.Format(kit.Value(current, "status")) == "prepare" {
m.Log(ice.LOG_MODIFY, "%s: %s %s: %s->%s", key, index, kit.Value(current, "status"), "status", "process")
kit.Value(current, "begin_time", m.Time())
kit.Value(current, "status", "process")
m.Echo(arg[1])
}
})
})
case "finish", "cancel":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, "status"), "status", arg[1])
kit.Value(current, "close_time", m.Time())
kit.Value(current, "status", arg[1])
m.Echo(arg[1])
})
})
}
return return
} }
if len(arg) < 5 { if m.Richs(TASK, nil, arg[0], nil) == nil {
m.Richs(cmd, nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { _task_create(m, arg[0])
if len(arg) == 0 { }
// 分类列表 if len(arg) == 5 {
m.Push(key, value["meta"], []string{"time", "count", "zone"}) arg = append(arg, m.Time())
return }
} if len(arg) == 6 {
arg = append(arg, m.Time("1h"))
field := []string{"begin_time", "id", "status", "type", "name", "text"}
if len(arg) == 1 {
// 任务列表
m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
m.Push("", value, field)
})
} else if len(arg) == 2 {
// 任务详情
m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) {
m.Push("detail", value)
})
} else {
name, value := "type", arg[2]
switch len(arg) {
case 3:
// 分类查询
name, value = "type", arg[2]
case 4:
// 名称查询
name, value = "name", arg[3]
}
m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) {
m.Push("", value, field)
})
}
m.Sort("time", "time_r")
})
return
} }
if m.Richs(cmd, nil, arg[0], nil) == nil { _task_insert(m, arg[0], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7:]...)
// 添加分类
m.Rich(cmd, nil, kit.Data("zone", arg[0]))
m.Log(ice.LOG_CREATE, "zone: %s", arg[0])
}
m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) {
// 词汇统计
web.Count(m, cmd, "meta.word.type", arg[2])
web.Count(m, cmd, "meta.word.name", arg[3])
web.Count(m, cmd, "meta.word.text", arg[4])
// 数据结构
extra := kit.Dict()
data := kit.Dict(
kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4],
"begin_time", kit.Select(m.Time(), m.Option("begin_time")), "close_time", kit.Select(m.Time(), m.Option("begin_time")), "status", "prepare",
"extra", extra,
)
// 扩展字段
for i := 5; i < len(arg); i += 2 {
switch arg[i] {
case "begin_time", "close_time", "status":
kit.Value(data, arg[i], arg[i+1])
default:
kit.Value(extra, arg[i], arg[i+1])
}
}
// 添加任务
n := m.Grow(cmd, kit.Keys("hash", key), data)
m.Echo("%s: %d", kit.Value(value, "meta.zone"), n)
})
}},
"plan": {Name: "plan scale:select=day|week|month|year begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict(
"display", "/plugin/local/team/plan.js", "detail", []string{"process", "finish", "cancel"},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 起始日期
first := time.Now()
if len(arg) > 1 {
first = time.Unix(int64(kit.Time(arg[1])), 0)
}
first = DateZero(m, first)
// 结束日期
last := time.Now()
if len(arg) > 2 {
last = time.Unix(int64(kit.Time(arg[2])), 0)
}
last = DateZero(m, last)
m.Option("cache.limit", -1)
switch head := kit.Simple(m.Confv(cmd, "meta.head")); arg[0] {
case "action":
switch arg[1] {
case "insert":
// 创建任务
m.Cmdy("task", arg[2], "", arg[3:])
default:
// 其它操作
m.Cmdy("task", arg)
}
case "day":
// 日计划
for i := 6; i < 24; i++ {
m.Push("hour", kit.Format("%02d", i))
m.Push("task", "")
m.Push("_id", "")
m.Push("_zone", "")
}
match := first.Format("2006-01-02")
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("day", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if now := kit.Format(value["begin_time"]); strings.Split(now, " ")[0] == match {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("hour", strings.Split(now, " ")[1][:2])
m.Push("task", string(b))
m.Push("_id", value["id"])
m.Push("_zone", key)
}
})
})
m.Sort("hour", "int")
case "week":
// 周计划
first = first.Add(-time.Duration((int64(first.Hour())*int64(time.Hour) + int64(first.Minute())*int64(time.Minute) + int64(first.Second())*int64(time.Second))))
one := first.AddDate(0, 0, -int(first.Weekday()))
end := first.AddDate(0, 0, 7-int(first.Weekday()))
// 查询任务
name := map[int][]string{}
list := map[int][]map[string]interface{}{}
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if t.After(one) && t.Before(end) {
index := t.Hour()*10 + int(t.Weekday())
list[index] = append(list[index], value)
name[index] = append(name[index], key)
}
}
})
})
// 展示任务
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("week", m.Option("template"))))
for i := 6; i < 24; i++ {
m.Push("hour", kit.Format("%02d", i))
for t := one; t.Before(end); t = t.AddDate(0, 0, 1) {
index := i*10 + int(t.Weekday())
note := []string{}
for i, v := range list[index] {
b, _ := kit.Render(kit.Format(template, name[index][i]), v)
note = append(note, string(b))
}
m.Push(head[int(t.Weekday())], strings.Join(note, ""))
}
}
case "month":
fallthrough
case "months":
// 月计划
one := first.AddDate(0, 0, -first.Day()+1)
end := last.AddDate(0, 1, -last.Day()+1)
template := m.Conf("plan", "meta.template.month")
// 查询任务
name := map[string][]string{}
list := map[string][]map[string]interface{}{}
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if index := t.Format("2006-01-02"); t.After(one) && t.Before(end) {
list[index] = append(list[index], value)
name[index] = append(name[index], key)
}
}
})
})
// 上月结尾
last := one.AddDate(0, 0, -int(one.Weekday()))
for day := last; day.Before(one); day = day.AddDate(0, 0, 1) {
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
// 本月日期
for day := one; day.Before(end); day = day.AddDate(0, 0, 1) {
note := []string{ShowDay(m, day)}
index := day.Format("2006-01-02")
for i, v := range list[index] {
b, _ := kit.Render(kit.Format(template, name[index][i]), v)
note = append(note, string(b))
// note = append(note, kit.Format(`%s: %s`, v["name"], v["text"]))
}
if len(note) > 1 {
note[0] = kit.Format(`%s<sup class="more">%d</sup>`, note[0], len(note)-1)
} else {
note[0] = kit.Format(`%s<sup class="less">%s</sup>`, note[0], "")
}
if arg[0] == "month" {
m.Push(head[int(day.Weekday())], strings.Join(note, ""))
} else {
m.Push(head[int(day.Weekday())], note[0])
}
}
// 下月开头
tail := end.AddDate(0, 0, 6-int(end.Weekday())+1)
for day := end; end.Weekday() != 0 && day.Before(tail); day = day.AddDate(0, 0, 1) {
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
case "year":
// 年计划
for i := 1; i < 13; i++ {
m.Push("month", kit.Format("%02d", i))
m.Push("task", "")
}
// 查询任务
match := first.Format("2006")
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if now := kit.Format(value["begin_time"]); now[0:4] == match && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("month", now[5:7])
m.Push("task", string(b))
}
})
})
m.Sort("month", "int")
case "long":
// 长计划
one := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-01-01", first.Year()-5), arg, 1))), 0)
end := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-12-31", first.Year()+5), arg, 2))), 0)
for day := one; day.Before(end); day = day.AddDate(1, 0, 0) {
m.Push("year", day.Year())
m.Push("task", "")
}
// 查询任务
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if t.After(one) && t.Before(end) && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("year", t.Year())
m.Push("task", string(b))
}
}
})
})
m.Sort("year", "int")
}
}},
"stat": {Name: "stat begin_time=@date end_time=@date auto", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
begin_time := kit.Time(kit.Select("1990-07-30", arg, 0))
end_time := kit.Time(kit.Select("1990-07-30", arg, 1))
now_time := kit.Time(m.Time())
m.Option("cache.limit", -1)
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
stat := map[string]int{}
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if len(arg) > 1 && kit.Time(kit.Format(value["begin_time"])) > end_time {
return
}
if len(arg) > 0 && kit.Time(kit.Format(value["begin_time"])) < begin_time {
return
}
if stat[kit.Format(value["status"])] += 1; value["status"] != "prepare" {
use := kit.Time(kit.Format(value["close_time"])) - kit.Time(kit.Format(value["begin_time"]))
if value["status"] == "process" {
use = now_time - kit.Time(kit.Format(value["begin_time"]))
}
stat["sum"] += use
if use > stat["max"] {
stat["max"] = use
}
if use < stat["min"] {
stat["min"] = use
}
}
stat["total"] += 1
})
m.Push("zone", kit.Value(value, "meta.zone"))
for _, k := range []string{"prepare", "process", "finish", "total"} {
m.Push(k, stat[k])
}
m.Push("sum", kit.FmtTime(int64(stat["sum"])*int64(time.Second)))
if stat["finish"] == 0 {
stat["finish"] = 1
}
m.Push("avg", kit.FmtTime(int64(stat["sum"]/stat["finish"])*int64(time.Second)))
m.Push("min", kit.FmtTime(int64(stat["min"])*int64(time.Second)))
m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second)))
})
}},
"miss": {Name: "miss zone=@key type=@key name=@key 添加:button text:textarea @begin_time=@date", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "input":
// 输入补全
switch arg[2] {
case "zone":
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Push("zone", kit.Value(value, "meta.zone"))
m.Push("count", kit.Value(value, "meta.count"))
})
case "type", "name":
m.Confm("task", kit.Keys("meta.word", arg[2]), func(key string, value string) {
m.Push(arg[2], key)
m.Push("count", value)
})
}
m.Sort("count", "int_r")
return
}
}
if len(arg) < 2 {
// 查询任务
m.Cmdy("task", arg)
return
}
// 创建任务
m.Cmdy("task", arg[0], "", arg[1:])
}}, }},
"plan": {Name: "plan", Help: "plan"},
"miss": {Name: "miss", Help: "miss"},
}, },
} }

8
core/team/team.js Normal file
View File

@ -0,0 +1,8 @@
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._target = "",
},
})
Volcanos("onaction", {help: "组件交互", list: [],
})
Volcanos("onexport", {help: "导出数据", list: [],
})

486
core/team/team_old.old Normal file
View File

@ -0,0 +1,486 @@
package team
import (
"github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
"github.com/shylinux/toolkits"
"encoding/csv"
"strings"
"time"
)
func DateZero(m *ice.Message, day time.Time) time.Time {
_, z := day.Zone()
day = day.Truncate(time.Hour * 24).Add(-time.Duration(z) * time.Second)
return day
}
func ShowDay(m *ice.Message, day time.Time) string {
if day.Day() == 1 {
if day.Month() == 1 {
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d年</span>`,
day.Year(), day.Month(), day.Day(), day.Year())
} else {
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d月</span>`,
day.Year(), day.Month(), day.Day(), day.Month())
}
}
return kit.Format(`<span data-year="%d" data-month="%d" data-day="%d">%d</span>`,
day.Year(), day.Month(), day.Day(), day.Day())
}
var Index = &ice.Context{Name: "team_old", Help: "团队中心",
Caches: map[string]*ice.Cache{},
Configs: map[string]*ice.Config{
"task": {Name: "task", Help: "任务", Value: kit.Data(kit.MDB_SHORT, "zone")},
"plan": {Name: "plan", Help: "计划", Value: kit.Data(kit.MDB_SHORT, "zone",
"head", []interface{}{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}, "template", kit.Dict(
"day", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.status}} {{.name}}: {{.text}}</div>`,
"week", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"month", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}" title="{{.text}}">{{.name}}</div>`,
"year", `<div class="task {{.status}}" data-zone="%s" data-id="{{.id}}" data-begin_time="{{.begin_time}}">{{.name}}: {{.text}}</div>`,
),
)},
},
Commands: map[string]*ice.Command{
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Load()
}},
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Save("task")
}},
"task": {Name: "task [zone=auto [id=auto]] auto", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if m.Option("_action") == "保存" {
arg = []string{"action", "export"}
}
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "export":
// 导出数据
m.Option("cache.limit", -2)
if f, p, e := kit.Create(kit.Select("usr/local/task.csv", arg, 2)); m.Assert(e) {
defer f.Close()
w := csv.NewWriter(f)
defer w.Flush()
w.Write([]string{"begin_time", "close_time", "status", "type", "name", "text", "extra", "zone"})
m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, zone map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, task map[string]interface{}) {
w.Write([]string{
kit.Format(task["begin_time"]),
kit.Format(task["close_time"]),
kit.Format(task["status"]),
kit.Format(task["type"]),
kit.Format(task["name"]),
kit.Format(task["text"]),
kit.Format(task["extra"]),
kit.Format(kit.Value(zone, "meta.zone")),
})
})
})
m.Log(ice.LOG_EXPORT, "%s", p)
m.Cmdy(ice.WEB_STORY, "catch", "csv", p)
}
case "import":
// 导入数据
m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) {
item := kit.Dict("time", data["time"],
"type", data["type"], "name", data["name"], "text", data["text"], "extra", kit.UnMarshal(data["extra"]),
"begin_time", data["begin_time"], "close_time", data["close_time"], "status", data["status"],
)
if m.Richs(cmd, nil, data["zone"], nil) == nil {
// 添加领域
m.Log(ice.LOG_CREATE, "zone: %s", data["zone"])
m.Rich(cmd, nil, kit.Data("zone", data["zone"]))
}
m.Richs(cmd, nil, data["zone"], func(key string, value map[string]interface{}) {
// 添加任务
n := m.Grow(cmd, kit.Keys("hash", key), item)
m.Log(ice.LOG_IMPORT, "%s: %d %s: %s", data["zone"], n, data["type"], data["name"])
})
})
case "modify":
// 任务修改
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 6), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3])
kit.Value(current, arg[2], arg[3])
})
})
case "process":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
if kit.Format(kit.Value(current, "status")) == "prepare" {
m.Log(ice.LOG_MODIFY, "%s: %s %s: %s->%s", key, index, kit.Value(current, "status"), "status", "process")
kit.Value(current, "begin_time", m.Time())
kit.Value(current, "status", "process")
m.Echo(arg[1])
}
})
})
case "finish", "cancel":
m.Richs(cmd, nil, kit.Select(m.Option("zone"), arg, 3), func(key string, account map[string]interface{}) {
m.Grows(cmd, kit.Keys("hash", key), "id", kit.Select(m.Option("id"), arg, 2), func(index int, current map[string]interface{}) {
m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, "status"), "status", arg[1])
kit.Value(current, "close_time", m.Time())
kit.Value(current, "status", arg[1])
m.Echo(arg[1])
})
})
}
return
}
if len(arg) < 5 {
m.Richs(cmd, nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) {
if len(arg) == 0 {
// 分类列表
m.Push(key, value["meta"], []string{"time", "count", "zone"})
return
}
field := []string{"begin_time", "id", "status", "type", "name", "text"}
if len(arg) == 1 {
// 任务列表
m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
m.Push("", value, field)
})
} else if len(arg) == 2 {
// 任务详情
m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) {
m.Push("detail", value)
})
} else {
name, value := "type", arg[2]
switch len(arg) {
case 3:
// 分类查询
name, value = "type", arg[2]
case 4:
// 名称查询
name, value = "name", arg[3]
}
m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) {
m.Push("", value, field)
})
}
m.Sort("time", "time_r")
})
return
}
if m.Richs(cmd, nil, arg[0], nil) == nil {
// 添加分类
m.Rich(cmd, nil, kit.Data("zone", arg[0]))
m.Log(ice.LOG_CREATE, "zone: %s", arg[0])
}
m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) {
// 词汇统计
web.Count(m, cmd, "meta.word.type", arg[2])
web.Count(m, cmd, "meta.word.name", arg[3])
web.Count(m, cmd, "meta.word.text", arg[4])
// 数据结构
extra := kit.Dict()
data := kit.Dict(
kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4],
"begin_time", kit.Select(m.Time(), m.Option("begin_time")), "close_time", kit.Select(m.Time(), m.Option("begin_time")), "status", "prepare",
"extra", extra,
)
// 扩展字段
for i := 5; i < len(arg); i += 2 {
switch arg[i] {
case "begin_time", "close_time", "status":
kit.Value(data, arg[i], arg[i+1])
default:
kit.Value(extra, arg[i], arg[i+1])
}
}
// 添加任务
n := m.Grow(cmd, kit.Keys("hash", key), data)
m.Echo("%s: %d", kit.Value(value, "meta.zone"), n)
})
}},
"plan": {Name: "plan scale:select=day|week|month|year begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict(
"display", "/plugin/local/team/plan.js", "detail", []string{"process", "finish", "cancel"},
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
// 起始日期
first := time.Now()
if len(arg) > 1 {
first = time.Unix(int64(kit.Time(arg[1])), 0)
}
first = DateZero(m, first)
// 结束日期
last := time.Now()
if len(arg) > 2 {
last = time.Unix(int64(kit.Time(arg[2])), 0)
}
last = DateZero(m, last)
m.Option("cache.limit", -1)
switch head := kit.Simple(m.Confv(cmd, "meta.head")); arg[0] {
case "action":
switch arg[1] {
case "insert":
// 创建任务
m.Cmdy("task", arg[2], "", arg[3:])
default:
// 其它操作
m.Cmdy("task", arg)
}
case "day":
// 日计划
for i := 6; i < 24; i++ {
m.Push("hour", kit.Format("%02d", i))
m.Push("task", "")
m.Push("_id", "")
m.Push("_zone", "")
}
match := first.Format("2006-01-02")
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("day", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if now := kit.Format(value["begin_time"]); strings.Split(now, " ")[0] == match {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("hour", strings.Split(now, " ")[1][:2])
m.Push("task", string(b))
m.Push("_id", value["id"])
m.Push("_zone", key)
}
})
})
m.Sort("hour", "int")
case "week":
// 周计划
first = first.Add(-time.Duration((int64(first.Hour())*int64(time.Hour) + int64(first.Minute())*int64(time.Minute) + int64(first.Second())*int64(time.Second))))
one := first.AddDate(0, 0, -int(first.Weekday()))
end := first.AddDate(0, 0, 7-int(first.Weekday()))
// 查询任务
name := map[int][]string{}
list := map[int][]map[string]interface{}{}
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if t.After(one) && t.Before(end) {
index := t.Hour()*10 + int(t.Weekday())
list[index] = append(list[index], value)
name[index] = append(name[index], key)
}
}
})
})
// 展示任务
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("week", m.Option("template"))))
for i := 6; i < 24; i++ {
m.Push("hour", kit.Format("%02d", i))
for t := one; t.Before(end); t = t.AddDate(0, 0, 1) {
index := i*10 + int(t.Weekday())
note := []string{}
for i, v := range list[index] {
b, _ := kit.Render(kit.Format(template, name[index][i]), v)
note = append(note, string(b))
}
m.Push(head[int(t.Weekday())], strings.Join(note, ""))
}
}
case "month":
fallthrough
case "months":
// 月计划
one := first.AddDate(0, 0, -first.Day()+1)
end := last.AddDate(0, 1, -last.Day()+1)
template := m.Conf("plan", "meta.template.month")
// 查询任务
name := map[string][]string{}
list := map[string][]map[string]interface{}{}
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if index := t.Format("2006-01-02"); t.After(one) && t.Before(end) {
list[index] = append(list[index], value)
name[index] = append(name[index], key)
}
}
})
})
// 上月结尾
last := one.AddDate(0, 0, -int(one.Weekday()))
for day := last; day.Before(one); day = day.AddDate(0, 0, 1) {
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
// 本月日期
for day := one; day.Before(end); day = day.AddDate(0, 0, 1) {
note := []string{ShowDay(m, day)}
index := day.Format("2006-01-02")
for i, v := range list[index] {
b, _ := kit.Render(kit.Format(template, name[index][i]), v)
note = append(note, string(b))
// note = append(note, kit.Format(`%s: %s`, v["name"], v["text"]))
}
if len(note) > 1 {
note[0] = kit.Format(`%s<sup class="more">%d</sup>`, note[0], len(note)-1)
} else {
note[0] = kit.Format(`%s<sup class="less">%s</sup>`, note[0], "")
}
if arg[0] == "month" {
m.Push(head[int(day.Weekday())], strings.Join(note, ""))
} else {
m.Push(head[int(day.Weekday())], note[0])
}
}
// 下月开头
tail := end.AddDate(0, 0, 6-int(end.Weekday())+1)
for day := end; end.Weekday() != 0 && day.Before(tail); day = day.AddDate(0, 0, 1) {
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
case "year":
// 年计划
for i := 1; i < 13; i++ {
m.Push("month", kit.Format("%02d", i))
m.Push("task", "")
}
// 查询任务
match := first.Format("2006")
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if now := kit.Format(value["begin_time"]); now[0:4] == match && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("month", now[5:7])
m.Push("task", string(b))
}
})
})
m.Sort("month", "int")
case "long":
// 长计划
one := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-01-01", first.Year()-5), arg, 1))), 0)
end := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-12-31", first.Year()+5), arg, 2))), 0)
for day := one; day.Before(end); day = day.AddDate(1, 0, 0) {
m.Push("year", day.Year())
m.Push("task", "")
}
// 查询任务
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if t.After(one) && t.Before(end) && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("year", t.Year())
m.Push("task", string(b))
}
}
})
})
m.Sort("year", "int")
}
}},
"stat": {Name: "stat begin_time=@date end_time=@date auto", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
begin_time := kit.Time(kit.Select("1990-07-30", arg, 0))
end_time := kit.Time(kit.Select("1990-07-30", arg, 1))
now_time := kit.Time(m.Time())
m.Option("cache.limit", -1)
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
stat := map[string]int{}
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if len(arg) > 1 && kit.Time(kit.Format(value["begin_time"])) > end_time {
return
}
if len(arg) > 0 && kit.Time(kit.Format(value["begin_time"])) < begin_time {
return
}
if stat[kit.Format(value["status"])] += 1; value["status"] != "prepare" {
use := kit.Time(kit.Format(value["close_time"])) - kit.Time(kit.Format(value["begin_time"]))
if value["status"] == "process" {
use = now_time - kit.Time(kit.Format(value["begin_time"]))
}
stat["sum"] += use
if use > stat["max"] {
stat["max"] = use
}
if use < stat["min"] {
stat["min"] = use
}
}
stat["total"] += 1
})
m.Push("zone", kit.Value(value, "meta.zone"))
for _, k := range []string{"prepare", "process", "finish", "total"} {
m.Push(k, stat[k])
}
m.Push("sum", kit.FmtTime(int64(stat["sum"])*int64(time.Second)))
if stat["finish"] == 0 {
stat["finish"] = 1
}
m.Push("avg", kit.FmtTime(int64(stat["sum"]/stat["finish"])*int64(time.Second)))
m.Push("min", kit.FmtTime(int64(stat["min"])*int64(time.Second)))
m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second)))
})
}},
"miss": {Name: "miss zone=@key type=@key name=@key 添加:button text:textarea @begin_time=@date", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "input":
// 输入补全
switch arg[2] {
case "zone":
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Push("zone", kit.Value(value, "meta.zone"))
m.Push("count", kit.Value(value, "meta.count"))
})
case "type", "name":
m.Confm("task", kit.Keys("meta.word", arg[2]), func(key string, value string) {
m.Push(arg[2], key)
m.Push("count", value)
})
}
m.Sort("count", "int_r")
return
}
}
if len(arg) < 2 {
// 查询任务
m.Cmdy("task", arg)
return
}
// 创建任务
m.Cmdy("task", arg[0], "", arg[1:])
}},
},
}
func init() { web.Index.Register(Index, &web.Frame{}) }

View File

@ -10,51 +10,48 @@ import (
"strings" "strings"
) )
const INNER = "inner" const (
const QRCODE = "qrcode" INNER = "inner"
const VEDIO = "vedio" QRCODE = "qrcode"
VEDIO = "vedio"
)
func _inner_protect(m *ice.Message, name string) bool {
ls := strings.Split(name, "/")
return !m.Right(ls) && m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true"
}
func _inner_binary(m *ice.Message, name string) bool {
return m.Conf(INNER, kit.Keys("meta.binary", _inner_ext(name))) == "true"
}
func _inner_ext(name string) string { func _inner_ext(name string) string {
return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), ".")))
} }
func _inner_binary(m *ice.Message, name string) bool { func _inner_sub(m *ice.Message, action string, name string, arg ...string) bool {
p := _inner_ext(name) if _inner_protect(m, name) {
if m.Conf(INNER, kit.Keys("meta.binary", p)) == "true" { m.Push("file", "../")
return true return true
} }
return false
} p := _inner_ext(name)
func _inner_protect(m *ice.Message, name string) bool { if m.Cmdy(kit.Keys(p, action), name, arg); len(m.Resultv()) > 0 && m.Result(0) != "warn: " {
if ls := strings.Split(name, "/"); !m.Right(ls) && m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true" {
return true return true
} }
return false return false
} }
func _inner_list(m *ice.Message, name string) { func _inner_list(m *ice.Message, name string) {
if _inner_protect(m, name) { if _inner_sub(m, "list", name) {
m.Push("file", "../")
return
}
p := _inner_ext(name)
if m.Cmdy(kit.Keys(p, "list"), name); len(m.Resultv()) > 0 && m.Result(0) != "warn: " {
return return
} }
if m.Set(ice.MSG_RESULT); strings.HasSuffix(name, "/") || !_inner_binary(m, name) { if m.Set(ice.MSG_RESULT); strings.HasSuffix(name, "/") || !_inner_binary(m, name) {
m.Cmdy("nfs.dir", name, "file size time") m.Cmdy("nfs.dir", name, "file size time")
} else {
m.Echo(name)
}
}
func _inner_save(m *ice.Message, name, text string) {
if _inner_protect(m, name) {
m.Echo("no right")
return return
} }
m.Echo(name)
if m.Cmdy(kit.Keys(strings.TrimPrefix(path.Ext(name), "."), "save"), name, text); len(m.Resultv()) > 0 { }
func _inner_save(m *ice.Message, name, text string) {
if _inner_sub(m, "save", name) {
return return
} }
@ -62,17 +59,16 @@ func _inner_save(m *ice.Message, name, text string) {
defer f.Close() defer f.Close()
m.Cmd(web.FAVOR, "inner.save", "shell", name, text) m.Cmd(web.FAVOR, "inner.save", "shell", name, text)
if n, e := f.WriteString(text); m.Assert(e) { if n, e := f.WriteString(text); m.Assert(e) {
m.Logs(ice.LOG_EXPORT, "file", name, "size", n) m.Log_EXPORT("file", name, "size", n)
} }
} }
} }
func _inner_plug(m *ice.Message, name string) { func _inner_plug(m *ice.Message, name string) {
p := _inner_ext(name) if _inner_sub(m, "plug", name) {
if msg := m.Cmd(kit.Keys(p, "plug"), name); m != msg && msg.Hand {
m.Copy(msg)
return return
} }
p := _inner_ext(name)
if ls := m.Confv(INNER, kit.Keys("meta.plug", p)); ls != nil { if ls := m.Confv(INNER, kit.Keys("meta.plug", p)); ls != nil {
m.Echo(kit.Format(ls)) m.Echo(kit.Format(ls))
return return
@ -81,17 +77,11 @@ func _inner_plug(m *ice.Message, name string) {
m.Echo("{}") m.Echo("{}")
} }
func _inner_show(m *ice.Message, name string) { func _inner_show(m *ice.Message, name string) {
if _inner_protect(m, name) { if _inner_sub(m, "show", name) {
m.Push("file", "../")
return return
} }
p := _inner_ext(name) p := _inner_ext(name)
if msg := m.Cmd(kit.Keys(p, "show"), name); m != msg && msg.Hand {
m.Copy(msg)
return
}
if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", p))); len(ls) > 0 { if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", p))); len(ls) > 0 {
m.Cmdy(ice.CLI_SYSTEM, ls, name) m.Cmdy(ice.CLI_SYSTEM, ls, name)
m.Set(ice.MSG_APPEND) m.Set(ice.MSG_APPEND)
@ -123,7 +113,10 @@ func init() {
"protect", kit.Dict("etc", "true", "var", "true", "usr", "true"), "protect", kit.Dict("etc", "true", "var", "true", "usr", "true"),
"binary", kit.Dict("bin", "true", "gz", "true"), "binary", kit.Dict("bin", "true", "gz", "true"),
"plug", kit.Dict( "plug", kit.Dict(
"py", kit.Dict("display", true, "profile", true), "py", kit.Dict(
"prefix", kit.Dict("#", "comment"),
"keyword", kit.Dict("print", "keyword"),
),
"md", kit.Dict("display", true, "profile", true), "md", kit.Dict("display", true, "profile", true),
"csv", kit.Dict("display", true), "csv", kit.Dict("display", true),
), ),
@ -133,30 +126,18 @@ func init() {
"go", []string{"go", "run"}, "go", []string{"go", "run"},
"js", []string{"node"}, "js", []string{"node"},
), ),
kit.MDB_SHORT, INNER,
)}, )},
}, },
Commands: map[string]*ice.Command{ Commands: map[string]*ice.Command{
INNER: {Name: "inner path=auto name=auto auto", Help: "编辑器", Meta: map[string]interface{}{ INNER: {Name: "inner path=auto name=auto auto", Help: "编辑器", Meta: map[string]interface{}{
"display": "/plugin/inner.js", "style": "editor", "display": "/plugin/inner.js", "style": "editor",
}, Action: map[string]*ice.Action{ }, Action: map[string]*ice.Action{
"history": {Name: "history path name", Help: "历史", Hand: func(m *ice.Message, arg ...string) { "cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
msg := m.Spawn() if m.Cmdy(kit.Split(arg[0])); !m.Hand {
web.StoryHistory(msg, path.Join("./", arg[0], arg[1])) m.Cmdy(ice.CLI_SYSTEM, kit.Split(arg[0]))
m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
if len(arg) > 2 && arg[2] != "" {
msg = m.Spawn()
web.StoryIndex(msg, arg[2])
m.Echo(msg.Result())
} }
}}, }},
"commit": {Name: "commit path name", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
web.StoryCatch(m, "", path.Join("./", arg[0], arg[1]))
}},
"record": {Name: "record", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
web.StoryAdd(m, "display", path.Join("./", m.Option("path"), m.Option("name"))+".display", m.Option("display"))
}},
"favor": {Name: "favor", Help: "收藏", Hand: func(m *ice.Message, arg ...string) { "favor": {Name: "favor", Help: "收藏", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) { m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
m.Push("image", kit.Format(`<a title="%s" href="%s" target="_blank"><img src="%s" width=200></a>`, m.Push("image", kit.Format(`<a title="%s" href="%s" target="_blank"><img src="%s" width=200></a>`,
@ -164,29 +145,8 @@ func init() {
m.Push("video", kit.Format(`<video src="%s" controls></video>`, value["text"])) m.Push("video", kit.Format(`<video src="%s" controls></video>`, value["text"]))
}) })
}}, }},
"recover": {Name: "recover", Help: "复盘", Hand: func(m *ice.Message, arg ...string) { "find": {Name: "find word", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
msg := m.Spawn() web.FavorList(m, arg[0], arg[1], arg[2:]...)
web.StoryHistory(msg, path.Join("./", arg[0], arg[1])+".display")
m.Copy(msg, ice.MSG_APPEND, "time", "count", "key", "drama")
if len(arg) > 2 && arg[2] != "" {
msg = m.Spawn()
web.StoryIndex(msg, arg[2])
m.Echo(msg.Result())
}
}},
"run": {Name: "run path name", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
_inner_show(m, path.Join("./", arg[0], arg[1]))
}},
"log": {Name: "log path name", Help: "日志", Hand: func(m *ice.Message, arg ...string) {
web.FavorList(m, "inner.run", "", "time", "id", "type", "name", "text")
}},
"plug": {Name: "plug path name", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_inner_plug(m, path.Join("./", arg[0], arg[1]))
}},
"save": {Name: "save path name content", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_inner_save(m, path.Join("./", arg[0], arg[1]), kit.Select(m.Option("content"), arg, 2))
}}, }},
"upload": {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) { "upload": {Name: "upload path name", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
web.StoryWatch(m, m.Option("data"), path.Join(m.Option("path"), m.Option("name"))) web.StoryWatch(m, m.Option("data"), path.Join(m.Option("path"), m.Option("name")))
@ -194,23 +154,43 @@ func init() {
"project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) { "project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) {
_inner_list(m, path.Join("./", kit.Select("", arg, 0))+"/") _inner_list(m, path.Join("./", kit.Select("", arg, 0))+"/")
}}, }},
"find": {Name: "find word", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
web.FavorList(m, arg[0], arg[1], arg[2:]...) "history": {Name: "history path name", Help: "历史", Hand: func(m *ice.Message, arg ...string) {
}}, msg := web.StoryHistory(m.Spawn(), path.Join("./", arg[0], arg[1]))
"action": {Name: "action path", Help: "命令", Hand: func(m *ice.Message, arg ...string) { m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
if m.Cmdy(kit.Split(arg[0])); !m.Hand {
m.Cmdy(ice.CLI_SYSTEM, kit.Split(arg[0])) if len(arg) > 2 && arg[2] != "" {
m.Echo(web.StoryIndex(m.Spawn(), arg[2]).Result())
} }
}}, }},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { "commit": {Name: "commit path name", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
_inner_main(m, arg...) web.StoryCatch(m, "", path.Join("./", arg[0], arg[1]))
}}, }},
"recover": {Name: "recover", Help: "复盘", Hand: func(m *ice.Message, arg ...string) {
msg := web.StoryHistory(m.Spawn(), path.Join("./", arg[0], arg[1])+".display")
m.Copy(msg, ice.MSG_APPEND, "time", "count", "key", "drama")
"video": {Name: "video", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 2 && arg[2] != "" {
m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) { m.Echo(web.StoryIndex(m.Spawn(), arg[2]).Result())
m.Echo(`<video src="%s" controls loop></video>`, value["text"]) }
}) }},
}}, "record": {Name: "record", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
web.StoryAdd(m, "display", path.Join("./", m.Option("path"), m.Option("name"))+".display", m.Option("display"))
}},
"log": {Name: "log path name", Help: "日志", Hand: func(m *ice.Message, arg ...string) {
web.FavorList(m, "inner.run", "", "time", "id", "type", "name", "text")
}},
"run": {Name: "run path name", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
_inner_show(m, path.Join("./", arg[0], arg[1]))
}},
"plug": {Name: "plug path name", Help: "插件", Hand: func(m *ice.Message, arg ...string) {
_inner_plug(m, path.Join("./", arg[0], arg[1]))
}},
"save": {Name: "save path name content", Help: "保存", Hand: func(m *ice.Message, arg ...string) {
_inner_save(m, path.Join("./", arg[0], arg[1]), kit.Select(m.Option("content"), arg, 2))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { _inner_main(m, arg...) }},
}, },
}, nil) }, nil)
} }

View File

@ -39,6 +39,11 @@ func init() {
} }
} }
}}, }},
"video": {Name: "video", Help: "视频", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) {
m.Echo(`<video src="%s" controls loop></video>`, value["text"])
})
}},
}, },
}, nil) }, nil)

View File

@ -33,7 +33,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
} }
switch level { switch level {
case LOG_CMDS, LOG_INFO, LOG_WARN: case LOG_INFO, LOG_WARN:
default: default:
_, file, line, _ := runtime.Caller(2) _, file, line, _ := runtime.Caller(2)
ls := strings.Split(file, "/") ls := strings.Split(file, "/")

14
type.go
View File

@ -4,8 +4,6 @@
package ice package ice
import ( import (
"reflect"
kit "github.com/shylinux/toolkits" kit "github.com/shylinux/toolkits"
"encoding/json" "encoding/json"
@ -87,29 +85,25 @@ func (c *Context) Run(m *Message, cmd *Command, key string, arg ...string) *Mess
if m.Hand = true; len(arg) > 1 && action != "" && cmd.Action != nil { if m.Hand = true; len(arg) > 1 && action != "" && cmd.Action != nil {
if h, ok := cmd.Action[action]; ok { if h, ok := cmd.Action[action]; ok {
p := reflect.ValueOf(h.Hand) m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3))
m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(p.Pointer(), 3))
h.Hand(m, args...) h.Hand(m, args...)
return m return m
} }
for _, h := range cmd.Action { for _, h := range cmd.Action {
if h.Name == action || h.Help == action { if h.Name == action || h.Help == action {
p := reflect.ValueOf(h.Hand) m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3))
m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(p.Pointer(), 3))
h.Hand(m, args...) h.Hand(m, args...)
return m return m
} }
} }
if h, ok := cmd.Action["action"]; ok { if h, ok := cmd.Action["action"]; ok {
p := reflect.ValueOf(h.Hand) m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3))
m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(p.Pointer(), 3))
h.Hand(m, arg[1:]...) h.Hand(m, arg[1:]...)
return m return m
} }
} }
p := reflect.ValueOf(cmd.Hand) m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(cmd.Hand, 3))
m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(p.Pointer(), 3))
cmd.Hand(m, c, key, arg...) cmd.Hand(m, c, key, arg...)
return m return m
} }