update
parent
4cb2bad653
commit
1bb46c638d
|
@ -14,7 +14,7 @@ var l zerolog.Logger
|
|||
|
||||
var db *gorm.DB
|
||||
|
||||
var color []string = []string{
|
||||
var Color []string = []string{
|
||||
"red", "pink", "purple", "deep-purple", "indigo", "blue", "light-blue", "cyan", "teal", "green",
|
||||
"light-green", "lime", "yellow", "amber", "orange", "deep-orange", "blue-grey",
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ type Event struct {
|
|||
Start time.Time
|
||||
End time.Time
|
||||
Name string `gorm:"not null"`
|
||||
Location string
|
||||
|
||||
Color string `gorm:"-"`
|
||||
|
||||
|
@ -48,6 +49,6 @@ func (e *Event) AfterFind(tx *gorm.DB) (err error) {
|
|||
return err
|
||||
}
|
||||
e.EventGroup = eg
|
||||
e.Color = color[e.EventGroup.Color%len(color)]
|
||||
e.Color = Color[e.EventGroup.Color%len(Color)]
|
||||
return
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ type EventGroup struct {
|
|||
// event header
|
||||
Hosts string
|
||||
Description string
|
||||
Location string
|
||||
|
||||
// ntu
|
||||
Class string
|
||||
CourseID string
|
||||
Semester string
|
||||
IsRegular bool
|
||||
|
||||
// UI
|
||||
Color int
|
||||
|
@ -48,7 +48,6 @@ func (eg *EventGroup) BeforeSave(tx *gorm.DB) (err error) {
|
|||
} else {
|
||||
eg.GroupID = 0
|
||||
}
|
||||
eg.Color = GetNewColor(eg.GroupName)
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -56,6 +55,7 @@ func (eg *EventGroup) BeforeCreate(tx *gorm.DB) (err error) {
|
|||
if eg.ID == "" {
|
||||
eg.ID = xid.New().String()
|
||||
}
|
||||
eg.Color = GetNewColor(eg.GroupName)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ func HasCalAccess(c *gin.Context, cal *Calendar, cid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func HasEventAccess(c *gin.Context, e *Event, cid string) error {
|
||||
err := db.First(e, "id = ?", cid).Error
|
||||
func HasEventAccess(c *gin.Context, e *Event, eid string) error {
|
||||
err := db.First(e, "id = ?", eid).Error
|
||||
if err != nil {
|
||||
return errors.NewError(404, err)
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func GetNewColor(GroupName string) int {
|
|||
if err := db.Select("color").
|
||||
Where("group_id = (select id from groups where name = ? )", GroupName).
|
||||
Last(eg).Error; err != nil {
|
||||
return rand.Intn(len(color))
|
||||
return rand.Intn(len(Color))
|
||||
}
|
||||
return eg.Color + 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue