mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
add plugin mind
This commit is contained in:
parent
624c0f3c90
commit
5e3dcff569
@ -4,5 +4,5 @@ var version = struct {
|
||||
host string
|
||||
self int
|
||||
}{
|
||||
"2019-09-10 15:30:05", "centos", 502,
|
||||
"2019-09-10 18:45:48", "centos", 508,
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"data": {Name: "data show|save|create|insert", Help: "数据", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"data": {Name: "data show|save|create|insert", Help: "数据", Form: map[string]int{"format": 1}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "show")
|
||||
}
|
||||
@ -431,10 +431,18 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
})
|
||||
|
||||
default: // 记录值
|
||||
m.Confm("flow", []string{m.Option("river"), "data", arg[1], "list", arg[2]}, func(key string, value string) {
|
||||
m.Push("key", key)
|
||||
m.Push("value", value)
|
||||
})
|
||||
index := kit.Int(arg[2]) - 1
|
||||
switch m.Option("format") {
|
||||
case "object":
|
||||
m.Confm("flow", []string{m.Option("river"), "data", arg[1], "list", kit.Format(index)}, func(key string, value string) {
|
||||
m.Push(key, value)
|
||||
})
|
||||
default:
|
||||
m.Confm("flow", []string{m.Option("river"), "data", arg[1], "list", kit.Format(index)}, func(key string, value string) {
|
||||
m.Push("key", key)
|
||||
m.Push("value", value)
|
||||
})
|
||||
}
|
||||
}
|
||||
m.Table()
|
||||
|
||||
@ -509,6 +517,12 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Log("info", "insert %s:%s %s", m.Option("river"), arg[1], kit.Format(data))
|
||||
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", "-2"}, data)
|
||||
m.Cmdy("ssh.data", "save", arg[1])
|
||||
|
||||
case "update":
|
||||
index := kit.Int(arg[2]) - 1
|
||||
for i := 3; i < len(arg) - 1; i += 2 {
|
||||
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", kit.Format(index), arg[i]}, arg[i+1])
|
||||
}
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
85
src/plugin/mind/index.go
Normal file
85
src/plugin/mind/index.go
Normal file
@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"contexts/cli"
|
||||
"contexts/ctx"
|
||||
"toolkit"
|
||||
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var Index = &ctx.Context{Name: "mind", Help: "思维导图",
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"doc": {Name: "doc", Help: "文档", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
m.Cmdy("ssh.data", "show", "doc")
|
||||
case 1:
|
||||
m.Cmdy("ssh.data", "show", "doc", arg[0])
|
||||
case 2:
|
||||
m.Cmdy("ssh.data", "insert", "doc", "title", arg[0], "content", arg[1])
|
||||
}
|
||||
return
|
||||
}},
|
||||
"xls": {Name: "xls", Help: "表格", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
m.Cmdy("ssh.data", "show", "xls")
|
||||
m.Meta["append"] = []string{"id", "title"}
|
||||
|
||||
case 1:
|
||||
var data map[int]map[int]string
|
||||
what := m.Cmd("ssh.data", "show", "xls", arg[0], "format", "object").Append("content")
|
||||
json.Unmarshal([]byte(what), &data)
|
||||
|
||||
max, n := 0, 0
|
||||
for i, v := range data {
|
||||
if i > n {
|
||||
n = i
|
||||
}
|
||||
for i := range v {
|
||||
if i > max {
|
||||
max = i
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Log("info", "m: %d n: %d", m, n)
|
||||
|
||||
for k := 0; k < n + 2; k++ {
|
||||
for i := 0; i < max + 2; i++ {
|
||||
m.Push(kit.Format(k), kit.Format(data[k][i]))
|
||||
}
|
||||
}
|
||||
|
||||
case 2:
|
||||
m.Cmdy("ssh.data", "insert", "xls", "title", arg[0], "content", arg[1])
|
||||
|
||||
default:
|
||||
data := map[int]map[int]string{}
|
||||
what := m.Cmd("ssh.data", "show", "xls", arg[0], "format", "object").Append("content")
|
||||
json.Unmarshal([]byte(what), &data)
|
||||
|
||||
for i := 1; i < len(arg) - 2; i += 3 {
|
||||
if _, ok := data[kit.Int(arg[i])]; !ok {
|
||||
data[kit.Int(arg[i])] = make(map[int]string)
|
||||
}
|
||||
data[kit.Int(arg[i])][kit.Int(arg[i+1])] = arg[i+2]
|
||||
}
|
||||
m.Cmdy("ssh.data", "update", "xls", arg[0], "content", kit.Format(data))
|
||||
}
|
||||
return
|
||||
}},
|
||||
"ppt": {Name: "ppt", Help: "文稿", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Echo(kit.Select("hello world", arg, 0))
|
||||
return
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
|
||||
}
|
75
src/plugin/mind/index.js
Normal file
75
src/plugin/mind/index.js
Normal file
@ -0,0 +1,75 @@
|
||||
|
||||
{init: function(run, field, option, output) {
|
||||
var stop = false
|
||||
return {
|
||||
ondaemon: {
|
||||
table: function(msg, cb) {
|
||||
if (stop) {return}
|
||||
var plugin = field.Plugin
|
||||
output.innerHTML = "", msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), "", function(event, value, name, line, index) {
|
||||
if (name == "id") {
|
||||
page.Sync("plugin_"+plugin.exports[0]).set(plugin.onexport[plugin.exports[2]||""](value, name, line))
|
||||
} else {
|
||||
var td = event.target
|
||||
function submit(event) {
|
||||
td.innerText = event.target.value
|
||||
if (event.target.value != value) {
|
||||
stop = true
|
||||
plugin.Run(event, [option.title.value, name, index-1, event.target.value], function() {
|
||||
plugin.Check()
|
||||
stop = false
|
||||
})
|
||||
}
|
||||
}
|
||||
kit.AppendChilds(td, [{type: "input", value: value, data: {onblur: function(event) {
|
||||
submit(event)
|
||||
}, onkeyup: function(event) {
|
||||
switch (event.key) {
|
||||
case "Enter":
|
||||
break
|
||||
case "Tab":
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
}, onkeydown: function(event) {
|
||||
console.log(event.key)
|
||||
switch (event.key) {
|
||||
case "Enter":
|
||||
if (event.shiftKey) {
|
||||
td.parentNode.previousSibling.querySelector("td").click()
|
||||
} else {
|
||||
td.parentNode.nextSibling.querySelector("td").click()
|
||||
}
|
||||
break
|
||||
case "Tab":
|
||||
if (event.shiftKey) {
|
||||
if (td.previousSibling) {
|
||||
td.previousSibling.click()
|
||||
} else {
|
||||
td.parentNode.previousSibling.querySelector("td").click()
|
||||
}
|
||||
} else {
|
||||
if (td.nextSibling) {
|
||||
td.nextSibling.click()
|
||||
} else {
|
||||
td.parentNode.nextSibling.querySelector("td").click()
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
}}}]).first.focus()
|
||||
}
|
||||
})
|
||||
typeof cb == "function" && cb(msg)
|
||||
},
|
||||
},
|
||||
|
||||
}
|
||||
}}
|
15
src/plugin/mind/index.shy
Normal file
15
src/plugin/mind/index.shy
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
kit doc "文档" private \
|
||||
text "" name title imports plugin_doc_id action auto \
|
||||
text "" name content \
|
||||
button "执行" \
|
||||
button "返回" click Last \
|
||||
exports doc_id id
|
||||
|
||||
kit xls "表格" "index.js" private \
|
||||
text "" name title imports plugin_xls_id action auto \
|
||||
text "" name content \
|
||||
button "执行" \
|
||||
button "返回" click Last \
|
||||
feature style "output full" \
|
||||
exports xls_id id
|
1
src/plugin/mind/local.shy
Normal file
1
src/plugin/mind/local.shy
Normal file
@ -0,0 +1 @@
|
||||
|
@ -253,6 +253,9 @@ fieldset.item>div.output>div.status>input.cmd {
|
||||
font-size:16px;
|
||||
width:250px;
|
||||
}
|
||||
fieldset.item div.output.full table td {
|
||||
height:16px;
|
||||
}
|
||||
|
||||
fieldset.item.select {
|
||||
background-color:gold;
|
||||
@ -284,6 +287,7 @@ fieldset table th.order {
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table td {
|
||||
min-height:16px;
|
||||
max-width:1200px;
|
||||
font-family:monospace;
|
||||
padding-left: 10px;
|
||||
|
@ -702,6 +702,7 @@ function Plugin(page, pane, field, runs) {
|
||||
var exports = JSON.parse(meta.exports||'["",""]')
|
||||
var deal = (feature && feature.display) || "table"
|
||||
var history = []
|
||||
output.className = feature.style || "item"
|
||||
|
||||
var plugin = Meta(field, (field.Script && field.Script.init || function() {
|
||||
})(run, field, option, output)||{}, {
|
||||
|
@ -407,19 +407,17 @@ kit = toolkit = {
|
||||
OrderTable: function(table, field, cb) {
|
||||
if (!table) {return}
|
||||
table.onclick = function(event) {
|
||||
var index = 0
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var head = target.parentElement.parentElement.querySelector("tr")
|
||||
kit.Selector(table, "tr.select", function(item) {
|
||||
item.className = ""
|
||||
})
|
||||
kit.Selector(table, "td.select", function(item) {
|
||||
item.className = ""
|
||||
})
|
||||
kit.Selector(table, "tr.select", function(item) {item.className = ""})
|
||||
kit.Selector(table, "td.select", function(item) {item.className = ""})
|
||||
kit.Selector(table, "tr", function(item, i) {item == target.parentElement && (index = i)})
|
||||
|
||||
target.parentElement.childNodes.forEach(function(item, i) {
|
||||
if (item != target) {
|
||||
return
|
||||
}
|
||||
if (item != target) {return}
|
||||
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
|
||||
@ -429,7 +427,7 @@ kit = toolkit = {
|
||||
if (name.startsWith(field)) {
|
||||
item.className = "select"
|
||||
item.parentElement.className = "select"
|
||||
typeof cb == "function" && cb(event, item.innerText, name,item.parentNode.Meta)
|
||||
typeof cb == "function" && cb(event, item.innerText, name, item.parentNode.Meta, index)
|
||||
}
|
||||
kit.CopyText()
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user