Browse Source

:sparkles: pr 删除

visuddhinanda 3 years ago
parent
commit
2afdf672f3
2 changed files with 62 additions and 4 deletions
  1. 21 2
      app/Http/Controllers/SentPrController.php
  2. 41 2
      public/app/term/note.js

+ 21 - 2
app/Http/Controllers/SentPrController.php

@@ -6,6 +6,7 @@ use App\Models\SentPr;
 use App\Models\Channel;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Log;
 
 class SentPrController extends Controller
 {
@@ -192,11 +193,29 @@ class SentPrController extends Controller
     /**
      * Remove the specified resource from storage.
      *
-     * @param  \App\Models\SentPr  $sentPr
+     * @param  int $id
      * @return \Illuminate\Http\Response
      */
-    public function destroy(SentPr $sentPr)
+    public function destroy($id)
     {
         //
+		Log::info("user_uid=" .$_COOKIE['user_uid']);
+		$old = SentPr::where('id', $id)->first();
+		$result = SentPr::where('id', $id)
+							->where('editor_uid', $_COOKIE["user_uid"])
+							->delete();
+		Log::info("delete=" .$result);
+		if($result>0){
+					#同时返回此句子pr数量
+		$count = SentPr::where('book_id' , $old->book_id)
+						->where('paragraph' , $old->paragraph)
+						->where('word_start' , $old->word_start)
+						->where('word_end' , $old->word_end)
+						->where('channel_uid' , $old->channel_uid)
+						->count();
+			return $this->ok($count);
+		}else{
+			return $this->error('not power');
+		}
     }
 }

+ 41 - 2
public/app/term/note.js

@@ -1077,7 +1077,7 @@ function render_one_sent_tran_a(iterator, diff = false) {
 			//修改按钮
 			html += render_icon_button("ic_mode_edit", "sent_tran_edit(this,'update')", gLocal.gui.modify);
 			//删除按钮
-			html += render_icon_button("ic_delete", "sent_pr_del(this)", gLocal.gui.delete);
+			html += render_icon_button("ic_delete", "note_pr_delete(this)", gLocal.gui.delete);
 		} else {
 			//非提交人
 			if (parseInt(iterator.mypower) >= 20) {
@@ -1503,7 +1503,10 @@ function myEndingTooltip(inStr){
 }
 //渲染pr按钮里面的数字
 function render_pr_number(pr_new,pr_all){
- let html = "<span class='icon'>✋</span><span class='num'>" + pr_new + "/" + pr_all + "</span>";
+	let html = "";
+	if(pr_all > 0){
+		html = "<span class='icon'>✋</span><span class='num'>" + pr_new + "/" + pr_all + "</span>";
+	}
  return html;	
 }
 function tran_sent_textarea_event_init() {
@@ -2065,6 +2068,42 @@ function note_pr_update(obj) {
 		$(sent_tran_div).addClass("loading");
 	}
 }
+//修改pr句子
+function note_pr_delete(obj) {
+	if(!confirm("要删除此修改建议吗?此操作无法恢复。")){
+		return;
+	}
+
+	let sent_tran_div = find_sent_tran_div(obj);
+	let id = sent_tran_div.attr("dbid");
+
+    fetch('/api/v2/sentpr/'+id,{
+        method: 'DELETE',
+        credentials: 'same-origin',
+        headers: {
+            'Content-Type': 'application/json'
+        },
+        body: JSON.stringify({
+			id: id,
+		})
+    })
+  .then(response => response.json())
+  .then(function(data){
+	console.log("note_pr_delete",data);
+	if(data.ok){
+		let sent_tran_parent = find_sent_tran_div(sent_tran_div.parent());
+		sent_tran_parent.find(".tag_list").first().children(".pr").first().html(render_pr_number(1,data.data));
+
+		sent_tran_div.removeClass("loading");
+		sent_tran_div.parent().html("");
+		ntf_show("删除成功");
+	}
+  });
+
+	if (sent_tran_div) {
+		$(sent_tran_div).addClass("loading");
+	}
+}
 
 //保存译文句子 新
 function note_sent_save_a(obj) {