mirror of https://github.com/jumpserver/jumpserver
update assets-group
parent
220892824c
commit
d2e989403f
|
@ -1,8 +1,7 @@
|
|||
# ~*~ coding: utf-8 ~*~
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework import viewsets, serializers
|
||||
|
||||
from rest_framework import viewsets, serializers,generics
|
||||
from .models import AssetGroup, Asset, IDC, AssetExtend
|
||||
|
||||
|
||||
|
@ -45,9 +44,11 @@ class AssetViewSet(viewsets.ModelViewSet):
|
|||
serializer_class = AssetSerializer
|
||||
|
||||
|
||||
class IDCViewSet(viewsets.ModelViewSet):
|
||||
class IDCViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
API endpoint that allows IDC to be viewed or edited.
|
||||
"""
|
||||
queryset = IDC.objects.all()
|
||||
serializer_class = IDCSerializer
|
||||
serializer_class = IDCSerializer
|
||||
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class AssetGroupForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = AssetGroup
|
||||
fields = [
|
||||
"name", "comment","system_users"
|
||||
"name", "comment","system_users",
|
||||
]
|
||||
widgets = {
|
||||
'name' : forms.TextInput(attrs={}),
|
||||
|
|
|
@ -37,18 +37,16 @@
|
|||
{{ form.name|bootstrap_horizontal }}
|
||||
{{ form.comment|bootstrap_horizontal }}
|
||||
<div class="hr-line-dashed"></div>
|
||||
<h3 class="widget-head-color-box">资产</h3>
|
||||
<div class="form-group">
|
||||
<label for="assets" class="col-sm-2 control-label">资产</label>
|
||||
<div class="col-sm-9">
|
||||
<select name="assets" id="assets" data-placeholder="选择资产" class="select2 form-control m-b" multiple tabindex="2">
|
||||
{% for asset in assets %}
|
||||
<option value="{{ asset.id }}">{{ asset.hostname }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<!--{{ form.name|bootstrap_horizontal }}-->
|
||||
<h3 class="widget-head-color-box">资产数量</h3>
|
||||
<div class="form-group">
|
||||
<label for="assets" class="col-sm-2 control-label">已有</label>
|
||||
<div class="col-sm-9" id="div1">
|
||||
<button type="button" class="btn btn-info btn-rounded" id="add_asset">
|
||||
0
|
||||
</button>
|
||||
<!--<input type="text" value="" name="id_list" id="id_list"/>-->
|
||||
</div>
|
||||
</div>
|
||||
<div class="hr-line-dashed"></div>
|
||||
<h3 class="widget-head-color-box">资产用户</h3>
|
||||
{{ form.system_users|bootstrap_horizontal }}
|
||||
|
@ -56,6 +54,7 @@
|
|||
<div class="col-sm-4 col-sm-offset-5">
|
||||
<button class="btn btn-white" type="reset"> 重置 </button>
|
||||
<button class="btn btn-primary" type="submit"> 提交 </button>
|
||||
<div id='box2'> </div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -68,13 +67,64 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模态框(Modal) -->
|
||||
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content" id="box">
|
||||
<!--此部分为主体内容,将远程加载进来-->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block custom_foot_js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2();
|
||||
$('.select2-system-user').select2();
|
||||
})
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#id_list").val("");
|
||||
});
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2();
|
||||
$('.select2-system-user').select2();
|
||||
})
|
||||
|
||||
$('#add_asset').on('click',function(){
|
||||
//$('#box2').load("{% url 'assets:asset-modal-list' %}");
|
||||
$('#modal').modal('show');
|
||||
});
|
||||
|
||||
$('#modal').modal({
|
||||
show:false,
|
||||
remote:"{% url 'assets:asset-modal-list' %}",
|
||||
});
|
||||
|
||||
$('#modal').on('show.bs.modal',function(){
|
||||
//alert('当调用show方法时,立即触发;')
|
||||
});
|
||||
|
||||
$('#modal').on('shown.bs.modal',function(){
|
||||
//alert('当弹窗完全加载完后,再触发;')
|
||||
});
|
||||
|
||||
$('#modal').on('hide.bs.modal',function(){
|
||||
//alert('当关闭时,立即触发;')
|
||||
});
|
||||
|
||||
$('#modal').on('hidden.bs.modal',function(){
|
||||
//alert('当关完全关闭后,再触发;')
|
||||
});
|
||||
|
||||
$('#modal').on('loaded.bs.modal',function(){
|
||||
//alert('当远程数据加载完毕后,再触发;')
|
||||
});
|
||||
|
||||
$('#save-btn').on('click',function(){
|
||||
alert('点击保存按钮时触发;')
|
||||
$('#modal').modal('hide');
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,66 @@
|
|||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel">分配/回收资产</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center">
|
||||
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
|
||||
</th>
|
||||
<th>资产名称</th>
|
||||
<th>IP</th>
|
||||
<th>硬件类型</th>
|
||||
<th>资产组</th>
|
||||
<th>部门</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for asset in asset_modal_list %}
|
||||
<tr>
|
||||
<td class="text-center">
|
||||
<input type="checkbox" name="checked" value="{{ asset.id }}">
|
||||
</td>
|
||||
<td>{{ asset.hostname }}</td>
|
||||
<td>{{ asset.ip }}</td>
|
||||
<td>虚拟机</td>
|
||||
<td>网络设备</td>
|
||||
<td>微信事业部</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" id="close-btn">
|
||||
关闭
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary" id="save-btn">
|
||||
保存
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$('#close-btn').on('click',function(){
|
||||
//alert('点击关闭按钮时触发;')
|
||||
$('#modal').modal('hide');
|
||||
});
|
||||
|
||||
$('#save-btn').on('click',function(){
|
||||
// alert('点击保存按钮时触发2;')
|
||||
var box = $("input[name='checked']:checked");
|
||||
var size=box.length;
|
||||
$("#add_asset").text(size);
|
||||
var ids=[];
|
||||
$("#div1").find("input").remove();
|
||||
for(var i=0;i<box.length;i++){
|
||||
var value = $(box[i]).val();
|
||||
$("#div1").append("<input type='hidden' name='assets' value='"+value+"'>");
|
||||
}
|
||||
$('#modal').modal('hide');
|
||||
|
||||
});
|
||||
|
||||
</script>
|
|
@ -9,13 +9,10 @@
|
|||
<th class="text-center">
|
||||
<input type="checkbox" id="check_all" onclick="checkAll('check_all', 'checked')">
|
||||
</th>
|
||||
{# <th class="text-center">{% trans 'ID' %}</th>#}
|
||||
<th class="text-center"><a href="{% url 'assets:idc-list' %}?sort=name">{% trans 'Name' %}</a></th>
|
||||
<th class="text-center">{% trans 'Asset num' %}</th>
|
||||
{# <th class="text-center">{% trans 'Bandwidth' %}</th>#}
|
||||
<th class="text-center">{% trans 'Contact' %}</th>
|
||||
<th class="text-center">{% trans 'Phone' %}</th>
|
||||
{# <th class="text-center">{% trans 'Address' %}</th>#}
|
||||
<th class="text-center">{% trans 'operation' %}</th>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# coding:utf-8
|
||||
from django.conf.urls import url, include
|
||||
import views
|
||||
import api
|
||||
# from .api import (
|
||||
# AssetGroupViewSet, AssetViewSet, IDCViewSet
|
||||
# )
|
||||
|
@ -19,6 +20,7 @@ urlpatterns = [
|
|||
url(r'^asset/(?P<pk>[0-9]+)$', views.AssetDetailView.as_view(), name='asset-detail'),
|
||||
url(r'^asset/(?P<pk>[0-9]+)/update', views.AssetUpdateView.as_view(), name='asset-update'),
|
||||
url(r'^asset/(?P<pk>[0-9]+)/delete$', views.AssetDeleteView.as_view(), name='asset-delete'),
|
||||
url(r'^asset-modal$', views.AssetModalListView.as_view(), name='asset-modal-list'),
|
||||
|
||||
# Resource asset group url
|
||||
url(r'^asset-group$', views.AssetGroupListView.as_view(), name='asset-group-list'),
|
||||
|
@ -50,5 +52,13 @@ urlpatterns = [
|
|||
url(r'^system-user/(?P<pk>[0-9]+)/asset$', views.SystemUserAssetView.as_view(), name='system-user-asset'),
|
||||
# url(r'^system-user/(?P<pk>[0-9]+)/asset-group$', views.SystemUserAssetGroupView.as_view(),
|
||||
# name='system-user-asset-group'),
|
||||
# url(r'^api/v1.0/', include(router.urls)),
|
||||
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
#json
|
||||
url(r'^v1/assets/$', api.AssetViewSet.as_view({'get':'list'}), name='assets-list-api'),
|
||||
url(r'^v1/idc/$', api.IDCViewSet.as_view({'get':'list'}), name='idc-list-json'),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# ~*~ coding: utf-8 ~*~
|
||||
#
|
||||
|
||||
from rest_framework import serializers
|
||||
from models import Asset
|
||||
|
||||
|
|
|
@ -100,6 +100,11 @@ class AssetDetailView(DetailView):
|
|||
kwargs.update(context)
|
||||
return super(AssetDetailView, self).get_context_data(**kwargs)
|
||||
|
||||
class AssetModalListView(AdminUserRequiredMixin, ListView):
|
||||
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
|
||||
model = Asset
|
||||
context_object_name = 'asset_modal_list'
|
||||
template_name = 'assets/asset_modal_list.html'
|
||||
|
||||
class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
|
||||
model = AssetGroup
|
||||
|
@ -119,11 +124,22 @@ class AssetGroupCreateView(AdminUserRequiredMixin, CreateView):
|
|||
kwargs.update(context)
|
||||
return super(AssetGroupCreateView, self).get_context_data(**kwargs)
|
||||
|
||||
# def form_valid(self, form):
|
||||
# asset_group = form.save()
|
||||
# assets_id_list = self.request.POST.getlist('assets', [])
|
||||
# assets = [get_object_or_404(Asset, id=asset_id) for asset_id in assets_id_list]
|
||||
# asset_group.created_by = self.request.user.username or 'Admin'
|
||||
# asset_group.assets.add(*tuple(assets))
|
||||
# asset_group.save()
|
||||
# return super(AssetGroupCreateView, self).form_valid(form)
|
||||
|
||||
|
||||
|
||||
def form_valid(self, form):
|
||||
asset_group = form.save()
|
||||
assets_id_list = self.request.POST.getlist('assets', [])
|
||||
assets = [get_object_or_404(Asset, id=asset_id) for asset_id in assets_id_list]
|
||||
assets = [get_object_or_404(Asset, id=int(asset_id)) for asset_id in assets_id_list]
|
||||
print assets
|
||||
asset_group.created_by = self.request.user.username or 'Admin'
|
||||
asset_group.assets.add(*tuple(assets))
|
||||
asset_group.save()
|
||||
|
@ -283,6 +299,7 @@ class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
|
|||
success_url = reverse_lazy('assets:idc-list')
|
||||
|
||||
|
||||
|
||||
class AdminUserListView(AdminUserRequiredMixin, ListView):
|
||||
model = AdminUser
|
||||
paginate_by = settings.CONFIG.DISPLAY_PER_PAGE
|
||||
|
@ -527,3 +544,5 @@ class SystemUserAssetView(AdminUserRequiredMixin, SingleObjectMixin, ListView):
|
|||
# kwargs.update(context)
|
||||
# return super(SystemUserAssetGroupView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue