Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
e89d3b38
Commit
e89d3b38
authored
Nov 17, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update asset
parent
6e69c018
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
225 additions
and
454 deletions
+225
-454
api.py
apps/assets/api.py
+8
-3
serializers.py
apps/assets/serializers.py
+15
-2
asset_detail.html
apps/assets/templates/assets/asset_detail.html
+1
-4
asset_group_detail.html
apps/assets/templates/assets/asset_group_detail.html
+58
-98
asset_group_list.html
apps/assets/templates/assets/asset_group_list.html
+47
-52
asset_list.html
apps/assets/templates/assets/asset_list.html
+82
-226
idc_assets.html
apps/assets/templates/assets/idc_assets.html
+1
-1
views.py
apps/assets/views.py
+11
-67
user_list.html
apps/users/templates/users/user_list.html
+2
-1
No files found.
apps/assets/api.py
View file @
e89d3b38
...
...
@@ -20,9 +20,14 @@ class AssetViewSet(viewsets.ModelViewSet):
def
get_queryset
(
self
):
queryset
=
super
(
AssetViewSet
,
self
)
.
get_queryset
()
idc
=
self
.
request
.
query_params
.
get
(
'idc'
,
''
)
if
idc
:
queryset
=
queryset
.
filter
(
idc__id
=
idc
)
idc_id
=
self
.
request
.
query_params
.
get
(
'idc_id'
,
''
)
asset_group_id
=
self
.
request
.
query_params
.
get
(
'asset_group_id'
,
''
)
if
idc_id
:
queryset
=
queryset
.
filter
(
idc__id
=
idc_id
)
if
asset_group_id
:
queryset
=
queryset
.
filter
(
groups__id
=
asset_group_id
)
return
queryset
...
...
apps/assets/serializers.py
View file @
e89d3b38
...
...
@@ -40,13 +40,26 @@ class SystemUserSerializer(serializers.ModelSerializer):
class
AssetSerializer
(
BulkSerializerMixin
,
serializers
.
ModelSerializer
):
system_users
=
SystemUserSerializer
(
many
=
True
,
read_only
=
True
)
admin_user
=
AdminUserSerializer
(
many
=
False
,
read_only
=
True
)
# system_users = SystemUserSerializer(many=True, read_only=True)
# admin_user = AdminUserSerializer(many=False, read_only=True)
hardware
=
serializers
.
SerializerMethodField
()
type_display
=
serializers
.
SerializerMethodField
()
class
Meta
(
object
):
model
=
Asset
list_serializer_class
=
BulkListSerializer
@staticmethod
def
get_hardware
(
obj
):
return
'
%
s
%
s
%
s'
%
(
obj
.
cpu
,
obj
.
memory
,
obj
.
disk
)
@staticmethod
def
get_type_display
(
obj
):
if
obj
.
type
:
return
obj
.
type
.
value
else
:
return
''
class
AssetGrantedSerializer
(
serializers
.
ModelSerializer
):
system_users
=
SystemUserSerializer
(
many
=
True
,
read_only
=
True
)
...
...
apps/assets/templates/assets/asset_detail.html
View file @
e89d3b38
...
...
@@ -19,9 +19,6 @@
<li
class=
"active"
>
<a
href=
""
class=
"text-center"
><i
class=
"fa fa-laptop"
></i>
{% trans 'Asset detail' %}
</a>
</li>
<li>
<a
href=
""
class=
"text-center"
><i
class=
"fa fa-bar-chart-o"
></i>
{% trans 'Asset login log' %}
</a>
</li>
<li
class=
"pull-right"
>
<a
class=
"btn btn-outline btn-default"
href=
"{% url 'assets:asset-update' pk=asset.id %}"
><i
class=
"fa fa-edit"
></i>
Update
</a>
</li>
...
...
@@ -236,7 +233,7 @@
</div>
<div
class=
"panel panel-warning"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans '
Asset group
s' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans '
System user
s' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table group_edit"
>
...
...
apps/assets/templates/assets/asset_group_detail.html
View file @
e89d3b38
...
...
@@ -23,48 +23,7 @@
</ul>
</div>
<div
class=
"tab-content"
>
<div
class=
"col-sm-7"
style=
"padding-left: 0;"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
class=
"label"
><b>
{{ asset_group.name }}
</b></span>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td>
{% trans 'Name' %}:
</td>
<td><b>
{{ asset_group.name }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Date created' %}:
</td>
<td><b>
{{ asset_group.date_created|date:"Y-m-d H:i:s" }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Created by' %}:
</td>
<td><b>
{{ asset_group.created_by }}
</b></td>
</tr>
<tr>
<td>
{% trans 'Comment' %}:
</td>
<td><b>
{{ asset_group.comment }}
</b></td>
</tr>
</tbody>
</table>
</div>
</div>
<div
class=
"col-sm-7"
style=
"padding-left: 0"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<span
style=
"float: left"
></span>
{% trans 'Asset list of ' %}
<b>
{{ asset_group.name }}
</b></span>
...
...
@@ -83,7 +42,7 @@
</div>
</div>
<div
class=
"ibox-content"
>
<table
class=
"table table-hover
"
>
<table
class=
"table table-hover
"
id=
"asset_list_table"
>
<thead>
<tr>
<th>
{% trans 'Hostname' %}
</th>
...
...
@@ -93,62 +52,35 @@
</tr>
</thead>
<tbody>
{% for asset in page_obj %}
<tr>
<td>
{{ asset.hostname }}
</td>
<td>
{{ asset.ip }}
</td>
<td>
{{ asset.port }}
</td>
<td>
Alive
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"row"
>
{% include '_pagination.html' %}
</div>
</div>
</div>
</div>
<div
class=
"col-sm-5"
style=
"padding-left: 0;padding-right: 0"
>
<div
class=
"panel panel-primary"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'A
ssociate system user
' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'A
dd asset to this group
' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
<tbody>
<tr
class=
"no-borders-tr"
>
<td
width=
"50%"
>
{% trans 'repush system user' %}:
</td>
<td>
<span
style=
"float: right"
>
<button
class=
"btn btn-danger btn-xs"
type=
"button"
><i
class=
"fa fa-refresh"
></i></button>
</span>
</td>
</tr>
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select
system user
' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for
group in groups
%}
<option
value=
"{{
group.id }}"
>
{{ group.name
}}
</option>
<select
data-placeholder=
"{% trans 'Select
assets
' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for
asset in assets_remain
%}
<option
value=
"{{
asset.id }}"
>
{{ asset.ip }}:{{ asset.port
}}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-primary btn-sm"
>
{% trans 'A
ssociate
' %}
</button>
<button
type=
"button"
class=
"btn btn-primary btn-sm"
>
{% trans 'A
dd
' %}
</button>
</td>
</tr>
</form>
{% for group in user.groups.all %}
<tr>
<td
><b>
{{ group.name }}
</b></td>
<td>
<button
class=
"btn btn-danger btn-xs"
type=
"button"
style=
"float: right;"
><i
class=
"fa fa-minus"
></i></button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
...
...
@@ -156,7 +88,7 @@
<div
class=
"panel panel-info"
>
<div
class=
"panel-heading"
>
<i
class=
"fa fa-info-circle"
></i>
{% trans 'A
dd asset to this group
' %}
<i
class=
"fa fa-info-circle"
></i>
{% trans 'A
ssociate system user
' %}
</div>
<div
class=
"panel-body"
>
<table
class=
"table"
>
...
...
@@ -164,20 +96,20 @@
<form>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<select
data-placeholder=
"{% trans 'Select
asset
user' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for
group in groups
%}
<option
value=
"{{
group.id }}"
>
{{ group
.name }}
</option>
<select
data-placeholder=
"{% trans 'Select
system
user' %}"
class=
"select2"
style=
"width: 100%"
multiple=
""
tabindex=
"4"
>
{% for
system_user in system_users_remain
%}
<option
value=
"{{
system_user.id }}"
>
{{ system_user
.name }}
</option>
{% endfor %}
</select>
</td>
</tr>
<tr
class=
"no-borders-tr"
>
<td
colspan=
"2"
>
<button
type=
"button"
class=
"btn btn-info btn-sm"
>
{% trans 'A
dd
' %}
</button>
<button
type=
"button"
class=
"btn btn-info btn-sm"
>
{% trans 'A
ssociate
' %}
</button>
</td>
</tr>
</form>
{% for
group in user.groups.all
%}
{% for
system_user in system_users
%}
<tr>
<td
><b>
{{ group.name }}
</b></td>
<td>
...
...
@@ -201,25 +133,52 @@
{% endblock %}
{% block custom_foot_js %}
<script>
{
#
function
switch_user_status
(
obj
)
{
#
}
{
#
var
status
=
$
(
obj
).
prop
(
'checked'
);
#
}
{
##
}
{
#
$
.
ajax
({
#
}
{
#
url
:
"{% url 'users:user-active-api' pk=user.id %}"
,
#
}
{
#
type
:
"PUT"
,
#
}
{
#
data
:
{
#
}
{
#
'is_active'
:
status
#
}
{
#
},
#
}
{
#
success
:
function
(
data
,
status
)
{
#
}
{
#
console
.
log
(
data
)
#
}
{
#
},
#
}
{
#
error
:
function
()
{
#
}
{
#
console
.
log
(
'error'
)
#
}
{
#
}
#
}
{
#
})
#
}
{
#
}
#
}
$
(
document
).
ready
(
function
()
{
$
(
'.select2'
).
select2
();
var
options
=
{
ele
:
$
(
'#asset_list_table'
),
buttons
:
[],
order
:
[],
select
:
[],
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "perms:asset-permission-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
targets
:
2
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
dataLength
=
cellData
.
length
;
$
(
td
).
html
(
dataLength
);
}},
{
targets
:
3
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
dataLength
=
cellData
.
length
;
$
(
td
).
html
(
dataLength
);
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
dataLength
=
cellData
.
length
;
$
(
td
).
html
(
dataLength
);
}},
{
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
)
{
var
btn
=
'<button class="btn btn-danger btn-xs btn_del_permission disabled" id=99991937 type="button" style="float: right;"><i class="fa fa-minus"></i></button>'
;
if
(
rowData
.
is_inherited
)
{
$
(
td
).
html
(
btn
)
}
else
{
btn
=
btn
.
replace
(
'99991937'
,
cellData
);
$
(
td
).
html
(
btn
.
replace
(
'disabled'
,
''
));
}
}}
],
ajax_url
:
'{% url "api-perms:asset-permission-list" %}?user={{ user.id }}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"name"
},
{
data
:
"assets"
},
{
data
:
"asset_groups"
},
{
data
:
"system_users"
},
{
data
:
"is_active"
},
{
data
:
"id"
}]
};
jumpserver
.
initDataTable
(
options
);
})
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/asset_group_list.html
View file @
e89d3b38
{% extends '_base_list.html' %}
{% load i18n %}
{% load common_tags %}
{% block content_left_head %}
<a
href=
"{% url 'assets:asset-group-create' %}"
class=
"btn btn-sm btn-primary "
>
{% trans "Create asset group" %}
</a>
{% load i18n static %}
{% block table_search %}
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll('check_all', 'checked')"
>
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-group-list' %}?sort=name"
>
{% trans 'Name' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Asset num' %}
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-group-list' %}?sort=date_expired"
>
{% trans 'Comment' %}
</a></th>
<th
class=
"text-center"
></th>
{% block table_container %}
<div
class=
"uc pull-left m-l-5 m-r-5"
>
<a
href=
"{% url "
assets:asset-group-create
"
%}"
class=
"btn btn-sm btn-primary"
>
{% trans "Create asset group" %}
</a>
</div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"admin_user_list_table"
>
<thead>
<tr>
<th
class=
"text-center"
>
<input
type=
"checkbox"
id=
"check_all"
class=
"ipt_check_all"
>
</th>
<th
class=
"text-center"
>
{% trans 'Name' %}
</th>
<th
class=
"text-center"
>
{% trans 'Asset' %}
</th>
<th
class=
"text-center"
>
{% trans 'Comment' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
{% endblock %}
{% block table_body %}
{% for asset_group in asset_group_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset_group.id }}"
>
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-group-detail' pk=asset_group.id %}"
>
{{ asset_group.name }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset_group.assets.count }}
</td>
<td
class=
"text-center"
>
{{ asset_group.comment|truncatewords:8 }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-group-update' pk=asset_group.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset_group.name }}','{% url 'assets:asset-group-delete' asset_group.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% block content_bottom_left %}{% endblock %}
{% block custom_foot_js %}
<script>
$
(
document
).
ready
(
function
(){
var
options
=
{
ele
:
$
(
'#admin_user_list_table'
),
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "assets:asset-group-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
targets
:
3
,
createdCell
:
function
(
td
,
cellData
)
{
var
innerHtml
=
cellData
.
length
>
30
?
cellData
.
substring
(
0
,
30
)
+
'...'
:
cellData
;
$
(
td
).
html
(
'<a href="javascript:void(0);" data-toggle="tooltip" title="'
+
cellData
+
'">'
+
innerHtml
+
'</a>'
);
}},
{
targets
:
4
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:asset-group-update" pk=99991937 %}" class="btn btn-xs m-l-xs btn-info">{% trans "Update" %}</a>'
.
replace
(
'99991937'
,
cellData
);
var
del_btn
=
'<a class="btn btn-xs btn-danger m-l-xs btn_asset_group_delete" data-uid="99991937">{% trans "Delete" %}</a>'
.
replace
(
'99991937'
,
cellData
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}],
ajax_url
:
'{% url "api-assets:asset-group-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"name"
},
{
data
:
"assets_amount"
},
{
data
:
"comment"
},
{
data
:
"id"
}]
};
jumpserver
.
initDataTable
(
options
);
});
</script>
{% endblock %}
{% block content_bottom_left %}
<form
id=
""
method=
"get"
action=
""
class=
" mail-search"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
>
<option>
{% trans 'Delete selected' %}
</option>
<option>
{% trans 'Update selected' %}
</option>
<option>
{% trans 'Deactive selected' %}
</option>
<option>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'search_btn'
type=
"submit"
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
</div>
</form>
{% endblock %}
apps/assets/templates/assets/asset_list.html
View file @
e89d3b38
...
...
@@ -8,16 +8,26 @@
<style>
.custom
{
/*float:left;*/
margin-right
:
5px
;
}
#modal
.modal-body
{
max-height
:
200px
;
}
</style>
{% endblock %}
{% block content_left_head %}{% endblock %}
{% block table_search %}{% endblock %}
{% block tags_list %}
{% block table_search %}
<div
class=
"html5buttons"
>
<div
class=
"dt-buttons btn-group"
>
<a
class=
"btn btn-default buttons-pdf"
tabindex=
"0"
href=
"#"
>
<span>
PDF
</span></a>
<a
class=
"btn btn-default buttons-excel"
tabindex=
"0"
href=
"#"
>
<span>
Excel
</span>
</a>
</div>
</div>
{% endblock %}
{% block tags_list %}
<div
class=
"ydxbd"
id=
"ydxbd"
style=
"display: none;"
>
<div
class=
"tagBtnList"
>
{% for tag in tag_list %}
...
...
@@ -35,73 +45,40 @@
</div>
{% endblock %}
{% block table_head %}
<th
class=
"text-center"
><input
type=
"checkbox"
id=
"check_all"
onclick=
"checkAll()"
></th>
<th
id=
"th_no"
>
id
</th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=hostname"
>
{% trans 'Hostname' %}
</a></th>
<th
class=
"text-center"
><a
href=
"{% url 'assets:asset-list' %}?sort=username"
>
{% trans 'IP' %}
</a></th>
<th
class=
"text-center"
>
{% trans 'Port' %}
</th>
<th
class=
"text-center"
>
{% trans 'Type' %}
</th>
<th
class=
"text-center"
>
{% trans 'Hardware' %}
</th>
<th
class=
"text-center"
>
{% trans 'Valid' %}
</th>
<th
class=
"text-center"
></th>
{% endblock %}
{% block table_body %}
{% for asset in asset_list %}
<tr
class=
"gradeX"
name=
"oAssets"
>
<td
class=
"text-center"
>
<input
type=
"checkbox"
name=
"checked"
value=
"{{ asset.id }}"
>
</td>
<td>
{{ asset.id }}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-detail' pk=asset.id %}"
>
{{ asset.hostname }}
</a>
</td>
<td
class=
"text-center"
>
{{ asset.ip }}
</td>
<td
class=
"text-center"
>
{{ asset.port }}
</td>
<td
class=
"text-center"
>
{{ asset.type }}
</td>
<td
class=
"text-center"
>
{{ asset.cpu }} {{ asset.memory }} {{ asset.disk }}
</td>
<td
class=
"text-center"
>
{% if asset.is_valid.0 %}
<i
class=
"fa fa-check text-navy"
></i>
{% else %}
<i
class=
"fa fa-times text-danger"
></i>
{% endif %}
</td>
<td
class=
"text-center"
>
<a
href=
"{% url 'assets:asset-update' pk=asset.id %}"
class=
"btn btn-xs btn-info"
>
{% trans 'Update' %}
</a>
<a
onclick=
"objectDelete(this,'{{ asset.hostname }}','{% url 'api-assets:asset-detail' pk=asset.id %}')"
class=
"btn btn-xs btn-danger del"
>
{% trans 'Delete' %}
</a>
</td>
</tr>
{% endfor %}
{% endblock %}
{% block content_bottom_left %}
<div
class=
"input-group"
id=
"actions"
>
<select
class=
"form-control m-b"
style=
"width: auto"
id=
"slct_bulk_update"
>
<option
value=
"delete"
>
{% trans 'Delete selected' %}
</option>
<option
value=
"update"
>
{% trans 'Update selected' %}
</option>
<option
value=
"deactive"
>
{% trans 'Deactive selected' %}
</option>
<option
value=
"export"
>
{% trans 'Export selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'btn_bulk_update'
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
{% block table_container %}
<div
class=
"uc pull-left m-l-5 m-r-5"
><a
href=
"{% url "
assets:asset-create
"
%}"
class=
"btn btn-sm btn-primary"
>
{% trans "Create asset" %}
</a></div>
<div
class=
"uc pull-left"
><a
href=
"javascript:void(0);"
class=
"btn btn-sm btn-primary"
data-toggle=
"modal"
data-target=
"#asset_import_modal"
>
{% trans "Import asset" %}
</a></div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"asset_list_table"
>
<thead>
<tr>
<th
class=
"text-center"
><input
type=
"checkbox"
class=
"ipt_check_all"
></th>
<th
class=
"text-center"
>
{% trans 'Hostname' %}
</th>
<th
class=
"text-center"
>
{% trans 'IP' %}
</th>
<th
class=
"text-center"
>
{% trans 'Port' %}
</th>
<th
class=
"text-center"
>
{% trans 'Type' %}
</th>
<th
class=
"text-center"
>
{% trans 'Env' %}
</th>
<th
class=
"text-center"
>
{% trans 'Hardware' %}
</th>
<th
class=
"text-center"
>
{% trans 'Valid' %}
</th>
<th
class=
"text-center"
>
{% trans 'Alive' %}
</th>
<th
class=
"text-center"
>
{% trans 'Action' %}
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div
id=
"actions"
class=
"hide"
>
<div
class=
"input-group"
>
<select
class=
"form-control m-b"
style=
"width: auto"
id=
"slct_bulk_update"
>
<option
value=
"delete"
>
{% trans 'Delete selected' %}
</option>
<option
value=
"update"
>
{% trans 'Update selected' %}
</option>
<option
value=
"deactive"
>
{% trans 'Deactive selected' %}
</option>
</select>
<div
class=
"input-group-btn pull-left"
style=
"padding-left: 5px;"
>
<button
id=
'btn_bulk_update'
style=
"height: 32px;"
class=
"btn btn-sm btn-primary"
>
{% trans 'Submit' %}
</button>
</div>
{% include "assets/_asset_bulk_update_modal.html" %}
<!-- 模态框(Modal) -->
<div
class=
"modal fade"
id=
"modal"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog modal-lg"
>
<div
class=
"modal-content"
id=
"box"
>
<!--此部分为主体内容,将远程加载进来-->
</div>
</div>
</div>
</div>
{% endblock %}
...
...
@@ -122,165 +99,43 @@
}
else
{
oDiv
.
style
.
display
=
"none"
;
}
};
//onload;
};
//onload;
$
(
document
).
ready
(
function
(){
$
(
'#modal'
).
modal
({
show
:
false
,
backdrop
:
'static'
,
keyboard
:
'false'
,
//remote:"{% url 'assets:asset-modal-update' %}",
});
$
(
'#asset_bulk_update_modal'
).
on
(
'shown.bs.modal'
,
function
(){
//alert('当弹窗完全加载完后,再触发;')
$
(
'.select2'
).
select2
();
$
(
"#id_tags"
).
select2
({
tags
:
true
,
maximumSelectionLength
:
8
,
//最多能够选择的个数
//closeOnSelect: false
});
});
$
(
'#asset_bulk_update_modal'
).
modal
({
show
:
false
,
backdrop
:
'static'
,
keyboard
:
'false'
,
});
var
oTags
=
document
.
getElementById
(
"ydxbd"
);
var
table
=
$
(
'#editable'
).
DataTable
({
"aLengthMenu"
:
[[
10
,
25
,
50
,
-
1
],
[
"10"
,
"25"
,
"50"
,
"all"
]],
"iDisplayLength"
:
25
,
"aaSorting"
:
[[
7
,
"asc"
]],
"aoColumnDefs"
:
[
{
"bSortable"
:
false
,
"aTargets"
:
[
0
]
}],
"bAutoWidth"
:
false
,
"language"
:
{
"url"
:
"/static/js/plugins/dataTables/i18n/zh-hans.json"
},
"dom"
:
'<"custom"fl>tip'
,
"initComplete"
:
function
()
{
//alert( 'DataTables has finished its initialisation.' );
$
(
'#editable_length'
).
before
(
"<a href=
\"
{% url 'assets:asset-create' %}
\"
class=
\"
btn btn-sm btn-primary custom
\"
> {% trans 'Create asset' %} </a> <button class='btn btn-sm btn-primary custom' id='zksx' onclick='tagShow()'>标签</button>"
);
$
(
'#editable'
).
before
(
oTags
);
},
columns
:
[
{
data
:
"checkbox"
},
{
data
:
"id"
},
{
data
:
"name"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"type"
},
{
data
:
"group"
},
{
data
:
"dp"
},
{
data
:
"op"
}
]
});
//将ID列隐藏
table
.
column
(
'1'
).
visible
(
false
);
$
(
'#editable tbody'
).
on
(
'click'
,
'tr'
,
function
()
{
//alert($(this).hasClass('selected'));
if
(
$
(
this
).
hasClass
(
'selected'
)){
$
(
this
).
removeClass
(
'selected'
);
this
.
children
[
0
].
children
[
0
].
checked
=
0
;
}
else
{
$
(
this
).
addClass
(
'selected'
);
this
.
children
[
0
].
children
[
0
].
checked
=
1
;
}
});
$
(
'#btn_bulk_update'
).
on
(
'click'
,
function
(){
var
column2
=
table
.
rows
(
'.selected'
).
data
();
var
id_list
=
[];
var
plain_id_list
=
[];
var
the_url
=
"{% url 'api-assets:asset-bulk-update' %}"
;
for
(
var
i
=
0
;
i
<
column2
.
length
;
i
++
){
id_list
.
push
({
id
:
column2
[
i
].
id
,
hostname
:
column2
[
i
].
ip
});
plain_id_list
.
push
(
parseInt
(
column2
[
i
].
id
));
}
var
url_delete
=
the_url
+
'?id__in='
+
JSON
.
stringify
(
plain_id_list
);
//APIUpdateAttr({url: url_delete, method: 'DELETE', success: success, error: fail});
function
doDelete
(){
swal
({
title
:
"{% trans 'Are you sure?' %}"
,
text
:
"{% trans 'This will delete the selected assets !!!' %}"
,
type
:
"warning"
,
showCancelButton
:
true
,
cancelButtonText
:
'Cancel'
,
confirmButtonColor
:
"#DD6B55"
,
confirmButtonText
:
"{% trans 'Confirm' %}"
,
closeOnConfirm
:
false
},
function
()
{
$
.
ajax
({
type
:
'DELETE'
,
url
:
url_delete
,
data
:{
data
:
'true'
,
},
success
:
function
(){
window
.
location
.
reload
();
}
});
});
}
function
doUpdate
()
{
// alert(plain_id_list);
// $('#asset_bulk_update_modal').modal('show');
window
.
location
.
href
=
"{% url 'assets:asset-modal-update' %}?plain_id_lists="
+
plain_id_list
}
var
action
=
$
(
'#slct_bulk_update option:selected'
).
val
();
if
(
id_list
.
length
===
0
)
{
action
=
'default'
;
}
switch
(
action
)
{
case
'deactive'
:
alert
(
action
+
"未完成"
);
//doDeactive();
break
;
case
'delete'
:
doDelete
();
break
;
case
'update'
:
doUpdate
();
break
;
case
'export'
:
alert
(
action
+
"未完成"
);
break
;
default
:
swal
({
title
:
"未选择任何元素"
,
text
:
"Please..."
});
break
;
}
});
//button
$
(
'#btn_asset_bulk_update'
).
on
(
'click'
,
function
(){
});
//button
});
//$(document).ready
var
bCheck
=
1
;
function
checkAll
(){
if
(
bCheck
){
$
(
"tr[name='oAssets']"
).
each
(
function
(){
oCheckbox
=
this
.
children
[
0
].
children
[
0
];
$
(
this
).
toggleClass
(
'selected'
,
true
);
oCheckbox
.
checked
=
1
;
});
document
.
getElementById
(
'check_all'
).
checked
=
1
;
bCheck
=
0
;
}
else
{
$
(
"tr[name='oAssets']"
).
each
(
function
(){
oCheckbox
=
this
.
children
[
0
].
children
[
0
];
$
(
this
).
toggleClass
(
'selected'
,
false
);
oCheckbox
.
checked
=
0
;
});
document
.
getElementById
(
'check_all'
).
checked
=
0
;
bCheck
=
1
;
var
options
=
{
ele
:
$
(
'#asset_list_table'
),
columnDefs
:
[
{
targets
:
1
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
detail_btn
=
'<a href="{% url "assets:asset-detail" pk=99991937 %}">'
+
cellData
+
'</a>'
;
$
(
td
).
html
(
detail_btn
.
replace
(
'99991937'
,
rowData
.
id
));
}},
{
targets
:
7
,
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
:
8
,
createdCell
:
function
(
td
,
cellData
)
{
if
(
!
cellData
)
{
$
(
td
).
html
(
'<i class="fa fa-circle text-danger"></i>'
)
}
else
{
$
(
td
).
html
(
'<i class="fa fa-circle text-navy"></i>'
)
}
}},
{
targets
:
9
,
createdCell
:
function
(
td
,
cellData
,
rowData
)
{
var
update_btn
=
'<a href="{% url "assets:asset-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
);
$
(
td
).
html
(
update_btn
+
del_btn
)
}}
],
ajax_url
:
'{% url "api-assets:asset-list" %}'
,
columns
:
[{
data
:
"id"
},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"type_display"
},
{
data
:
"env"
},
{
data
:
"hardware"
},
{
data
:
"is_active"
},
{
data
:
"is_active"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
}
;
var
table
=
jumpserver
.
initDataTable
(
options
)
;
});
</script>
{% endblock %}
\ No newline at end of file
apps/assets/templates/assets/idc_assets.html
View file @
e89d3b38
...
...
@@ -118,7 +118,7 @@
$
(
td
).
html
(
'<i class="fa fa-check text-navy"></i>'
)
}
}}],
ajax_url
:
'{% url "api-assets:asset-list" %}?idc={{ idc.id }}'
,
ajax_url
:
'{% url "api-assets:asset-list" %}?idc
_id
={{ idc.id }}'
,
columns
:
[{
data
:
function
(){
return
""
}},
{
data
:
"hostname"
},
{
data
:
"ip"
},
{
data
:
"port"
},
{
data
:
"type"
},
{
data
:
"is_active"
}]
};
...
...
apps/assets/views.py
View file @
e89d3b38
...
...
@@ -16,23 +16,9 @@ from .forms import *
from
.hands
import
AdminUserRequiredMixin
class
AssetListView
(
AdminUserRequiredMixin
,
ListView
):
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
model
=
Asset
context_object_name
=
'asset_list'
class
AssetListView
(
AdminUserRequiredMixin
,
TemplateView
):
template_name
=
'assets/asset_list.html'
def
get_queryset
(
self
):
queryset
=
super
(
AssetListView
,
self
)
.
get_queryset
()
queryset
=
sorted
(
queryset
,
key
=
self
.
sorted_by_valid_and_ip
)
return
queryset
@staticmethod
def
sorted_by_valid_and_ip
(
asset
):
ip_list
=
int_seq
(
asset
.
ip
.
split
(
'.'
))
ip_list
.
insert
(
0
,
asset
.
is_valid
[
0
])
return
ip_list
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'app'
:
'Assets'
,
...
...
@@ -73,7 +59,6 @@ class AssetCreateView(AdminUserRequiredMixin, CreateAssetTagsMiXin, CreateView):
class
AssetModalCreateView
(
AdminUserRequiredMixin
,
CreateAssetTagsMiXin
,
ListView
):
model
=
Asset
# tag_type = 'asset'
form_class
=
AssetCreateForm
template_name
=
'assets/asset_modal_update.html'
success_url
=
reverse_lazy
(
'assets:asset-list'
)
...
...
@@ -119,16 +104,10 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateAssetTagsMiXin, UpdateView):
'admin_user'
,
]
self
.
assets_ids
=
self
.
request
.
POST
.
getlist
(
'assets_ids'
)
print
self
.
assets_ids
self
.
new_form
=
self
.
request
.
POST
.
copy
()
print
len
(
self
.
new_form
)
print
type
(
self
.
new_form
)
for
i
in
default_keys
:
if
self
.
new_form
.
has_key
(
i
):
self
.
new_form
.
pop
(
i
)
print
self
.
new_form
.
items
()
for
i
in
self
.
new_form
:
print
i
return
super
(
AssetUpdateView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
...
...
@@ -145,10 +124,7 @@ class AssetUpdateView(AdminUserRequiredMixin, UpdateAssetTagsMiXin, UpdateView):
return
super
(
AssetUpdateView
,
self
)
.
form_invalid
(
form
)
def
form_valid
(
self
,
form
):
print
self
.
new_form
.
keys
()
print
form
.
clean
()
.
keys
()
asset
=
form
.
save
(
commit
=
False
)
print
"1111"
def
prn_obj_key
(
obj_form
):
return
obj_form
.
clean
()
.
keys
()
...
...
@@ -264,12 +240,8 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
return
super
(
AssetGroupCreateView
,
self
)
.
form_valid
(
form
)
class
AssetGroupListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
AssetGroup
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
context_object_name
=
'asset_group_list'
class
AssetGroupListView
(
AdminUserRequiredMixin
,
TemplateView
):
template_name
=
'assets/asset_group_list.html'
ordering
=
'-id'
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
...
...
@@ -280,34 +252,22 @@ class AssetGroupListView(AdminUserRequiredMixin, ListView):
kwargs
.
update
(
context
)
return
super
(
AssetGroupListView
,
self
)
.
get_context_data
(
**
kwargs
)
def
get_queryset
(
self
):
self
.
queryset
=
super
(
AssetGroupListView
,
self
)
.
get_queryset
()
self
.
keyword
=
keyword
=
self
.
request
.
GET
.
get
(
'keyword'
,
''
)
self
.
sort
=
sort
=
self
.
request
.
GET
.
get
(
'sort'
,
'-date_created'
)
if
keyword
:
self
.
queryset
=
self
.
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
Q
(
comment__icontains
=
keyword
))
if
sort
:
self
.
queryset
=
self
.
queryset
.
order_by
(
sort
)
return
self
.
queryset
class
AssetGroupDetailView
(
SingleObjectMixin
,
AdminUserRequiredMixin
,
ListView
):
class
AssetGroupDetailView
(
AdminUserRequiredMixin
,
DetailView
):
model
=
AssetGroup
template_name
=
'assets/asset_group_detail.html'
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
(
queryset
=
AssetGroup
.
objects
.
all
())
return
super
(
AssetGroupDetailView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
get_queryset
(
self
):
return
self
.
object
.
assets
.
all
()
context_object_name
=
'asset_group'
def
get_context_data
(
self
,
**
kwargs
):
assets_remain
=
Asset
.
objects
.
exclude
(
id__in
=
self
.
object
.
assets
.
all
())
system_users
=
self
.
object
.
system_users
.
all
()
system_users_remain
=
SystemUser
.
objects
.
exclude
(
id__in
=
system_users
)
context
=
{
'app'
:
_
(
'Assets'
),
'action'
:
_
(
'Asset group detail'
),
'asset_group'
:
self
.
object
,
'assets_remain'
:
assets_remain
,
'system_users'
:
system_users
,
'system_users_remain'
:
system_users_remain
,
}
kwargs
.
update
(
context
)
return
super
(
AssetGroupDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
@@ -343,9 +303,6 @@ class AssetGroupDeleteView(AdminUserRequiredMixin, DeleteView):
class
IDCListView
(
AdminUserRequiredMixin
,
TemplateView
):
# model = IDC
# paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
# context_object_name = 'idc_list'
template_name
=
'assets/idc_list.html'
def
get_context_data
(
self
,
**
kwargs
):
...
...
@@ -357,19 +314,6 @@ class IDCListView(AdminUserRequiredMixin, TemplateView):
kwargs
.
update
(
context
)
return
super
(
IDCListView
,
self
)
.
get_context_data
(
**
kwargs
)
# def get_queryset(self):
# self.queryset = super(IDCListView, self).get_queryset()
# self.keyword = keyword = self.request.GET.get('keyword', '')
# self.sort = sort = self.request.GET.get('sort', '-date_created')
#
# if keyword:
# self.queryset = self.queryset.filter(Q(name__icontains=keyword) |
# Q(comment__icontains=keyword))
#
# if sort:
# self.queryset = self.queryset.order_by(sort)
# return self.queryset
class
IDCCreateView
(
AdminUserRequiredMixin
,
CreateView
):
model
=
IDC
...
...
apps/users/templates/users/user_list.html
View file @
e89d3b38
...
...
@@ -83,7 +83,8 @@ $(document).ready(function(){
}}],
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"
}]
{
data
:
"groups_display"
},
{
data
:
"is_valid"
},
{
data
:
"id"
}],
op_html
:
$
(
'#actions'
).
html
()
};
var
table
=
jumpserver
.
initDataTable
(
options
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment