Browse Source

编辑器中显示数据库里句子其他译文

visuddhinanda 5 years ago
parent
commit
d15fc2b3b2

+ 25 - 20
app/pali_sent/pali_sent_list.js

@@ -1,14 +1,13 @@
 //输入段落列表,得到巴利句子列表
 //输入段落列表,得到巴利句子列表
-var _PaliSentList = new PaliSentList();
+var refresh_callback;
 class PaliSentList {
 class PaliSentList {
   constructor() {
   constructor() {
-    this.paraList = Array;
+    this.paraList = new Array();
     this.buffer = new Array();
     this.buffer = new Array();
-    this.refresh_callback = null;
   }
   }
 
 
   pushPara(book, para) {
   pushPara(book, para) {
-    for (const iterator of sentList) {
+    for (const iterator of this.paraList) {
       if (iterator.book == book && iterator.para == para) {
       if (iterator.book == book && iterator.para == para) {
         return;
         return;
       }
       }
@@ -16,31 +15,35 @@ class PaliSentList {
     this.paraList.push({ book: book, para: para });
     this.paraList.push({ book: book, para: para });
   }
   }
 
 
+  queryCallback(data, status) {
+    switch (status) {
+      case "success":
+        try {
+          let arrSent = JSON.parse(data);
+          this.buffer = arrSent;
+          if (refresh_callback) {
+            refresh_callback(arrSent);
+          }
+        } catch (e) {}
+        break;
+      case "":
+        break;
+    }
+  }
   refresh(callback) {
   refresh(callback) {
-    this.refresh_callback = callback;
+    refresh_callback = callback;
     $.post(
     $.post(
       "../pali_sent/pali_sent_list.php",
       "../pali_sent/pali_sent_list.php",
       {
       {
         para: JSON.stringify(this.paraList),
         para: JSON.stringify(this.paraList),
       },
       },
-      function (data, status) {
-        switch (status) {
-          case "successful":
-            try {
-              let arrSent = JSON.parse(data);
-              this.buffer = arrSent;
-              if (refresh_callback) {
-                refresh_callback(arrSent);
-              }
-            } catch (e) {}
-            break;
-          case "":
-            break;
-        }
-      }
+      this.queryCallback
     );
     );
   }
   }
 
 
+  getSentList() {
+    return buffer;
+  }
   getSentText(book, para, start, end) {
   getSentText(book, para, start, end) {
     for (const iterator of buffer) {
     for (const iterator of buffer) {
       if (
       if (
@@ -54,3 +57,5 @@ class PaliSentList {
     }
     }
   }
   }
 }
 }
+
+var _PaliSentList = new PaliSentList();

+ 3 - 3
app/pali_sent/pali_sent_list.php

@@ -15,14 +15,14 @@ $dns = "sqlite:"._FILE_DB_PALI_SENTENCE_;
 $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
 $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 
 
-$query="SELECT * FROM sentence WHERE (book = ?  AND paragraph = ?  ) ";
+$query="SELECT begin,end ,text FROM pali_sent WHERE (book = ?  AND paragraph = ?  ) ";
 $stmt = $dbh->prepare($query);
 $stmt = $dbh->prepare($query);
-foreach ($sentList as $key => $value) {
+foreach ($paraList as $key => $value) {
     # code...
     # code...
     $stmt->execute(array($value->book,$value->para));
     $stmt->execute(array($value->book,$value->para));
     $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
          $sent["info"]=array("book"=>$value->book,"para"=>$value->para);
          $sent["info"]=array("book"=>$value->book,"para"=>$value->para);
-        $sent["data"]=$valueSent;
+        $sent["data"]=$Fetch;
         $output[] = $sent;  
         $output[] = $sent;  
 }
 }
 
 

+ 3 - 0
app/studio/editor.php

@@ -39,6 +39,8 @@ else{$currDevice="computer";}
 
 
 <title id="file_title"><?php echo $_local->gui->pcd_studio; ?></title>
 <title id="file_title"><?php echo $_local->gui->pcd_studio; ?></title>
 	<script language="javascript" src="config.js"></script>
 	<script language="javascript" src="config.js"></script>
+	<script language="javascript" src="../pali_sent/pali_sent_list.js"></script>
+	<script language="javascript" src="../usent/usent_ref.js"></script>
 	<script language="javascript" src="js/data.js"></script>
 	<script language="javascript" src="js/data.js"></script>
 	<script language="javascript" src="js/common.js"></script>
 	<script language="javascript" src="js/common.js"></script>
 	<script language="javascript" src="js/render.js"></script>	
 	<script language="javascript" src="js/render.js"></script>	
@@ -57,6 +59,7 @@ else{$currDevice="computer";}
 	<script language="javascript" src="../public/js/comm.js"></script>
 	<script language="javascript" src="../public/js/comm.js"></script>
 	<script language="javascript" src="../public/js/localforage.min.js"></script>
 	<script language="javascript" src="../public/js/localforage.min.js"></script>
 	<script language="javascript" src="../public/script/my.js"></script>
 	<script language="javascript" src="../public/script/my.js"></script>
+
 	
 	
 	<script language="javascript" src="module/editor/language/default.js"></script>	
 	<script language="javascript" src="module/editor/language/default.js"></script>	
 	<script src="js/jquery-3.3.1.min.js"></script>
 	<script src="js/jquery-3.3.1.min.js"></script>

+ 24 - 7
app/studio/js/data.js

@@ -6,8 +6,6 @@ var gXmlOldVerData; //old ver xml file xml doc
 var g_filename = ""; //工程文件名
 var g_filename = ""; //工程文件名
 var arrDocFileInfo = null;
 var arrDocFileInfo = null;
 
 
-var _user_sent_buffer = new USentResult(); //数据库中的全部参考译文句子
-
 //全部的逐词译单词xml 节点数组
 //全部的逐词译单词xml 节点数组
 var gXmlAllWordInWBW = new Array();
 var gXmlAllWordInWBW = new Array();
 
 
@@ -210,7 +208,7 @@ function doc_file_info_get() {
           }
           }
         }
         }
       } catch (e) {
       } catch (e) {
-        console(e);
+        console.error(e);
       }
       }
     }
     }
   );
   );
