list 页面查询
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import django_filters
|
||||
from django_filters import rest_framework
|
||||
|
||||
from server.models import CooperationMind
|
||||
|
||||
|
||||
class CooperationMindFilter(django_filters.rest_framework.FilterSet):
|
||||
"""
|
||||
思维导图filter
|
||||
"""
|
||||
coop_mind_name = rest_framework.CharFilter(field_name='coop_mind_name', lookup_expr='icontains')
|
||||
|
||||
class Meta:
|
||||
model = CooperationMind
|
||||
fields = "__all__"
|
||||
@@ -0,0 +1,12 @@
|
||||
from rest_framework import serializers
|
||||
from server.models import *
|
||||
|
||||
|
||||
class CooperationMindSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
思维导图序列号
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = CooperationMind
|
||||
fields = "__all__"
|
||||
+4
-3
@@ -3,8 +3,9 @@ from django.urls import path
|
||||
from server.views import *
|
||||
|
||||
urlpatterns = [
|
||||
path('', list),
|
||||
path('create', JsMindLogView.as_view()),
|
||||
path('detail', detail),
|
||||
path('', to_list), # 跳转列表界面
|
||||
path('detail', to_detail), # 跳转详情界面
|
||||
path('create', JsMindLogView.as_view()), # 创建思维导图
|
||||
path('list', JsMindLogView.as_view()), # 查询思维导图
|
||||
path('jsmind_op', JsMindCallbackView.as_view()),
|
||||
]
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from rest_framework.pagination import PageNumberPagination
|
||||
|
||||
|
||||
class NewPagination(PageNumberPagination):
|
||||
page_size = 2
|
||||
page_size_query_param = 'page_size'
|
||||
+44
-13
@@ -1,34 +1,65 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from server.models import *
|
||||
from datetime import datetime as dt
|
||||
from rest_framework.generics import GenericAPIView
|
||||
from server.util import build_response
|
||||
|
||||
from django.shortcuts import render
|
||||
from rest_framework.generics import *
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from server.filters import CooperationMindFilter
|
||||
from server.models import *
|
||||
from server.serializers import CooperationMindSerializer
|
||||
from server.util.mix_util import build_response
|
||||
from server.util.pagination import NewPagination
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
|
||||
|
||||
def list(request):
|
||||
def to_list(request):
|
||||
"""
|
||||
列表界面
|
||||
"""
|
||||
return render(request, "html/list.html")
|
||||
|
||||
|
||||
def detail(request):
|
||||
def to_detail(request):
|
||||
"""
|
||||
详情页面
|
||||
"""
|
||||
return render(request, "html/detail.html")
|
||||
|
||||
|
||||
class JsMindLogView(GenericAPIView):
|
||||
def get(self, request):
|
||||
pass
|
||||
class JsMindLogView(ListAPIView):
|
||||
"""
|
||||
思维导图view
|
||||
"""
|
||||
queryset = CooperationMind.objects.all()
|
||||
serializer_class = CooperationMindSerializer
|
||||
filter_backends = [DjangoFilterBackend]
|
||||
filter_class = CooperationMindFilter
|
||||
pagination_class = NewPagination
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self.list(request, *args, **kwargs)
|
||||
|
||||
# def get(self, request):
|
||||
# qs = self.filter_queryset(self.get_queryset())
|
||||
# page = self.paginate_queryset(qs)
|
||||
# if page:
|
||||
# serializer_obj = self.get_serializer(instance=page, many=True)
|
||||
# return self.get_paginated_response({'code': 0, 'res': "success", 'msg': serializer_obj.data})
|
||||
#
|
||||
# serializer_obj = self.get_serializer(instance=qs, many=True)
|
||||
# return Response({'code': 0, 'res': "success", 'msg': serializer_obj.data}, )
|
||||
|
||||
def post(self, request):
|
||||
"""
|
||||
查询思维导图
|
||||
"""
|
||||
coop_mind_name = request.data.get('mind_name')
|
||||
CooperationMind(coop_mind_name=coop_mind_name, client_id='', snapshot_log_id=-1, creator=-1).save()
|
||||
return build_response()
|
||||
snapshot_data = request.data.get('snapshot_data')
|
||||
print(snapshot_data)
|
||||
mind = CooperationMind(coop_mind_name=coop_mind_name, client_id='', snapshot_log_id=-1, creator=-1, snapshot_data=snapshot_data)
|
||||
mind.save()
|
||||
return build_response(data=mind.id)
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
+95
-20
@@ -49,7 +49,30 @@
|
||||
},
|
||||
// 获取数据
|
||||
fetch_data: function () {
|
||||
console.log(this.opts)
|
||||
const get_param = {'page': this.current_page, 'page_size': this.limit}
|
||||
if (this.get_coop_mind_name()) {
|
||||
get_param.coop_mind_name = this.get_coop_mind_name()
|
||||
}
|
||||
$.get('list', get_param, function (resp) {
|
||||
console.log(resp)
|
||||
$('#layui-table tbody').empty()
|
||||
const results = resp.results
|
||||
results.forEach(item => {
|
||||
const tr = `<tr>
|
||||
<td>${item.coop_mind_name}</td>
|
||||
<td>${item.creator}</td>
|
||||
<td>${item.create_time}</td>
|
||||
<td>${item.update_time}</td>
|
||||
<td></td>
|
||||
</tr>`
|
||||
$('#layui-table tbody').append(tr)
|
||||
})
|
||||
})
|
||||
// 分页组件
|
||||
this.auto_page_bar()
|
||||
},
|
||||
get_coop_mind_name: function () {
|
||||
return $('#mind_name').val()
|
||||
},
|
||||
// 显示分页组件
|
||||
auto_page_bar: function () {
|
||||
@@ -75,6 +98,17 @@
|
||||
}
|
||||
}
|
||||
return target;
|
||||
},
|
||||
json2string: function (json) {
|
||||
if (!!JSON) {
|
||||
try {
|
||||
return JSON.stringify(json);
|
||||
} catch (e) {
|
||||
logger.warn(e);
|
||||
logger.warn('can not convert to string');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +117,59 @@
|
||||
const view = new listView({'page_bar_elem': 'page_bar'})
|
||||
view.init()
|
||||
view.fetch_data()
|
||||
view.auto_page_bar()
|
||||
|
||||
// 绑定事件
|
||||
$('#c_').click(function () {
|
||||
const mind_name = $('#mind_name').val()
|
||||
if (mind_name) {
|
||||
$.post('create', {'mind_name': mind_name}, function (resp) {
|
||||
const snapshot_data = {
|
||||
id: 'root',
|
||||
topic: 'jsMind',
|
||||
children: [
|
||||
{
|
||||
id: 'easy',
|
||||
topic: 'Easy',
|
||||
direction: 'left',
|
||||
expanded: false,
|
||||
children: [
|
||||
{id: 'easy1', topic: 'Easy to show'},
|
||||
{id: 'easy2', topic: 'Easy to edit'},
|
||||
{id: 'easy3', topic: 'Easy to store'},
|
||||
{id: 'easy4', topic: 'Easy to embed'}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'open',
|
||||
topic: 'Open Source',
|
||||
direction: 'right',
|
||||
expanded: true,
|
||||
children: [
|
||||
{id: 'open1', topic: 'on GitHub'},
|
||||
{id: 'open2', topic: 'BSD License'}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'powerful',
|
||||
topic: 'Powerful',
|
||||
direction: 'right',
|
||||
children: [
|
||||
{id: 'powerful1', topic: 'Base on Javascript'},
|
||||
{id: 'powerful2', topic: 'Base on HTML5'},
|
||||
{id: 'powerful3', topic: 'Depends on you'}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'other',
|
||||
topic: 'test node',
|
||||
direction: 'left',
|
||||
children: [
|
||||
{id: 'other1', topic: "I'm from local variable"},
|
||||
{id: 'other2', topic: 'I can do everything'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
$.post('create', {'mind_name': mind_name, 'snapshot_data': view.json2string(snapshot_data)}, function (resp) {
|
||||
console.log(resp)
|
||||
view.fetch_data()
|
||||
})
|
||||
@@ -103,35 +183,30 @@
|
||||
<body>
|
||||
<div style="margin-top: 5px;">
|
||||
<div class="layui-input-inline">
|
||||
<input name="mind_name" required lay-verify="required" placeholder="请输入思维导图名称" autocomplete="off" class="layui-input" id="mind_name">
|
||||
<input name="mind_name" required lay-verify="required" autocomplete="off" class="layui-input" id="mind_name" value="pp">
|
||||
</div>
|
||||
<button type="button" class="layui-btn" id="c_">创建导图</button>
|
||||
<button type="button" class="layui-btn">搜索</button>
|
||||
</div>
|
||||
<table class="layui-table">
|
||||
<table class="layui-table" id="layui-table">
|
||||
<colgroup>
|
||||
<col width="150">
|
||||
<col width="200">
|
||||
<col width="500">
|
||||
<col width="100">
|
||||
<col width="300">
|
||||
<col width="300">
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>昵称</th>
|
||||
<th>加入时间</th>
|
||||
<th>签名</th>
|
||||
<th>名称</th>
|
||||
<th>创建人</th>
|
||||
<th>创建时间</th>
|
||||
<th>更新时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>贤心</td>
|
||||
<td>2016-11-29</td>
|
||||
<td>人生就像是一场修行</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>许闲心</td>
|
||||
<td>2016-11-28</td>
|
||||
<td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="page_bar"></div>
|
||||
|
||||
Reference in New Issue
Block a user