Browse Source

添加了部分cron的list页面

pull/530/head
yumaojun03 8 years ago
parent
commit
b348f7f1ce
  1. 53
      apps/ops/templates/cron/list.html
  2. 6
      apps/ops/templates/sudo/list.html
  3. 6
      apps/ops/views.py
  4. 32
      apps/static/js/jumpserver.js

53
apps/ops/templates/cron/list.html

@ -3,9 +3,9 @@
{% block table_search %}
{% endblock %}
{% block table_container %}
<div class="uc pull-left m-l-5 m-r-5"><a href="{% url "users:user-create" %}" class="btn btn-sm btn-primary"> {% trans "Create sudo" %} </a></div>
<div class="uc pull-left"><a href="javascript:void(0);" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#user_import_modal"> {% trans "Import user" %} </a></div>
<table class="table table-striped table-bordered table-hover " id="user_list_table" >
<div class="uc pull-left m-l-5 m-r-5"><a href="{% url "users:user-create" %}" class="btn btn-sm btn-primary"> {% trans "Create cron" %} </a></div>
{#<div class="uc pull-left"><a href="javascript:void(0);" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#user_import_modal"> {% trans "Import user" %} </a></div>#}
<table class="table table-striped table-bordered table-hover " id="cron_list_table">
<thead>
<tr>
<th class="text-center">
@ -13,10 +13,9 @@
<input id="" type="checkbox" class="ipt_check_all">
</th>
<th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Username' %}</th>
<th class="text-center">{% trans 'Role' %}</th>
<th class="text-center">{% trans 'User group' %}</th>
<th class="text-center">{% trans 'Active' %}</th>
<th class="text-center">{% trans 'Time' %}</th>
<th class="text-center">{% trans 'Job' %}</th>
<th class="text-center">{% trans 'User' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
</tr>
</thead>
@ -38,7 +37,7 @@
</div>
</div>
{% include "users/_user_bulk_update_modal.html" %}
{% include "users/_user_import_modal.html" %}
{#{% include "users/_user_import_modal.html" %}#}
{% endblock %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
@ -46,24 +45,19 @@
<script>
$(document).ready(function(){
var options = {
ele: $('#user_list_table'),
ele: $('#cron_list_table'),
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var detail_btn = '<a href="{% url "users:user-detail" pk=99991937 %}">' + cellData + '</a>';
var detail_btn = '<a href="{% url "ops:page-cron-detail" pk=99991937 %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('99991937', rowData.id));
}},
{targets: 4, createdCell: function (td, cellData) {
var innerHtml = cellData.length > 20 ? cellData.substring(0, 20) + '...': cellData;
$(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
{targets: 2, createdCell: function (td, cellData, rowData) {
var cron_time_tmp = "{0} {1} {2} {3} {4} (分    周)";
var cron_time = cron_time_tmp.format(rowData.minute, rowData.hour, rowData.day, rowData.month, rowData.weekday);
var innerHtml = '<span>' + cron_time + '</span>';
$(td).html(innerHtml.replace('99991937', rowData.id));
}},
{targets: 5, createdCell: function (td, cellData) {
if (!cellData) {
$(td).html('<i class="fa fa-times text-danger"></i>')
} else {
$(td).html('<i class="fa fa-check text-navy"></i>')
}
}},
{targets: 6, createdCell: function (td, cellData, rowData) {
{targets: 4, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
if (rowData.id === 1 || rowData.username == "admin") {
@ -72,9 +66,8 @@ $(document).ready(function(){
$(td).html(update_btn + del_btn)
}
}}],
ajax_url: '{% url "api-users:user-list" %}',
columns: [{data: "id"}, {data: "username" }, {data: "name" }, {data: "get_role_display" },
{data: "groups_display" }, {data: "is_valid" }, {data: "id" }],
ajax_url: '{% url "api-ops:crontable-list" %}',
columns: [{data: "id"}, {data: "name" }, {data: "month" }, {data: "job" }, {data: "user" }, {data: "id" }],
op_html: $('#actions').html()
};
var table = jumpserver.initDataTable(options);
@ -89,7 +82,7 @@ $(document).ready(function(){
}).on('click', '#btn_bulk_update', function(){
var action = $('#slct_bulk_update').val();
var $data_table = $('#user_list_table').DataTable();
var $data_table = $('#cron_list_table').DataTable();
var id_list = [];
var plain_id_list = [];
$data_table.rows({selected: true}).every(function(){
@ -121,7 +114,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'User Deleted.' %}";
swal("{% trans 'User Delete' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#cron_list_table').DataTable().ajax.reload();
};
var fail = function() {
var msg = "{% trans 'User Deleting failed.' %}";
@ -157,7 +150,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'User Deleted.' %}";
swal("{% trans 'User Delete' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#cron_list_table').DataTable().ajax.reload();
};
var fail = function() {
var msg = "{% trans 'User Deleting failed.' %}";
@ -198,7 +191,7 @@ $(document).ready(function(){
new_groups = body.groups.map(Number);
body.groups = new_groups;
}
var $data_table = $('#user_list_table').DataTable()
var $data_table = $('#cron_list_table').DataTable()
var post_list = [];
$data_table.rows({selected: true}).every(function(){
var content = Object.assign({id: this.data().id}, body);
@ -211,7 +204,7 @@ $(document).ready(function(){
var success = function() {
var msg = "{% trans 'The selected users has been updated successfully.' %}";
swal("{% trans 'User Updated' %}", msg, "success");
$('#user_list_table').DataTable().ajax.reload();
$('#cron_list_table').DataTable().ajax.reload();
jumpserver.checked = false;
};
APIUpdateAttr({url: the_url, method: 'PATCH', body: JSON.stringify(post_list), success: success});
@ -225,7 +218,7 @@ $(document).ready(function(){
$('<span />', {class: 'help-block text-danger'}).html(data.msg).insertAfter($('#id_excel'));
} else {
$('#user_import_modal').modal('hide');
var $data_table = $('#user_list_table').DataTable();
var $data_table = $('#cron_list_table').DataTable();
toastr.success("{% trans 'Import User Success.' %}");
$data_table.ajax.reload();
}

6
apps/ops/templates/sudo/list.html

@ -14,7 +14,6 @@
<th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Privileges' %}</th>
<th class="text-center">{% trans 'Extra Lines' %}</th>
<th class="text-center">{% trans 'Created' %}</th>
<th class="text-center">{% trans 'Action' %}</th>
</tr>
@ -51,7 +50,7 @@ $(document).ready(function(){
var detail_btn = '<a href="{% url "ops:page-sudo-detail" pk=99991937 %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('99991937', rowData.id));
}},
{targets: 5, createdCell: function (td, cellData, rowData) {
{targets: 4, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "users:user-update" pk=99991937 %}" class="btn btn-xs btn-info">{% trans "Update" %}</a>'.replace('99991937', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="99991937">{% trans "Delete" %}</a>'.replace('99991937', cellData);
if (rowData.id === 1 || rowData.username == "admin") {
@ -61,8 +60,7 @@ $(document).ready(function(){
}
}}],
ajax_url: '{% url "api-ops:sudo-list" %}',
columns: [{data: "id"}, {data: "name" }, {data: "privilege_items" }, {data: "extra_lines" },
{data: "created_time" }, {data: "id" }],
columns: [{data: "id"}, {data: "name" }, {data: "privilege_items" }, {data: "extra_lines" }, {data: "id" }],
op_html: $('#actions').html()
};
var table = jumpserver.initDataTable(options);

6
apps/ops/views.py

@ -34,14 +34,14 @@ class SudoDetailView(DetailView):
template_name = 'sudo/detail.html'
class CronListView(AdminUserRequiredMixin, ListSudoPrivilegesMixin, ListView):
class CronListView(AdminUserRequiredMixin, ListView):
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
model = CronTable
context_object_name = 'crons'
template_name = 'sudo/list.html'
template_name = 'cron/list.html'
class CronCreateView(AdminUserRequiredMixin, CreateSudoPrivilegesMixin, CreateView):
class CronCreateView(AdminUserRequiredMixin, CreateView):
model = CronTable
template_name = 'cron/create.html'

32
apps/static/js/jumpserver.js

@ -333,3 +333,35 @@ jumpserver.initDataTable = function (options) {
return table;
};
/**
* 替换所有匹配exp的字符串为指定字符串
* @param exp 被替换部分的正则
* @param newStr 替换成的字符串
*/
String.prototype.replaceAll = function (exp, newStr) {
return this.replace(new RegExp(exp, "gm"), newStr);
};
/**
* 原型字符串格式化
* @param args 格式化参数值
*/
String.prototype.format = function(args) {
var result = this;
if (arguments.length < 1) {
return result;
}
var data = arguments;
if (arguments.length == 1 && typeof (args) == "object") {
data = args;
}
for ( var key in data) {
var value = data[key];
if (undefined != value) {
result = result.replaceAll("\\{" + key + "\\}", value);
}
}
return result;
}

Loading…
Cancel
Save