Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app/controllers/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,62 @@ func (this *TaskController) List() {
this.display()
}

func (this *TaskController) Search() {
page, _ := this.GetInt("page")
if page < 1 {
page = 1
}
groupId, _ := this.GetInt("groupid")
filters := make([]interface{}, 0)
if groupId > 0 {
filters = append(filters, "group_id", groupId)
}
command := this.GetString("command")
filters = append(filters, "command__icontains", command)
result, count := models.TaskGetList(page, this.pageSize, filters...)

list := make([]map[string]interface{}, len(result))
for k, v := range result {
row := make(map[string]interface{})
row["id"] = v.Id
row["name"] = v.TaskName
row["cron_spec"] = v.CronSpec
row["status"] = v.Status
row["description"] = v.Description

e := jobs.GetEntryById(v.Id)
if e != nil {
row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s")
row["prev_time"] = "-"
if e.Prev.Unix() > 0 {
row["prev_time"] = beego.Date(e.Prev, "Y-m-d H:i:s")
} else if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
}
row["running"] = 1
} else {
row["next_time"] = "-"
if v.PrevTime > 0 {
row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s")
} else {
row["prev_time"] = "-"
}
row["running"] = 0
}
list[k] = row
}

// 分组列表
groups, _ := models.TaskGroupGetList(1, 100)

this.Data["pageTitle"] = "任务列表"
this.Data["list"] = list
this.Data["groups"] = groups
this.Data["groupid"] = groupId
this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("TaskController.Search", "groupid", groupId, "command", command), true).ToString()
this.display()
}

// 添加任务
func (this *TaskController) Add() {

Expand Down Expand Up @@ -164,6 +220,10 @@ func (this *TaskController) Edit() {
this.ajaxMsg(err.Error(), MSG_ERR)
}

jobs.RemoveJob(id)
task.Status = 0
task.Update()

this.ajaxMsg("", MSG_OK)
}

Expand Down
11 changes: 11 additions & 0 deletions static/css/bootstrap.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,17 @@ background-repeat:no-repeat;
line-height: 22px;
padding: 6px 14px;
}
.btn-large-group {
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
-ms-border-radius: 6px;
-o-border-radius: 6px;
border-radius: 6px;
font-size: 16px;
line-height: 24px;
line-height: 22px;
padding: 1px 14px;
}
.btn-large [class^="icon-"] {
margin-top: 1px;
}
Expand Down
36 changes: 36 additions & 0 deletions views/layout/layout.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
<!DOCTYPE html>
<html lang="en">

<style type="text/css">
.searchinput{
border-right-width: 0px;
padding-left: 3px;
width: 168px;
font-family: arial;
float: left;
border-top-width: 0px;
border-bottom-width: 0px;
color: #636365;
margin-left: 4px;
font-size: 8pt;
vertical-align: middle;
border-left-width: 0px;
margin-right: 3px;
}
.searchaction{
width: 21px;
/*float: left;*/
float: right;
height: 17px;
}
</style>

<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -82,6 +106,18 @@
</a>
</li>
</ul>
<ul class="nav pull-right" style="padding-top: 18px;">

<form action="../task/search" name="search" method="get">
<input type="text" name="command" title="Search" class="searchinput" id="searchinput" onkeydown="if (event.keyCode==13) {}" onblur="if(this.value=='')value='- 命令脚本 -';" onfocus="if(this.value=='- 命令脚本 -')value='';" value="- 命令脚本 -" size="10"/>

<input type="image" width="21" height="17" class="searchaction" onclick="
if(document.forms['search'].searchinput.value=='- 命令脚本 -')
document.forms['search'].searchinput.value='';
" src="/static/img/magglass.gif"/>
</form>

</ul>
</div> <!-- /container -->
</div> <!-- /subnavbar-inner -->
</div> <!-- /subnavbar -->
Expand Down
2 changes: 1 addition & 1 deletion views/task/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h3>任务列表</h3>

<div class="btn-group btn-large" style="float:right">
<form method="post" name="s" action="{{urlfor "TaskController.List"}}">
<select name="groupid" class="btn-large">
<select name="groupid" class="btn-large-group">
<option value="0">全部分组</option>
{{range $k, $v := .groups}}
<option value="{{$v.Id}}" {{if eq $v.Id $.groupid}}selected{{end}}>{{$v.GroupName}}</option>
Expand Down