1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 17:44:05 +08:00
This commit is contained in:
shaoying 2020-06-11 14:54:07 +08:00
parent 00e223f14b
commit ec7f874653
7 changed files with 87 additions and 884 deletions

View File

@ -1,16 +0,0 @@
Volcanos("onimport", {help: "导入数据", list: [],
init: function(can, msg, cb, output, option) {output.innerHTML = "";
msg.Table(function(value, index) {
can.page.Append(can, output, [{view: ["stat", "div", "hello"]}])
})
},
})
Volcanos("onaction", {help: "组件交互", list: [],
})
Volcanos("onchoice", {help: "组件菜单", list: [],
})
Volcanos("ondetail", {help: "组件详情", list: [],
})
Volcanos("onexport", {help: "导出数据", list: [],
})

View File

@ -11,14 +11,28 @@ import (
)
const (
ZONE = "zone"
PLAN = "plan"
TASK = "task"
MISS = "miss"
)
const (
ZONE = "zone"
LEVEL = "level"
STATUS = "status"
SCORE = "score"
BEGIN_TIME = "begin_time"
CLOSE_TIME = "close_time"
EXPORT = "usr/export/web.team/task.csv"
)
const (
ScaleDay = "day"
ScaleWeek = "week"
ScaleMonth = "month"
ScaleYear = "year"
ScaleLong = "long"
)
const (
StatusPrepare = "prepare"
StatusProcess = "process"
@ -27,15 +41,15 @@ const (
)
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{}) {
m.Richs(TASK, nil, kit.Select(kit.MDB_FOREACH, 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", zone)
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
m.Push(ZONE, zone)
m.Push(zone, value)
})
return
}
m.Grows(TASK, kit.Keys("hash", key), "id", id, func(index int, value map[string]interface{}) {
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
m.Push("detail", value)
})
})
@ -44,7 +58,7 @@ func _task_list(m *ice.Message, zone string, id string, field ...interface{}) {
func _task_create(m *ice.Message, zone string) {
if m.Richs(TASK, nil, zone, nil) == nil {
m.Rich(TASK, nil, kit.Data(ZONE, zone))
m.Log_CREATE("zone", zone)
m.Log_CREATE(ZONE, zone)
}
}
func _task_export(m *ice.Message, file string) {
@ -56,29 +70,29 @@ func _task_export(m *ice.Message, file string) {
defer w.Flush()
m.Assert(w.Write([]string{
"zone", "id", "time",
"type", "name", "text",
"level", "status", "score",
"begin_time", "close_time",
"extra",
ZONE, kit.MDB_ID, kit.MDB_TIME,
kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT,
LEVEL, STATUS, SCORE,
BEGIN_TIME, CLOSE_TIME,
kit.MDB_EXTRA,
}))
count := 0
m.Option("cache.limit", -2)
m.Richs(TASK, nil, "*", func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
m.Richs(TASK, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
m.Assert(w.Write(kit.Simple(
kit.Format(kit.Value(val, "meta.zone")),
kit.Format(value["id"]),
kit.Format(value["time"]),
kit.Format(value["type"]),
kit.Format(value["name"]),
kit.Format(value["text"]),
kit.Format(value["level"]),
kit.Format(value["status"]),
kit.Format(value["score"]),
kit.Format(value["begin_time"]),
kit.Format(value["close_time"]),
kit.Format(value["extra"]),
kit.Format(value[kit.MDB_ID]),
kit.Format(value[kit.MDB_TIME]),
kit.Format(value[kit.MDB_TYPE]),
kit.Format(value[kit.MDB_NAME]),
kit.Format(value[kit.MDB_TEXT]),
kit.Format(value[LEVEL]),
kit.Format(value[STATUS]),
kit.Format(value[SCORE]),
kit.Format(value[BEGIN_TIME]),
kit.Format(value[CLOSE_TIME]),
kit.Format(value[kit.MDB_EXTRA]),
)))
count++
})
@ -103,11 +117,11 @@ func _task_import(m *ice.Message, file string) {
data := kit.Dict()
for i, k := range heads {
switch k {
case "zone":
case ZONE:
zone = lines[i]
case "id":
case kit.MDB_ID:
continue
case "extra":
case kit.MDB_EXTRA:
kit.Value(data, k, kit.UnMarshal(lines[i]))
default:
kit.Value(data, k, lines[i])
@ -116,8 +130,8 @@ func _task_import(m *ice.Message, file string) {
_task_create(m, zone)
m.Richs(TASK, nil, zone, func(key string, value map[string]interface{}) {
id := m.Grow(TASK, kit.Keys("hash", key), data)
m.Log_INSERT("zone", zone, "id", id)
id := m.Grow(TASK, kit.Keys(kit.MDB_HASH, key), data)
m.Log_INSERT(ZONE, zone, kit.MDB_ID, id)
count++
})
}
@ -126,105 +140,101 @@ func _task_import(m *ice.Message, file string) {
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(
id := m.Grow(TASK, kit.Keys(kit.MDB_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, "level", 3, "score", 3,
BEGIN_TIME, begin_time, CLOSE_TIME, begin_time,
STATUS, StatusPrepare, LEVEL, 3, SCORE, 3,
kit.MDB_EXTRA, kit.Dict(arg),
))
m.Log_INSERT("zone", zone, "id", id, "type", kind, "name", name)
m.Log_INSERT(ZONE, zone, kit.MDB_ID, id, kit.MDB_TYPE, kind, kit.MDB_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.Richs(TASK, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
switch pro {
case "id", "time":
case ZONE, kit.MDB_ID, kit.MDB_TIME:
m.Info("not allow %v", key)
case "status":
if value["status"] == set {
case STATUS:
if value[STATUS] == set {
break
}
switch value["status"] {
switch value[STATUS] {
case StatusCancel, StatusFinish:
m.Info("not allow %v", key)
return
}
switch set {
case StatusProcess:
kit.Value(value, "begin_time", m.Time())
kit.Value(value, BEGIN_TIME, m.Time())
case StatusCancel, StatusFinish:
kit.Value(value, "close_time", m.Time())
kit.Value(value, CLOSE_TIME, m.Time())
}
fallthrough
default:
m.Log_MODIFY("zone", zone, "id", id, "key", pro, "value", set, "old", old)
m.Log_MODIFY(ZONE, zone, kit.MDB_ID, id, kit.MDB_KEY, pro, kit.MDB_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")
m.Richs(TASK, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), kit.MDB_ID, id, func(index int, value map[string]interface{}) {
m.Log_DELETE(ZONE, zone, kit.MDB_ID, id)
kit.Value(value, STATUS, StatusCancel)
})
})
}
var Index = &ice.Context{Name: "team", Help: "团队中心",
Configs: map[string]*ice.Config{
TASK: {Name: "task", Help: "task", Value: kit.Data(kit.MDB_SHORT, "zone")},
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_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(TASK) }},
PLAN: {Name: "plan scale:select=day|week|month|year|long begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict(
"display", "/plugin/local/team/miss.js", "detail", []string{"prepare", "process", "finish", "cancel"},
"display", "/plugin/local/team/plan.js", "detail", []string{StatusPrepare, StatusProcess, StatusCancel, StatusFinish},
), Action: map[string]*ice.Action{
"insert": {Name: "insert zone type name text begin_time end_time", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
kit.MDB_INSERT: {Name: "insert zone type name text begin_time end_time", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
_task_create(m, arg[0])
_task_insert(m, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5])
}},
"delete": {Name: "delete key value", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
_task_delete(m, m.Option("zone"), m.Option("id"))
kit.MDB_DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
_task_delete(m, m.Option(ZONE), m.Option(kit.MDB_ID))
}},
"modify": {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case "status":
}
_task_modify(m, m.Option("zone"), m.Option("id"), arg[0], arg[1], arg[2])
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
_task_modify(m, m.Option(ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], arg[2])
}},
"import": {Name: "import file...", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
kit.MDB_IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
_task_import(m, kit.Select(EXPORT, arg, 0))
}},
"export": {Name: "export file...", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
kit.MDB_EXPORT: {Name: "export file", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
_task_export(m, kit.Select(EXPORT, arg, 0))
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
begin_time := time.Now()
if len(arg) > 1 {
begin_time, _ = time.ParseInLocation("2006-01-02 15:04:05", arg[1], time.Local)
begin_time, _ = time.ParseInLocation(ice.ICE_TIME, arg[1], time.Local)
}
end_time := begin_time
switch begin_time = begin_time.Add(-time.Duration(begin_time.UnixNano()) % (24 * time.Hour)); arg[0] {
case "day":
case ScaleDay:
end_time = begin_time.AddDate(0, 0, 1)
case "week":
case ScaleWeek:
begin_time = begin_time.AddDate(0, 0, -int(begin_time.Weekday()))
end_time = begin_time.AddDate(0, 0, 7)
case "month":
case ScaleMonth:
begin_time = begin_time.AddDate(0, 0, -begin_time.Day()+1)
end_time = begin_time.AddDate(0, 1, 0)
case "year":
case ScaleYear:
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
end_time = begin_time.AddDate(1, 0, 0)
case "long":
case ScaleLong:
begin_time = begin_time.AddDate(0, 0, -begin_time.YearDay()+1)
begin_time = begin_time.AddDate(-begin_time.Year()%5, 0, 0)
end_time = begin_time.AddDate(5, 0, 0)
@ -232,25 +242,25 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
begin_time = begin_time.Add(-8 * time.Hour)
end_time = end_time.Add(-8 * time.Hour)
m.Debug("begin: %v end: %v", begin_time, end_time)
m.Logs("info", "begin", begin_time, "end", end_time)
m.Richs(TASK, nil, kit.Select("*", m.Option("zone")), func(key string, val map[string]interface{}) {
m.Richs(TASK, nil, kit.Select(kit.MDB_FOREACH, m.Option(ZONE)), func(key string, val map[string]interface{}) {
zone := kit.Format(kit.Value(val, "meta.zone"))
m.Grows(TASK, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
begin, _ := time.ParseInLocation("2006-01-02 15:04:05", kit.Format(value["begin_time"]), time.Local)
m.Grows(TASK, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
begin, _ := time.ParseInLocation(ice.ICE_TIME, kit.Format(value[BEGIN_TIME]), time.Local)
if begin_time.Before(begin) && begin.Before(end_time) {
m.Push("zone", zone)
m.Push(ZONE, zone)
m.Push(zone, value)
}
})
})
}},
TASK: {Name: "task zone=auto id=auto auto", Help: "任务", Action: map[string]*ice.Action{
"delete": {Name: "delete key value", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
_task_delete(m, m.Option("zone"), m.Option("id"))
kit.MDB_DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
_task_delete(m, m.Option(ZONE), m.Option(kit.MDB_ID))
}},
"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])
kit.MDB_MODIFY: {Name: "modify key value old", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
_task_modify(m, m.Option(ZONE), m.Option(kit.MDB_ID), arg[0], arg[1], arg[2])
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 3 {
@ -258,9 +268,6 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
return
}
if m.Richs(TASK, nil, arg[0], nil) == nil {
_task_create(m, arg[0])
}
if len(arg) == 5 {
arg = append(arg, m.Time())
}
@ -268,6 +275,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心",
arg = append(arg, m.Time("1h"))
}
_task_create(m, arg[0])
_task_insert(m, arg[0], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7:]...)
}},
MISS: {Name: "miss", Help: "miss", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

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

View File

@ -1,486 +0,0 @@
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

@ -1,198 +0,0 @@
package wiki
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/web"
kit "github.com/shylinux/toolkits"
"os"
"path"
"strings"
)
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_sub(m *ice.Message, action string, name string, arg ...string) bool {
if _inner_protect(m, name) {
m.Push("file", "../")
return 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_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")
return
}
m.Echo(name)
}
func _inner_save(m *ice.Message, name, text string) {
if _inner_sub(m, "save", name) {
return
}
if f, e := os.Create(name); m.Assert(e) {
defer f.Close()
m.Cmd(web.FAVOR, "inner.save", "shell", name, text)
if n, e := f.WriteString(text); m.Assert(e) {
m.Log_EXPORT("file", name, "size", n)
}
}
}
func _inner_plug(m *ice.Message, name string) {
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
}
m.Echo("{}")
}
func _inner_show(m *ice.Message, name string) {
if _inner_sub(m, "show", name) {
return
}
p := _inner_ext(name)
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)
m.Cmd(web.FAVOR, "inner.run", "shell", name, m.Result())
return
}
switch m.Set(ice.MSG_RESULT); p {
case "csv":
m.CSV(m.Cmdx("nfs.cat", name))
case "md":
m.Cmdy("web.wiki.md.note", name)
case "shy":
m.Echo(strings.ReplaceAll(strings.Join(m.Cmd("web.wiki.word", name).Resultv(), ""), "\n", " "))
}
}
func _inner_main(m *ice.Message, arg ...string) {
if len(arg) > 2 && arg[2] != "" {
web.StoryIndex(m, arg[2])
return
}
_inner_list(m, path.Join(arg...))
}
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
INNER: {Name: "inner", Help: "编辑器", Value: kit.Data(
"protect", kit.Dict("etc", "true", "var", "true", "usr", "true"),
"binary", kit.Dict("bin", "true", "gz", "true"),
"plug", kit.Dict(
"py", kit.Dict(
"prefix", kit.Dict("#", "comment"),
"keyword", kit.Dict("print", "keyword"),
),
"md", kit.Dict("display", true, "profile", true),
"csv", kit.Dict("display", true),
),
"show", kit.Dict(
"sh", []string{"bash"},
"py", []string{"python"},
"go", []string{"go", "run"},
"js", []string{"node"},
),
)},
},
Commands: map[string]*ice.Command{
INNER: {Name: "inner path=tmp name=hi.qrc key auto", Help: "编辑器", Meta: map[string]interface{}{
"display": "/plugin/inner.js", "style": "editor",
}, Action: map[string]*ice.Action{
"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]))
}
}},
"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(`<a title="%s" href="%s" target="_blank"><img src="%s" width=200></a>`,
value["name"], value["text"], value["extra.poster"]))
m.Push("video", kit.Format(`<video src="%s" controls></video>`, value["text"]))
})
}},
"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")))
}},
"project": {Name: "project path", Help: "项目", Hand: func(m *ice.Message, arg ...string) {
_inner_list(m, path.Join("./", kit.Select("", 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())
}
}},
"commit": {Name: "commit path name", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
msg := web.StoryCatch(m.Spawn(), "", path.Join("./", arg[0], arg[1]))
m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
}},
"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")
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) {
msg := web.StoryAdd(m.Spawn(), "display", path.Join("./", m.Option("path"), m.Option("name"))+".display", m.Option("display"))
m.Copy(msg, ice.MSG_APPEND, "time", "count", "key")
}},
"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)
}

