From b3a09d726fadb29027f071e7d99e7003ff15707e Mon Sep 17 00:00:00 2001 From: shy Date: Sat, 9 Dec 2023 08:32:08 +0800 Subject: [PATCH] opt m.FormatMeta --- const.js | 3 ++- frame.js | 13 ++++++------- lib/base.js | 3 +-- lib/misc.js | 3 ++- lib/page.js | 2 ++ plugin/story/stats.js | 13 +++++-------- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/const.js b/const.js index 198ad79a..c05dcd48 100644 --- a/const.js +++ b/const.js @@ -43,6 +43,7 @@ var ice = { MSG_USERNICK: "user.nick", MSG_USERNAME: "user.name", MSG_USERROLE: "user.role", MSG_LANGUAGE: "user.lang", MSG_MODE: "sess.mode", MSG_THEME: "sess.theme", MSG_TITLE: "sess.title", MSG_RIVER: "sess.river", MSG_STORM: "sess.storm", MSG_DAEMON: "sess.daemon", LOG_DISABLE: "log.disable", LOG_TRACEID: "log.id", + MSG_COST: "sess.cost", MSG_DEBUG: "debug", ErrWarn: "warn: ", ErrNotLogin: "not login: ", ErrNotRight: "not right: ", ErrNotValid: "not valid: ", ErrNotFound: "not found: ", @@ -74,7 +75,7 @@ var web = {CHAT: "chat", PORTAL: "portal", STUDIO: "studio", SERVICE: "service", VENDOR: "vendor", SERVE: "serve", SPACE: "space", ROUTE: "route", DREAM: "dream", SPIDE: "spide", TOKEN: "token", SHARE: "share", COUNT: "count", - ADMIN: "admin", + STATS: "stats", ADMIN: "admin", WORKER: "worker", SERVER: "server", GATEWAY: "gateway", ONLINE: "online", OFFLINE: "offline", OPEN: "open", LINK: "link", HTTP: "http", DOMAIN: "domain", URL: "url", diff --git a/frame.js b/frame.js index fbce5a5a..71aeaed6 100644 --- a/frame.js +++ b/frame.js @@ -17,18 +17,16 @@ Volcanos(chat.ONENGINE, {_init: function(can, meta, list, cb, target) { if (!sub || !mod || !fun) { can.misc.Warn(ice.ErrNotFound, cmds); return can.base.isFunc(cb) && cb(msg.Echo(ice.ErrWarn, ice.ErrNotFound, cmds)) } return can.core.CallFunc(fun, {event: event, can: sub, msg: msg, cmds: cmds.slice(2), cb: cb, target: sub._target, button: key, cmd: key, arg: cmds.slice(2), list: cmds.slice(2)}, mod) }, - _remote: function(event, can, msg, panel, cmds, cb) { var sub = msg._can; + _remote: function(event, can, msg, panel, cmds, cb) { var sub = msg._can if (panel.onengine._plugin(event, can, msg, panel, cmds, cb)) { return } if (panel.onengine._engine(event, can, msg, panel, cmds, cb)) { return } if (panel.onengine._static(event, can, msg, panel, cmds, cb)) { return } var toast, _toast = msg.Option(chat._TOAST); if (_toast) { can.onmotion.delay(can, function() { if (msg._can && msg._can._toast) { return } toast = toast||can.user.toastProcess(msg._can, _toast) }, 500) } if (can.base.isUndefined(msg[ice.MSG_DAEMON])) { can.base.isUndefined(sub._daemon) && can.ondaemon._list[0] && (sub._daemon = can.ondaemon._list.push(sub)-1) if (sub._daemon) { msg.Option(ice.MSG_DAEMON, can.core.Keys(can.ondaemon._list[0], sub._daemon)) } - } can.page.exportValue(sub, msg) - if (!can.misc.CookieSessid(can) && can.user.info.sessid) { msg.Option(ice.MSG_SESSID, can.user.info.sessid) } - msg.OptionDefault(ice.MSG_THEME, can.getHeaderTheme()) + } if (!can.misc.CookieSessid(can) && can.user.info.sessid) { msg.Option(ice.MSG_SESSID, can.user.info.sessid) } var names = msg.Option(chat._NAMES)||panel._names||((can.Conf("iceberg")||Volcanos.meta.iceberg)+"/chat/"+panel._name+"/") - names = can.base.MergeURL(names, ice.MSG_INDEX, sub.ConfIndex(), ice.MSG_LANGUAGE, can.user.info.language, ice.MSG_THEME, can.getHeader(chat.THEME)) + names = can.base.MergeURL(names, ice.MSG_INDEX, sub.ConfIndex()), can.page.exportValue(sub, msg) can.onengine.signal(panel, chat.ONREMOTE, can.request({}, {_follow: panel._follow, _msg: msg, _cmds: cmds, names: names})) can.misc.Run(event, can, {names: names}, cmds, function(msg) { toast && toast.close && toast.close(), toast = true can.base.isFunc(cb) && cb(msg), Volcanos.meta.pack[can.core.Keys(panel._name, cmds.join(mdb.FS))] = msg @@ -247,7 +245,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { can.core.CallFunc([sub, chat.ONIMPORT, chat._INIT], {can: sub, msg: msg, cb: function(msg) { if (action !== false) { can.onkeymap._build(sub) can.onmotion.clear(can, can._action), sub.onappend._action(sub, can.Conf(ice.MSG_ACTION)||msg.Option(ice.MSG_ACTION), action||can._action) - sub.onappend._status(sub, sub.onexport&&sub.onexport.list||msg.Option(ice.MSG_STATUS)), can.user.isMobile || sub.onappend.tools(sub, msg) + sub.onappend._status(sub, sub.onexport&&sub.onexport.list||msg.Option(ice.MSG_STATUS), null, msg), can.user.isMobile || sub.onappend.tools(sub, msg) can.core.Item(can.Action(), function(key) { var value = can.misc.sessionStorage(can, [can.ConfIndex(), ctx.ACTION, key]); value && can.Action(key, value[0]) }) } can.onappend.style(sub, sub.Conf(ctx.STYLE)), can.onmotion.story.auto(can, can._output) if (can.onimport.size) { @@ -260,13 +258,14 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { }, target: output}) }) }, - _status: function(can, list, status) { status = status||can._status, can.onmotion.clear(can, status); var keys = {} + _status: function(can, list, status, msg) { status = status||can._status, can.onmotion.clear(can, status); var keys = {} can.core.List((can.base.Obj(list, can.core.Value(can, [chat.ONEXPORT, mdb.LIST]))||[]).concat(can.misc.Search(can, log.DEBUG)==ice.TRUE? [ {name: html.HEIGHT, value: can.ConfHeight()}, {name: html.WIDTH, value: can.ConfWidth()}, ]: []), function(item) { item = can.base.isString(item)? {name: item}: item if (item && item.name == web.SPACE && item.value) { item.value = can.page.Format(html.A, can.misc.MergePodCmd(can, {pod: item.value}), item.value) } if (can.base.beginWith(item.value, nfs.PS, ice.HTTP)) { item.value = can.page.Format(html.A, item.value, item.value.split("?")[0]) } if (keys[item.name]) { return can.Status(item.name, item.value) } keys[item.name] = item + msg && item.name == cli.COST && (item.value = msg.Option(ice.MSG_COST)||item.value) can.page.Append(can, status, [{view: html.ITEM, list: [ {text: [can.page.Color(can.user.trans(can, item.name, null, html.INPUT)), html.LABEL]}, {text: [": ", html.LABEL]}, {text: [(item.value == undefined? "": (item.value+"").trim())+"", html.SPAN, item.name]}, ], onclick: function(event) { can.user.copy(event, can, item.value) }}]) diff --git a/lib/base.js b/lib/base.js index 0444b312..1e12d751 100644 --- a/lib/base.js +++ b/lib/base.js @@ -108,7 +108,7 @@ Volcanos("base", { h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24) h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000 h = parseInt(n/60000), h > 0 && (res += h+"m"), n = n % 60000 - h = parseInt(n/1000), h > 0 && (res += h), n = n % 1000 + h = parseInt(n/1000), h > 0 && (res += h+"s"), n = n % 1000 return res + (n > 0? nfs.PT+parseInt(n/10): "") + "s" }, isNight: function() { var now = new Date(); return now.getHours() < 7 || now.getHours() > 17 }, @@ -116,7 +116,6 @@ Volcanos("base", { isString: function(val) { return typeof val == code.STRING }, isObject: function(val) { return typeof val == code.OBJECT }, isArray: function(val) { return Array.isArray(val) }, - // isArray: function(val) { return typeof val == code.OBJECT && val.length != undefined }, isFunc: function(val) { return typeof val == code.FUNCTION }, isUndefined: function(val) { return val == undefined }, isNull: function(val) { return val == null }, diff --git a/lib/misc.js b/lib/misc.js index 70ed4679..30c980b5 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -94,6 +94,7 @@ Volcanos("misc", { }) }, POST: function(can, msg, url, form, cb, cbs) { var xhr = new XMLHttpRequest(), begin = new Date(); msg._xhr = xhr + xhr._begin = begin var data = can.core.ItemForm(form, function(v, i, k) { return k+mdb.EQ+encodeURIComponent(v) }).join("&") if (data && can.base.isIn(msg._method, http.GET, http.DELETE)) { url += (url.indexOf("?") == -1? "?": "&")+data, data = "" } xhr.open(msg._method||http.POST, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return } @@ -116,7 +117,7 @@ Volcanos("misc", { } try { xhr.send(data) } catch(e) { can.misc.Warn(e), cbs && cbs(e) } }, WSS: function(can, args, cb, onopen, onclose, onerror, _msg) { if (can.user.isIE) { return } - var msg = can.request(); can.page.exportValue(can, msg), args[ice.MSG_THEME] = can.getHeaderTheme() + var msg = can.request(); can.page.exportValue(can, msg) can.core.List(msg.Option(), function(value) { args[value] = msg.Option(value) }) var url = location.protocol.replace(ice.HTTP, "ws")+"//"+location.host+"/space/" if (url.indexOf(html.CHROME) == 0) { url = "ws://localhost:9020/space/" } diff --git a/lib/page.js b/lib/page.js index 7ae46edb..0aafb3d1 100644 --- a/lib/page.js +++ b/lib/page.js @@ -381,8 +381,10 @@ Volcanos("page", { can.base.isIn(name, mdb.REMOVE, mdb.DELETE, mdb.PRUNES, mdb.PRUNE, nfs.TRASH, "drop", cli.STOP, "stopall")? "danger": "" }, exportValue: function(can, msg, target) { target = target||can._output + msg.OptionDefault(ice.MSG_THEME, can.getHeaderTheme()) msg.OptionDefault(ice.MSG_BG, can.page.styleValue(can, "--plugin-bg-color", target)) msg.OptionDefault(ice.MSG_FG, can.page.styleValue(can, "--plugin-fg-color", target)) + msg.OptionDefault(ice.MSG_LANGUAGE, can.user.info.language) return msg }, styleValue: function(can, key, target) { const styles = getComputedStyle(target||document.body); return styles.getPropertyValue(key) }, diff --git a/plugin/story/stats.js b/plugin/story/stats.js index 3114fdb7..e77dfeba 100644 --- a/plugin/story/stats.js +++ b/plugin/story/stats.js @@ -1,12 +1,9 @@ Volcanos(chat.ONIMPORT, { - _init: function(can, msg) { can.onappend.style(can, ["stats", html.FLEX], can._output) - var list = {} - var stats = {}, units = {}, trans = {}, index = {}; msg.Table(function(value) { + _init: function(can, msg) { can.onappend.style(can, [web.STATS, html.FLEX], can._output) + var list = {}, stats = {}, units = {}, trans = {}, index = {}; msg.Table(function(value) { stats[value.name] = parseFloat(stats[value.name]||"0") + parseFloat(value.value) - units[value.name] = value.units - trans[value.name] = value._trans - index[value.name] = value.index - list[value.name] = value + units[value.name] = value.units, trans[value.name] = value._trans + index[value.name] = value.index, list[value.name] = value }) function fmts(value) { var ls = [] while (value > 0) { ls.push(value%1000) @@ -16,7 +13,7 @@ Volcanos(chat.ONIMPORT, { } can.user.trans(can, trans, null, html.INPUT) can.core.Item(stats, function(name, value) { can.page.Append(can, can._output, [{view: [[html.ITEM, name, html.FLEX]], list: [ - {view: mdb.VALUE, list: [{text: can.base.trimSuffix(fmts(parseFloat(value).toFixed(2))+"", ".00")}, {text: [units[name], "", "units"]}]}, + {view: mdb.VALUE, list: [{text: can.base.trimSuffix(fmts(parseFloat(value).toFixed(2))+"", ".00")}, {text: [units[name], "", mall.UNITS]}]}, {view: [mdb.NAME, "", can.user.trans(can, name, trans[name]||null, html.INPUT)]}, ], onclick: function() { can.onappend.plugin(can, {space: list[name].space, index: index[name], style: html.FLOAT})