@@ -612,11 +610,27 @@ function projectDataParse(xmlBookData) {
   gXmlBookDataHead = xmlBookData.getElementsByTagName("head")[0];
   gXmlBookDataHead = xmlBookData.getElementsByTagName("head")[0];
   gXmlBookDataInlineDict = xmlBookData.getElementsByTagName("dict")[0];
   gXmlBookDataInlineDict = xmlBookData.getElementsByTagName("dict")[0];
   gXmlBookDataHeadToc = xmlBookData.getElementsByTagName("toc")[0];
   gXmlBookDataHeadToc = xmlBookData.getElementsByTagName("toc")[0];
-  if (xmlBookData.getElementsByTagName("message")) {
-    gXmlBookDataMsg = gXmlBookData.getElementsByTagName("message")[0];
-  } else {
-    gXmlBookDataMsg = null;
+
+  //扫描文档,获取句子列表
+  allBlock = gXmlBookDataBody.getElementsByTagName("block");
+  for (const iterator of allBlock) {
+    let xmlParInfo = iterator.getElementsByTagName("info")[0];
+
+    let book = getNodeText(xmlParInfo, "book");
+    let para = getNodeText(xmlParInfo, "paragraph");
+    _PaliSentList.pushPara(book, para);
   }
   }
+  _PaliSentList.refresh(function (data) {
+    for (const iterator of data) {
+      let book = iterator.info.book;
+      let para = iterator.info.para;
+      for (const sent of iterator.data) {
+        _user_sent_buffer.pushSent(book, para, sent.begin, sent.end);
+      }
+    }
+    _user_sent_buffer.refresh();
+  });
+
   //解析消息队列
   //解析消息队列
   localforage
   localforage
     .getItem("msg_" + g_docid)
     .getItem("msg_" + g_docid)
@@ -657,10 +671,13 @@ function projectDataParse(xmlBookData) {
   com_XmlAllWordRefresh();
   com_XmlAllWordRefresh();
   //更新工程资源列表
   //更新工程资源列表
   editor_project_updataProjectInfo();
   editor_project_updataProjectInfo();
+
+  /*
   //解析内联字典数据
   //解析内联字典数据
   ildDataParse(gXmlBookDataInlineDict);
   ildDataParse(gXmlBookDataInlineDict);
   //将内联字典数据导入已经下载的词的列表
   //将内联字典数据导入已经下载的词的列表
   dict_inid_ild_word_list();
   dict_inid_ild_word_list();
+  */
 }
 }
 
 
 /*
 /*

+ 63 - 38
app/studio/js/render.js

@@ -429,7 +429,7 @@ function updataHeadingBlockInHtml(book, par) {
   }
   }
 }
 }
 
 
-function renderBlock() { }
+function renderBlock() {}
 /*
 /*
 重绘翻译数据块
 重绘翻译数据块
 */
 */
