bugfix#编辑主机或任务,所有记录均被更新

pull/21/merge
ouqiang 2017-04-21 10:17:03 +08:00
parent ae11ed45ee
commit d1d2685827
5 changed files with 10 additions and 15 deletions

View File

@ -29,8 +29,8 @@ func (host *Host) Create() (insertId int16, err error) {
return
}
func (host *Host) UpdateBean() (int64, error) {
return Db.Cols("name,alias,username,password,port,remark,auth_type,private_key").Update(host)
func (host *Host) UpdateBean(id int16) (int64, error) {
return Db.ID(id).Cols("name,alias,username,password,port,remark,auth_type,private_key").Update(host)
}

View File

@ -55,8 +55,8 @@ func (task *Task) Create() (insertId int, err error) {
return
}
func (task *Task) UpdateBean() (int64, error) {
return Db.UseBool("status").Update(task)
func (task *Task) UpdateBean(id int) (int64, error) {
return Db.ID(id).UseBool("status").Update(task)
}
// 更新

View File

@ -87,9 +87,7 @@ func Store(ctx *macaron.Context, form HostForm) string {
if nameExist {
return json.CommonFailure("主机名已存在")
}
if form.Id > 0 {
hostModel.Id = form.Id
}
hostModel.Name = form.Name
hostModel.Alias = form.Alias
hostModel.Username = form.Username
@ -100,7 +98,7 @@ func Store(ctx *macaron.Context, form HostForm) string {
hostModel.AuthType = form.AuthType
isCreate := false
if id > 0 {
_, err = hostModel.UpdateBean()
_, err = hostModel.UpdateBean(id)
} else {
isCreate = true
id, err = hostModel.Create()

View File

@ -92,9 +92,6 @@ func Store(ctx *macaron.Context, form TaskForm) string {
return json.CommonFailure("请选择主机名")
}
if form.Id > 0 {
taskModel.Id = form.Id
}
taskModel.Name = form.Name
taskModel.Protocol = form.Protocol
taskModel.Command = form.Command
@ -109,7 +106,7 @@ func Store(ctx *macaron.Context, form TaskForm) string {
if id == 0 {
id, err = taskModel.Create()
} else {
_, err = taskModel.UpdateBean()
_, err = taskModel.UpdateBean(id)
}
if err != nil {
return json.CommonFailure("保存失败", err)

View File

@ -35,7 +35,7 @@
<td>{{{.Port}}}</td>
<td></td>
<td>{{{.Remark}}}</td>
<td id="operation">
<td class="operation">
<a class="ui purple button" href="/host/edit/{{{.Id}}}">编辑</a>
<button class="ui positive button" onclick="util.removeConfirm('/host/remove/{{{.Id}}}')">删除</button>
<button class="ui blue button" @click="ping({{{.Id}}})">连接测试</button>
@ -49,14 +49,14 @@
<script type="text/javascript">
var Vue = new Vue({
el: '#operation',
el: '.ui.striped.table',
methods: {
ping: function(id) {
swal({
title: '',
text: "连接中.......",
type: 'info',
closeOnConfirm: true
showConfirmButton: false
});
util.get("/host/ping/" + id, function(code, message) {
swal('操作成功', '连接成功', 'success');