diff --git a/base/web/story.go b/base/web/story.go index 02a4ce29..83e2f635 100644 --- a/base/web/story.go +++ b/base/web/story.go @@ -372,9 +372,9 @@ func _story_history(m *ice.Message, name string) { } } -func StoryHistory(m *ice.Message, name string) { _story_history(m, name) } -func StoryIndex(m *ice.Message, name string) { _story_index(m, name, true) } -func StoryWatch(m *ice.Message, index string, file string) { _story_watch(m, index, file) } +func StoryHistory(m *ice.Message, name string) *ice.Message { _story_history(m, name); return m } +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 StoryCatch(m *ice.Message, mime string, file string) { _story_catch(m, "catch", kit.Select(mime, strings.TrimPrefix(path.Ext(file), ".")), file, "") } diff --git a/core/chat/action.go b/core/chat/action.go index 80f54fc7..406354eb 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -81,6 +81,11 @@ func _action_order(m *ice.Message, arg ...string) { 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:]) if m.Set(ice.MSG_RESULT); !m.Right(cmds) { m.Render("status", 403, "not auth") diff --git a/core/chat/river.go b/core/chat/river.go index 60274f73..7cc38860 100644 --- a/core/chat/river.go +++ b/core/chat/river.go @@ -21,6 +21,8 @@ func _river_right(m *ice.Message, action string) bool { } 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, 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}) diff --git a/core/team/miss.js b/core/team/miss.js deleted file mode 100644 index b2b08e7e..00000000 --- a/core/team/miss.js +++ /dev/null @@ -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: [], -}) - diff --git a/core/team/team.go b/core/team/team.go index 948dfadf..22cff921 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -4,482 +4,104 @@ 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 -} +const ( + TASK = "task" + ZONE = "zone" +) -func ShowDay(m *ice.Message, day time.Time) string { - if day.Day() == 1 { - if day.Month() == 1 { - return kit.Format(`%d年`, - day.Year(), day.Month(), day.Day(), day.Year()) - } else { - return kit.Format(`%d月`, - day.Year(), day.Month(), day.Day(), day.Month()) +const ( + StatusPrepare = "prepare" + StatusProcess = "process" + StatusCancel = "cancel" + StatusFinish = "finish" +) + +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 } - } - return kit.Format(`%d`, - day.Year(), day.Month(), day.Day(), day.Day()) + m.Grows(TASK, kit.Keys("hash", key), "id", id, func(index int, value map[string]interface{}) { + m.Push("detail", value) + }) + }) +} +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: "团队中心", - 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", `
{{.status}} {{.name}}: {{.text}}
`, - "week", `
{{.name}}
`, - "month", `
{{.name}}
`, - "year", `
{{.name}}: {{.text}}
`, - ), - )}, + TASK: {Name: "task", Help: "task", Value: kit.Data(kit.MDB_SHORT, "zone")}, }, 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") - }}, + 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]) - }) - }) - } + TASK: {Name: "task zone=auto id=auto auto", Help: "任务", Action: map[string]*ice.Action{ + "modify": {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { + _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) { + _task_delete(m, m.Option("zone"), m.Option("id")) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) < 3 { + _task_list(m, kit.Select("", arg, 0), kit.Select("", 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(TASK, nil, arg[0], nil) == nil { + _task_create(m, arg[0]) + } + if len(arg) == 5 { + arg = append(arg, m.Time()) + } + if len(arg) == 6 { + arg = append(arg, m.Time("1h")) } - 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%d`, note[0], len(note)-1) - } else { - note[0] = kit.Format(`%s%s`, 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:]) + _task_insert(m, arg[0], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7:]...) }}, + "plan": {Name: "plan", Help: "plan"}, + "miss": {Name: "miss", Help: "miss"}, }, } diff --git a/core/team/team.js b/core/team/team.js new file mode 100644 index 00000000..2a9e0700 --- /dev/null +++ b/core/team/team.js @@ -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: [], +}) + diff --git a/core/team/team_old.old b/core/team/team_old.old new file mode 100644 index 00000000..92e4dd37 --- /dev/null +++ b/core/team/team_old.old @@ -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(`%d年`, + day.Year(), day.Month(), day.Day(), day.Year()) + } else { + return kit.Format(`%d月`, + day.Year(), day.Month(), day.Day(), day.Month()) + } + } + return kit.Format(`%d`, + 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", `
{{.status}} {{.name}}: {{.text}}
`, + "week", `
{{.name}}
`, + "month", `
{{.name}}
`, + "year", `
{{.name}}: {{.text}}
`, + ), + )}, + }, + 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%d`, note[0], len(note)-1) + } else { + note[0] = kit.Format(`%s%s`, 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{}) } diff --git a/core/wiki/inner.go b/core/wiki/inner.go index ef09b635..17a3e04b 100644 --- a/core/wiki/inner.go +++ b/core/wiki/inner.go @@ -10,51 +10,48 @@ import ( "strings" ) -const INNER = "inner" -const QRCODE = "qrcode" -const VEDIO = "vedio" +const ( + INNER = "inner" + 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 { return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) } -func _inner_binary(m *ice.Message, name string) bool { - p := _inner_ext(name) - if m.Conf(INNER, kit.Keys("meta.binary", p)) == "true" { +func _inner_sub(m *ice.Message, action string, name string, arg ...string) bool { + if _inner_protect(m, name) { + m.Push("file", "../") return true } - return false -} -func _inner_protect(m *ice.Message, name string) bool { - if ls := strings.Split(name, "/"); !m.Right(ls) && m.Conf(INNER, kit.Keys("meta.protect", ls[0])) == "true" { + + p := _inner_ext(name) + if m.Cmdy(kit.Keys(p, action), name, arg); len(m.Resultv()) > 0 && m.Result(0) != "warn: " { return true } return false } func _inner_list(m *ice.Message, name string) { - if _inner_protect(m, 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: " { + if _inner_sub(m, "list", name) { return } if m.Set(ice.MSG_RESULT); strings.HasSuffix(name, "/") || !_inner_binary(m, name) { 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 } - - if m.Cmdy(kit.Keys(strings.TrimPrefix(path.Ext(name), "."), "save"), name, text); len(m.Resultv()) > 0 { + m.Echo(name) +} +func _inner_save(m *ice.Message, name, text string) { + if _inner_sub(m, "save", name) { return } @@ -62,17 +59,16 @@ func _inner_save(m *ice.Message, name, text string) { defer f.Close() m.Cmd(web.FAVOR, "inner.save", "shell", name, text) 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) { - p := _inner_ext(name) - if msg := m.Cmd(kit.Keys(p, "plug"), name); m != msg && msg.Hand { - m.Copy(msg) + if _inner_sub(m, "plug", name) { return } + p := _inner_ext(name) if ls := m.Confv(INNER, kit.Keys("meta.plug", p)); ls != nil { m.Echo(kit.Format(ls)) return @@ -81,17 +77,11 @@ func _inner_plug(m *ice.Message, name string) { m.Echo("{}") } func _inner_show(m *ice.Message, name string) { - if _inner_protect(m, name) { - m.Push("file", "../") + if _inner_sub(m, "show", name) { return } 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 { m.Cmdy(ice.CLI_SYSTEM, ls, name) m.Set(ice.MSG_APPEND) @@ -123,7 +113,10 @@ func init() { "protect", kit.Dict("etc", "true", "var", "true", "usr", "true"), "binary", kit.Dict("bin", "true", "gz", "true"), "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), "csv", kit.Dict("display", true), ), @@ -133,30 +126,18 @@ func init() { "go", []string{"go", "run"}, "js", []string{"node"}, ), - kit.MDB_SHORT, INNER, )}, }, Commands: map[string]*ice.Command{ INNER: {Name: "inner path=auto name=auto auto", Help: "编辑器", Meta: map[string]interface{}{ "display": "/plugin/inner.js", "style": "editor", }, Action: map[string]*ice.Action{ - "history": {Name: "history path name", Help: "历史", Hand: func(m *ice.Message, arg ...string) { - msg := m.Spawn() - web.StoryHistory(msg, path.Join("./", arg[0], arg[1])) - 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()) + "cmd": {Name: "cmd arg", Help: "命令", Hand: func(m *ice.Message, arg ...string) { + if m.Cmdy(kit.Split(arg[0])); !m.Hand { + m.Cmdy(ice.CLI_SYSTEM, kit.Split(arg[0])) } }}, - "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) { m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) { m.Push("image", kit.Format(``, @@ -164,29 +145,8 @@ func init() { m.Push("video", kit.Format(``, value["text"])) }) }}, - "recover": {Name: "recover", Help: "复盘", Hand: func(m *ice.Message, arg ...string) { - msg := m.Spawn() - 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)) + "find": {Name: "find word", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + web.FavorList(m, arg[0], arg[1], arg[2:]...) }}, "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"))) @@ -194,23 +154,43 @@ func init() { "project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) { _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:]...) - }}, - "action": {Name: "action path", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - if m.Cmdy(kit.Split(arg[0])); !m.Hand { - m.Cmdy(ice.CLI_SYSTEM, kit.Split(arg[0])) + + "history": {Name: "history path name", Help: "历史", Hand: func(m *ice.Message, arg ...string) { + msg := web.StoryHistory(m.Spawn(), path.Join("./", arg[0], arg[1])) + m.Copy(msg, ice.MSG_APPEND, "time", "count", "key") + + 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) { - _inner_main(m, arg...) - }}, + "commit": {Name: "commit path name", Help: "提交", Hand: func(m *ice.Message, arg ...string) { + 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) { - m.Cmd(ice.WEB_FAVOR, arg, "extra", "extra.poster").Table(func(index int, value map[string]string, header []string) { - m.Echo(``, value["text"]) - }) - }}, + if len(arg) > 2 && arg[2] != "" { + m.Echo(web.StoryIndex(m.Spawn(), arg[2]).Result()) + } + }}, + "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) } diff --git a/core/wiki/video.go b/core/wiki/video.go index 87ca5acd..0e795504 100644 --- a/core/wiki/video.go +++ b/core/wiki/video.go @@ -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(``, value["text"]) + }) + }}, }, }, nil) diff --git a/info.go b/info.go index c655c3f2..47e6d2b0 100644 --- a/info.go +++ b/info.go @@ -33,7 +33,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message { } switch level { - case LOG_CMDS, LOG_INFO, LOG_WARN: + case LOG_INFO, LOG_WARN: default: _, file, line, _ := runtime.Caller(2) ls := strings.Split(file, "/") diff --git a/type.go b/type.go index a8aef74d..4994e807 100644 --- a/type.go +++ b/type.go @@ -4,8 +4,6 @@ package ice import ( - "reflect" - kit "github.com/shylinux/toolkits" "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 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(p.Pointer(), 3)) + m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3)) h.Hand(m, args...) return m } for _, h := range cmd.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(p.Pointer(), 3)) + m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3)) h.Hand(m, args...) return m } } 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(p.Pointer(), 3)) + m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(h.Hand, 3)) h.Hand(m, arg[1:]...) return m } } - p := reflect.ValueOf(cmd.Hand) - m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(p.Pointer(), 3)) + m.Log(LOG_CMDS, "%s.%s %d %v %s", c.Name, key, len(arg), arg, kit.FileLine(cmd.Hand, 3)) cmd.Hand(m, c, key, arg...) return m }