@@ -634,7 +634,7 @@ function renderTranslateParBlockInner(elementBlock) {
   return output;
   return output;
 }
 }
 
 
-function renderTranslateParBlockInnerPreview(strText) { }
+function renderTranslateParBlockInnerPreview(strText) {}
 function updateTranslationPreview_a(blockId, text) {
 function updateTranslationPreview_a(blockId, text) {
   var out = "";
   var out = "";
   var newText = text;
   var newText = text;
@@ -1333,8 +1333,10 @@ function render_sent_tool_bar(elementBlock, begin) {
   }
   }
   output += "[" + gLocal.gui.scan_in_reader + "]";
   output += "[" + gLocal.gui.scan_in_reader + "]";
   output += "</a>";
   output += "</a>";
-  output += "<guide gid='sent_func' style='margin:unset;'></guide></span></span>";
-  output += "<span style='flex: 3;'><guide gid='sent_trans' style='margin:unset;'></guide></span>";
+  output +=
+    "<guide gid='sent_func' style='margin:unset;'></guide></span></span>";
+  output +=
+    "<span style='flex: 3;'><guide gid='sent_trans' style='margin:unset;'></guide></span>";
   output += "</div>";
   output += "</div>";
   return output;
   return output;
 }
 }
@@ -1542,11 +1544,30 @@ function renderWordParBlockInner(elementBlock) {
           "' begin='" +
           "' begin='" +
           sent_begin +
           sent_begin +
           "' end=''>";
           "' end=''>";
+        let usent_count = _user_sent_buffer.getSentNum(
+          book,
+          paragraph,
+          sent_begin,
+          word_id
+        );
         let netSent = doc_msg_get_trans(book, paragraph, sent_begin, 0);
         let netSent = doc_msg_get_trans(book, paragraph, sent_begin, 0);
         let sender = "";
         let sender = "";
         if (netSent.length > 0) {
         if (netSent.length > 0) {
           output += netSent[netSent.length - 1].data.text;
           output += netSent[netSent.length - 1].data.text;
           sender = netSent[netSent.length - 1].sender;
           sender = netSent[netSent.length - 1].sender;
+        } else if (usent_count > 0) {
+          output += _user_sent_buffer.getSentText(
+            book,
+            paragraph,
+            sent_begin,
+            word_id
+          )[0].text;
+          sender = _user_sent_buffer.getSentText(
+            book,
+            paragraph,
+            sent_begin,
+            word_id
+          )[0].editor;
         }
         }
         output += "</div>";
         output += "</div>";
         output +=
         output +=
@@ -1554,7 +1575,7 @@ function renderWordParBlockInner(elementBlock) {
           "<span><span>过滤</span><span class='author'>" +
           "<span><span>过滤</span><span class='author'>" +
           sender +
           sender +
           "</span><span class='tag'>tag</span></span>" +
           "</span><span class='tag'>tag</span></span>" +
-          "<span class='tools'>" +
+          "<span><span class='tools'>" +
           "<button>采纳</button>" +
           "<button>采纳</button>" +
           "<button onclick=\"show_tran_net('" +
           "<button onclick=\"show_tran_net('" +
           book +
           book +
@@ -1565,7 +1586,9 @@ function renderWordParBlockInner(elementBlock) {
           "','" +
           "','" +
           word_id +
           word_id +
           "')\">更多</button>" +
           "')\">更多</button>" +
-          "</span>" +
+          "</span><span>" +
+          usent_count +
+          "</span></span>" +
           "</div>";
           "</div>";
         output += "</div>";
         output += "</div>";
         //句子预览结束
         //句子预览结束
@@ -1631,8 +1654,10 @@ function renderWordParBlockInner(elementBlock) {
           "' target='_blank'>";
           "' target='_blank'>";
         output += "[" + gLocal.gui.scan_in_reader + "]";
         output += "[" + gLocal.gui.scan_in_reader + "]";
         output += "</a>";
         output += "</a>";
-        output += "<guide gid='sent_func' style='margin:unset;'></guide></span></span>";
-        output += "<span style='flex: 3;'><guide gid='sent_trans' style='margin:unset;'></guide></span>";
+        output +=
+          "<guide gid='sent_func' style='margin:unset;'></guide></span></span>";
+        output +=
+          "<span style='flex: 3;'><guide gid='sent_trans' style='margin:unset;'></guide></span>";
         output += "</div>";
         output += "</div>";
 
 
         output += "<div class='sent_wbw'>";
         output += "<div class='sent_wbw'>";
@@ -2472,12 +2497,12 @@ function renderWordDetailByElement(xmlElement) {
             ) {
             ) {
               arrMeaning.push(
               arrMeaning.push(
                 g_DictWordList[iDict].dictID +
                 g_DictWordList[iDict].dictID +
-                "$" +
-                arrMeaning.length +
-                "$$" +
-                arrMean[i] +
-                "$" +
-                g_DictWordList[iDict].Language
+                  "$" +
+                  arrMeaning.length +
+                  "$$" +
+                  arrMean[i] +
+                  "$" +
+                  g_DictWordList[iDict].Language
               );
               );
             }
             }
           }
           }
@@ -2527,12 +2552,12 @@ function renderWordDetailByElement(xmlElement) {
               ) {
               ) {
                 arrMeaning.push(
                 arrMeaning.push(
                   g_DictWordList[iDict].dictID +
                   g_DictWordList[iDict].dictID +
-                  "$" +
-                  arrMeaning.length +
-                  "$*$" +
-                  getLocalParentFormulaStr(wordGramma0, arrMean[i]) +
-                  "$" +
-                  g_DictWordList[iDict].Language
+                    "$" +
+                    arrMeaning.length +
+                    "$*$" +
+                    getLocalParentFormulaStr(wordGramma0, arrMean[i]) +
+                    "$" +
+                    g_DictWordList[iDict].Language
                 );
                 );
               }
               }
             }
             }
