forked from x/ContextOS
add bench.quick
Change-Id: I2a92a3ecc530c2aa60bf08e0d549601f5ff5fa47
This commit is contained in:
parent
6c8439711e
commit
f7bf81abb8
6
Makefile
6
Makefile
@ -23,9 +23,9 @@ install_all: install
|
||||
run:
|
||||
etc/bootstrap.sh
|
||||
shy:
|
||||
cp -r src/ ~/shycontext/
|
||||
cp -r usr/template/ ~/shycontext/usr/
|
||||
cp -r usr/librarys/ ~/shycontext/usr/
|
||||
cp -r src/contexts ~/context/src/
|
||||
cp -r usr/template ~/context/usr/
|
||||
cp -r usr/librarys/ ~/context/usr/
|
||||
|
||||
tar:
|
||||
[ -e tar ] || mkdir tar
|
||||
|
@ -609,7 +609,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
return
|
||||
}
|
||||
|
||||
if m.Sess("nfs").Cmd("path", arg[0]).Results(0) {
|
||||
if m.Sess("nfs").Cmd("path", arg[0]).Results(0) && arg[0] != "bench" {
|
||||
m.Start(fmt.Sprintf("shell%d", m.Capi("nshell", 1)), "shell", arg...)
|
||||
if len(arg) < 2 || arg[1] != "async" {
|
||||
m.Wait()
|
||||
@ -624,7 +624,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
// "source_ctx": m.Option("current_ctx"),
|
||||
// "source_cmd": strings.Join(arg, " "),
|
||||
// })
|
||||
//
|
||||
//
|
||||
if m.Options("current_ctx") {
|
||||
args := []string{"context", m.Option("current_ctx")}
|
||||
arg = append(args, arg...)
|
||||
|
@ -227,7 +227,7 @@ func (web *WEB) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
|
||||
web.ServeMux = http.NewServeMux()
|
||||
web.Template = template.New("render").Funcs(ctx.CGI)
|
||||
template.Must(web.Template.ParseGlob(path.Join(m.Conf("template_dir"), m.Conf("template_sub"), "/*.tmpl")))
|
||||
web.Template.ParseGlob(path.Join(m.Conf("template_dir"), m.Conf("template_sub"), "/*.tmpl"))
|
||||
return web
|
||||
}
|
||||
func (web *WEB) Start(m *ctx.Message, arg ...string) bool {
|
||||
@ -356,6 +356,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
"base": []interface{}{"key", "share", "comment", "creator", "create_time", "modify_time", "commands"},
|
||||
"link": []interface{}{"share", "comment", "creator", "link"},
|
||||
}, Help: "工作流"},
|
||||
"docker_view": &ctx.Config{Name: "docker_view", Value: map[string]interface{}{
|
||||
"top": 200, "left": 10, "width": 480, "height": 320,
|
||||
}, Help: "工作流"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"client": &ctx.Command{Name: "client address [output [editor]]", Help: "添加浏览器配置, address: 默认地址, output: 输出路径, editor: 编辑器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
|
@ -4,15 +4,37 @@ var code = {
|
||||
inputs: [],
|
||||
ninput: 0,
|
||||
|
||||
quick_txt: false,
|
||||
ntext: 1,
|
||||
|
||||
ncommand: 1,
|
||||
show_result: true,
|
||||
show_height: "30px",
|
||||
hide_height: "14px",
|
||||
scroll_x: 50,
|
||||
scroll_y: 50,
|
||||
current_cmd: "",
|
||||
}
|
||||
|
||||
function copy_to_clipboard(text) {
|
||||
function save_clipboard(item) {
|
||||
var txt = []
|
||||
var li = item.parentElement.children
|
||||
for (var i = 0; i < li.length; i++) {
|
||||
if (li[i].dataset["text"]) {
|
||||
txt.push(li[i].dataset["text"])
|
||||
}
|
||||
}
|
||||
|
||||
context.GET("", {
|
||||
"componet_bench": context.Search("bench"),
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "bench "+context.Search("bench")+".clipstack"+" '"+JSON.stringify(txt)+"'"
|
||||
}, function(msg) {
|
||||
alert("保存成功")
|
||||
})
|
||||
}
|
||||
function copy_to_clipboard(text, skip_docker) {
|
||||
var clipboard = modify_node(".clipboard", {"value": text})
|
||||
clipboard.select()
|
||||
document.execCommand("copy")
|
||||
@ -21,6 +43,31 @@ function copy_to_clipboard(text) {
|
||||
var clipstack = document.querySelector("#clipstack")
|
||||
insert_child(clipstack, "option").value = text
|
||||
clipstack.childElementCount > 3 && clipstack.removeChild(clipstack.lastElementChild)
|
||||
|
||||
if (skip_docker) {
|
||||
return
|
||||
}
|
||||
|
||||
var txt = document.querySelector("div.workflow>ul>li>ul.txt")
|
||||
var target = append_child(txt, "li", {
|
||||
"innerText": format_date(new Date())+" "+(code.ntext++)+": "+text,
|
||||
"dataset": {
|
||||
"text": text,
|
||||
"action": "copy_txt",
|
||||
},
|
||||
"onclick": function(event) {
|
||||
if (event.altKey) {
|
||||
target.parentElement.removeChild(target)
|
||||
return
|
||||
}
|
||||
if (event.shiftKey) {
|
||||
var cmd = document.querySelector("form.option.command"+code.current_cmd+" input[name=cmd]")
|
||||
cmd && (cmd.value += " "+text)
|
||||
return
|
||||
}
|
||||
copy_to_clipboard(text, true)
|
||||
},
|
||||
})
|
||||
}
|
||||
function add_keymap(input) {
|
||||
if (code.ninput < code.keymap.length && input.style.display != "none") {
|
||||
@ -52,7 +99,7 @@ function add_sort(append, field, cb) {
|
||||
var has = document.querySelector("td.clip")
|
||||
has && (has.className = "")
|
||||
target.className = "clip"
|
||||
copy_to_clipboard(target.innerText)
|
||||
copy_to_clipboard(target.innerText, !event.shiftKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,7 +134,18 @@ function del_command(target) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function shrink_command_result() {
|
||||
code.show_result = !code.show_result
|
||||
document.querySelectorAll("form.option input[name=cmd]").forEach(function(input) {
|
||||
for (var command = input; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
||||
var append = command.querySelector("table.append")
|
||||
var result = command.querySelector("code.result pre")
|
||||
// append.style.display = (code.show_result||!append.querySelector("tr"))? "": "none"
|
||||
result.style.height = (code.show_result||result.innerText=="")? "": code.show_height
|
||||
})
|
||||
}
|
||||
function add_command(init) {
|
||||
var order = code.ncommand
|
||||
var name = "command"+code.ncommand++
|
||||
|
||||
var fieldset = append_child(document.querySelector("body"), "fieldset")
|
||||
@ -100,14 +158,15 @@ function add_command(init) {
|
||||
"componet_name": "command",
|
||||
"componet_bench": context.Search("bench"),
|
||||
"componet_name_alias": name,
|
||||
"componet_name_order": code.ncommand-1,
|
||||
"componet_name_order": order,
|
||||
}
|
||||
})
|
||||
|
||||
append_child(option, "input", {"style": {"display": "none"}})
|
||||
add_keymap(append_child(option, "input", {
|
||||
"name": "cmd", "className": "cmd",
|
||||
"onkeyup": function(event){onaction(event, "input")}
|
||||
"onkeyup": function(event) {onaction(event, "input")},
|
||||
"onfocus": function(event) {code.current_cmd=order}
|
||||
})).focus()
|
||||
|
||||
add_sort(append_child(fieldset, "table", {"className": "append "+name}))
|
||||
@ -119,14 +178,12 @@ function add_command(init) {
|
||||
|
||||
var cmds = document.querySelector("div.workflow ul.cmd")
|
||||
var cmd = append_child(cmds, "li", {
|
||||
"innertText": code.ncommand+": ",
|
||||
"innertText": order+": ",
|
||||
"className": name,
|
||||
"dataset": {
|
||||
"cmd": code.ncommand-1,
|
||||
"cmd": order,
|
||||
}
|
||||
})
|
||||
|
||||
init_docker()
|
||||
return fieldset
|
||||
}
|
||||
|
||||
@ -141,8 +198,7 @@ function send_command(form, cb) {
|
||||
|
||||
var order = (data["componet_name_order"]||"")
|
||||
var cmd = document.querySelector("div.workflow>ul>li>ul>li.command"+order)
|
||||
var now = new Date()
|
||||
cmd && (cmd.innerText = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDay()+" "+now.getHours()+":"+now.getMinutes()+":"+now.getSeconds()+" : "+order+" "+data["cmd"])
|
||||
cmd && (cmd.innerText = format_date(new Date())+" "+order+": "+data["cmd"])
|
||||
|
||||
context.GET("", data, function(msg) {
|
||||
msg = msg[0]
|
||||
@ -350,14 +406,19 @@ function onaction(event, action, arg) {
|
||||
add_command()
|
||||
break
|
||||
case "z":
|
||||
code.show_result = !code.show_result
|
||||
document.querySelectorAll("form.option input[name=cmd]").forEach(function(input) {
|
||||
for (var command = input; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
||||
var append = command.querySelector("table.append")
|
||||
var result = command.querySelector("code.result pre")
|
||||
// append.style.display = (code.show_result||!append.querySelector("tr"))? "": "none"
|
||||
result.style.height = (code.show_result||result.innerText=="")? "": code.show_height
|
||||
})
|
||||
shrink_command_result()
|
||||
break
|
||||
case "s":
|
||||
save_clipboard(document.querySelector("div.workflow>ul>li>ul.txt>li[data-action=save_txt"))
|
||||
break
|
||||
case "y":
|
||||
copy_to_clipboard(prompt("text"))
|
||||
break
|
||||
case "r":
|
||||
location.reload()
|
||||
break
|
||||
case "t":
|
||||
location.search = ""
|
||||
break
|
||||
case "0":
|
||||
document.querySelector("form.option.command input[name=cmd]").focus()
|
||||
@ -401,11 +462,12 @@ function onaction(event, action, arg) {
|
||||
break
|
||||
}
|
||||
|
||||
for (var command = target; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
||||
var option = command.querySelector("form.option")
|
||||
var append = command.querySelector("table.append")
|
||||
var result = command.querySelector("code.result pre")
|
||||
|
||||
if (event.ctrlKey) {
|
||||
for (var command = target; command.tagName != "FIELDSET"; command = command.parentElement) {}
|
||||
var option = command.querySelector("form.option")
|
||||
var append = command.querySelector("table.append")
|
||||
var result = command.querySelector("code.result pre")
|
||||
// yt
|
||||
switch (event.key) {
|
||||
case "1":
|
||||
@ -417,11 +479,16 @@ function onaction(event, action, arg) {
|
||||
case "7":
|
||||
case "8":
|
||||
case "9":
|
||||
var item = document.querySelectorAll("table.append.command"+(parseInt(option.dataset.componet_name_order)-1)+" td")
|
||||
if (event.shiftKey) {
|
||||
var item = document.querySelectorAll("table.append.command1 td")
|
||||
if (code.quick_txt) {
|
||||
var item = document.querySelectorAll("div.workflow>ul>li>ul.txt>li[data-text]")
|
||||
target.value += item[parseInt(event.key)-1].dataset["text"]
|
||||
} else {
|
||||
var item = document.querySelectorAll("table.append.command"+(parseInt(option.dataset.componet_name_order)-1)+" td")
|
||||
if (event.shiftKey) {
|
||||
var item = document.querySelectorAll("table.append.command1 td")
|
||||
}
|
||||
target.value += item[parseInt(event.key)-1].innerText
|
||||
}
|
||||
target.value += item[parseInt(event.key)-1].innerText
|
||||
break
|
||||
case "0":
|
||||
var pre_pre = document.querySelector("code.result.command"+(parseInt(option.dataset.componet_name_order)-1)+" pre")
|
||||
@ -731,8 +798,8 @@ function init_bench() {
|
||||
}
|
||||
|
||||
function init_docker() {
|
||||
// 移动
|
||||
document.querySelectorAll("div.workflow").forEach(function(item) {
|
||||
what = item
|
||||
var moving = false
|
||||
item.onclick = function(event) {
|
||||
if (event.target != item) {
|
||||
@ -747,39 +814,95 @@ function init_docker() {
|
||||
if (moving) {
|
||||
item.style.left = (item.offsetLeft+event.movementX)+"px"
|
||||
item.style.top = (item.offsetTop+event.movementY)+"px"
|
||||
context.Cookie("docker_left", item.style.left)
|
||||
context.Cookie("docker_top", item.style.top)
|
||||
}
|
||||
}
|
||||
item.style.left = context.Cookie("docker_left")
|
||||
item.style.top = context.Cookie("docker_top")
|
||||
})
|
||||
|
||||
document.querySelectorAll("div.workflow>span").forEach(function(item) {
|
||||
// 固定
|
||||
document.querySelectorAll("div.workflow>div").forEach(function(item) {
|
||||
item.onclick = function(event) {
|
||||
item.dataset["hide"] = !right(item.dataset["hide"])
|
||||
item.parentElement.className = right(item.dataset["hide"])? "workflow min": "workflow"
|
||||
item.dataset["show"] = !right(item.dataset["show"])
|
||||
item.parentElement.className = right(item.dataset["show"])? "workflow max": "workflow"
|
||||
context.Cookie("docker_class", item.parentElement.className)
|
||||
}
|
||||
if (context.Cookie("docker_class")) {
|
||||
item.parentElement.className = context.Cookie("docker_class")
|
||||
}
|
||||
})
|
||||
// 折叠
|
||||
document.querySelectorAll("ul.docker>li>span").forEach(function(item) {
|
||||
item.onclick = function(event) {
|
||||
item.dataset["hide"] = !right(item.dataset["hide"])
|
||||
item.nextElementSibling.style.display = right(item.dataset["hide"])? "none": ""
|
||||
}
|
||||
})
|
||||
|
||||
var txt = bench.clipstack
|
||||
if (txt) {
|
||||
text = JSON.parse(txt)
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
copy_to_clipboard(text[i])
|
||||
}
|
||||
}
|
||||
// 事件
|
||||
document.querySelectorAll("ul.docker>li>ul>li").forEach(function(item) {
|
||||
item.onclick = function(event) {
|
||||
var target = event.target
|
||||
var data = item.dataset
|
||||
switch (data["action"]) {
|
||||
case "create_fly":
|
||||
location.search = ""
|
||||
case "quick_txt":
|
||||
code.quick_txt = !code.quick_txt
|
||||
target.className= code.quick_txt? "quick": ""
|
||||
break
|
||||
case "copy_txt":
|
||||
if (event.altKey) {
|
||||
target.parentElement.removeChild(target)
|
||||
return
|
||||
}
|
||||
if (event.shiftKey) {
|
||||
var cmd = document.querySelector("form.option.command"+code.current_cmd+" input[name=cmd]")
|
||||
cmd && (cmd.value += " "+text)
|
||||
return
|
||||
}
|
||||
copy_to_clipboard(data["text"], true)
|
||||
break
|
||||
case "save_txt":
|
||||
save_clipboard(item)
|
||||
return
|
||||
case "create_txt":
|
||||
copy_to_clipboard(prompt("text"))
|
||||
return
|
||||
case "shrink_cmd":
|
||||
shrink_command_result()
|
||||
return
|
||||
case "create_cmd":
|
||||
add_command()
|
||||
return
|
||||
case "refresh_fly":
|
||||
location.reload()
|
||||
return
|
||||
case "create_fly":
|
||||
location.search = ""
|
||||
return
|
||||
case "rename_fly":
|
||||
context.GET("", {
|
||||
"componet_bench": context.Search("bench"),
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "bench "+context.Search("bench")+".comment"+" "+prompt("name"),
|
||||
})
|
||||
location.reload()
|
||||
return
|
||||
}
|
||||
if (data["key"] && context.Search("bench") != data["key"]) {
|
||||
context.Search("bench", data["key"])
|
||||
return
|
||||
}
|
||||
var cmd = document.querySelector("form.option.command"+data["cmd"]+" input[name=cmd]")
|
||||
cmd.focus()
|
||||
cmd && cmd.focus()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -174,7 +174,6 @@ function insert_button(which, value, callback) {
|
||||
"type": "button", "value": value, "onclick": callback,
|
||||
})
|
||||
}
|
||||
|
||||
function right(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
@ -187,3 +186,28 @@ function right(arg) {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function format_date(arg) {
|
||||
var date = arg.getDate()
|
||||
if (date < 10) {
|
||||
date = "0"+date
|
||||
}
|
||||
var month = arg.getMonth()+1
|
||||
if (month < 10) {
|
||||
month = "0"+month
|
||||
}
|
||||
var hour = arg.getHours()
|
||||
if (hour < 10) {
|
||||
hour = "0"+hour
|
||||
}
|
||||
var minute = arg.getMinutes()
|
||||
if (minute < 10) {
|
||||
minute = "0"+minute
|
||||
}
|
||||
var second = arg.getSeconds()
|
||||
if (second < 10) {
|
||||
second = "0"+second
|
||||
}
|
||||
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
|
||||
}
|
||||
|
||||
|
@ -22,30 +22,35 @@
|
||||
</style>
|
||||
<style>
|
||||
div.workflow {
|
||||
font-size:14px;
|
||||
font-family:monospace;
|
||||
position:fixed;
|
||||
background-color:red;
|
||||
top:200px;
|
||||
left:20px;
|
||||
width:40px;
|
||||
background-color:#498bb1a8;
|
||||
border:solid 3px red;
|
||||
color:#e6dd37;
|
||||
top:{{conf . "docker_view" "top"}}px;
|
||||
left:{{conf . "docker_view" "left"}}px;
|
||||
width:60px;
|
||||
height:20px;
|
||||
overflow:hidden;
|
||||
}
|
||||
div.workflow:hover {
|
||||
width:480px;
|
||||
height:200px;
|
||||
div.workflow:hover, div.workflow.min:hover {
|
||||
width:{{conf . "docker_view" "width"}}px;
|
||||
height:{{conf . "docker_view" "height"}}px;
|
||||
overflow:scroll;
|
||||
}
|
||||
div.workflow.min {
|
||||
width:40px;
|
||||
height:20px;
|
||||
div.workflow.max {
|
||||
width:{{conf . "docker_view" "width"}}px;
|
||||
height:{{conf . "docker_view" "height"}}px;
|
||||
}
|
||||
div.workflow ul.docker ul li {
|
||||
div.workflow ul.docker ul li.quick {
|
||||
background-color:red;
|
||||
}
|
||||
div.workflow ul.docker ul li:hover {
|
||||
background-color:green;
|
||||
background-color:red;
|
||||
}
|
||||
div.workflow ul.docker li span:hover {
|
||||
background-color:green;
|
||||
background-color:red;
|
||||
}
|
||||
form.option div {
|
||||
float:left;
|
||||
@ -155,27 +160,41 @@
|
||||
|
||||
{{define "docker"}}
|
||||
{{$key := option . "bench"}}
|
||||
{{$username := option . "username"|option}}
|
||||
{{$bench := conf . "bench" $key}}
|
||||
<script>var workflow = {{conf . "bench"}}</script>
|
||||
<div class="workflow">
|
||||
<span>flow</span>
|
||||
<div> bench</div>
|
||||
<ul class="docker">
|
||||
<li><span>工作流</span>
|
||||
<ul class="fly">
|
||||
<li data-action="create_fly">+ 创建工作流</li>
|
||||
{{range $key, $item := conf . "bench"}}
|
||||
<li data-key="{{$key}}">{{index $item "modify_time"}} {{index $item "comment"}}({{index $item "creator"}})</li>
|
||||
{{end}}
|
||||
<li><span>粘贴板</span>
|
||||
<ul class="txt">
|
||||
<li data-action="save_txt">+ 保存粘贴板(Ctrl+S)</li>
|
||||
<li data-action="create_txt">+ 添加粘贴板(Ctrl+Y)</li>
|
||||
<li data-action="quick_txt">+ 快捷粘贴板</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><span>命令行</span>
|
||||
<ul class="cmd">
|
||||
<li data-action="create_cmd">+ 创建命令行</li>
|
||||
<li data-action="shrink_cmd">+ 折叠命令行(Ctrl+Z)</li>
|
||||
<li data-action="create_cmd">+ 添加命令行(Ctrl+M)</li>
|
||||
{{range $index, $cmd := index $bench "commands"}}
|
||||
<li class="command{{$index}}" data-cmd="{{$index}}">{{index $cmd "now"|option}} {{$index}}: {{index $cmd "cmd"|option}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</li>
|
||||
<li><span>工作流</span>
|
||||
<ul class="fly">
|
||||
<li data-action="refresh_fly">+ 刷新工作流(Ctrl+R)</li>
|
||||
<li data-action="create_fly">+ 添加工作流(Ctrl+T)</li>
|
||||
{{range $key, $item := conf . "bench"}}
|
||||
{{$creator := index $item "creator"}}
|
||||
{{if eq $creator $username}}
|
||||
<li data-key="{{$key}}">{{index $item "modify_time"}} {{index $item "comment"}}({{index $item "creator"}})</li>
|
||||
{{end}}
|
||||
{{end}}
|
||||
<li data-action="rename_fly">+ 命名工作流</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
@ -273,3 +292,4 @@
|
||||
<script src="/librarys/code.js"></script>
|
||||
</body>
|
||||
{{end}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user