提交 c940a4c0 编写于 作者: baltery's avatar baltery

[Fixture] 增加 task list 删除按钮

上级 3f72ce4b
......@@ -12,8 +12,7 @@ def update_assets_hardware_info(assets):
task_tuple = (
('setup', ''),
)
task_name = ','.join([asset.hostname for asset in assets])
summary, result = run_AdHoc(task_tuple, assets, record=True, task_name=task_name)
summary, result = run_AdHoc(task_tuple, assets, record=False)
for hostname, info in result['contacted'].items():
if info:
info = info[0]['ansible_facts']
......
......@@ -104,37 +104,6 @@ function tagShow() {
}
} //onload;
function objDelete(obj, name, url) {
function doDelete() {
var body = {};
var success = function() {
swal('Deleted!', "[ "+name+"]"+" has been deleted ", "success");
$(obj).parent().parent().remove();
};
var fail = function() {
swal("Failed", "Delete"+"[ "+name+" ]"+"failed", "error");
};
APIUpdateAttr({
url: url,
body: JSON.stringify(body),
method: 'DELETE',
success: success,
error: fail
});
}
swal({
title: 'Are you sure delete ?',
text: " [" + name + "] ",
type: "warning",
showCancelButton: true,
cancelButtonText: 'Cancel',
confirmButtonColor: "#DD6B55",
confirmButtonText: 'Confirm',
closeOnConfirm: false
}, function () {
doDelete()
});
}
$(document).ready(function(){
var options = {
......@@ -214,15 +183,10 @@ $(document).ready(function(){
.on('click', '.btn_asset_delete', function () {
var $this = $(this);
var $data_table = $("#asset_list_table").DataTable();
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
var uid = $this.data('uid');
var the_url = '{% url "api-assets:asset-detail" pk=99991937 %}'.replace('99991937', uid);
console.log(the_url);
objDelete($this, name, the_url);
setTimeout( function () {
$data_table.ajax.reload();
}, 3000);
objectDelete($this, name, the_url);
})
.on('click', '#btn_bulk_update', function () {
......
# ~*~ coding: utf-8 ~*~
from rest_framework import viewsets
from .hands import IsSuperUser
from .models import Task
from .serializers import TaskSerializer
class TaskViewSet(viewsets.ModelViewSet):
queryset = Task.objects.all()
serializer_class = TaskSerializer
permission_classes = (IsSuperUser,)
from views import *
\ No newline at end of file
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals, print_function
from rest_framework.exceptions import APIException
from django.utils.translation import ugettext as _
class ServiceUnavailable(APIException):
status_code = default_code = 503
default_detail = _('Service temporarily unavailable, try again later.')
class ServiceNotImplemented(APIException):
status_code = default_code = 501
default_detail = _('This service maybe implemented in the future, but now not implemented!')
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from rest_framework import permissions
class AdminUserRequired(permissions.BasePermission):
"""
Custom permission to only allow admin user to access the resource.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True
# Write permissions are only allowed to the admin role.
return request.user.is_staff
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from rest_framework import viewsets
from serializers import *
from permissions import *
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from users.permissions import IsSuperUser
# ~*~ coding: utf-8 ~*~
from __future__ import unicode_literals
from rest_framework import serializers
from .models import Task
class TaskSerializer(serializers.ModelSerializer):
class Meta:
model = Task
fields = '__all__'
......@@ -35,7 +35,7 @@
{% endblock %}
{% block table_head %}
<th></th>
<th class="text-center"></th>
<th class="text-center">{% trans 'Name' %}</th>
<th class="text-center">{% trans 'Asset' %}</th>
<th class="text-center">{% trans 'Success' %}</th>
......@@ -69,6 +69,7 @@
<td class="text-center">{{ object.timedelta }} s</td>
<td class="text-center">
<a href="{% url 'ops:task-run' pk=object.uuid %}" class="btn btn-xs btn-info">{% trans "Run again" %}</a>
<a data-uid="{{ object.uuid }}" class="btn btn-xs btn-danger btn-del">{% trans "Delete" %}</a>
</td>
</tr>
{% endfor %}
......@@ -92,45 +93,14 @@
forceParse: false,
autoclose: true
});
}).on('click', '.btn-del', function () {
var $this = $(this);
var name = $(this).closest("tr").find(":nth-child(2)").children('a').html();
var uid = $this.data('uid');
var the_url = '{% url "api-ops:task-detail" pk=99991937 %}'.replace('99991937', uid);
objectDelete($this, name, the_url);
})
</script>
{# function terminateConnection(data) {#}
{# function success() {#}
{# window.setTimeout(function () {#}
{# window.location.reload()#}
{# }, 300)#}
{# }#}
{# var the_url = "{% url 'api-applications:terminate-connection' %}";#}
{# APIUpdateAttr({url: the_url, method: 'POST', body: JSON.stringify(data), success: success, success_message: 'Terminate success'});#}
{# }#}
{# $(document).ready(function() {#}
{# $('table').DataTable({#}
{# "searching": false,#}
{# "paging": false,#}
{# "bInfo" : false,#}
{# "order": []#}
{# });#}
{# $('.select2').select2();#}
{# $('#date .input-daterange').datepicker({#}
{# dateFormat: 'mm/dd/yy',#}
{# keyboardNavigation: false,#}
{# forceParse: false,#}
{# autoclose: true#}
{# });#}
{# }).on('click', '.btn-term', function () {#}
{# var $this = $(this);#}
{# var proxy_log_id = $this.attr('value');#}
{# var data = {#}
{# proxy_log_id: proxy_log_id#}
{# };#}
{# terminateConnection(data)#}
{# }).on('click', '#btn_bulk_update', function () {#}
{# var data = [];#}
{# $('.cbx-term:checked').each(function () {#}
{# data.push({proxy_log_id: $(this).attr('value')})#}
{# });#}
{# terminateConnection(data)#}
{# })#}
{# </script>#}
{% endblock %}
......@@ -2,6 +2,12 @@
from __future__ import unicode_literals
from rest_framework.routers import DefaultRouter
from .. import api
urlpatterns = []
\ No newline at end of file
router = DefaultRouter()
router.register(r'v1/tasks', api.TaskViewSet, 'task')
urlpatterns = []
urlpatterns += router.urls
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册