View File

@ -1,47 +0,0 @@
package wiki
import (
ice "github.com/shylinux/icebergs"
kit "github.com/shylinux/toolkits"
qrs "github.com/skip2/go-qrcode"
"github.com/tuotoo/qrcode"
"os"
)
func init() {
Index.Register(&ice.Context{Name: "qrc", Help: "二维码",
Configs: map[string]*ice.Config{
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data(
"plug", `{"display": {"height": "400px"}}`,
)},
},
Commands: map[string]*ice.Command{
"list": {Name: "list name", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, e := os.Open(arg[0]); e == nil {
defer f.Close()
if q, e := qrcode.Decode(f); e == nil {
m.Echo(q.Content)
return
}
}
m.Echo("hello world")
}},
"save": {Name: "save name text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if qr, e := qrs.New(arg[1], qrs.Medium); m.Assert(e) {
if f, e := os.Create(arg[0]); m.Assert(e) {
defer f.Close()
m.Assert(qr.Write(kit.Int(kit.Select("256", arg, 2)), f))
m.Echo(arg[0])
}
}
}},
"plug": {Name: "plug name text", Help: "插件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(m.Conf(QRCODE, "meta.plug"))
}},
"show": {Name: "show name", Help: "渲染", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(`<img src="/share/local/%s">`, arg[0])
}},
},
}, nil)
}

View File

@ -1,50 +0,0 @@
package wiki
import (
ice "github.com/shylinux/icebergs"
kit "github.com/shylinux/toolkits"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/av/avutil"
"github.com/nareix/joy4/format"
)
func init() {
format.RegisterAll()
Index.Register(&ice.Context{Name: "m4v", Help: "视频",
Configs: map[string]*ice.Config{
VEDIO: {Name: "vedio", Help: "视频", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
"list": {Name: "list name", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(arg[0])
}},
"save": {Name: "save name text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Cmdy("nfs.qrcodes", arg)
}},
"show": {Name: "show name", Help: "渲染", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if file, e := avutil.Open(arg[0]); m.Assert(e) {
if streams, e := file.Streams(); m.Assert(e) {
for _, stream := range streams {
m.Info("what %v", kit.Formats(stream))
if stream.Type().IsAudio() {
} else if stream.Type().IsVideo() {
vstream := stream.(av.VideoCodecData)
m.Push("type", vstream.Type().String())
m.Push("width", vstream.Width())
m.Push("height", vstream.Height())
}
}
}
}
}},
"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)
}