Mercurial > hg > extraction-interface
changeset 63:3395385476d1 extractapp
bug fixed: popup tag window is closed automatically when saving text file
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 01 Apr 2015 15:10:35 +0200 |
parents | 3fb9e3884401 |
children | ca6bf3532830 |
files | controllers/extractapp.php js/taggingtext.js models/extractapp.php views/Extractapp/TaggingText.php |
diffstat | 4 files changed, 117 insertions(+), 252 deletions(-) [+] |
line wrap: on
line diff
--- 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) {
--- 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+"<br>Value: "+tagObject.text()+"<br>"; - - - var newbutton = $('<button>Remove this</button>').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=/<div(.*?)<\/div>/g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - $(this).parent().parent().replaceWith( textKeep ); - }); - newbutton.appendTo(newdiv); - - var newbutton = $('<button>Remove this(with newline)</button>').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=/<div(.*?)<\/div>/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 = $('<button>Remove all</button>').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=/<div(.*?)<\/div>/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+")</"+tagName+">", "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 = $('<button>Remove all(with newline)</button>').mouseup(function (e2) { - var textKeep = $(this).parent().parent().html(); - var regexText=/<div(.*?)<\/div>/g; - var replaceText=""; - textKeep = textKeep.replace(regexText, replaceText); - - $(this).parent().remove(); - - var el = document.getElementById("editable-area"); - var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "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+"<br>Value: "+tagObject.text()+"<br>"; + + var newbutton = $('<button>Remove this</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().parent().replaceWith( textKeep ); + }); + newbutton.appendTo(newdiv); + + var newbutton = $('<button>Remove this(with newline)</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/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 = $('<button>Remove all</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/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+")</"+tagName+">", "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 = $('<button>Remove all(with newline)</button>').mouseup(function (e2) { + var textKeep = $(this).parent().parent().html(); + var regexText=/<div(.*?)<\/div>/g; + var replaceText=""; + textKeep = textKeep.replace(regexText, replaceText); + + $(this).parent().remove(); + + var el = document.getElementById("editable-area"); + var regexText=new RegExp("<br><"+tagName+">("+textKeep+")</"+tagName+">", "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({
--- 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"."<br>"; + //$this->branch_id = 1; // local test sets branch_id to 1 $this->messages['debug'] .= "[Debug] from my local"."<br>"; $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", "<br>", $stringInput); - $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); - */ - - // the text is from database - $stringInput = $lg_text; - $stringInput = preg_replace("/<(.*?)>/u", "○", $stringInput); - $stringInput = preg_replace("/ /u", "○", $stringInput); - $stringInput = preg_replace("/\n/u", "<br>", $stringInput); - $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $stringInput); - $lg_text = $stringInput; - - $this->lg_text = $lg_text; - } - // TODO: comparison not correct private function Taglist_infileUpToDate($taglistArray) { @@ -340,6 +300,7 @@ $text .= "<author>".$b[2]."</author>\n"; $text .= "<year>".$b[3]."</year>\n"; $text .= "<pagenumber>".$b[4]."</pagenumber>\n"; + $text .= "<dynasty>".$b[5]."</dynasty>\n"; $text .= "</book>\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("/</u", "<", $value); $outputTableArray[$count]["full"] = $value; } - /* - echo "<br>"."DEBUG: outputTableArray:"."<br>"; - 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", "<br>", $stringInput); $stringInput = preg_replace("/【(.*?)】/u", "【<a href=\"review_index_xml_images.php?books_id=".$bookId."&pages=\\1&entry=0\" target=\"_bookImg\">\\1</a>】", $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 }
--- 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 @@ ?> + <html> <head> -<title></title> + <meta charset="UTF-8"> + <title>Extraction Interface</title> <style> dynasty @@ -81,7 +83,7 @@ function reloadText() { // confirm to reload - var r = confirm("Your editing will be discarded. Are you sure you want to reload?"); + var r = confirm("Are you sure you want to load the latest version (in a new tab)?"); if (r != true) { return; } @@ -89,7 +91,6 @@ var form = document.createElement("form"); form.setAttribute("method", "post"); form.setAttribute("action", "./TaggingText"); // hand to controller - //form.setAttribute("target", "_self"); form.setAttribute("target", "_blank"); var hiddenField = document.createElement("input"); @@ -167,7 +168,6 @@ }); - // --- handle old version taglist --- var _GET = JSON.parse('<?php echo json_encode($_GET) ?>'); if (_GET['id']) { // === This case should only be possible for developing on local machine ==== @@ -183,6 +183,7 @@ } + // --- handle old version taglist --- // --- TODO: check if taglist in file is up-to-date --- /* var taglist_infile = JSON.parse('<?php echo json_encode($taglist_infile) ?>'); @@ -216,15 +217,9 @@ }); -$(document).on("click", "name", function (e) { - - if ( $("#editTextId").html() != "Edit the text" ) return 0; - if ( $(this).prop("tagName").toLowerCase() != "name" ) return 0; - - removeTagNewDiv( e, "name", $(this) ); -}); $(document).on("mouseup", '#editable-area', function (e) { + $('.questionMarkClass').remove(); $('.tagItemDivClass').remove(); @@ -244,7 +239,7 @@ newdiv.style.cssText = 'top:'+e.pageY+'; left:'+e.pageX+'; position:absolute; background-color: white; border:1px solid black; padding: 5px'; newdiv.style.backgroundColor = "white"; - newdiv.style.zIndex = 2; + newdiv.style.zIndex = "3"; //console.log(selection.getRangeAt(0).cloneContents()); if ( container.innerHTML.indexOf( "br" ) != -1 ) { @@ -608,7 +603,10 @@ } function saveTextToLGService() { - + // clean editable-area + $('.questionMarkClass').remove(); + $('.tagItemDivClass').remove(); + // ------------- var info = JSON.parse('<?php echo json_encode($info) ?>'); var topic_id = JSON.parse('<?php echo json_encode($default_topic_id) ?>'); @@ -661,63 +659,13 @@ console.log("complete saving to LGService"); - - /* - - if (info) { - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "fileId"); - hiddenField.setAttribute("value", info['file_id']); - form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "branchId"); - hiddenField.setAttribute("value", info['branch_id']); - form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "userId"); - hiddenField.setAttribute("value", info['user_id']); - form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "sectionId"); - hiddenField.setAttribute("value", info['section_id']); - form.appendChild(hiddenField); - - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "bookId"); - hiddenField.setAttribute("value", info['book_id']); - form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "sectionName"); - hiddenField.setAttribute("value", info['section_name']); - form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "bookName"); - hiddenField.setAttribute("value", info['book_name']); - form.appendChild(hiddenField); - - } - - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "text"); - var el = document.getElementById("editable-area"); - //var text = encodeURIComponent(el.innerHTML); - var text = el.innerHTML; - hiddenField.setAttribute("value", text); - form.appendChild(hiddenField); - - if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { - document.body.appendChild(form); - form.submit(); - } else { - form.submit(); // works under IE and Chrome, but not FF - } - */ } function chooseTopic(default_topic_id) { var t = JSON.parse( '<?php echo json_encode($topiclistArray) ?>' ); var info = JSON.parse('<?php echo json_encode($info) ?>'); + $('#load_topic_div').html(""); $('#load_topic_div').css("display", "block"); @@ -901,19 +849,12 @@ // cut textarea_text by cursorPosition var text_before_cursor = textarea_text.substring(0,cursorPosition); var text_after_cursor = textarea_text.substring(cursorPosition, textarea_text.length); - $('#smartRegexPopUpText').val( text_before_cursor+" ["+wordlistValue[2]+"] "+text_after_cursor); + + // default length is 1, which means {1,1} + $('#smartRegexPopUpText').val( text_before_cursor+"["+wordlistValue[2]+"]{1,1}"+text_after_cursor); } } -/* -<?php - foreach ( $wordlistArray as $wordlistValue ) { - echo "if ( $('#smartRegexPopUpSelectWord').val() == \"".$wordlistValue[0]."\") {"; - echo "$('#smartRegexPopUpText').val(\"".$wordlistValue[2]."\");"; - echo "}"; - } -?> -*/ }); @@ -923,11 +864,8 @@ <div id="dialog-form" title="config tags for topic" style="position:fixed; top: 30px; "> </div> -<!-- -<div class="info-board" style="margin:10 30 10 30;max-width:1270;height:70px;overflow:scroll;overflow-x:hidden;"> ---> <div class="info-board"> - <p class="bg-danger"> <?php echo $messages['error']; ?> </p> + <p class="bg-danger"><strong><?php echo $messages['error']; ?> </strong></p> <p class="bg-warning"> <?php echo $messages['warning']; ?> <button id="reloadTextButton" onclick="reloadText(<?php echo $default_topic_id; ?>)" style="display:none;">Load Latest Version</button> </p>