Explorar el Código

:sparkles: 支持pr修改

visuddhinanda hace 3 años
padre
commit
471b892168
Se han modificado 3 ficheros con 77 adiciones y 12 borrados
  1. 13 5
      app/Http/Controllers/SentPrController.php
  2. 3 0
      app/Models/SentPr.php
  3. 61 7
      public/app/term/note.js

+ 13 - 5
app/Http/Controllers/SentPrController.php

@@ -37,7 +37,8 @@ class SentPrController extends Controller
         $data = $request->all();
         $data = $request->all();
 
 
 		
 		
-		#新建
+		#查询是否存在 
+		#同样的内容只能提交一次
 		$exists = SentPr::where('book_id',$data['book'])
 		$exists = SentPr::where('book_id',$data['book'])
 						->where('paragraph',$data['para'])
 						->where('paragraph',$data['para'])
 						->where('word_start',$data['begin'])
 						->where('word_start',$data['begin'])
@@ -168,13 +169,20 @@ class SentPrController extends Controller
         }else{
         }else{
 			$user_uid = $_COOKIE['user_uid'];
 			$user_uid = $_COOKIE['user_uid'];
 		}
 		}
-		
-		if($sentPr->editor_uid==$user_uid){
-			$sentPr->update([
+		$sentPr = SentPr::where('id',$request->get('id'));
+		if($sentPr->value('editor_uid')==$user_uid){
+			$update = $sentPr->update([
 				"content"=>$request->get('text'),
 				"content"=>$request->get('text'),
 				"modify_time"=>time()*1000,
 				"modify_time"=>time()*1000,
 			]);
 			]);
-			return $this->ok($sentPr);
+			if($update >= 0){
+				$data = SentPr::where('id',$request->get('id'))->first();
+				$data->id = sprintf("%d",$data->id);
+				return $this->ok($data);
+			}else{
+				return $this->error('没有更新');
+			}
+			
 		}else{
 		}else{
 			return $this->error('not power');
 			return $this->error('not power');
 		}
 		}

+ 3 - 0
app/Models/SentPr.php

@@ -8,4 +8,7 @@ use Illuminate\Database\Eloquent\Model;
 class SentPr extends Model
 class SentPr extends Model
 {
 {
     use HasFactory;
     use HasFactory;
+	protected $casts = [
+		'id' => 'string'
+	];
 }
 }

+ 61 - 7
public/app/term/note.js

@@ -2032,12 +2032,7 @@ function note_pr_update(obj) {
 
 
 	let id = $(obj).attr("dbid");
 	let id = $(obj).attr("dbid");
 	let channel_type = $(obj).attr("channel_type");
 	let channel_type = $(obj).attr("channel_type");
-	let sid = $(obj).attr("sid").split("-");
-	let book = sid[0];
-	let para = sid[1];
-	let begin = sid[2];
-	let end = sid[3];
-	let channel = $(obj).attr("channel");
+
 	let text = $(obj).val();
 	let text = $(obj).val();
 	let sent_tran_div = find_sent_tran_div(obj);
 	let sent_tran_div = find_sent_tran_div(obj);
 
 
@@ -2062,7 +2057,9 @@ function note_pr_update(obj) {
 		})
 		})
     })
     })
   .then(response => response.json())
   .then(response => response.json())
-  .then(data => console.log(data));
+  .then(function(data){
+	pr_update_callback(data);
+  });
 
 
 	if (sent_tran_div) {
 	if (sent_tran_div) {
 		$(sent_tran_div).addClass("loading");
 		$(sent_tran_div).addClass("loading");
@@ -2283,6 +2280,61 @@ function pr_create_callback(data) {
 	}
 	}
 }
 }
 
 
+function pr_update_callback(data) {
+	let response;
+	if(typeof data=="string"){
+		try {
+			response = JSON.parse(data);
+		} catch (e) {
+			alert(e.message);
+			console.error('pr_create_callback',data);
+			return;
+		}			
+		
+	}else{
+		response = data;
+	}
+
+	
+	if (!response.ok) {
+		ntf_show("修改建议更新失败");
+		console.log("pr_update_callback", response.message);
+		return;
+	}
+	let result = response.data;
+	{
+		let sid = result.book_id + "-" + result.paragraph + "-" + result.word_start + "-" + result.word_end;
+
+		let sent_tran_div = $(
+			".sent_tran[dbid='" + result.id + "']"
+		);
+		if (sent_tran_div) {
+			sent_tran_div.removeClass("loading");
+			let orgText = "";
+			for (const oneSent of _arrData) {
+				if (
+					oneSent.book == result.book_id &&
+					oneSent.para == result.paragraph &&
+					oneSent.begin == result.word_start &&
+					oneSent.end == result.word_end
+				) {
+					for (const tran of oneSent.translation) {
+						if (tran.channal == result.channel_uid) {
+							orgText = tran.text;
+							break;
+						}
+					}
+					break;
+				}
+			}
+			let tranText = str_diff(orgText, result.content);
+			sent_tran_div.find(".preview").html(tranText);
+		}
+		
+		ntf_show("成功更新修改建议");
+	}
+}
+
 //保存译文句子
 //保存译文句子
 function note_sent_save() {
 function note_sent_save() {
 	let id = $("#edit_dialog_text").attr("sent_id");
 	let id = $("#edit_dialog_text").attr("sent_id");
@@ -2539,7 +2591,9 @@ function note_get_pr(channel, id) {
 			if (result.length > 0) {
 			if (result.length > 0) {
 				let html = "<div class='compact pr'>";
 				let html = "<div class='compact pr'>";
 				for (const iterator of result) {
 				for (const iterator of result) {
+					html += "<div class='pr_shell'>";
 					html += render_one_sent_tran_a(iterator, true);
 					html += render_one_sent_tran_a(iterator, true);
+					html += "</div>";
 				}
 				}
 				html += "</div>";
 				html += "</div>";
 				$(".sent_tran[channel='" + channel + "'][sid='" + id + "']")
 				$(".sent_tran[channel='" + channel + "'][sid='" + id + "']")