mirror of
https://shylinux.com/x/education
synced 2025-04-25 10:08:05 +08:00
opt some
This commit is contained in:
parent
e4e1a032ba
commit
7c796c4ae0
@ -7,7 +7,7 @@ import (
|
||||
"shylinux.com/x/education/src/jiaowuxitong/model"
|
||||
)
|
||||
|
||||
type Class struct { Table }
|
||||
type Class struct{ Table }
|
||||
|
||||
func (s Class) Inputs(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
|
@ -2,32 +2,40 @@ package jiaowuxitong
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
"shylinux.com/x/community/src/gonganxitong"
|
||||
"shylinux.com/x/education/src/jiaowuxitong/model"
|
||||
"shylinux.com/x/mysql-story/src/db"
|
||||
)
|
||||
|
||||
type Table struct {
|
||||
db.Table
|
||||
inputs string `name"inputs" role:"void"`
|
||||
gonganxitong.Table
|
||||
list string `name:"list class_uid uid auto" role:"void"`
|
||||
}
|
||||
|
||||
func (s Table) Init(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Config(web.PORTAL) == ice.TRUE, func() { portal{}.Show(m) })
|
||||
}
|
||||
func (s Table) Inputs(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case model.CLASS_TYPE:
|
||||
for k, v := range ClassTypeList {
|
||||
m.Push(arg[0], k).Push(model.NAME, v)
|
||||
}
|
||||
m.SortInt(arg[0]).DisplayInputKeyNameIconTitle()
|
||||
case model.USER_CLASS_ROLE:
|
||||
for k, v := range UserClassRoleList {
|
||||
if k != UserClassCreator && k != UserClassVisitor {
|
||||
m.Push(arg[0], k).Push(model.NAME, v)
|
||||
}
|
||||
}
|
||||
m.SortInt(arg[0]).DisplayInputKeyNameIconTitle()
|
||||
default:
|
||||
s.Table.Inputs(m, arg...)
|
||||
}
|
||||
}
|
||||
func (s Table) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
if len(arg) == 0 || len(arg) == 1 {
|
||||
if m.IsTech() {
|
||||
s.Table.List(m)
|
||||
}
|
||||
} else if len(arg) == 2 {
|
||||
s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1])
|
||||
}
|
||||
func (s Table) RewriteAppend(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
kit.If(key == model.CLASS_TYPE, func() { value = ClassType(kit.Int(value)).String() })
|
||||
kit.If(key == model.USER_CLASS_ROLE, func() { value = UserClassRole(kit.Int(value)).String() })
|
||||
return value
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
$output div.item.card div.status { white-space:pre; }
|
@ -4,13 +4,11 @@ import (
|
||||
"shylinux.com/x/ice"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
"shylinux.com/x/community/src/gonganxitong"
|
||||
"shylinux.com/x/education/src/jiaowuxitong/model"
|
||||
)
|
||||
|
||||
type homework struct {
|
||||
Table
|
||||
user gonganxitong.User
|
||||
portal string `data:"true"`
|
||||
create string `name:"create content*" role:"void"`
|
||||
}
|
||||
@ -19,16 +17,14 @@ func (s homework) Create(m *ice.Message, arg ...string) {
|
||||
s.Table.Create(m, kit.Simple(arg, m.OptionSimple(model.USER_UID, model.CLASS_UID))...)
|
||||
}
|
||||
func (s homework) List(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
if m.IsTech() {
|
||||
s.Table.Select(m)
|
||||
}
|
||||
} else if len(arg) == 1 {
|
||||
if len(arg) == 1 {
|
||||
s.Table.Select(m, model.CLASS_UID, arg[0])
|
||||
} else if len(arg) == 2 {
|
||||
s.Table.SelectDetail(m, model.CLASS_UID, arg[0], model.UID, arg[1])
|
||||
} else {
|
||||
s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1])
|
||||
return
|
||||
}
|
||||
s.SelectJoin(m, s.user, "name", "avatar").Display("").DisplayCSS("")
|
||||
s.SelectJoinUser(m).Display("")
|
||||
}
|
||||
|
||||
func init() { ice.TeamCtxCmd(homework{}) }
|
||||
|
@ -1,21 +1,14 @@
|
||||
var UID = "uid", CLASS_NAME = "class_name"
|
||||
Volcanos(chat.ONIMPORT, {
|
||||
_init: function(can, msg) {
|
||||
if (msg.IsDetail()) { var value = msg.TableDetail()
|
||||
can.page.Append(can, can._output, [can.onimport.itemcard(can, value, [
|
||||
can.onimport.itemcards(can, msg, function(value) { return [
|
||||
{view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
|
||||
{view: html.STATUS, list: [{text: value.content}]},
|
||||
])])
|
||||
msg.Option("_share_content", value.content)
|
||||
can.user.title([can.ConfHelp(), can.sup.Conf(CLASS_NAME), can.base.trimPrefix(value.created_at.split(" ")[0], can.base.Time(null, "%y-"))].join(" "))
|
||||
] })
|
||||
if (msg.IsDetail()) { var value = msg.TableDetail(); msg.Option("_share_content", value.content)
|
||||
can.onexport.title(can, can.base.trimPrefix(value.created_at.split(" ")[0], can.base.Time(null, "%y-")))
|
||||
} else {
|
||||
can.page.Append(can, can._output, msg.Table(function(value) {
|
||||
return can.onimport.itemcard(can, value, [
|
||||
{view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
|
||||
{view: html.STATUS, list: [{text: value.content}]},
|
||||
])
|
||||
}))
|
||||
can.user.title([can.ConfHelp(), can.sup.Conf(CLASS_NAME)].join(" "))
|
||||
can.onexport.title(can)
|
||||
}
|
||||
},
|
||||
})
|
@ -5,28 +5,29 @@ import "shylinux.com/x/mysql-story/src/db"
|
||||
const (
|
||||
UID = "uid"
|
||||
NAME = "name"
|
||||
TYPE = "type"
|
||||
ROLE = "role"
|
||||
GRADE = "grade"
|
||||
CREATED_AT = "created_at"
|
||||
USER_UID = "user_uid"
|
||||
USER_CLASS_ROLE = "user_class_role"
|
||||
CLASS_UID = "class_uid"
|
||||
CLASS_NAME = "class_name"
|
||||
CLASS_TYPE = "class_type"
|
||||
SCHOOL_UID = "school_uid"
|
||||
SCHOOL_NAME = "school_name"
|
||||
CITY_NAME = "city_name"
|
||||
CITY_UID = "city_uid"
|
||||
)
|
||||
|
||||
type UserClass struct {
|
||||
db.Model
|
||||
db.ModelWithUID
|
||||
UserUID string `gorm:"type:char(32);index"`
|
||||
ClassUID string `gorm:"type:char(32);index"`
|
||||
Role uint8
|
||||
}
|
||||
type Class struct {
|
||||
db.ModelWithUID
|
||||
SchoolUID string `gorm:"type:char(32)"`
|
||||
Grade string `gorm:"type:char(32)"`
|
||||
Name string `gorm:"type:varchar(256)"`
|
||||
Type uint8
|
||||
}
|
||||
type School struct {
|
||||
db.ModelWithUID
|
||||
|
@ -1 +0,0 @@
|
||||
$output { background-color:var(--plugin-bg-color); }
|
@ -1,95 +1,13 @@
|
||||
package jiaowuxitong
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
import "shylinux.com/x/community/src/gonganxitong"
|
||||
|
||||
"shylinux.com/x/community/src/gonganxitong"
|
||||
"shylinux.com/x/education/src/jiaowuxitong/model"
|
||||
)
|
||||
|
||||
type portal struct {
|
||||
type Portal struct {
|
||||
gonganxitong.Portal
|
||||
city gonganxitong.City
|
||||
user gonganxitong.User
|
||||
userClass userClass
|
||||
class Class
|
||||
school school
|
||||
list string `name:"list class_uid index uid auto" role:"void"`
|
||||
classCreate string `name:"classCreate city_name* school_name* grade*:select name*" role:"void"`
|
||||
classRemove string `name:"classRemove class_uid*" role:"void"`
|
||||
placeCreate string `name:"placeCreate city_name* school_name* grade*:select name*" role:"void"`
|
||||
}
|
||||
|
||||
func (s portal) Inputs(m *ice.Message, arg ...string) {
|
||||
s.class.Inputs(m, arg...)
|
||||
}
|
||||
func (s portal) List(m *ice.Message, arg ...string) {
|
||||
if m.Option("form") == "table" {
|
||||
s.Hash.List(m, arg...).SortInt(mdb.ORDER)
|
||||
return
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate, s.ScanQRCode)
|
||||
kit.If(!m.IsErr() && m.Length() == 0, func() {
|
||||
m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate, s.ScanQRCode)
|
||||
})
|
||||
} else if len(arg) == 2 {
|
||||
msg := m.Cmd(s.class, s.class.Select, model.UID, arg[0])
|
||||
m.Option(model.CLASS_NAME, msg.Append(model.NAME))
|
||||
m.Cmdy(ctx.COMMAND, arg[1]).Push(ctx.ARGS, arg[0])
|
||||
} else {
|
||||
s.Portal.List(m, arg...)
|
||||
}
|
||||
m.Display("").DisplayCSS("")
|
||||
}
|
||||
func (s portal) ClassCreate(m *ice.Message, arg ...string) {
|
||||
defer m.ToastProcess()()
|
||||
if s.city.FindOrCreateByName(m, arg...); m.IsErr() {
|
||||
return
|
||||
}
|
||||
if s.school.FindOrCreateByName(m, arg...); m.IsErr() {
|
||||
return
|
||||
}
|
||||
if m.Cmdy(s.class, s.class.Create, arg[2:]).IsErr() {
|
||||
return
|
||||
}
|
||||
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, m.Result())
|
||||
m.Cmdy(s.userClass, s.userClass.Create, args).ProcessRefresh()
|
||||
}
|
||||
func (s portal) ClassRemove(m *ice.Message, arg ...string) {
|
||||
defer m.ToastProcess()()
|
||||
args := m.OptionSimple(model.USER_UID, model.CLASS_UID)
|
||||
msg := m.Cmd(s.userClass, s.userClass.Select, args)
|
||||
if m.WarnNotFound(msg.Length() == 0, "class") {
|
||||
return
|
||||
}
|
||||
m.Cmdy(s.userClass, s.userClass.Delete, msg.AppendSimple(model.UID))
|
||||
m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID))
|
||||
m.ProcessRefresh()
|
||||
}
|
||||
func (s portal) ScanQRCode(m *ice.Message, arg ...string) {
|
||||
defer m.ToastProcess()()
|
||||
if m.Option(mdb.TYPE) == mdb.TEXT {
|
||||
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, m.Option(mdb.TEXT))
|
||||
m.Cmdy(s.userClass, s.userClass.Create, args, model.ROLE, UserClassVisitor)
|
||||
}
|
||||
if m.Option(mdb.TYPE) == web.LINK {
|
||||
args := m.ParseURL(m.Option(mdb.TEXT))
|
||||
if len(args) > 1 && args[1] == m.Prefix("apply") {
|
||||
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, args[0])
|
||||
m.Cmdy(s.userClass, s.userClass.Create, args, model.ROLE, UserClassVisitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func init() { ice.TeamCtxCmd(portal{}) }
|
||||
|
||||
func (s portal) Show(m *ice.Message, arg ...string) {
|
||||
m.GoSleep("30ms", func() {
|
||||
cmd := m.GetCommand()
|
||||
m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon, ctx.INDEX, m.PrefixKey())
|
||||
})
|
||||
func init() {
|
||||
gonganxitong.PortalCmd(Portal{Portal: gonganxitong.NewPortal(userClass{}, Class{}, school{})})
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
var UID = "uid", CLASS_UID = "class_uid", CLASS_NAME = "class_name"
|
||||
Volcanos(chat.ONIMPORT, {
|
||||
_init: function(can, msg) { can.user.isMobile && can.isCmdMode() && can.onappend.style(can, html.OUTPUT)
|
||||
can.require([
|
||||
"usr/community/src/gonganxitong/portal.js", "usr/community/src/gonganxitong/portal.css?render=replace&index="+can.ConfIndex(),
|
||||
], function() {
|
||||
can.onimport.myPortal(can, msg, CLASS_UID, CLASS_NAME, "我的班级")
|
||||
})
|
||||
},
|
||||
myValue: function(can, value) {
|
||||
return [
|
||||
{view: html.TITLE, list: [{text: value.class_name}]},
|
||||
{view: html.STATUS, list: [{text: value.class_uid.slice(0, 8)}, {text: value.school_name}, {text: value.grade}]},
|
||||
]
|
||||
},
|
||||
})
|
@ -1,33 +1,28 @@
|
||||
{
|
||||
"portal": "教务系统",
|
||||
"scanQRCode": "扫码添加",
|
||||
"classCreate": "创建班级",
|
||||
"classRemove": "删除班级",
|
||||
"qrcode": "班级码",
|
||||
"placeCreate": "创建班级",
|
||||
"placeRemove": "删除班级",
|
||||
"homework": "家庭作业",
|
||||
"icons": {
|
||||
"scanQRCode": "bi bi-qr-code-scan",
|
||||
"classCreate": "bi bi-plus-square-dotted",
|
||||
"qrcode": "https://img.icons8.com/officel/80/qr-code.png"
|
||||
"homework": "https://img.icons8.com/officel/80/homework.png"
|
||||
},
|
||||
"style": {
|
||||
"classRemove": "danger"
|
||||
"placeRemove": "danger"
|
||||
},
|
||||
"input": {
|
||||
"address": "地址",
|
||||
"grade": "入学年份",
|
||||
"open_id": "外键",
|
||||
"user_uid": "用户",
|
||||
"user_name": "用户昵称",
|
||||
"user_class_role": "用户角色",
|
||||
"class_uid": "班级",
|
||||
"class_name": "班级名称",
|
||||
"school_uid": "学校",
|
||||
"school_name": "学校名称",
|
||||
"place_address": "学校地址",
|
||||
"city_name": "城市名称"
|
||||
},
|
||||
"value": {
|
||||
|
||||
|
||||
"class_type": {
|
||||
},
|
||||
"user_class_role": {
|
||||
"teacher": "老师"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
chapter "教务系统"
|
||||
|
||||
field web.code.mysql.client
|
||||
field web.code.mysql.query args `mysql jiaowuxitong`
|
||||
field web.code.db.database
|
||||
|
@ -1,26 +0,0 @@
|
||||
package jiaowuxitong
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
|
||||
"shylinux.com/x/education/src/jiaowuxitong/model"
|
||||
)
|
||||
|
||||
type qrcode struct {
|
||||
portal portal
|
||||
userClass userClass
|
||||
list string `name:"list place_uid auto" role:"void"`
|
||||
}
|
||||
|
||||
func (s qrcode) Init(m *ice.Message, arg ...string) {
|
||||
s.portal.Show(m)
|
||||
}
|
||||
func (s qrcode) List(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd(s.userClass, m.Option(model.USER_UID), arg[0])
|
||||
m.FieldsSetDetail()
|
||||
kit.For([]string{model.CITY_NAME, model.SCHOOL_NAME, model.CLASS_NAME}, func(key string) { m.Push(key, msg.Append(key)) })
|
||||
m.EchoQRCode(s.portal.Link(m, arg[0], m.Prefix("apply")))
|
||||
}
|
||||
|
||||
func init() { ice.TeamCtxCmd(qrcode{}) }
|
@ -13,9 +13,20 @@ type userClass struct {
|
||||
}
|
||||
|
||||
func (s userClass) List(m *ice.Message, arg ...string) {
|
||||
s.Tables(m, s.class, s.school).Fields(m,
|
||||
s.Key(s.class, model.CREATED_AT), model.SCHOOL_NAME, model.GRADE, model.CLASS_NAME, model.CLASS_UID, model.SCHOOL_UID,
|
||||
).Orders(m, s.Desc(model.CREATED_AT)).Select(m, model.USER_UID, arg[0])
|
||||
s.Tables(m, s.class, s.school).FieldsWithCreatedAT(m, s,
|
||||
model.CLASS_NAME, model.CLASS_TYPE, model.USER_CLASS_ROLE,
|
||||
model.SCHOOL_NAME, model.GRADE,
|
||||
model.CLASS_UID, model.CITY_UID,
|
||||
)
|
||||
if len(arg) == 1 {
|
||||
s.Select(m, model.USER_UID, arg[0])
|
||||
} else if len(arg) == 2 {
|
||||
s.SelectDetail(m, model.USER_UID, arg[0], model.CLASS_UID, arg[1])
|
||||
} else {
|
||||
return
|
||||
}
|
||||
s.SelectJoinCity(m)
|
||||
s.RewriteAppend(m)
|
||||
}
|
||||
|
||||
func init() { ice.TeamCtxCmd(userClass{}) }
|
||||
@ -24,18 +35,18 @@ type UserClassRole int
|
||||
|
||||
const (
|
||||
UserClassCreator UserClassRole = iota
|
||||
UserClassVisitor
|
||||
UserClassTeacher
|
||||
UserClassStudent
|
||||
UserClassParent
|
||||
UserClassVisitor
|
||||
)
|
||||
|
||||
var UserClassRoleList = map[UserClassRole]string{
|
||||
UserClassCreator: "creator",
|
||||
UserClassVisitor: "visitor",
|
||||
UserClassTeacher: "teacher",
|
||||
UserClassStudent: "student",
|
||||
UserClassParent: "parent",
|
||||
UserClassVisitor: "visitor",
|
||||
}
|
||||
|
||||
func (s UserClassRole) String() string { return UserClassRoleList[s] }
|
||||
|
Loading…
x
Reference in New Issue
Block a user