@@ -2582,12 +2607,12 @@ function renderWordDetailByElement(xmlElement) {
               ) {
               ) {
                 arrMeaning.push(
                 arrMeaning.push(
                   g_DictWordList[iDict].dictID +
                   g_DictWordList[iDict].dictID +
-                  "$" +
-                  arrMeaning.length +
-                  "$**$" +
-                  getLocalParentFormulaStr(wordGramma1, arrMean[i]) +
-                  "$" +
-                  g_DictWordList[iDict].Language
+                    "$" +
+                    arrMeaning.length +
+                    "$**$" +
+                    getLocalParentFormulaStr(wordGramma1, arrMean[i]) +
+                    "$" +
+                    g_DictWordList[iDict].Language
                 );
                 );
               }
               }
             }
             }
@@ -3062,7 +3087,7 @@ function renderWordDetailByElement(xmlElement) {
   return _txtOutDetail;
   return _txtOutDetail;
 }
 }
 
 
-function renderWordNoteDivByParaNo(book, paragraph) { }
+function renderWordNoteDivByParaNo(book, paragraph) {}
 /*
 /*
 paragraph word note
 paragraph word note
 */
 */
@@ -3261,7 +3286,7 @@ function updateWordNote(element) {
   }
   }
 }
 }
 
 
