diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go
index cfe7c8a..f37e215 100644
--- a/cmd/dashboard/controller/common_page.go
+++ b/cmd/dashboard/controller/common_page.go
@@ -27,7 +27,7 @@ func (cp *commonPage) home(c *gin.Context) {
dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock()
data := gin.H{
- "Servers": dao.ServerList,
+ "Servers": dao.SortedServerList,
"CustomCode": dao.Conf.Site.CustomCode,
}
u, ok := c.Get(model.CtxKeyAuthorizedUser)
@@ -54,7 +54,7 @@ func (cp *commonPage) ws(c *gin.Context) {
defer conn.Close()
for {
dao.ServerLock.RLock()
- err = conn.WriteJSON(dao.ServerList)
+ err = conn.WriteJSON(dao.SortedServerList)
dao.ServerLock.RUnlock()
if err != nil {
break
diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go
index a62cc23..eb3f666 100644
--- a/cmd/dashboard/controller/member_api.go
+++ b/cmd/dashboard/controller/member_api.go
@@ -56,7 +56,8 @@ func (ma *memberAPI) delete(c *gin.Context) {
defer dao.ServerLock.Unlock()
err = dao.DB.Delete(&model.Server{}, "id = ?", id).Error
if err == nil {
- delete(dao.ServerList, strconv.FormatUint(id, 10))
+ delete(dao.ServerList, id)
+ dao.ReSortServer()
}
case "notification":
err = dao.DB.Delete(&model.Notification{}, "id = ?", id).Error
@@ -82,9 +83,10 @@ func (ma *memberAPI) delete(c *gin.Context) {
}
type serverForm struct {
- ID uint64
- Name string `binding:"required"`
- Secret string
+ ID uint64
+ Name string `binding:"required"`
+ DisplayIndex int
+ Secret string
}
func (ma *memberAPI) addOrEditServer(c *gin.Context) {
@@ -97,14 +99,15 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
defer dao.ServerLock.Unlock()
s.Name = sf.Name
s.Secret = sf.Secret
+ s.DisplayIndex = sf.DisplayIndex
s.ID = sf.ID
- }
- if sf.ID == 0 {
- s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, admin.ID))
- s.Secret = s.Secret[:10]
- err = dao.DB.Create(&s).Error
- } else {
- err = dao.DB.Save(&s).Error
+ if sf.ID == 0 {
+ s.Secret = com.MD5(fmt.Sprintf("%s%s%d", time.Now(), sf.Name, admin.ID))
+ s.Secret = s.Secret[:10]
+ err = dao.DB.Create(&s).Error
+ } else {
+ err = dao.DB.Save(&s).Error
+ }
}
if err != nil {
c.JSON(http.StatusOK, model.Response{
@@ -115,7 +118,8 @@ func (ma *memberAPI) addOrEditServer(c *gin.Context) {
}
s.Host = &model.Host{}
s.State = &model.State{}
- dao.ServerList[fmt.Sprintf("%d", s.ID)] = &s
+ dao.ServerList[s.ID] = &s
+ dao.ReSortServer()
c.JSON(http.StatusOK, model.Response{
Code: http.StatusOK,
})
diff --git a/cmd/dashboard/controller/member_page.go b/cmd/dashboard/controller/member_page.go
index 8c22b8b..97c0cde 100644
--- a/cmd/dashboard/controller/member_page.go
+++ b/cmd/dashboard/controller/member_page.go
@@ -32,7 +32,7 @@ func (mp *memberPage) server(c *gin.Context) {
defer dao.ServerLock.RUnlock()
c.HTML(http.StatusOK, "dashboard/server", mygin.CommonEnvironment(c, gin.H{
"Title": "服务器管理",
- "Servers": dao.ServerList,
+ "Servers": dao.SortedServerList,
}))
}
diff --git a/cmd/dashboard/main.go b/cmd/dashboard/main.go
index ac983fc..ea3c50c 100644
--- a/cmd/dashboard/main.go
+++ b/cmd/dashboard/main.go
@@ -1,7 +1,6 @@
package main
import (
- "fmt"
"time"
"github.com/patrickmn/go-cache"
@@ -17,7 +16,7 @@ import (
func init() {
var err error
- dao.ServerList = make(map[string]*model.Server)
+ dao.ServerList = make(map[uint64]*model.Server)
dao.Conf = &model.Config{}
err = dao.Conf.Read("data/config.yaml")
if err != nil {
@@ -43,8 +42,9 @@ func initDB() {
innerS := s
innerS.Host = &model.Host{}
innerS.State = &model.State{}
- dao.ServerList[fmt.Sprintf("%d", innerS.ID)] = &innerS
+ dao.ServerList[innerS.ID] = &innerS
}
+ dao.ReSortServer()
}
func main() {
diff --git a/model/server.go b/model/server.go
index 8b2dc58..de87d14 100644
--- a/model/server.go
+++ b/model/server.go
@@ -11,8 +11,9 @@ import (
// Server ..
type Server struct {
Common
- Name string
- Secret string `json:"-"`
+ Name string
+ DisplayIndex int // 展示权重,越大越靠前
+ Secret string `json:"-"`
Host *Host `gorm:"-"`
State *State `gorm:"-"`
diff --git a/resource/static/main.js b/resource/static/main.js
index 2aedffb..aa5c653 100644
--- a/resource/static/main.js
+++ b/resource/static/main.js
@@ -36,7 +36,10 @@ function showFormModal(modelSelector, formID, URL, getData) {
form.children('.message').remove()
btn.toggleClass('loading')
const data = getData ? getData() : $(formID).serializeArray().reduce(function (obj, item) {
- obj[item.name] = (item.name.endsWith('_id') || item.name === 'id' || item.name === 'ID' || item.name === 'RequestType' || item.name === 'RequestMethod') ? parseInt(item.value) : item.value;
+ obj[item.name] = (item.name.endsWith('_id') ||
+ item.name === 'id' || item.name === 'ID' ||
+ item.name === 'RequestType' || item.name === 'RequestMethod' ||
+ item.name === 'DisplayIndex') ? parseInt(item.value) : item.value;
return obj;
}, {});
$.post(URL, JSON.stringify(data)).done(function (resp) {
diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html
index 99fe3eb..e5842a1 100644
--- a/resource/template/common/footer.html
+++ b/resource/template/common/footer.html
@@ -9,7 +9,7 @@
-
+