From a3b3f0aa945411e89071e3206976e960ace9bd05 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sat, 15 Dec 2018 11:23:08 +0800 Subject: [PATCH] add some Change-Id: Icd9aa865f02675b59091145b2c08269fe50c912b --- src/contexts/web/web.go | 8 +- src/examples/{lark/lark.go => chat/chat.go} | 16 +- src/examples/{jira/jira.go => team/team.go} | 10 +- usr/template/chat/chat.tmpl | 218 ++++++++++++++++++++ usr/template/code/code.tmpl | 8 +- 5 files changed, 241 insertions(+), 19 deletions(-) rename src/examples/{lark/lark.go => chat/chat.go} (71%) rename src/examples/{jira/jira.go => team/team.go} (68%) create mode 100644 usr/template/chat/chat.tmpl diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 7e604c71..49ea9824 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -906,6 +906,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if len(arg) > 0 && arg[0] == "check" { // 检查工作流 bench := m.Confv("bench", m.Option("bench")).(map[string]interface{}) + m.Log("fuck", "waht %v", bench) if bench["creator"].(string) != arg[1] { switch bench["share"].(string) { case "private": @@ -1007,15 +1008,16 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } if !right { - lark := m.Find("web.lark") + lark := m.Find("web.chat.lark") if lark != nil && m.Confs("login_lark") { right = ctx.Right(lark.Cmd("auth", m.Option("username"), "check", m.Option("cmd")).Result(0)) } } bench_share := "" + bench, ok := m.Confv("bench", m.Option("bench")).(map[string]interface{}) if right && !m.Confs("bench_disable") { - if _, ok := m.Confv("bench", m.Option("bench")).(map[string]interface{}); !ok { // 创建工作流 + if !ok { // 创建工作流 m.Append("redirect", fmt.Sprintf("%s?bench=%s", m.Option("index_path"), m.Spawn().Cmd("bench", "create").Append("key"))) return } @@ -1098,7 +1100,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if order != "" || (val["pre_run"] != nil && val["pre_run"].(bool)) { if val["componet_cmd"] != nil { - if bench_share != "protected" { + if len(bench) > 0 && bench_share != "protected" { now := time.Now().Format(m.Conf("time_format")) m.Confv("bench", []interface{}{m.Option("bench"), "commands", m.Option("componet_name_order")}, map[string]interface{}{ "cmd": args[1:], diff --git a/src/examples/lark/lark.go b/src/examples/chat/chat.go similarity index 71% rename from src/examples/lark/lark.go rename to src/examples/chat/chat.go index f50360b0..1ce5d9ce 100644 --- a/src/examples/lark/lark.go +++ b/src/examples/chat/chat.go @@ -1,4 +1,4 @@ -package lark +package chat import ( "contexts/ctx" @@ -9,13 +9,13 @@ import ( "net/http" ) -var Index = &ctx.Context{Name: "lark", Help: "会议中心", +var Index = &ctx.Context{Name: "chat", Help: "会议中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{ - "lark_msg": &ctx.Config{Name: "lark_msg", Value: []interface{}{}, Help: "聊天记录"}, + "chat_msg": &ctx.Config{Name: "chat_msg", Value: []interface{}{}, Help: "聊天记录"}, }, Commands: map[string]*ctx.Command{ - "/lark": &ctx.Command{Name: "user", Help: "应用示例", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { + "/chat": &ctx.Command{Name: "user", Help: "应用示例", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { r := m.Optionv("request").(*http.Request) w := m.Optionv("response").(http.ResponseWriter) @@ -32,13 +32,13 @@ var Index = &ctx.Context{Name: "lark", Help: "会议中心", fmt.Fprintf(w, "{\"challenge\": \"%s\"}", data["challenge"]) return } - m.Confv("lark_msg", "-1", data) + m.Confv("chat_msg", "-1", data) }}, }, } func init() { - lark := &web.WEB{} - lark.Context = Index - web.Index.Register(Index, lark) + chat := &web.WEB{} + chat.Context = Index + web.Index.Register(Index, chat) } diff --git a/src/examples/jira/jira.go b/src/examples/team/team.go similarity index 68% rename from src/examples/jira/jira.go rename to src/examples/team/team.go index 292641b6..8a9e8449 100644 --- a/src/examples/jira/jira.go +++ b/src/examples/team/team.go @@ -1,11 +1,11 @@ -package jira +package team import ( "contexts/ctx" "contexts/web" ) -var Index = &ctx.Context{Name: "jira", Help: "任务中心", +var Index = &ctx.Context{Name: "team", Help: "任务中心", Caches: map[string]*ctx.Cache{}, Configs: map[string]*ctx.Config{}, Commands: map[string]*ctx.Command{ @@ -16,7 +16,7 @@ var Index = &ctx.Context{Name: "jira", Help: "任务中心", } func init() { - jira := &web.WEB{} - jira.Context = Index - web.Index.Register(Index, jira) + team := &web.WEB{} + team.Context = Index + web.Index.Register(Index, team) } diff --git a/usr/template/chat/chat.tmpl b/usr/template/chat/chat.tmpl new file mode 100644 index 00000000..189dbe6e --- /dev/null +++ b/usr/template/chat/chat.tmpl @@ -0,0 +1,218 @@ +{{define "head"}} + + + + +code + + + + +{{end}} + +{{define "void"}}{{end}} + +{{define "detail"}}{{detail .}}{{end}} +{{define "option"}}{{option .}}{{end}} +{{define "append"}}{{append .}}{{end}} +{{define "result"}}{{result .}}{{end}} + +{{define "clipboard"}} +
clipboard + + + +
+{{end}} + +{{define "componet"}} +
{{option .Meta "componet_help"}}({{option .Meta "componet_ctx"}}.{{option .Meta "componet_cmd"}}) + {{$form_type := option . "form_type"|meta}} + {{$msg := .}} + + {{if eq $form_type "upload"}} + {{end}} +
+ + {{range $index, $input := option . "inputs"}} +
+ {{$type := index $input "type"}} + {{if index $input "label"}} + + {{end}} + {{if eq $type "button"}} + + {{else if eq $type "submit"}} + + {{else if eq $type "file"}} + + {{else if eq $type "choice"}} + {{$default_value := index $input "value"}} + + {{else if eq $type "password"}} + + {{else}} + {{$name := index $input "name"}} + {{$value := option $msg $name|option}} + + {{end}} +
+ {{end}} +
+
+ {{if eq $form_type "upload"}} + {{end}} + + {{if index .Meta "display_append"}} + {{option .Meta "display_append"}} + {{else}} + + {{$msg := .}} + {{range $field := append .}}{{end}} + {{range $line := table .}} + {{range $field := append $msg}}{{end}} + {{end}} +
{{$field}}
{{index $line $field|unescape}}
+ {{end}} + + {{if index .Meta "display_result"}} + {{option .Meta "display_result"}} + {{else}} +
{{result .Meta}}
+ {{end}} +
+{{end}} + +{{define "tail"}} + + + +{{end}} diff --git a/usr/template/code/code.tmpl b/usr/template/code/code.tmpl index e1148bfb..8d8a2348 100644 --- a/usr/template/code/code.tmpl +++ b/usr/template/code/code.tmpl @@ -169,8 +169,10 @@ @@ -179,7 +181,7 @@
  • + 刷新工作流(Ctrl+R)
  • + 添加工作流(Ctrl+T)
  • {{range $key, $item := conf . "bench"}} - {{$creator := index $item "creator"}} + {{$creator := index $item "creator"|option}} {{if eq $creator $username}}
  • {{index $item "modify_time"}} {{index $item "comment"}}({{slice $key 0 6}})
  • {{end}}