diff --git a/server/urls.py b/server/urls.py index 1d537c4..79d4063 100644 --- a/server/urls.py +++ b/server/urls.py @@ -25,6 +25,7 @@ urlpatterns = [ path('d', JsMindView.as_view()), # 获得导图详情 path('s_d', JsMindShareView.as_view()), # 获得导图详情 path('delete', JsMindView.as_view()), # 删除思维导图 + path('delete_cancel', JsMindView.as_view()), # 思维导图恢复 path('share', JsMindShareView.as_view()), # 分享思维导图,查询等 path('star', JsMindStarView.as_view()), # 收藏思维导图 diff --git a/server/views/mind_map.py b/server/views/mind_map.py index 8698192..87ba7c2 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -69,12 +69,19 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView): """ 创建思维导图 """ - coop_mind_name = request.data.get('mind_name') user = request.user - data_format = 'node_tree' - mind = CooperationMind(coop_mind_name=coop_mind_name, client_uuid='', mind_log_id=-1, creator_user_id=user.id, snapshot_data=SNAPSHOT_JSON_DATA, data_format=data_format) - mind.save() - return build_response(data=mind.id) + coop_mind_name = request.data.get('mind_name') + coop_mind_id = request.data.get('coop_mind_id') + op_type = request.data.get('op_type') + if op_type == "delete_cancel": + CooperationMind.objects.filter(id=coop_mind_id, creator_user_id=user.id).update(deleted=False) + return build_response() + else: + user = request.user + data_format = 'node_tree' + mind = CooperationMind(coop_mind_name=coop_mind_name, client_uuid='', mind_log_id=-1, creator_user_id=user.id, snapshot_data=SNAPSHOT_JSON_DATA, data_format=data_format) + mind.save() + return build_response(data=mind.id) def delete(self, request): # 删除 @@ -219,8 +226,6 @@ class JsMindStarView(LoginRequiredJSONMixin, ListAPIView): post_body = request.POST # 思维导图id coop_mind_id = post_body.get('coop_mind_id') - # 操作类型 - op_type = post_body.get('op_type') if coop_mind_id is None: return build_response(CODE_FAILED, msg="参数错误") @@ -233,3 +238,14 @@ class JsMindStarView(LoginRequiredJSONMixin, ListAPIView): star = CooperationMindStar(operator_user_id=user.id, coop_mind_id=coop_mind_id, coop_mind_name=mind.coop_mind_name) star.save() return build_response() + + def delete(self, request): + """ + 取消收藏 + """ + print('dlete') + post_body = request.POST + user = request.user + coop_mind_id = post_body.get('coop_mind_id') + CooperationMindStar.objects.filter(operator_user_id=user.id, coop_mind_id=coop_mind_id).delete() + return build_response() diff --git a/static/html/dashboard.html b/static/html/dashboard.html index afdcce2..5c6da54 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -100,7 +100,6 @@ let idx = 0 let row = $(`
`) - results.forEach(function (item) { const uuid = me.get_uu_id() @@ -114,7 +113,9 @@ sub_btn = `取消分享 查看分享链接` } else if (page_tag === 'star') { - sub_btn = `取消收藏` + sub_btn = `取消收藏` + } else if (page_tag === 'recycle') { + sub_btn = `恢复` } const content = `
@@ -149,11 +150,14 @@ }, /**分页组件*/ init_pagination: function (count, page_size) { + const container = $('#pagination_div') /**计算页数*/ - if (count <= 0) return + if (count <= 0) { + container.empty() + return + } const all_page = (count <= page_size) ? 1 : (count % page_size > 0) ? Math.floor(count / page_size) + 1 : Math.floor(count / page_size) - const container = $('#pagination_div') const navigation = $(``) const navigation_ul = $(``) @@ -231,6 +235,42 @@ async: false }); }, + /** 删除恢复*/ + del_cancel: function (mind_id) { + const me = this + $.ajax({ + type: "post", + url: "delete_cancel", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: {'coop_mind_id': mind_id, 'op_type': 'delete_cancel'}, + dataType: "json", + success: function (resp) { + common_alert(resp.msg) + if (me.is_success_resp(resp)) { + me.fetch_mind() + } + }, + async: false + }); + }, + /** 取消收藏 */ + un_star: function (mind_id) { + const me = this + $.ajax({ + type: "delete", + url: "star", + headers: {"X-CSRFToken": $.cookie("csrftoken")}, + data: {'coop_mind_id': mind_id}, + dataType: "json", + success: function (resp) { + common_alert(resp.msg) + if (me.is_success_resp(resp)) { + me.fetch_mind() + } + }, + async: false + }); + }, /**获得分享信息*/ fetch_share_info: function (mind_id) { const me = this diff --git a/static/js/mind/modal.js b/static/js/mind/modal.js index bc1ad69..f455461 100644 --- a/static/js/mind/modal.js +++ b/static/js/mind/modal.js @@ -4,21 +4,22 @@ const modal = `