diff --git a/base/web/matrix.css b/base/web/matrix.css new file mode 100644 index 00000000..bae40fff --- /dev/null +++ b/base/web/matrix.css @@ -0,0 +1,18 @@ +fieldset.web.matrix>div.output>table.content thead { z-index:2; } +fieldset.web.matrix>div.output>table.content th { font-family:unset; padding:var(--table-padding); } +fieldset.web.matrix>div.output>table.content th i { padding:var(--input-padding); position:unset; display:unset; } +fieldset.web.matrix>div.output>table.content td:hover { color:unset; } +fieldset.web.matrix>div.output>table.content div.item { display:flex; align-items:center; } +fieldset.web.matrix>div.output>table.content div.item:hover { background-color:unset; color:unset; } +fieldset.web.matrix>div.output>table.content div.item img { height:var(--header-height); width:var(--header-height); margin-right:var(--input-margin); } +fieldset.web.matrix>div.output>table.content div.item div.title { text-align:left; } +fieldset.web.matrix>div.output>table.content div.item div.title:hover { background-color:unset; } +fieldset.web.matrix>div.output>table.content div.item div.status i { font-size:var(--status-font-size); padding:0; } +fieldset.web.matrix>div.output>table.content div.item div.action { overflow:hidden; } +fieldset.web.matrix>div.output>table.content div.item div.action input.icons { display:none; } +fieldset.web.matrix>div.output>table.content div.item.danger div.status { color:var(--danger-bg-color); } +fieldset.web.matrix>div.output>table.content div.item.danger div.status i { color:var(--danger-bg-color); } +fieldset.web.matrix>div.output>table.content tr:not(:hover) div.item div.action { visibility:hidden; } +body:not(.mobile) fieldset.web.matrix>div.output>table.content th:first-child { position:sticky; left:2px; z-index:2; } +body:not(.mobile) fieldset.web.matrix>div.output>table.content td:first-child { background-color:var(--plugin-bg-color); position:sticky; left:2px; z-index:1; } + diff --git a/base/web/matrix.go b/base/web/matrix.go new file mode 100644 index 00000000..94c57ee8 --- /dev/null +++ b/base/web/matrix.go @@ -0,0 +1,75 @@ +package web + +import ( + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" + "shylinux.com/x/icebergs/base/ctx" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + kit "shylinux.com/x/toolkits" +) + +func _matrix_list(m *ice.Message, domain string) (server []string) { + fields := kit.Split(mdb.Config(m, mdb.FIELD)) + button := []ice.Any{PORTAL, DESKTOP, ADMIN, VIMER, XTERM, OPEN, kit.Select(UPGRADE, COMPILE, domain == "")} + value := kit.Dict(cli.ParseMake(m.Cmdx(Space(m, domain), cli.RUNTIME))) + value[mdb.TYPE], value[mdb.ICONS] = SERVER, kit.Select(nfs.USR_ICONS_ICEBERGS, ice.SRC_MAIN_ICO, domain == "") + value[DOMAIN] = kit.Select(ice.CONTEXTS, domain) + m.PushRecord(value, fields...).PushButton(button...) + m.Cmd(Space(m, domain), DREAM, ice.Maps{"space.timeout": "3s", "dream.simple": ice.TRUE}).Table(func(value ice.Maps) { + switch value[mdb.TYPE] { + case WORKER: + value[DOMAIN] = kit.Select(ice.CONTEXTS, domain) + m.PushRecord(value, fields...).PushButton(button...) + case SERVER: + server = append(server, kit.Keys(domain, value[mdb.NAME])) + } + }) + return +} +func _matrix_cmd(m *ice.Message, action string, arg ...string) { + domain := kit.Keys(kit.Select("", m.Option(DOMAIN), m.Option(DOMAIN) != ice.CONTEXTS), m.Option(mdb.NAME)) + switch action { + case PORTAL, DESKTOP, ADMIN, OPEN: + if kit.HasPrefixList(arg, ctx.RUN) { + ProcessIframe(m, "", "", arg...) + } else { + title, link := kit.Keys(domain, action), m.MergePodCmd(domain, action) + kit.If(action == OPEN, func() { title, link = domain, m.MergePod(domain) }) + ProcessIframe(m, title, link, arg...).ProcessField(ctx.ACTION, action, ctx.RUN) + } + default: + if kit.HasPrefixList(arg, ctx.RUN) { + ctx.ProcessFloat(m, action, arg, arg...) + } else { + m.Option(ice.POD, domain) + kit.If(action == XTERM, func() { arg = []string{cli.SH} }) + ctx.ProcessFloat(m, action, arg, arg...).ProcessField(ctx.ACTION, action, ctx.RUN) + } + } +} + +const MATRIX = "matrix" + +func init() { + Index.MergeCommands(ice.Commands{ + MATRIX: {Name: "matrix list", Help: "空间矩阵", Actions: ice.MergeActions(ice.Actions{ + INSTALL: {Hand: func(m *ice.Message, arg ...string) { + m.Cmd(Space(m, m.Option(DOMAIN)), DREAM, ctx.ACTION, mdb.CREATE, m.OptionSimple(mdb.NAME, mdb.ICONS, nfs.REPOS), nfs.BINARY, UserHost(m)+S(m.Option(mdb.NAME))) + m.Cmd(Space(m, m.Option(DOMAIN)), DREAM, ctx.ACTION, cli.START, m.OptionSimple(mdb.NAME)) + }}, + }, ctx.ConfAction(mdb.FIELD, "time,domain,status,type,name,text,icons,repos,binary,module,version")), Hand: func(m *ice.Message, arg ...string) { + if kit.HasPrefixList(arg, ctx.ACTION) { + _matrix_cmd(m, arg[1], arg[2:]...) + return + } + GoToast(m, "", func(toast func(name string, count, total int)) []string { + kit.For(_matrix_list(m, ""), func(domain string, index int, total int) { + toast(domain, index, total) + _matrix_list(m, domain) + }) + return nil + }).Sort("name,domain", "str_r", "str_r").Display("") + }}, + }) +} diff --git a/base/web/matrix.js b/base/web/matrix.js new file mode 100644 index 00000000..4c8fffcc --- /dev/null +++ b/base/web/matrix.js @@ -0,0 +1,26 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { var list = {}, domain = {contexts: true} + msg.Table(function(value) { var name = value.name||ice.CONTEXTS; domain[value.domain] = true, list[name] = list[name]||{}, list[name][value.domain] = value }) + var ui = can.page.Append(can, can._output, [{view: [wiki.CONTENT, html.TABLE], list: [{type: html.THEAD, list: [{type: html.TR, list: can.core.Item(domain, function(domain) { + var item = list[ice.CONTEXTS][domain] + return {type: html.TH, list: [{view: [html.ITEM], list: [{img: can.misc.Resource(can, item.icons||nfs.USR_ICONS_ICEBERGS)}, + {view: wiki.TITLE, list: [{text: item.domain}, can.onappend.label(can, item, {version: icon.version, compile: icon.compile}), can.onappend.buttons(can, item)]}, + ]}]} + }) }]}, {type: html.TBODY}] }]) + can.core.Item(list, function(name, value) { var i = 0; if (name == ice.CONTEXTS) { return } + can.page.Append(can, ui.tbody, [{type: html.TR, list: can.core.Item(domain, function(domain) { i++ + var item = value[domain]||{} + return {type: html.TD, list: [{view: [[html.ITEM, can.core.Value(list, can.core.Keys(name, domain, nfs.VERSION)) != can.core.Value(list, can.core.Keys(name, ice.CONTEXTS, nfs.VERSION))? "danger": ""]], list: item.name? [ + {img: can.misc.Resource(can, item.icons||nfs.USR_ICONS_VOLCANOS)}, + {view: wiki.TITLE, list: [{text: item.name}, can.onappend.label(can, item, {version: icon.version, time: icon.compile, time: icon.compile}), can.onappend.buttons(can, item)]}, + ]: [ + {view: html.ACTION, _init: function(target) { var worker = list[name][ice.CONTEXTS], server = list[ice.CONTEXTS][domain] + can.onappend.input(can, {type: html.BUTTON, name: code.INSTALL, onclick: function(event) { + can.Update(can.request(event, {name: name, domain: domain, port: server.port}, worker), [ctx.ACTION, code.INSTALL]) + }}, "", target) + }}, + ]}]} + }) }]) + }), can.onmotion.delay(can, function() { can.Status(mdb.COUNT, can.core.Item(list).length+"x"+can.core.Item(domain).length) }) + }, +}, [""])