# HG changeset patch # User Zoe Hong # Date 1427893835 -7200 # Node ID 3395385476d19376727aaa76c4d222589532c792 # Parent 3fb9e3884401fdcf94b454d82028729483f30640 bug fixed: popup tag window is closed automatically when saving text file diff -r 3fb9e3884401 -r 3395385476d1 controllers/extractapp.php --- a/controllers/extractapp.php Tue Mar 31 14:55:58 2015 +0200 +++ b/controllers/extractapp.php Wed Apr 01 15:10:35 2015 +0200 @@ -59,13 +59,16 @@ $viewmodel->messages['info'] .= "Welcome to Extraction Interface. "; if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) { + // --- Existing branch case --- // get text from fileId, from LGService $viewmodel->GetInfoFromPreviousPage($this->postdata); $viewmodel->GetTextFromFileId(); } else if ($this->postdata['sectionId'] != 0 && $this->postdata['userId'] != 0) { + // --- New branch case --- // get text from sectionId from LGService $viewmodel->GetInfoFromPreviousPage($this->postdata); + $viewmodel->GetBookMetaData($this->postdata); $viewmodel->GetTextFromSectionId(); } else if ($this->postdata['sectionId'] != 0) { diff -r 3fb9e3884401 -r 3395385476d1 js/taggingtext.js --- a/js/taggingtext.js Tue Mar 31 14:55:58 2015 +0200 +++ b/js/taggingtext.js Wed Apr 01 15:10:35 2015 +0200 @@ -45,83 +45,6 @@ alert( "Tagged "+matchedCount+" entities!" ); } - -function removeTagNewDiv( eventObject, tagName, tagObject ) { - saveUndoText(); - var newdiv = document.createElement("div"); - newdiv.id = "questionMarkId"; - newdiv.setAttribute("class", "questionMarkClass"); - newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; - newdiv.innerHTML = "Tag: "+tagName+"
Value: "+tagObject.text()+"
"; - - - var newbutton = $('').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=//g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - $(this).parent().parent().replaceWith( textKeep ); - }); - newbutton.appendTo(newdiv); - - var newbutton = $('').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=//g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - var newLineBefore = $(this).parent().parent().prev(); - if ( newLineBefore.prop("tagName") == "BR" ) { - $(this).parent().parent().prev().replaceWith( ); - } - $(this).parent().parent().replaceWith( textKeep ); - }); - newbutton.appendTo(newdiv); - - var newbutton = $('').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=//g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - $(this).parent().parent().replaceWith( textKeep ); - - var el = document.getElementById("editable-area"); - var regexText=new RegExp("<"+tagName+">("+textKeep+")", "g"); - var replaceText="$1"; - var str="" + el.innerHTML; - - if ( str.match(regexText)==null ) { - alert( "Removed 1 entity!" ); - } else { - alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" ); - } - el.innerHTML = str.replace(regexText, replaceText); - }); - newbutton.appendTo(newdiv); - - var newbutton = $('').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=//g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - $(this).parent().remove(); - - var el = document.getElementById("editable-area"); - var regexText=new RegExp("
<"+tagName+">("+textKeep+")", "g"); - var replaceText="$1"; - var str="" + el.innerHTML; - - alert( "Removed "+str.match(regexText).length+" entities!" ); - el.innerHTML = str.replace(regexText, replaceText); - }); - newbutton.appendTo(newdiv); - - tagObject.append(newdiv); -} - function removeEmptyNodes( node ) { if (node.hasChildNodes()) { var children = node.childNodes; @@ -279,6 +202,82 @@ } +function removeTagNewDiv( eventObject, tagName, tagObject ) { + saveUndoText(); + var newdiv = document.createElement("div"); + newdiv.id = "questionMarkId"; + newdiv.setAttribute("class", "questionMarkClass"); + + newdiv.style.cssText = 'top:'+eventObject.pageY+'; left:'+eventObject.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px; z-index:4'; + newdiv.innerHTML = "Tag: "+tagName+"
Value: "+tagObject.text()+"
"; + + var newbutton = $('').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=//g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().parent().replaceWith( textKeep ); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=//g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + var newLineBefore = $(this).parent().parent().prev(); + if ( newLineBefore.prop("tagName") == "BR" ) { + $(this).parent().parent().prev().replaceWith( ); + } + $(this).parent().parent().replaceWith( textKeep ); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=//g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().parent().replaceWith( textKeep ); + + var el = document.getElementById("editable-area"); + var regexText=new RegExp("<"+tagName+">("+textKeep+")", "g"); + var replaceText="$1"; + var str="" + el.innerHTML; + + if ( str.match(regexText)==null ) { + alert( "Removed 1 entity!" ); + } else { + alert( "Removed "+(parseInt(str.match(regexText).length)+1)+" entities!" ); + } + el.innerHTML = str.replace(regexText, replaceText); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=//g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().remove(); + + var el = document.getElementById("editable-area"); + var regexText=new RegExp("
<"+tagName+">("+textKeep+")", "g"); + var replaceText="$1"; + var str="" + el.innerHTML; + + alert( "Removed "+str.match(regexText).length+" entities!" ); + el.innerHTML = str.replace(regexText, replaceText); + }); + newbutton.appendTo(newdiv); + + tagObject.append(newdiv); +} + function saveText(section_id) { var el = document.getElementById("editable-area"); $.ajax({ diff -r 3fb9e3884401 -r 3395385476d1 models/extractapp.php --- a/models/extractapp.php Tue Mar 31 14:55:58 2015 +0200 +++ b/models/extractapp.php Wed Apr 01 15:10:35 2015 +0200 @@ -9,13 +9,9 @@ } protected $section_id = 0, $data_path, $file_id = 0, $current_fileId=0, - $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = ""; + $branch_id = 0, $user_id = 0, $lg_text = "", $topic, $taglist_infile = "", $book_meta = "",$book_dynasty=""; public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>""); - private function Initialize($_urlvalues) { - $this->SetSectionId($_urlvalues); - - } public function GetTextFromFileId() { // remove $_postdata as input /* @@ -52,6 +48,19 @@ } + public function GetBookMetaData($_postdata) { + // TODO: get book_meta from $_postdata, depended on LGService + + + // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty) + $book_meta = array(); + array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data","no_data")); // missing author,year,pagenumber + + $this->book_meta = $book_meta; + + } + + public function GetTextFromSectionId() { // remove $_postdata as input /* $section_id = $_postdata['sectionId']; @@ -68,13 +77,7 @@ $lg_text_url = $this->get_text_from_sectionId_url.$this->section_id; $lg_text = file_get_contents($lg_text_url); - // TODO: get book_meta from $_postdata and set $this->book_meta: book_id,book_name,author,year,pagenumber - $book_meta = array(); - array_push($book_meta, array($this->book_id,$this->book_name,"no_data","no_data","no_data")); // missing author,year,pagenumber - $this->book_meta = $book_meta; - - $stringInput = $lg_text; $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); @@ -88,8 +91,7 @@ public function GetTextFromLocal($_id){ $this->section_id = $_id; - $this->branch_id = 1; // local test sets branch_id to 1 - // $this->messages .= "DEBUG: from my local"."
"; + //$this->branch_id = 1; // local test sets branch_id to 1 $this->messages['debug'] .= "[Debug] from my local"."
"; $this->lg_text = $this->GetSectionContent(); @@ -135,50 +137,8 @@ $this->book_meta = json_decode($_postdata['book_meta']); } - } - public function InitData($_postdata) { - $file_id = $_postdata['fileId']; - $branch_id = $_postdata['branchId']; - $section_id = $_postdata['sectionId']; - - $this->branch_id = $branch_id; - $this->file_id = $file_id; - $this->user_id = $_postdata['userId']; - $this->section_id = $section_id; - - if ($file_id != 0 && $branch_id != 0) { - // get from URL with file_id - $lg_text_url = $this->get_text_from_fileId_url.$file_id; - } else if ($section_id != 0) { - // get from URL with section_id - $lg_text_url = $this->get_text_from_sectionId_url.$section_id; - } else { - echo "wrong url!!"; - return; - } - - - $lg_text = file_get_contents($lg_text_url); - - /* - $stringInput = preg_replace("/ /u", "○", $stringInput); - $stringInput = preg_replace("/\n/u", "
", $stringInput); - $stringInput = preg_replace("/【(.*?)】/u", "【\\1】", $stringInput); - */ - - // the text is from database - $stringInput = $lg_text; - $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); - $stringInput = preg_replace("/ /u", "○", $stringInput); - $stringInput = preg_replace("/\n/u", "
", $stringInput); - $stringInput = preg_replace("/【(.*?)】/u", "【\\1】", $stringInput); - $lg_text = $stringInput; - - $this->lg_text = $lg_text; - } - // TODO: comparison not correct private function Taglist_infileUpToDate($taglistArray) { @@ -340,6 +300,7 @@ $text .= "".$b[2]."\n"; $text .= "".$b[3]."\n"; $text .= "".$b[4]."\n"; + $text .= "".$b[5]."\n"; $text .= "\n"; } // taglist @@ -553,33 +514,18 @@ // === for export table === public function ExportTable($postdata) { - // $this->Initialize($urlvalues); $content = $postdata['content']; $topic = $postdata['topic']; $section_id = $postdata['sectionId']; //$section_id = $this->section_id; - - // TODO: this should be get from LGService: sectionName, bookId, bookName $sectionName = $postdata['sectionName']; $bookId = $postdata['bookId']; $bookName = $postdata['bookName']; - - // --- replace if get info from LGService - /* - $section_info = $this->GetSectionInfo(); - - $sectionName = $section_info['sectionName']; - $bookId = $section_info['bookId']; - - $books_info = $this->GetBooksInfo($bookId); - $bookName = $books_info['bookName']; - */ - // ===== - + // ===== $outputTableArray = array(); @@ -644,10 +590,6 @@ $value = preg_replace("/"."DEBUG: outputTableArray:"."
"; - var_dump($outputTableArray); - */ $topic_tag = $this->GetTopicTag($topic); @@ -705,7 +647,6 @@ foreach ($result as $row) { $taglistArray[$row[0]] = array($row[1], $row[2], $row[3]); //$taglistArray[$row['id']] = array($row['name'], $row['tag'], $row['color']); - // TODO: the format is not good, so I use $row[0], $row[1],... This could be changed some time. } $topic_tag_name = $this->GetTopicTag($topic_id); @@ -1129,25 +1070,6 @@ return strlen($b)-strlen($a); } - // TODO: delete this - private function SetSectionId($_urlvalues) { - // TODO: maybe get user info also - // get book id from url - if ($_urlvalues['id'] != "") { - $section_id = $_urlvalues['id']; - } else { - return json_encode("Error: No section id"); - /* ???? */ - /* - $get_book_id = $urlvalues['book']; - $get_start = $urlvalues['start']; - $get_end = $urlvalues['end']; - */ - } - $this->section_id = $section_id; - - } - private function GetSectionId() { if (is_numeric($this->section_id)) { @@ -1207,7 +1129,7 @@ $book_meta = $xml->book; $book_metaArray = array(); foreach ($book_meta as $row) { - array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber )); + array_push($book_metaArray, array((string)$row->id,(string)$row->name,(string)$row->author,(string)$row->year,(string)$row->pagenumber,(string)$row->dynasty )); } if ($book_metaArray) { $this->book_meta = $book_metaArray; @@ -1243,6 +1165,9 @@ $stringInput = preg_replace("/ /u", "○", $stringInput); $stringInput = preg_replace("/\n/u", "
", $stringInput); $stringInput = preg_replace("/【(.*?)】/u", "【\\1】", $stringInput); + + $this->branch_id = 1; // testing at local + } else { $query = sprintf("SELECT `content`, `line`, `books_id` FROM `contents` WHERE `books_id`=\"%s\" AND `line`>=%d AND `line`<=%d", $bookId, $startPage, $endPage); $result = mysql_query($query); @@ -1265,7 +1190,7 @@ $book_meta = array(); $books_result = $this->GetBooksByID($bookId); while ($row = mysql_fetch_assoc($books_result)) { - array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'])); + array_push($book_meta, array($row['id'],$row['name'],$row['author'],(string)$row['start_year'],(string)$row['line'],(string)$row['dynasty'])); // use 'start_year' as year, 'line' is pagenumber } diff -r 3fb9e3884401 -r 3395385476d1 views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Tue Mar 31 14:55:58 2015 +0200 +++ b/views/Extractapp/TaggingText.php Wed Apr 01 15:10:35 2015 +0200 @@ -16,9 +16,11 @@ ?> + - + + Extraction Interface