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 @@
-
+