diff --git a/server/filters.py b/server/filters.py new file mode 100644 index 0000000..56c2bcc --- /dev/null +++ b/server/filters.py @@ -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__" diff --git a/server/serializers.py b/server/serializers.py new file mode 100644 index 0000000..5d246a0 --- /dev/null +++ b/server/serializers.py @@ -0,0 +1,12 @@ +from rest_framework import serializers +from server.models import * + + +class CooperationMindSerializer(serializers.ModelSerializer): + """ + 思维导图序列号 + """ + + class Meta: + model = CooperationMind + fields = "__all__" diff --git a/server/urls.py b/server/urls.py index 502153d..7592255 100644 --- a/server/urls.py +++ b/server/urls.py @@ -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()), ] diff --git a/server/util/__init__.py b/server/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/util.py b/server/util/mix_util.py similarity index 100% rename from server/util.py rename to server/util/mix_util.py diff --git a/server/util/pagination.py b/server/util/pagination.py new file mode 100644 index 0000000..3418cf5 --- /dev/null +++ b/server/util/pagination.py @@ -0,0 +1,6 @@ +from rest_framework.pagination import PageNumberPagination + + +class NewPagination(PageNumberPagination): + page_size = 2 + page_size_query_param = 'page_size' diff --git a/server/views.py b/server/views.py index 0232368..3b0a733 100644 --- a/server/views.py +++ b/server/views.py @@ -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. diff --git a/static/html/list.html b/static/html/list.html index 212b5c7..754ca84 100644 --- a/static/html/list.html +++ b/static/html/list.html @@ -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 = ` + ${item.coop_mind_name} + ${item.creator} + ${item.create_time} + ${item.update_time} + + ` + $('#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 @@
- +
- +
- - + + + + - - - + + + + + - - - - - - - - - - +
昵称加入时间签名名称创建人创建时间更新时间操作
贤心2016-11-29人生就像是一场修行
许闲心2016-11-28于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…