-function updateWordCommentary(element) { }
+function updateWordCommentary(element) {}
 
 
 //根据xmlDocument 对象中的单词序号修改单词块的显示(不含Pali)
 //根据xmlDocument 对象中的单词序号修改单词块的显示(不含Pali)
 //返回 无
 //返回 无
@@ -3384,13 +3409,13 @@ function prev_page() {
   gVisibleParEndOld = gVisibleParEnd;
   gVisibleParEndOld = gVisibleParEnd;
   if (
   if (
     g_allparlen_array[gVisibleParEnd - 1] -
     g_allparlen_array[gVisibleParEnd - 1] -
-    g_allparlen_array[gVisibleParBegin - 1] <=
+      g_allparlen_array[gVisibleParBegin - 1] <=
     gDisplayCapacity
     gDisplayCapacity
   ) {
   ) {
     gVisibleParBegin -= 1;
     gVisibleParBegin -= 1;
   } else if (
   } else if (
     g_allparlen_array[gVisibleParEnd + 1] -
     g_allparlen_array[gVisibleParEnd + 1] -
-    g_allparlen_array[gVisibleParBegin - 1] >
+      g_allparlen_array[gVisibleParBegin - 1] >
     gDisplayCapacity
     gDisplayCapacity
   ) {
   ) {
     gVisibleParBegin -= 1;
     gVisibleParBegin -= 1;
@@ -3417,13 +3442,13 @@ function next_page() {
 
 
   if (
   if (
     g_allparlen_array[gVisibleParEnd + 1] -
     g_allparlen_array[gVisibleParEnd + 1] -
-    g_allparlen_array[gVisibleParBegin + 1] <=
+      g_allparlen_array[gVisibleParBegin + 1] <=
     gDisplayCapacity
     gDisplayCapacity
   ) {
   ) {
     gVisibleParEnd += 1;
     gVisibleParEnd += 1;
   } else if (
   } else if (
     g_allparlen_array[gVisibleParEnd + 1] -
     g_allparlen_array[gVisibleParEnd + 1] -
-    g_allparlen_array[gVisibleParBegin + 1] >
+      g_allparlen_array[gVisibleParBegin + 1] >
     gDisplayCapacity
     gDisplayCapacity
   ) {
   ) {
     gVisibleParBegin += 1;
     gVisibleParBegin += 1;
@@ -3860,12 +3885,12 @@ function refreshNoteNumber() {
     let id = $(this).attr("wid");
     let id = $(this).attr("wid");
     $(this).html(
     $(this).html(
       "<a href='#word_note_root_" +
       "<a href='#word_note_root_" +
-      id +
-      "' name=\"word_note_" +
-      id +
-      '">[' +
-      (index + 1) +
-      "]</a>"
+        id +
+        "' name=\"word_note_" +
+        id +
+        '">[' +
+        (index + 1) +
+        "]</a>"
     );
     );
   });
   });
 
 

+ 4 - 3
app/usent/sent_query.php

@@ -17,15 +17,16 @@ $dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
 /* 开始一个事务,关闭自动提交 */
 /* 开始一个事务,关闭自动提交 */
 
 
-$query="SELECT * FROM sentence WHERE (book = ?  AND paragraph = ? AND begin = ? AND end = ? text <> '' ) order by modify_time DESC limit 0,10";
+$query="SELECT * FROM sentence WHERE (book = ?  AND paragraph = ? AND begin = ? AND end = ? AND text <> '' ) order by modify_time DESC limit 0,10";
 $stmt = $dbh->prepare($query);
 $stmt = $dbh->prepare($query);
 foreach ($sentList as $key => $value) {
 foreach ($sentList as $key => $value) {
     # code...
     # code...
     $stmt->execute(array($value->book,$value->para,$value->start,$value->end));
     $stmt->execute(array($value->book,$value->para,$value->start,$value->end));
     $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
-    $sent["info"]=array($value);
+    $sent = array();
+    $sent["info"]=$value;
     $sent["data"]=$Fetch;
     $sent["data"]=$Fetch;
-    $sent["length"]=count($Fetch);//句子个数
+    $sent["count"]=count($Fetch);//句子个数
     $output[] = $sent;
     $output[] = $sent;
 }
 }
 
 

+ 27 - 21
app/usent/usent_ref.js

@@ -1,12 +1,13 @@
+var _usent_buffer;
 class USentResult {
 class USentResult {
   constructor(filter = {}) {
   constructor(filter = {}) {
     this.filter = filter;
     this.filter = filter;
-    this.sentList = Array;
+    this.sentList = new Array();
     this.buffer = new Array();
     this.buffer = new Array();
   }
   }
 
 
   pushSent(book, para, start, end) {
   pushSent(book, para, start, end) {
-    for (const iterator of sentList) {
+    for (const iterator of this.sentList) {
       if (
       if (
         iterator.book == book &&
         iterator.book == book &&
         iterator.para == para &&
         iterator.para == para &&
@@ -21,6 +22,18 @@ class USentResult {
   newSent(sent) {
   newSent(sent) {
     this.buffer.push(sent);
     this.buffer.push(sent);
   }
   }
+  queryCallback(data, status) {
+    switch (status) {
+      case "success":
+        try {
+          let arrSent = JSON.parse(data);
+          _usent_buffer = arrSent;
+        } catch (e) {}
+        break;
+      case "":
+        break;
+    }
+  }
   refresh() {
   refresh() {
     $.post(
     $.post(
       "../usent/sent_query.php",
       "../usent/sent_query.php",
@@ -28,42 +41,35 @@ class USentResult {
         sent: JSON.stringify(this.sentList),
         sent: JSON.stringify(this.sentList),
         filter: JSON.stringify(this.filter),
         filter: JSON.stringify(this.filter),
       },
       },
-      function (data, status) {
-        switch (status) {
-          case "successful":
-            try {
-              let arrSent = JSON.parse(data);
-              this.buffer = arrSent;
-            } catch (e) {}
-            break;
-          case "":
-            break;
-        }
-      }
+      this.queryCallback
     );
     );
   }
   }
   getSentNum(book, para, start, end) {
   getSentNum(book, para, start, end) {
-    for (const iterator of buffer) {
+    for (const iterator of _usent_buffer) {
       if (
       if (
         iterator.info.book == book &&
         iterator.info.book == book &&
         iterator.info.para == para &&
         iterator.info.para == para &&
         iterator.info.start == start &&
         iterator.info.start == start &&
         iterator.info.end == end
         iterator.info.end == end
       ) {
       ) {
-        return iterator.length;
+        return iterator.count;
       }
       }
     }
     }
+    return 0;
   }
   }
   getSentText(book, para, start, end, num = 1) {
   getSentText(book, para, start, end, num = 1) {
-    for (const iterator of buffer) {
+    for (const iterator of _usent_buffer) {
       if (
       if (
-        iterator.book == book &&
-        iterator.para == para &&
-        iterator.start == start &&
-        iterator.end == end
+        iterator.info.book == book &&
+        iterator.info.para == para &&
+        iterator.info.start == start &&
+        iterator.info.end == end
       ) {
       ) {
         return iterator.data;
         return iterator.data;
       }
       }
     }
     }
+    return null;
   }
   }
 }
 }
+
+var _user_sent_buffer = new USentResult(); //数据库中的全部参考译文句子