From 592dff8a9e1ce192484317560dd4ec588b3e8522 Mon Sep 17 00:00:00 2001 From: shy Date: Sun, 26 Nov 2023 00:03:40 +0800 Subject: [PATCH] opt favor --- base/cli/qrcode.go | 4 +- base/web/agent.go | 1 + base/web/cache.go | 1 + base/web/dream.go | 11 ++++-- base/web/html/html.go | 10 +++++ conf.go | 3 ++ core/chat/action.go | 8 +++- core/chat/favor.go | 79 +++++++++++++++++++++---------------- core/chat/location/amap.js | 2 +- core/chat/macos/desktop.css | 4 +- core/mall/admin.go | 6 --- core/wiki/word.go | 15 ++++++- meta.go | 28 ++++++++++++- option.go | 7 ++-- 14 files changed, 124 insertions(+), 55 deletions(-) create mode 100644 base/web/agent.go diff --git a/base/cli/qrcode.go b/base/cli/qrcode.go index 9a602081..6b9e312d 100644 --- a/base/cli/qrcode.go +++ b/base/cli/qrcode.go @@ -71,8 +71,8 @@ func init() { _qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0)) } else { m.OptionDefault(SIZE, kit.Select("320", "368", m.IsWeixinUA())) - m.Option(FG, kit.Select(m.Option("--plugin-fg-color"), arg, 1)) - m.Option(BG, kit.Select(m.Option("--plugin-bg-color"), arg, 2)) + m.Option(FG, kit.Select(m.Option(ice.MSG_FG), arg, 1)) + m.Option(BG, kit.Select(m.Option(ice.MSG_BG), arg, 2)) switch m.Option(ice.MSG_THEME) { case LIGHT, WHITE: m.OptionDefault(FG, BLACK, BG, WHITE) diff --git a/base/web/agent.go b/base/web/agent.go new file mode 100644 index 00000000..efb38952 --- /dev/null +++ b/base/web/agent.go @@ -0,0 +1 @@ +package web diff --git a/base/web/cache.go b/base/web/cache.go index 77799964..58e8cbd7 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -103,6 +103,7 @@ const ( WRITE = "write" UPLOAD = "upload" DOWNLOAD = "download" + PREVIEW = "preview" IMAGE = "image" VIDEO = "video" diff --git a/base/web/dream.go b/base/web/dream.go index fca3ab7a..db294f81 100644 --- a/base/web/dream.go +++ b/base/web/dream.go @@ -35,7 +35,11 @@ func _dream_list(m *ice.Message) *ice.Message { } else { m.Push(nfs.VERSION, "") m.Push(mdb.TYPE, WORKER) - m.Push(cli.STATUS, cli.STOP) + if nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) { + m.Push(cli.STATUS, cli.STOP) + } else { + m.Push(cli.STATUS, cli.BEGIN) + } m.Push(mdb.TEXT, "") if nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) { m.PushButton(cli.START, nfs.TRASH) @@ -46,8 +50,7 @@ func _dream_list(m *ice.Message) *ice.Message { } } }) - return m.Sort("status,type,name", ice.STR, ice.STR, ice.STR_R).StatusTimeCount() - + return m.Sort("status,type,name", []string{cli.START, cli.STOP, cli.BEGIN}, ice.STR, ice.STR_R).StatusTimeCount() } func _dream_start(m *ice.Message, name string) { if m.Warn(name == "", ice.ErrNotValid, mdb.NAME) { @@ -179,7 +182,7 @@ func init() { gdb.Event(m, DREAM_INPUTS, arg) } }}, - mdb.CREATE: {Name: "create name*=hi icon@icon repos binary template", Hand: func(m *ice.Message, arg ...string) { + mdb.CREATE: {Name: "create name*=hi icon@icons repos binary template", Hand: func(m *ice.Message, arg ...string) { kit.If(!strings.Contains(m.Option(mdb.NAME), "-") || !strings.HasPrefix(m.Option(mdb.NAME), "20"), func() { m.Option(mdb.NAME, m.Time("20060102-")+m.Option(mdb.NAME)) }) m.OptionDefault(mdb.ICON, nfs.USR_ICONS_ICEBERGS) kit.If(mdb.Config(m, nfs.REPOS), func(p string) { m.OptionDefault(nfs.REPOS, p+m.Option(mdb.NAME)) }) diff --git a/base/web/html/html.go b/base/web/html/html.go index ed0ba5e1..479731f3 100644 --- a/base/web/html/html.go +++ b/base/web/html/html.go @@ -51,3 +51,13 @@ func IsVideo(name, mime string) bool { func IsAudio(name, mime string) bool { return strings.HasPrefix(mime, "audio/") } + +const ( + GetLocation = "getLocation" + ConnectWifi = "ConnectWifi" + GetClipboardData = "getClipboardData" + ScanQRCode = "scanQRCode" + ChooseImage = "chooseImage" + Record1 = "record1" + Record2 = "record2" +) diff --git a/conf.go b/conf.go index 04072137..acfb5f7c 100644 --- a/conf.go +++ b/conf.go @@ -199,6 +199,7 @@ const ( // MSG MSG_ACTION = "_action" MSG_STATUS = "_status" + MSG_SPACE = "_space" MSG_INDEX = "_index" MSG_SCRIPT = "_script" MSG_OUTPUT = "_output" @@ -221,6 +222,8 @@ const ( // MSG MSG_USERZONE = "user.zone" MSG_LANGUAGE = "user.lang" + MSG_BG = "sess.bg" + MSG_FG = "sess.fg" MSG_MODE = "sess.mode" MSG_THEME = "sess.theme" MSG_TITLE = "sess.title" diff --git a/core/chat/action.go b/core/chat/action.go index d3b86503..43904ce5 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -74,7 +74,13 @@ func init() { } else if m.Warn(!_river_right(m, arg[0]), ice.ErrNotRight, arg) { return } - if len(arg) == 2 { + if web.PodCmd(m, web.SPACE, arg...) { + m.Table(func(value ice.Maps) { + m.StatusTimeCount() + m.Push(web.SPACE, m.Option(ice.MSG_USERPOD)) + }) + return + } else if len(arg) == 2 { ctx.OptionFromConfig(m, MENUS) _action_list(m, arg[0], arg[1]) } else { diff --git a/core/chat/favor.go b/core/chat/favor.go index af1164cf..a3c277c4 100644 --- a/core/chat/favor.go +++ b/core/chat/favor.go @@ -11,6 +11,7 @@ import ( "shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" + "shylinux.com/x/icebergs/base/web/html" kit "shylinux.com/x/toolkits" ) @@ -53,34 +54,28 @@ func init() { } gdb.Event(m, "", arg) }}, - "getClipboardData": {Name: "favor create", Help: "粘贴"}, - "getLocation": {Name: "favor create", Help: "定位"}, - "scanQRCode": {Name: "favor create", Help: "扫码"}, - "record1": {Name: "favor upload", Help: "截图"}, - "record2": {Name: "favor upload", Help: "录屏"}, - mdb.CREATE: {Name: "create type name text*", Hand: func(m *ice.Message, arg ...string) { + html.GetLocation: {Name: "favor create", Help: "定位"}, + html.GetClipboardData: {Name: "favor create", Help: "粘贴"}, + html.ScanQRCode: {Name: "favor create", Help: "扫码"}, + html.Record1: {Name: "favor upload", Help: "截图"}, + html.Record2: {Name: "favor upload", Help: "录屏"}, + mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { if strings.HasPrefix(m.Option(mdb.TEXT), ice.HTTP) { m.OptionDefault(mdb.TYPE, mdb.LINK, mdb.NAME, kit.ParseURL(m.Option(mdb.TEXT)).Host) } mdb.HashCreate(m, m.OptionSimple()) }}, + mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { + kit.If(!web.PodCmd(m, web.SPACE, kit.Simple(ctx.ACTION, m.ActionKey(), arg)...), func() { mdb.HashRemove(m, arg) }) + }}, web.UPLOAD: {Hand: func(m *ice.Message, arg ...string) { m.Cmd("", mdb.CREATE, m.OptionSimple(mdb.TYPE, mdb.NAME, mdb.TEXT)) }}, web.DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen(web.MergeURL2(m, web.SHARE_LOCAL+m.Option(mdb.TEXT), nfs.FILENAME, m.Option(mdb.NAME))) }}, - ctx.INDEX: {Help: "命令", Hand: func(m *ice.Message, arg ...string) { - if kit.HasPrefixList(arg, ctx.RUN) { - msg := mdb.HashSelects(m.Spawn(), arg[1]) - ctx.ProcessField(m, msg.Append(mdb.NAME), kit.Split(msg.Append(mdb.TEXT)), kit.Simple(ctx.RUN, arg[2:])...) - } else { - msg := mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)) - ctx.ProcessField(m, msg.Append(mdb.NAME), kit.Split(msg.Append(mdb.TEXT)), arg...) - m.Option(ice.FIELD_PREFIX, ctx.ACTION, m.ActionKey(), ctx.RUN, m.Option(mdb.HASH)) - } - }}, - cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, m.Option(mdb.TEXT)) }}, + web.PREVIEW: {Hand: FavorPreview}, + cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, m.Option(mdb.TEXT)) }}, }, FavorAction(), mdb.ExportHashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,type,name,text")), Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 && arg[0] == ctx.ACTION { if m.Option(ice.MSG_INDEX) == m.PrefixKey() { @@ -90,24 +85,16 @@ func init() { m.Cmdy(m.Option(ice.MSG_INDEX), arg[3:]) } return - } - if mdb.HashSelect(m, arg...); len(arg) == 0 { + } else if mdb.HashSelect(m, arg...); len(arg) == 0 { defer web.PushPodCmd(m, "", arg...) - if m.IsMobileUA() { - m.Action(mdb.CREATE, web.UPLOAD, "getClipboardData", "getLocation", "scanQRCode") + if m.SortStrR(mdb.TIME); m.IsMobileUA() { + m.Action(mdb.CREATE, web.UPLOAD, html.GetClipboardData, html.GetLocation, html.ScanQRCode) } else { - m.Action(mdb.CREATE, web.UPLOAD, "getClipboardData", "record1", "record2") + m.Action(mdb.CREATE, web.UPLOAD, html.GetClipboardData, html.Record1, html.Record2) } - m.SortStrR(mdb.TIME) } else { - if web.PodCmd(m, web.SPACE, arg...) { - return - } else if m.Length() == 0 { - return - } - text := m.Append(mdb.TEXT) - m.PushQRCode(cli.QRCODE, text) - m.PushScript(text) + m.PushQRCode(cli.QRCODE, m.Append(mdb.TEXT)) + m.PushScript(m.Append(mdb.TEXT)) } m.Table(func(value ice.Maps) { delete(value, ctx.ACTION) @@ -116,12 +103,10 @@ func init() { return } switch value[mdb.TYPE] { - case ctx.INDEX: - m.PushButton(ctx.INDEX, mdb.REMOVE) case cli.OPENS: m.PushButton(cli.OPENS, mdb.REMOVE) default: - m.PushButton(mdb.REMOVE) + m.PushButton(web.PREVIEW, mdb.REMOVE) } }) }}, @@ -129,3 +114,29 @@ func init() { } func FavorAction() ice.Actions { return gdb.EventsAction(FAVOR_INPUTS, FAVOR_TABLES, FAVOR_ACTION) } +func FavorPreview(m *ice.Message, arg ...string) { + if kit.HasPrefixList(arg, ctx.RUN) { + if pod := arg[1]; pod != "" { + arg[1] = "" + m.Options(ice.MSG_USERPOD, pod).Cmdy(web.SPACE, pod, m.CommandKey(), ctx.ACTION, m.ActionKey(), arg) + } else { + index, args := favorPreview(m, arg[2], arg...) + ctx.ProcessField(m, index, args, kit.Simple(ctx.RUN, arg[3:])...) + } + } else if !web.PodCmd(m, web.SPACE, kit.Simple(ctx.ACTION, m.ActionKey(), arg)...) { + index, args := favorPreview(m, m.Option(mdb.HASH), arg...) + ctx.ProcessField(m, index, args, arg...).Push(ice.MSG_SPACE, m.Option(ice.MSG_USERPOD)) + m.Option(ice.FIELD_PREFIX, ctx.ACTION, m.ActionKey(), ctx.RUN, m.Option(ice.MSG_USERPOD), m.Option(mdb.HASH)) + } +} +func favorPreview(m *ice.Message, h string, arg ...string) (string, []string) { + msg := mdb.HashSelects(m.Spawn(), h) + index, args := msg.Append(mdb.TYPE), kit.Split(msg.Append(mdb.TEXT)) + switch msg.Append(mdb.TYPE) { + case ctx.INDEX: + index = msg.Append(mdb.NAME) + case nfs.SHY: + index = web.WIKI_WORD + } + return index, args +} diff --git a/core/chat/location/amap.js b/core/chat/location/amap.js index 970c2f13..b6df346c 100644 --- a/core/chat/location/amap.js +++ b/core/chat/location/amap.js @@ -29,7 +29,7 @@ Volcanos(chat.ONIMPORT, { })) }, _style: function(can, style) { - style = {"light": "normal", "dark": "grey"}[style]||style + style = {"light": "normal", "dark": "grey", "black": "blue", "white": "macaron", "silver": "grey", "blue": "graffiti", "red": "graffiti"}[style]||style can.ui.map.setMapStyle("amap://styles/"+can.Action("style", style)) return style }, diff --git a/core/chat/macos/desktop.css b/core/chat/macos/desktop.css index 1cd134fc..17cc7516 100644 --- a/core/chat/macos/desktop.css +++ b/core/chat/macos/desktop.css @@ -26,7 +26,9 @@ fieldset.macos.desktop>div.output>div.desktop>fieldset>div.item.button { border- fieldset.macos.desktop>div.output>div.desktop>fieldset>legend { padding:0 10px; margin:10px; box-shadow:none; } fieldset.macos.desktop>div.output>div.desktop>fieldset>legend:not(:hover) { background-color:transparent; } fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>*:not(.textarea) { margin:10px 0px 10px 10px; } -fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.icon { margin:12px 0 8px; } +fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.icon { margin:10px 0; } +fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.icon.refresh { margin:8px 0 12px; } +fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.icon.goback { margin:8px 0 12px; } fieldset.macos.desktop>div.output>div.desktop>fieldset:not(:hover)>form.option>div.icon { visibility:hidden; } fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.item.button:not(.select)>span.icon { font-size:32px; line-height:30px; } fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.item.button.prunes>span.icon { font-size:20px; line-height:32px; } diff --git a/core/mall/admin.go b/core/mall/admin.go index cae0f34b..7a36c2d5 100644 --- a/core/mall/admin.go +++ b/core/mall/admin.go @@ -4,7 +4,6 @@ import ( ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" ) @@ -19,11 +18,6 @@ func init() { }, ctx.ConfAction(ctx.TOOLS, Prefix(GOODS)), GOODS), Hand: func(m *ice.Message, arg ...string) { m.Cmdy(GOODS, arg).PushAction(mdb.MODIFY, mdb.REMOVE) m.Action(mdb.CREATE) - kit.If(len(arg) > 0, func() { - kit.For(kit.Split(m.Append(nfs.IMAGE)), func(p string) { - m.EchoImages(web.MergeURL2(m, web.SHARE_CACHE+p, ice.POD, m.Append(web.SPACE))) - }) - }) ctx.DisplayTable(m) _status_amount(m) }}, diff --git a/core/wiki/word.go b/core/wiki/word.go index ed6642c5..33b360c5 100644 --- a/core/wiki/word.go +++ b/core/wiki/word.go @@ -2,6 +2,7 @@ package wiki import ( "net/http" + "path" "strings" ice "shylinux.com/x/icebergs" @@ -24,7 +25,7 @@ const WORD = "word" func init() { Index.MergeCommands(ice.Commands{ - WORD: {Name: "word path=src/main.shy@key auto play", Help: "上下文", Icon: "Books.png", Actions: ice.MergeActions(ice.Actions{ + WORD: {Name: "word path=src/main.shy@key auto favor play", Help: "上下文", Icon: "Books.png", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { WordAlias(m, NAVMENU, TITLE, NAVMENU) WordAlias(m, PREMENU, TITLE, PREMENU) @@ -36,6 +37,14 @@ func init() { WordAlias(m, CHAIN, CHART, CHAIN) WordAlias(m, SEQUENCE, CHART, SEQUENCE) }}, + mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { + if mdb.IsSearchPreview(m, arg) { + mdb.HashSelects(m.Spawn()).SortStrR(mdb.TIME).TablesLimit(5, func(value ice.Maps) { + // m.PushSearch(mdb.TYPE, nfs.SHY, mdb.NAME, path.Base(value[nfs.PATH]), mdb.TEXT, value[nfs.PATH]) + m.PushSearch(mdb.TYPE, nfs.SHY, mdb.NAME, value[mdb.TIME], mdb.TEXT, value[nfs.PATH]) + }) + } + }}, mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { m.OptionFields("path,size,time") @@ -59,6 +68,10 @@ func init() { code.COMPLETE: {Hand: func(m *ice.Message, arg ...string) { kit.If(kit.IsIn(kit.Split(m.Option(mdb.TEXT))[0], IMAGE, VIDEO, AUDIO), func() { m.Cmdy(FEEL).CutTo(nfs.PATH, mdb.NAME) }) }}, + "favor": {Help: "收藏", Icon: "bi bi-star", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(web.CHAT_FAVOR, mdb.CREATE, mdb.TYPE, nfs.SHY, mdb.NAME, path.Base(arg[0]), mdb.TEXT, arg[0]) + m.ProcessHold("favor success") + }}, }, aaa.RoleAction(), WikiAction("", nfs.SHY), mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path")), Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 { mdb.HashCreate(m.Spawn(), nfs.PATH, arg[0]) diff --git a/meta.go b/meta.go index 5f704c70..6a8ff60d 100644 --- a/meta.go +++ b/meta.go @@ -261,13 +261,28 @@ const ( INT = "int" ) -func (m *Message) Sort(key string, arg ...string) *Message { +func (m *Message) Sort(key string, arg ...Any) *Message { if m.FieldsIsDetail() { return m } + order := map[string]map[string]int{} keys, cmps := kit.Split(kit.Select("type,name,text", key)), kit.Simple() for i, k := range keys { - cmp := kit.Select("", arg, i) + cmp := "" + if i < len(arg) { + switch v := arg[i].(type) { + case string: + cmp = v + case map[string]int: + order[k] = v + case []string: + list := map[string]int{} + for i, v := range v { + list[v] = i + 1 + } + order[k] = list + } + } if cmp == "" { cmp = INT for _, v := range m.value(k) { @@ -283,6 +298,15 @@ func (m *Message) Sort(key string, arg ...string) *Message { gt := func(i, j int) bool { for s, k := range keys { if a, b := list[i][k], list[j][k]; a != b { + if v, ok := order[k]; ok { + if v[a] > v[b] { + return true + } else if v[a] < v[b] { + return false + } else { + continue + } + } switch cmp := cmps[s]; cmp { case STR, STR_R: if a > b { diff --git a/option.go b/option.go index 0012ec06..b071e818 100644 --- a/option.go +++ b/option.go @@ -79,9 +79,10 @@ func (m *Message) Status(arg ...Any) *Message { return m.Options(MSG_STATUS, kit.Format(list)) } func (m *Message) StatusTime(arg ...Any) *Message { - traceid := []string{} - kit.If(m.Option(MSG_DEBUG) == TRUE, func() { traceid = m.OptionSimple(LOG_TRACEID) }) - return m.Status(TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost(), traceid) + args := []string{} + kit.If(m.Option(MSG_USERPOD), func(p string) { args = append(args, SPACE, p) }) + kit.If(m.Option(MSG_DEBUG) == TRUE, func() { args = append(args, m.OptionSimple(LOG_TRACEID)...) }) + return m.Status(TIME, m.Time(), arg, kit.MDB_COST, m.FormatCost(), args) } func (m *Message) StatusTimeCount(arg ...Any) *Message { return m.StatusTime(append([]Any{kit.MDB_COUNT, kit.Split(m.FormatSize())[0]}, arg...))