diff --git a/server/util/constant_util.py b/server/util/constant_util.py index 505ee18..4de4476 100644 --- a/server/util/constant_util.py +++ b/server/util/constant_util.py @@ -1,2 +1,47 @@ CODE_SUCCESS = 0 CODE_FAILED = -1 + +snapshot_json_data = """{ + "id": "root", + "topic": "MindMap", + "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": "left", + "expanded": false, + "children": [ + {"id": "open1", "topic": "on GitHub"}, + {"id": "open2", "topic": "BSD License"} + ] + }, + { + "id": "powerful", + "topic": "Powerful", + "direction": "right", + "expanded": false, + "children": [ + {"id": "powerful1", "topic": "Base on Javascript"}, + {"id": "powerful2", "topic": "Base on HTML5"}, + {"id": "powerful3", "topic": "Depends on you"} + ] + }, + { + "id": "other", + "topic": "多人协作", + "direction": "right" + } + ] +}""" diff --git a/server/views/mind_map.py b/server/views/mind_map.py index 7d0758e..24edc99 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -10,6 +10,7 @@ from server.serializers import * from server.util.mix_util import build_response from server.pagination import DefaultNumberPagination from server_auth.lib.auth import LoginRequiredJSONMixin +from server.util.constant_util import * class JsMindView(LoginRequiredJSONMixin, ListAPIView): @@ -41,9 +42,10 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView): 创建思维导图 """ coop_mind_name = request.data.get('mind_name') - snapshot_data = request.data.get('snapshot_data') - data_format = request.data.get('data_format') - mind = CooperationMind(coop_mind_name=coop_mind_name, client_id='', mind_log_id=-1, creator=9527, snapshot_data=snapshot_data, data_format=data_format) + user = request.user + snapshot_data = snapshot_json_data + data_format = 'node_tree' + mind = CooperationMind(coop_mind_name=coop_mind_name, client_id='', mind_log_id=-1, creator=user.id, snapshot_data=snapshot_data, data_format=data_format) mind.save() return build_response(data=mind.id) diff --git a/static/html/dashboard.html b/static/html/dashboard.html index e860fce..6879aaf 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -179,6 +179,9 @@ if (resp.code !== 0) { return } + // clear + $('main .container-fluid').empty() + // 解析结果 const results = resp.results let idx = 0 @@ -217,7 +220,27 @@ const mind_name = $('#mindName').val() if (!mind_name) { common_alert_('请输入导图名称') + return } + + const post_data = {'mind_name': mind_name} + $.ajax({ + type: "post", + url: "create", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: post_data, + dataType: "json", + success: function (resp) { + fetch_mind() + $('#newMindModal').modal('hide') + // 新页面打开 + setTimeout(function () { + const id = resp.data + window.open('detail?id=' + id) + }, 500) + }, + async: false + }); }) /**如果已经登录则查询列表*/ diff --git a/static/html/list.html b/static/html/list.html index 49d745d..a3e7215 100644 --- a/static/html/list.html +++ b/static/html/list.html @@ -196,52 +196,8 @@ function create_inner() { const mind_name = $('#mind_name_crt').val() if (mind_name) { - 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: 'left', - expanded: false, - children: [ - {id: 'open1', topic: 'on GitHub'}, - {id: 'open2', topic: 'BSD License'} - ] - }, - { - id: 'powerful', - topic: 'Powerful', - direction: 'right', - expanded: false, - children: [ - {id: 'powerful1', topic: 'Base on Javascript'}, - {id: 'powerful2', topic: 'Base on HTML5'}, - {id: 'powerful3', topic: 'Depends on you'} - ] - }, - { - id: 'other', - topic: '多人协作', - direction: 'right' - } - ] - } // post start - const post_data = {'mind_name': mind_name, 'data_format': 'node_tree', 'snapshot_data': view.json2string(snapshot_data)} + const post_data = {'mind_name': mind_name} $.ajax({ type: "post", url: "create",