`, arg[0])}
for _, l := range strings.Split(strings.Join(arg[1:], "\n"), "\n") {
switch list = append(list, "
"); arg[0] {
case kit.SSH_SHELL:
list = append(list, "")
default:
list = append(list, "")
}
list = append(list, "", l, "")
list = append(list, "
")
}
list = append(list, "
")
return strings.Join(list, "")
default:
return arg[0]
}
return ""
}
func (m *Message) PushRender(key, view, name string, arg ...string) *Message {
return m.Push(key, Render(m, view, name, arg))
}
func (m *Message) PushDownload(key string, arg ...interface{}) { // [name] file
m.Push(key, Render(m, RENDER_DOWNLOAD, arg...))
}
func (m *Message) PushAnchor(arg ...interface{}) { // [name] link
if m.IsCliUA() {
return
}
m.Push(kit.MDB_LINK, Render(m, RENDER_ANCHOR, arg...))
}
func (m *Message) PushButton(arg ...string) {
if m.IsCliUA() {
return
}
m.Push(kit.MDB_ACTION, Render(m, RENDER_BUTTON, strings.Join(arg, ",")))
}
func (m *Message) PushScript(arg ...string) *Message { // [type] text...
return m.Push(kit.MDB_SCRIPT, Render(m, RENDER_SCRIPT, arg))
}
func (m *Message) PushImages(key, src string, arg ...string) { // key src [size]
m.Push(key, Render(m, RENDER_IMAGES, src, arg))
}
func (m *Message) PushVideos(key, src string, arg ...string) { // key src [size]
m.Push(key, Render(m, RENDER_VIDEOS, src, arg))
}
func (m *Message) PushQRCode(key string, text string, arg ...string) { // key text [size]
m.Push(key, Render(m, RENDER_QRCODE, text, arg))
}
func (m *Message) PushAction(list ...interface{}) {
m.Table(func(index int, value map[string]string, head []string) {
m.PushButton(kit.Simple(list...)...)
})
}
func (m *Message) EchoAnchor(arg ...interface{}) *Message { // [name] link
return m.Echo(Render(m, RENDER_ANCHOR, arg...))
}
func (m *Message) EchoButton(arg ...string) *Message {
return m.Echo(Render(m, RENDER_BUTTON, strings.Join(arg, ",")))
}
func (m *Message) EchoScript(arg ...string) *Message {
return m.Echo(Render(m, RENDER_SCRIPT, arg))
}
func (m *Message) EchoImages(src string, arg ...string) *Message {
return m.Echo(Render(m, RENDER_IMAGES, src, arg))
}
func (m *Message) EchoQRCode(text string, arg ...string) *Message { // text [size]
return m.Echo(Render(m, RENDER_QRCODE, text, arg))
}
func (m *Message) SortInt(key string) { m.Sort(key, "int") }
func (m *Message) SortIntR(key string) { m.Sort(key, "int_r") }
func (m *Message) SortStr(key string) { m.Sort(key, "str") }
func (m *Message) SortStrR(key string) { m.Sort(key, "str_r") }
func (m *Message) SortTime(key string) { m.Sort(key, "time") }
func (m *Message) SortTimeR(key string) { m.Sort(key, "time_r") }
func (m *Message) FormatMeta() string { return m.Format("meta") }
func (m *Message) FormatSize() string { return m.Format("size") }
func (m *Message) RenameAppend(from, to string) {
for i, v := range m.meta[MSG_APPEND] {
if v == from {
m.meta[MSG_APPEND][i] = to
m.meta[to] = m.meta[from]
delete(m.meta, from)
}
}
}
type Option struct {
Name string
Value interface{}
}
func OptionFields(str string) Option { return Option{"fields", str} }
func OptionHash(str string) Option { return Option{kit.MDB_HASH, str} }
type Sort struct {
Fields string
Method string
}
func (m *Message) Toast(content string, arg ...interface{}) {
if m.Option(MSG_USERPOD) != "" {
return
}
if len(arg) > 1 {
switch val := arg[1].(type) {
case string:
if value, err := time.ParseDuration(val); err == nil {
arg[1] = int(value / time.Millisecond)
}
}
}
m.Cmd("web.space", m.Option(MSG_DAEMON), "toast", "", content, arg)
}
func (m *Message) GoToast(title string, cb func(toast func(string, int, int))) {
m.Go(func() {
cb(func(name string, count, total int) {
m.Toast(
kit.Format("%s %s/%s", name, strings.TrimSuffix(kit.FmtSize(int64(count)), "B"), strings.TrimSuffix(kit.FmtSize(int64(total)), "B")),
kit.Format("%s %d%%", title, count*100/total),
kit.Select("1000", "10000", count < total),
count*100/total,
)
})
})
}
func (m *Message) Fields(condition bool, fields string) string {
return m.Option("fields", kit.Select(kit.Select("detail", fields, condition), m.Option("fields")))
}
func (m *Message) Action(arg ...string) {
m.Option(MSG_ACTION, kit.Format(arg))
}
func (m *Message) Status(arg ...interface{}) {
args := kit.Simple(arg)
list := []map[string]string{}
for i := 0; i < len(args)-1; i += 2 {
list = append(list, map[string]string{
"name": args[i], "value": args[i+1],
})
}
m.Option(MSG_STATUS, kit.Format(list))
}
func (m *Message) Process(action string, arg ...interface{}) {
m.Option(MSG_PROCESS, action)
m.Option("_arg", arg...)
}
func (m *Message) ProcessRewrite(arg ...interface{}) {
m.Process(PROCESS_REWRITE)
m.Option("_arg", arg...)
}
func (m *Message) ProcessRefresh(delay string) {
if d, e := time.ParseDuration(delay); e == nil {
m.Option("_delay", int(d/time.Millisecond))
}
m.Process(PROCESS_REFRESH)
}
func (m *Message) ProcessField(arg ...interface{}) {
m.Process(PROCESS_FIELD)
m.Option("_prefix", arg...)
}
func (m *Message) ProcessInner() { m.Process(PROCESS_INNER) }
func (m *Message) ProcessHold() { m.Process(PROCESS_HOLD) }
func (m *Message) ProcessBack() { m.Process(PROCESS_BACK) }
func (m *Message) Upload(dir string) {
up := kit.Simple(m.Optionv(MSG_UPLOAD))
if p := path.Join(dir, up[1]); m.Option(MSG_USERPOD) == "" {
// 本机文件
m.Cmdy("web.cache", "watch", up[0], p)
} else {
// 下拉文件
m.Cmdy("web.spide", "dev", "save", p, "GET",
kit.MergeURL2(m.Option(MSG_USERWEB), path.Join("/share/cache", up[0])))
}
}
func (m *Message) OptionFields(str string) { m.Option("fields", str) }
func (m *Message) OptionLoad(file string) *Message {
if f, e := os.Open(file); e == nil {
defer f.Close()
var data interface{}
json.NewDecoder(f).Decode(&data)
kit.Fetch(data, func(key string, value interface{}) { m.Option(key, kit.Simple(value)) })
}
return m
}
func (m *Message) Confi(key string, sub string) int {
return kit.Int(m.Conf(key, sub))
}
func (m *Message) Capi(key string, val ...interface{}) int {
if len(val) > 0 {
m.Cap(key, kit.Int(m.Cap(key))+kit.Int(val[0]))
}
return kit.Int(m.Cap(key))
}