diff --git a/src/operation/container.css b/src/operation/container.css new file mode 100644 index 0000000..1c00370 --- /dev/null +++ b/src/operation/container.css @@ -0,0 +1,3 @@ +$output div.code { + padding:0; +} \ No newline at end of file diff --git a/src/operation/container.go b/src/operation/container.go new file mode 100644 index 0000000..67ad4dd --- /dev/null +++ b/src/operation/container.go @@ -0,0 +1,60 @@ +package operation + +import ( + "shylinux.com/x/ice" + "shylinux.com/x/icebergs/base/aaa" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/web" + kit "shylinux.com/x/toolkits" + + "shylinux.com/x/operation/src/operation/model" +) + +type container struct { + Table + order string `data:"1"` + fields string `data:"name,module,version"` + create string `name:"create uid* domain module version" role:"leader"` + remove string `name:"remove" role:"leader"` + apply string `name:"apply" role:"void"` + rename string `name:"rename name" role:"void"` + open string `name:"open" role:"void"` +} + +func (s container) Create(m *ice.Message, arg ...string) { + s.Table.Insert(m, kit.Simple(arg, m.OptionSimple(model.CLOUD_UID))...) +} +func (s container) Rename(m *ice.Message, arg ...string) { + s.Table.Update(m, m.OptionSimple(model.NAME), m.OptionSimple(model.CLOUD_UID, model.UID)...) +} +func (s container) List(m *ice.Message, arg ...string) { + if len(arg) == 1 { + s.Select(m, model.CLOUD_UID, arg[0], model.USER_UID, m.Option(model.USER_UID)).PushAction(s.Open, s.Rename) + kit.If(m.Length() == 0, func() { m.EchoInfoButton("请申请云容器", s.Apply) }) + kit.If(s.IsLeader(m), func() { m.Action(s.Create, s.Apply) }, func() { + if m.Length() > 0 { + m.Action() + } + }) + } else { + s.SelectDetail(m, model.UID, arg[1], model.CLOUD_UID, arg[0], model.USER_UID, m.Option(model.USER_UID)).PushAction(s.Open, s.Rename) + m.EchoIFrame(web.S(arg[1])) + } + m.Display("").DisplayCSS("") +} +func (s container) Apply(m *ice.Message, arg ...string) { + s.Transaction(m, func() { + msg := m.Spawn() + msg = s.Limit(msg, 1).SelectForUpdate(msg, "(user_uid IS NULL OR user_uid = '') AND cloud_uid = ?", m.Option(model.CLOUD_UID)) + if m.Warn(msg.Length() == 0, "容器不够用啦!") { + return + } + s.Update(m, m.OptionSimple(model.USER_UID), msg.AppendSimple(model.UID)...) + m.Cmd(web.SPACE, msg.Append(model.UID), aaa.USER, mdb.CREATE, aaa.TECH, m.Option(model.USER_UID), kit.Dict(ice.MSG_USERROLE, aaa.TECH)) + }) +} +func (s container) Open(m *ice.Message, arg ...string) { + m.ProcessOpen(m.Options(ice.MSG_USERPOD, "").MergePod(m.Option(model.UID))) +} + +func init() { ice.TeamCtxCmd(container{}) } diff --git a/src/operation/container.js b/src/operation/container.js new file mode 100644 index 0000000..0e4caa8 --- /dev/null +++ b/src/operation/container.js @@ -0,0 +1,9 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { + can.onimport.myView(can, msg, function(value) { return [ + {view: html.TITLE, list: [value.name||"container", can.onimport.titleAction(can, value)]}, + {view: html.STATUS, list: [value.uid.slice(0, 6), can.onimport.timeView(can, value), value.user_name]}, + {view: html.STATUS, list: [value.module, value.version]}, + ] }) + }, +}) \ No newline at end of file diff --git a/src/operation/model/model.go b/src/operation/model/model.go index f6d3b1f..d8cdb01 100644 --- a/src/operation/model/model.go +++ b/src/operation/model/model.go @@ -28,5 +28,14 @@ type Release struct { db.ModelContent CloudUID string `gorm:"type:char(32);index"` } +type Container struct { + db.ModelWithUID + CloudUID string `gorm:"type:char(32);index"` + UserUID string `gorm:"type:char(32);index"` + Name string `gorm:"type:varchar(32);index"` + Module string `gorm:"type:varchar(255);index"` + Version string `gorm:"type:varchar(32);index"` + Domain string `gorm:"type:char(255);index"` +} -func init() { db.CmdModels("", &UserCloud{}, &Cloud{}, &Release{}) } +func init() { db.CmdModels("", &UserCloud{}, &Cloud{}, &Release{}, &Container{}) } diff --git a/src/operation/portal.json b/src/operation/portal.json index 5fa609a..84000f6 100644 --- a/src/operation/portal.json +++ b/src/operation/portal.json @@ -1,7 +1,9 @@ { "portal": "系统运维", + "container": "容器", "release": "发布", "icons": { + "container": "https://img.icons8.com/officel/80/activity-grid.png", "release": "https://img.icons8.com/officel/80/activity-grid.png" }, "input": { diff --git a/src/operation/release.go b/src/operation/release.go index 4b3df82..a437ae2 100644 --- a/src/operation/release.go +++ b/src/operation/release.go @@ -9,6 +9,8 @@ type release struct { remove string `name:"remove" role:"leader"` } -func (s release) List(m *ice.Message, arg ...string) { s.ValueList(m, arg).Display("") } +func (s release) List(m *ice.Message, arg ...string) { + s.ValueList(m, arg).Display("") +} func init() { ice.TeamCtxCmd(release{}) }