From 7592655c2dff386d952948c1e08421ec93d39504 Mon Sep 17 00:00:00 2001 From: naiba Date: Wed, 20 Jan 2021 22:15:47 +0800 Subject: [PATCH] =?UTF-8?q?[dashboard=200.3.3]=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1=E5=8F=AF=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/dashboard/controller/member_api.go | 30 ++++++++++++++++- resource/static/main.js | 41 ++++++++++++++++++++++-- resource/template/common/footer.html | 2 +- resource/template/component/cron.html | 10 ++++-- resource/template/dashboard/cron.html | 2 +- resource/template/dashboard/setting.html | 1 + service/dao/dao.go | 2 +- 7 files changed, 79 insertions(+), 9 deletions(-) diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index cfe334d..9edd26b 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -33,7 +33,7 @@ func (ma *memberAPI) serve() { Redirect: "/login", })) - mr.POST("/logout", ma.logout) + mr.GET("/search-server", ma.searchServer) mr.POST("/server", ma.addOrEditServer) mr.POST("/monitor", ma.addOrEditMonitor) mr.POST("/cron", ma.addOrEditCron) @@ -41,6 +41,7 @@ func (ma *memberAPI) serve() { mr.POST("/alert-rule", ma.addOrEditAlertRule) mr.POST("/setting", ma.updateSetting) mr.DELETE("/:model/:id", ma.delete) + mr.POST("/logout", ma.logout) } func (ma *memberAPI) delete(c *gin.Context) { @@ -102,6 +103,33 @@ func (ma *memberAPI) delete(c *gin.Context) { }) } +type searchResult struct { + Name string `json:"name,omitempty"` + Value uint64 `json:"value,omitempty"` + Text string `json:"text,omitempty"` +} + +func (ma *memberAPI) searchServer(c *gin.Context) { + var servers []model.Server + likeWord := "%" + c.Query("word") + "%" + dao.DB.Select("id,name").Where("id = ? OR name LIKE ? OR tag LIKE ? OR note LIKE ?", + c.Query("word"), likeWord, likeWord, likeWord).Find(&servers) + + var resp []searchResult + for i := 0; i < len(servers); i++ { + resp = append(resp, searchResult{ + Value: servers[i].ID, + Name: servers[i].Name, + Text: servers[i].Name, + }) + } + + c.JSON(http.StatusOK, map[string]interface{}{ + "success": true, + "results": resp, + }) +} + type serverForm struct { ID uint64 Name string `binding:"required"` diff --git a/resource/static/main.js b/resource/static/main.js index ee24ca7..087d5b1 100644 --- a/resource/static/main.js +++ b/resource/static/main.js @@ -36,10 +36,22 @@ 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') || + // ID 类的数据 + if ((item.name.endsWith('_id') || item.name === 'id' || item.name === 'ID' || item.name === 'RequestType' || item.name === 'RequestMethod' || - item.name === 'DisplayIndex' || item.name === 'Type') ? parseInt(item.value) : item.value; + item.name === 'DisplayIndex' || item.name === 'Type')) { + obj[item.name] = parseInt(item.value); + } else { + obj[item.name] = item.value; + } + + if (item.name == 'ServersRaw') { + if (item.value.length > 2) { + obj[item.name] = '[' + item.value.substr(3, item.value.length - 1) + ']' + } + } + return obj; }, {}); $.post(URL, JSON.stringify(data)).done(function (resp) { @@ -108,6 +120,7 @@ function addOrEditServer(server) { modal.find('input[name=name]').val(server ? server.Name : null) modal.find('input[name=Tag]').val(server ? server.Tag : null) modal.find('input[name=DisplayIndex]').val(server ? server.DisplayIndex : null) + modal.find('textarea[name=Note]').val(server ? server.Note : null) if (server) { modal.find('.secret.field').attr('style', '') modal.find('input[name=secret]').val(server.Secret) @@ -136,7 +149,16 @@ function addOrEditCron(cron) { modal.find('input[name=ID]').val(cron ? cron.ID : null) modal.find('input[name=Name]').val(cron ? cron.Name : null) modal.find('input[name=Scheduler]').val(cron ? cron.Scheduler : null) - modal.find('input[name=ServersRaw]').val(cron ? cron.ServersRaw : '[]') + var servers + if (cron) { + servers = cron.ServersRaw + serverList = JSON.parse(servers) + const node = modal.find('i.dropdown.icon') + for (let i = 0; i < serverList.length; i++) { + node.after('ID:' + serverList[i] + '') + } + } + modal.find('input[name=ServersRaw]').val(cron ? '[],' + servers.substr(1, servers.length - 2) : '[]') modal.find('textarea[name=Command]').val(cron ? cron.Command : null) if (cron && cron.PushSuccessful) { modal.find('.ui.push-successful.checkbox').checkbox('set checked') @@ -197,3 +219,16 @@ function logout(id) { }); }) } + +$(document).ready(() => { + try { + $('.ui.servers.search.dropdown').dropdown({ + clearable: true, + apiSettings: { + url: '/api/search-server?word={query}', + cache: false, + }, + }) + } catch (error) { + } +}) \ No newline at end of file diff --git a/resource/template/common/footer.html b/resource/template/common/footer.html index 74de7bc..4793e7d 100644 --- a/resource/template/common/footer.html +++ b/resource/template/common/footer.html @@ -8,7 +8,7 @@ - + diff --git a/resource/template/component/cron.html b/resource/template/component/cron.html index 42cae30..78f8490 100644 --- a/resource/template/component/cron.html +++ b/resource/template/component/cron.html @@ -18,7 +18,12 @@
- +
@@ -30,7 +35,8 @@

计划的格式为:* * * * * 分 时 天 月 星期,详情见 计划表达式格式
+ href="https://pkg.go.dev/github.com/robfig/cron/v3#hdr-CRON_Expression_Format" + target="_blank">计划表达式格式
命令:Shell 命令,就像写脚本一样就可以,如果遇到 xxx 命令找不到,可能是 PATH 环境变量的问题,source ~/.bashrc 或者使用绝对路径执行。

diff --git a/resource/template/dashboard/cron.html b/resource/template/dashboard/cron.html index 733a822..ad5cfe8 100644 --- a/resource/template/dashboard/cron.html +++ b/resource/template/dashboard/cron.html @@ -42,7 +42,7 @@
diff --git a/resource/template/dashboard/setting.html b/resource/template/dashboard/setting.html index dd9167f..5aa6c54 100644 --- a/resource/template/dashboard/setting.html +++ b/resource/template/dashboard/setting.html @@ -15,6 +15,7 @@
diff --git a/service/dao/dao.go b/service/dao/dao.go index 9165cd2..362c858 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -34,7 +34,7 @@ var CronLock sync.RWMutex var Crons map[uint64]*model.Cron var Cron *cron.Cron -var Version = "v0.3.2" +var Version = "v0.3.3" func ReSortServer() { ServerLock.RLock()