1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

add wiki farvor

This commit is contained in:
shaoying 2019-12-01 17:18:36 +08:00
parent 882e4b4211
commit 2cdc04f9a0
11 changed files with 177 additions and 51 deletions

View File

@ -434,6 +434,13 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
arg = append(arg, "show")
}
if m.Conf("data", "local") == "single" {
m.Confm("flow", func(key string, value map[string]interface{}) {
m.Log("info", "river map %v->%v", m.Option("river"), key)
m.Option("river", key)
})
}
switch arg[0] {
case "show":
if len(arg) > 1 && arg[1] == "" {

View File

@ -356,7 +356,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
if m.Cmd("/upload"); m.Options("dream") {
// 下发文件
m.Cmd("ssh._route", m.Option("dream"), "web.get", "dev", "/download/"+m.Append("hash"),
"save", m.Conf("login", "script")+"/"+m.Append("name"))
"save", m.Conf("login", "meta.script")+"/"+m.Append("name"))
}
m.Echo("code: %s\n", m.Append("code"))
m.Echo("hash: %s\n", m.Append("hash"))
@ -497,7 +497,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
// 生成脚本
m.Echo("#/bin/sh\n\n")
m.Cmd(prefix, "list", m.Option("favor"), "", kit.Select("10", m.Option("limit")), "0", "tab", m.Option("tab")).Table(func(index int, value map[string]string) {
m.Cmd(prefix, "list", m.Option("favor"), "", kit.Select("1000", m.Option("limit")), "0", "tab", m.Option("tab")).Table(func(index int, value map[string]string) {
m.Echo("# %v:%v\n%v\n\n", value["tab"], value["note"], value["word"])
})
@ -553,7 +553,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
case "git":
if s, e := os.Stat(path.Join(p, ".git")); e == nil && s.IsDir() {
if s, e := os.Stat(path.Join(p, ".git")); e == nil && s.IsDir() || arg[1] == "init" {
m.Cmdy(".git", p, arg[1:])
break
}
@ -644,7 +644,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
return
case "favor":
env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment")
env := m.Cmdx(prefix, "show-environment", "-g") + m.Cmdx(prefix, "show-environment", "-t", arg[0])
for _, l := range strings.Split(env, "\n") {
if strings.HasPrefix(l, "ctx_") {
v := strings.SplitN(l, "=", 2)
@ -917,15 +917,13 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
switch arg[0] {
case "init":
if s, e := os.Stat(path.Join(prefix[len(prefix)-1], ".git")); e == nil && s.IsDir() {
if len(arg) > 1 {
m.Cmdy(prefix, "remote", "add", "-f", kit.Select("origin", arg, 2), arg[1])
}
} else if len(arg) > 1 {
m.Cmdy(prefix, "clone", arg[1], ".")
} else {
if _, e := os.Stat(path.Join(prefix[len(prefix)-1], ".git")); e != nil {
m.Cmdy(prefix, "init")
}
if len(arg) > 1 {
m.Cmdy(prefix, "remote", "add", "-f", kit.Select("origin", arg, 2), arg[1])
m.Cmdy(prefix, "pull", kit.Select("origin", arg, 2), kit.Select("master", arg, 3))
}
m.Confm("git", "alias", func(key string, value string) {
m.Cmdy(prefix, "config", "alias."+key, value)

View File

@ -9,6 +9,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"path"
"strconv"
"strings"
@ -18,7 +20,9 @@ import (
var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"login": {Name: "login", Value: map[string]interface{}{"check": "false"}, Help: "用户登录"},
"login": {Name: "login", Value: map[string]interface{}{"check": "false", "meta": map[string]interface{}{
"script": "usr/script",
}}, Help: "用户登录"},
"componet": {Name: "componet", Value: map[string]interface{}{
"index": []interface{}{
map[string]interface{}{"name": "wiki",
@ -239,12 +243,58 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
return
}},
"refer": {Name: "refer", Help: "链接地址", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
m.Set("option", "render", "raw").Echo(`%s: <a href="%s" target="_blank">%s</a>`, arg[0], arg[1], arg[1])
if len(arg) == 1 {
cmd, arg = arg[0], arg[1:]
for _, l := range strings.Split(strings.TrimSpace(cmd), "\n") {
if l = strings.TrimSpace(l); len(l) > 0 {
arg = append(arg, kit.Split(l, ' ', 2)...)
}
}
}
m.Set("option", "render", "order")
for i := 0; i < len(arg)-1; i += 2 {
m.Push("list", fmt.Sprintf(`%s: <a href="%s" target="_blank">%s</a>`, arg[i], arg[i+1], arg[i+1]))
}
return
}},
"favor": {Name: "favor type tab", Help: "链接地址", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
msg := m.Cmd("ssh.data", "show", "tip", "", "1000", "0", "tab", arg[1])
switch arg[0] {
case "script":
m.Set("option", "render", "code")
if b, e := ioutil.ReadFile(path.Join(m.Conf("login", "meta.script"), arg[1])); e == nil {
m.Echo(string(b))
}
case "li":
m.Set("option", "render", "order")
msg.Table(func(index int, value map[string]string) {
m.Push("list", fmt.Sprintf(`%s: <a href="%s" target="_blank">%s</a>`, value["note"], value["word"], value["word"]))
})
case "sh":
m.Set("option", "render", "code")
m.Echo("#! /bin/sh\n")
m.Echo("# %v\n", arg[1])
m.Echo("\n")
msg.Table(func(index int, value map[string]string) {
m.Echo("# %d %v\n%v\n\n", index, value["note"], value["word"])
})
}
return
}},
"shell": {Name: "shell dir cmd", Help: "命令行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Option("render", "code")
m.Echo("$ %v\n", strings.Join(arg[1:], " "))
m.Cmdy("cli.system", "cmd_dir", arg[0], "bash", "-c", strings.Join(arg[1:], " "))
return
}},
"title": {Name: "title text", Help: "一级标题", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
m.Set("option", "render", cmd).Echo(kit.Select("", arg, 0))
ns := strings.Split(m.Conf("runtime", "node.name"), "-")
m.Set("option", "render", cmd).Echo(kit.Select(ns[len(ns)-1], arg, 0))
return
}},
"chapter": {Name: "chaper text", Help: "二级标题", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
@ -267,11 +317,6 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
return
}},
"runs": {Name: "run", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Option("render", "code")
m.Cmdy(arg).Set("append")
return
}},
"run": {Name: "run", Help: "便签", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Option("render", "raw")
m.Cmdy(arg)

View File

@ -51,7 +51,7 @@ kit cmd "命令" private "_:context" _ _ command \
kit dir "目录" private "_:nfs.dir" _ _ time size line path \
text "" name pod imports plugin_pod action auto \
text "usr/script" name dir imports plugin_dir action auto view long \
text "usr/local" name dir imports plugin_dir action auto view long \
button "浏览" action auto \
button "返回" cb Last \
feature display editor \

View File

@ -59,7 +59,7 @@ kit command "命令" private "web.code.docker" "command" \
text "" name arg view long \
button "执行"
kit git "记录" private "_:web.code.zsh" "@pod"\
kit git "记录" private "_:web.code.zsh" "@you"\
text "usr/local" name dir imports plugin_git_path action auto \
select "git" name cmd values git \
select "status" name cmd values "diff status commit branch remote pull push sum init" action auto \

View File

@ -42,3 +42,15 @@ kit xls "表格" "index.js" "index.css" private "web.wiki.xls" \
feature style "mind" \
exports xls_id id
kit audio "" public "web.wiki.audio" \
text "" name dream imports plugin_you \
button "查看"
kit vedio "视频" public "web.wiki.vedio" \
text "" name dream imports plugin_you \
button "查看"
kit vedio "视频" public "web.wiki.vedio" \
text "usr/local/vedio/5b58edd8b722c7ac7d86c5281276b7ed_wm.mp4" name file \
feature display video \
button "查看"

View File

@ -1,6 +1,6 @@
kit tips "便签" private "_:web.code.favor" "@you" list \
text "tip" name favor view tiny \
text "tip" name table view tiny \
text "" name index imports plugin_vim_favor view tiny action auto \
text "" name limit view tiny \
text "" name offend view tiny \

View File

@ -397,6 +397,18 @@ var page = Page({
"绘图": function(event, value) {
page.plugin && page.plugin.Plugin.onfigure("canvas")
},
"视频": function(event, value) {
page.plugin && page.plugin.Plugin.onfigure("video")
},
"音频": function(event, value) {
page.plugin && page.plugin.Plugin.onfigure("audio")
},
"相册": function(event, value) {
page.plugin && page.plugin.Plugin.onfigure("album")
},
"媒体": function(event, value) {
page.plugin && page.plugin.Plugin.onfigure("media")
},
"复制": function(event, value) {
page.plugin && page.plugin.Plugin.Clone()
@ -434,7 +446,7 @@ var page = Page({
},
Button: [["layout", "工作", "办公", "聊天", "最高", "最宽", "最大"],
"", "刷新", "清屏", "并行", "串行",
"", ["display", "表格", "编辑", "绘图"],
"", ["display", "表格", "编辑", "绘图", "媒体"],
"", "复制", "删除", "加参", "减参",
"", "执行", "下载", "清空", "返回",
"", kit.CreateMeta("input", "pod"),

View File

@ -467,3 +467,15 @@ fieldset div.output div.story {
padding:16px;
border:solid 2px green;
}
fieldset.item div.output div.story.code {
color:white;
font-size:14px;
font-family:monospace;
background-color:#272822;
white-space:pre;
padding:10px;
overflow:auto;
border:solid 3px green;
max-height:640px;
}

View File

@ -1480,7 +1480,19 @@ function Output(plugin, type, msg, cb, target, option) {
return (target.value = args[0]) || plugin.Zone("value", args[0])
},
size: function(cb, ncol, nrow) {ncol = ncol || 1, nrow = nrow || 1
plugin.onfigure.meta.size(function(width, height) {
cb(width/ncol-10, height/nrow-10)
})
},
onimport: shy("导入数据", {
_video: function(msg, line, width, height) {
kit.AppendChild(target, [{type: "video", style: {width: width},
data: {controls: "controls", autoplay: false, loop: true, src: line.file}}])
},
_image: function(msg, line, width, height) {
kit.AppendChild(target, [{type: "img", data: {src: line.file}, style: {width: width}}])
},
_table: function(msg, list) {
return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), msg.Table(), list), "", output.onexport, function(event, value, name, line, index) {
var td = event.target
@ -1552,19 +1564,49 @@ function Output(plugin, type, msg, cb, target, option) {
)
})
},
_code: function(msg) {
_code: function(msg, line) {
return msg.result && msg.result.length > 0 && kit.OrderCode(kit.AppendChild(target, [{view: ["code", "div", msg.Results()]}]).first)
},
code: function(msg, cb) {
_svg: function(width, height, src) {
kit.AppendChild(target, '<embed src="'+src+'" width="'+width+'" height="'+height+'" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />')
},
svg: function(msg, cb) {var meta = output.onimport.meta
plugin.onfigure.meta.size(function(width, height) {
meta._svg(output.target, width, height*1.6, msg.result.join(""))
})
},
code: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", output.onimport.meta._code(msg)
typeof cb == "function" && cb(msg)
},
table: function(msg, cb) {
table: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = ""
output.onimport.meta._table(msg, msg.append) || output.onimport.meta._code(msg)
typeof cb == "function" && cb(msg)
},
inner: function(msg, cb) {
album: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", msg.Table(function(line) {meta._image(msg, line)})
},
video: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", msg.Table(function(line) {meta._video(msg, line)})
},
audio: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", msg.Table(function(line) {meta._audio(msg, line)})
},
media: function(msg, cb) {var meta = output.onimport.meta
output.size(function(width, height) {
target.innerHTML = "", msg.Table(function(line) {var ls = (line.file||line.path).split(".")
line.file = line.file? line.file: "/download/"+line.path
switch (ls[ls.length-1].toLowerCase()) {
case "mp4": meta._video(msg, line, width, height); break
case "png": meta._image(msg, line, width, height); break
case "svg": meta._svg(msg, line, width, height); break
}
})
}, 3)
},
inner: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", plugin.onfigure.meta.max(target)
output.onimport.meta._table(msg, msg.append) || kit.OrderCode(kit.ModifyNode(target, msg.result.join("")))
kit._call(cb, [msg])
@ -1596,15 +1638,7 @@ function Output(plugin, type, msg, cb, target, option) {
}
})
},
_svg: function(target, width, height, src) {
target.innerHTML = '<embed src="'+src+'" width="'+width+'" height="'+height+'" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />'
},
svg: function(msg, cb) {
plugin.onfigure.meta.size(function(width, height) {
output.onimport.meta._svg(output.target, width, height*1.6, msg.result.join(""))
})
},
editor: function(msg, cb) {
editor: function(msg, cb) {var meta = output.onimport.meta
output.onimport.meta.table(msg, cb)
var current = page.Sync("plugin_editor_index").get()
@ -1625,14 +1659,13 @@ function Output(plugin, type, msg, cb, target, option) {
})
}
},
canvas: function(msg, cb) {
canvas: function(msg, cb) {var meta = output.onimport.meta
target.innerHTML = "", plugin.onfigure.meta.size(function(width, height) {
Canvas(plugin, option, target, width-45, height-175, 10, msg)
})
},
}, function(type, msg, cb) {var meta = arguments.callee.meta
page.output = target
meta[type](msg, cb)
}, function(type, msg, cb) {var meta = output.onimport.meta
page.output = target, meta[type](msg, cb)
}),
ondetail: shy("菜单列表", {
"删除": "_table",
@ -1646,9 +1679,10 @@ function Output(plugin, type, msg, cb, target, option) {
"清空": "clear",
"复制": "Copy",
"下载": "Download",
"绘图": function() {plugin.onfigure("canvas")},
"表格": function() {plugin.onfigure("table")},
}, ["返回", "清空", "复制", "下载", "绘图", "表格"], function(event, value, meta) {
"媒体": function() {plugin.onfigure("media")},
"绘图": function() {plugin.onfigure("canvas")},
}, ["返回", "清空", "复制", "下载", "表格", "媒体", "绘图"], function(event, value, meta) {
return output._call(meta[value], event)
}),
onaction: shy("事件列表", {

View File

@ -1,16 +1,22 @@
{{define "table"}}<table class="story" data-scene='{{options . "scene"}}'
data-enjoy='{{options . "enjoy"}}' data-happy='{{options . "happy"}}'>{{range $i, $line := .|trans}}
{{define "table"}}
<table class="story" data-scene='{{options . "scene"}}' data-enjoy='{{options . "enjoy"}}' data-happy='{{options . "happy"}}'>
{{range $i, $line := .|trans}}
{{if eq $i 0}}
<tr>{{range $i, $v := $line}}<th>{{$v}}</th>{{end}}</tr>
<tr>{{range $i, $v := $line}}<th>{{$v}}</th>{{end}}</tr>
{{else}}
<tr>{{range $i, $v := $line}}<td>{{$v}}</td>{{end}}</tr>
<tr>{{range $i, $v := $line}}<td>{{$v}}</td>{{end}}</tr>
{{end}}
{{end}}</table>{{end}}
{{end}}
</table>
{{end}}
{{define "order"}}<ul class="story" data-scene='{{options . "scene"}}'
data-enjoy='{{options . "enjoy"}}' data-happy='{{options . "happy"}}'>
{{define "order"}}
<ul class="story" data-scene='{{options . "scene"}}' data-enjoy='{{options . "enjoy"}}' data-happy='{{options . "happy"}}'>
{{range $i, $line := .Meta.list}}<li>{{$line}}</li>{{end}}
</ul>{{end}}
</ul>
{{end}}
{{define "code"}}<div class="story">{{results .}}</div>{{end}}
{{define "code"}}
<div class="story code">{{results .}}</div>
{{end}}