checklist.hbs
4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href="/"><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="/servers">系统管理</a></li>
<li>代码检查记录</li>
</ul>
<h4>代码检查记录一览</h4>
</div>
</div>
<!-- media -->
</div>
<div class="contentpanel project-index-page">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right">
<a class="btn btn-success btn-rounded mr20 check-btn"><i class="glyphicon glyphicon-plus"></i> 新增检查</a>
</div>
<h4 class="panel-title">检查记录</h4>
</div>
<div class="panel-body">
<table id="table-oper-log" class="table table-striped table-bordered building-table">
<thead>
<tr>
<th>项目名</th>
<th>分支名</th>
<th>状态</th>
<th>检查时间</th>
<th>操作</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script>
$(document).on('ready pjax:success', function() {
var table = $("#table-oper-log").DataTable({
pageLength: 25,
retrieve: true,
responsive: true,
processing: true,
serverSide: true,
ajax: {
url: '/check/list/query',
type: "POST"
},
columns: [
{data: "projectname"},
{data: "branch"},
{data: "state"},
{data: "buildtime"},
{data: "_id"}
],
order: [[3, 'desc']],
columnDefs: [{
targets: 2,
render: function(data, type, row) {
var color = 'warning';
if (data == 'success') {
color = 'success';
} else if (data == 'fail') {
color = 'danger';
}
var id = row._id.split('_');
id = id[id.length - 1];
var html = '<span id="b-' + id + '" class="label label-' + color + '">';
if (data != 'success' && data != 'fail') {
html += '<i class="fa fa-spinner fa-spin fa-fw margin-bottom"></i>';
}
html += '<span class="state">' + data + '</span></span>';
return html;
}
}, {
targets: 4,
render: function(data, type, row) {
return '<button class="btn btn-success btn-log" data-id="' + data + '">查看</button>';
}
}]
});
$(this).on('draw.dt', function() {
$('.btn-log').click(function() {
var id = $(this).data('id');
location.href = '/check/log?id=' + id;
});
});
$('.check-btn').click(function() {
var i = layer.prompt({
title: '输入项目名及分支名(格式为 项目:分支)',
value: 'xxx:xx'
}, function(value) {
value = value.replace(/x/g,'').split(":");
var projectname = value[0];
var branch = value[1];
if (!projectname || !branch) {
layer.msg('请输入正确的项目名及分支名');
return;
}
$.post('/check/exec', {
name: projectname,
branch: branch
}, function(ret) {
if (ret.code == 200) {
table.ajax.reload();
layer.close(i);
} else {
layer.msg(ret.msg, {icon: 5});
}
});
});
});
});
$(function(){
var ws = io();
ws.on('connect', function() {
ws.on('/check/state', function(data) {
var id = data.id.split('_');
id = id[id.length - 1];
var $dom = $('#b-' + id);
$dom.find('.state').text(data.state);
if (data.state == 'success') {
$dom.removeClass('label-warning').addClass('label-success')
$dom.find('i').remove();
} else if (data.state == 'fail') {
$dom.removeClass('label-warning').addClass('label-danger');
$dom.find('i').remove();
}
});
});
ws.on('error', function() {
console.log('connect fail');
});
});
</script>