changeset 58:a11f9103b8db extractapp

New: 1.display messages 2.handle saving conflict:up-to-date or reload text
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 31 Mar 2015 10:59:52 +0200
parents 5cf9720a2e25
children 6e44605eb4f6
files config/config.php controllers/extractapp.php data/regex_files/test_regex.txt data/wordlist/4.txt models/extractapp.php views/Extractapp/ConfigTagsInTopic.php views/Extractapp/TaggingText.php views/maintemplate.php views/maintemplate_local.php
diffstat 9 files changed, 76 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/config/config.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/config/config.php	Tue Mar 31 10:59:52 2015 +0200
@@ -1,8 +1,8 @@
 <?php
 
-$at_local = false;
+$AT_LOCAL = false;
 
-if (!$at_local) {
+if (!$AT_LOCAL) {
 	// host at localgazetteers-dev server
 	$mysql_database = "Gazetteer";
 	$mysql_server = "localhost";
--- a/controllers/extractapp.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/controllers/extractapp.php	Tue Mar 31 10:59:52 2015 +0200
@@ -23,7 +23,7 @@
                 $this->ReturnView($viewmodel->StartTagging(), true); 
                 break;   
             case 'SaveFullTextToLGService':
-                $viewmodel->messages .= "SaveFullTextToLGService! "."<br>";
+                $viewmodel->messages['info'] .= "SaveFullTextToLGService! "."<br>";
                 $viewmodel->GetInfoFromPreviousPage($this->postdata);
                 $response = $viewmodel->SaveFullTextToLGService($this->postdata);
                 $viewmodel->UpdateInfoByResponseFromLGService($response);    // update file_id, branch_id, user_id
@@ -38,7 +38,7 @@
                 $viewmodel->SmartRegexSave($this->postdata);
                 break;
             case 'ReloadText':
-                $viewmodel->messages .= "Reload the latest text "."<br>";
+                $viewmodel->messages['info'] .= "Reload the latest text "."<br>";
                 $viewmodel->GetInfoFromPreviousPage($this->postdata);
                 $viewmodel->ReloadSetting();    // set file_id = current_fileId, current_fileId = 0
                 $viewmodel->GetTextFromFileId();
@@ -46,7 +46,7 @@
                 break;
 
             case 'ContinueTagging':
-                $viewmodel->messages .= "(Countinue tagging) "."<br>";
+                $viewmodel->messages['info'] .= "(Countinue tagging) "."<br>";
                 if ($this->postdata['topic']) {
                     $viewmodel->SetTopic($this->postdata['topic']);
                 }
@@ -56,7 +56,7 @@
 
 
             default:    // first time visit extraction interface from LGService
-                $viewmodel->messages .= "Welcome to Extraction Interface. "."<br>";
+                $viewmodel->messages['info'] .= "Welcome to Extraction Interface. "."<br>";
 
                 if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) {
                     // get text from fileId, from LGService
@@ -78,7 +78,7 @@
                     break;                    
 
                 } else {
-                    $viewmodel->messages .= "wrong url!!";
+                    $viewmodel->messages['error'] .= "wrong url!!";
                     return;
                 }
 
--- a/data/regex_files/test_regex.txt	Mon Mar 30 17:23:47 2015 +0200
+++ b/data/regex_files/test_regex.txt	Tue Mar 31 10:59:52 2015 +0200
@@ -1,1 +1,1 @@
-<span class="span_product_name" id="regex_elem_1" regextext="[^○如>〈】]{1,2}[稻|麥|豆|瓜|竹|菜|魚]" regexreplace="product_name" style="border: 1px solid black; width: 100px;">物產 test</span><span class="span_null" id="regex_elem_3" regextext="asdf" regexreplace="null" style="border: 1px solid black; width: 100px;">wdf</span><span class="span_null" id="regex_elem_5" regextext="asdf" regexreplace="null" style="border: 1px solid black; width: 100px;">vvvv234</span><span class="span_null" id="regex_elem_6" regextext="○" regexreplace="null" style="border: 1px solid black; width: 100px;">QQQ空白</span><span class="span_product_name" id="regex_elem_8" regextext="dddd" regexreplace="product_name" style="border: 1px solid black; width: 100px;">v222</span><span class="span_shu" id="regex_elem_9" regextext="" regexreplace="shu" style="border: 1px solid black; width: 100px;">v</span><span class="span_othername" id="regex_elem_10" regextext="○" regexreplace="othername" style="border: 1px solid black; width: 100px;">QQQ空白</span><span class="span_null" id="regex_elem_13" regextext="asdf" regexreplace="null" style="border: 1px solid black; width: 100px;">wdf</span><span class="span_othername" id="regex_elem_14" regextext="asdf" regexreplace="othername" style="border: 1px solid black; width: 100px;">w</span>
\ No newline at end of file
+<span class="span_product_name" id="regex_elem_1" regextext="[^○如>〈】]{1,2}[稻|麥|豆|瓜|竹|菜|魚]" regexreplace="product_name" style="border: 1px solid black; width: 100px;">物產 test</span><span class="span_null" id="regex_elem_3" regextext="asdf" regexreplace="null" style="border: 1px solid black; width: 100px;">wdf</span><span class="span_null" id="regex_elem_5" regextext="asasasas" regexreplace="null" style="border: 1px solid black; width: 100px;">vvvv234test</span><span class="span_null" id="regex_elem_6" regextext="○" regexreplace="null" style="border: 1px solid black; width: 100px;">QQQ空白</span><span class="span_product_name" id="regex_elem_8" regextext="dddd" regexreplace="product_name" style="border: 1px solid black; width: 100px;">v222</span><span class="span_shu" id="regex_elem_9" regextext="" regexreplace="shu" style="border: 1px solid black; width: 100px;">v</span><span class="span_othername" id="regex_elem_10" regextext="○" regexreplace="othername" style="border: 1px solid black; width: 100px;">QQQ空白</span><span class="span_null" id="regex_elem_13" regextext="asdf" regexreplace="null" style="border: 1px solid black; width: 100px;">wdf</span><span class="span_othername" id="regex_elem_14" regextext="asdf" regexreplace="othername" style="border: 1px solid black; width: 100px;">w</span>
\ No newline at end of file
--- a/data/wordlist/4.txt	Mon Mar 30 17:23:47 2015 +0200
+++ b/data/wordlist/4.txt	Tue Mar 31 10:59:52 2015 +0200
@@ -1,1 +1,1 @@
-一test<div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>七</div><div>八</div><div>九</div><div>十</div></div>
\ No newline at end of file
+一<div><div>二</div><div>三</div><div>四</div><div>五</div><div>六</div><div>七</div><div>八</div><div>九</div><div>十</div></div>
\ No newline at end of file
--- a/models/extractapp.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/models/extractapp.php	Tue Mar 31 10:59:52 2015 +0200
@@ -10,7 +10,7 @@
     
     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 = "";
-    public $messages = "";
+    public $messages = array('info'=>"",'error'=>"",'warning'=>"",'debug'=>"");
 
     private function Initialize($_urlvalues) {
         $this->SetSectionId($_urlvalues);
@@ -89,7 +89,8 @@
     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->messages .= "DEBUG: from my local"."<br>";
+        $this->messages['debug'] .= "[Debug] from my local"."<br>";
         $this->lg_text = $this->GetSectionContent();
 
     }
@@ -279,11 +280,24 @@
                 //'current_fileId'=>$this->file_id);
                 //'current_fileId'=>'123');
 
+        $this->messages['debug'] .= "[Debug] ";
+        $this->messages['debug'] .= "file_id=".$this->file_id.", section_id=".$this->section_id;
+        $this->messages['debug'] .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic;
+        $this->messages['debug'] .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name;
+        $this->messages['debug'] .= ", current_fileId=".$this->current_fileId."<br>";
+
+        $this->messages['info'] .= "[Info] book name: ".$this->book_name;
+        $this->messages['info'] .= ", section id: ". $this->section_id;
+        $this->messages['info'] .= ", branch id: ".$this->branch_id;
+        $this->messages['info'] .= "<br>";
+
+        /*
         $this->messages .= "Info: ";
         $this->messages .= "file_id=".$this->file_id.", section_id=".$this->section_id;
         $this->messages .= ", user_id=".$this->user_id.", branch_id=".$this->branch_id.", topic_id=".$this->topic;
         $this->messages .= ", book_id=".$this->book_id.", book_name=".$this->book_name.", section_name=".$this->section_name;
         $this->messages .= ", current_fileId=".$this->current_fileId."<br>";
+        */
 
         $data['messages'] = $this->messages;
 
@@ -348,15 +362,20 @@
 
         $status = (string)$response["status"];
         if ($status == "ok") {
-            $this->messages .= "Saving success.";
+            $this->messages['info'] .= "[Info] Saving success. <br>";
+            //$this->messages .= "Saving success.";
             $this->file_id = (string)$response_file["id"]; 
             $this->branch_id = (string)$response_branch["id"];
 
         } else if ($status == "error") {
             // saving not success
+            $this->messages['warning'] .= "[Warning] Saving Failed! ".(string)$response["message"]."<br>";
+            $this->messages['warning'] .= "[Warning] Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>";
+
+            /*
             $this->messages .= "Saving Failed! ".(string)$response["message"]."<br>";
             $this->messages .= "Please check branch ".$this->branch_id." in LGService, and modify from the latest version. <br>";
-
+            */
             $response_currentFile = $response["currentFile"];
             //$this->current_fileId = $response["currentFileId"];
             $this->current_fileId = (string)$response_currentFile["id"];
@@ -409,12 +428,16 @@
     public function SaveFullTextToLGService($_postdata) {
         // save tagged text (full text) by Jorge's API to lg service
         // --------
+        global $AT_LOCAL;
+
         if ($_postdata['text']){
             $date = date('Y_m_d_H_i_s', time());
             if ( file_exists("data/parsing_files/".$_postdata['sectionId'].".txt") ) {
                 $oldFile = file_get_contents("data/parsing_files/".$_postdata['sectionId'].".txt");
                 //saving in my local machine in developing phrase
-                //file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
+                if ($AT_LOCAL) {
+                    file_put_contents("data/parsing_files/".$_postdata['sectionId']."_".$date.".txt", $oldFile);
+                }
             }
             
             if (get_magic_quotes_gpc()) {
@@ -437,7 +460,9 @@
             $require = $this->AppendMetaData($require);
                 
             //saving in my local machine in developing phrase
-            //file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
+            if ($AT_LOCAL) {
+                file_put_contents("data/parsing_files/".$_postdata['sectionId'].".txt", $require);
+            }
         } 
 
         // ------
@@ -483,10 +508,11 @@
             'Content-type: multipart/form-data;charset=utf-8'                                                          
         ));       
 
-        // execute the request
-        // **** commended to DEBUG ***
-        $output = curl_exec($ch);
-        // *****
+        if (!$AT_LOCAL) {
+            // execute the request
+            $output = curl_exec($ch);
+        }
+
 
         // output the profile information - includes the header
         //echo($output) . PHP_EOL;
--- a/views/Extractapp/ConfigTagsInTopic.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/views/Extractapp/ConfigTagsInTopic.php	Tue Mar 31 10:59:52 2015 +0200
@@ -85,7 +85,7 @@
 
 </script>
 
-<div class="container-fluid" style="margin-left:30%;">
+<div class="container-fluid" style="margin-left:10%; margin-right:10%">
    
 		<form name="config" autocomplete='off' action="Javascript:checkTopic(document.config.InTopic)">
 			<h3>Topic: <?php echo $topic_name;?> </h3>
--- a/views/Extractapp/TaggingText.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/views/Extractapp/TaggingText.php	Tue Mar 31 10:59:52 2015 +0200
@@ -107,14 +107,16 @@
 
 }
 
-// TODO: Popup to proceeding the saving situations
 function handleFileVersionConflict() {
     var info = JSON.parse('<?php echo json_encode($info) ?>');
     console.log("currentFileId="+info['current_fileId']);
     
-    if (info['current_fileId'] != 0 && info['current_fileId'] != info['file_id']){
+    // if (info['current_fileId'] != 0 && info['current_fileId'] != info['file_id']){
+    if (info['current_fileId'] != 0){
         // -- there might be conflicts between different version
         alert("Your saving failed! Someone edited this file and saved before you.");
+        $('#reloadTextButton').css("display", "block");
+
         return;
     }
     return;
@@ -794,7 +796,6 @@
   
 }
 
-// --- for config tags in topic ---
 function _postForContineTagging(form) {
     var hiddenField = document.createElement("input");      
     hiddenField.setAttribute("name", "text");
@@ -930,7 +931,14 @@
 </div>
 
 
-<p class="bg-info" style="margin:10 30 10 30; max-width:1250"> <?php echo $messages; ?> </p>
+<div style="margin:10 30 10 30; max-width:1250">
+    <p class="bg-info" style=""> <?php echo $messages['info']; ?> </p>
+    <p class="bg-warning" style=""> <?php echo $messages['warning']; ?> </p>
+    <p class="bg-danger" style=""> <?php echo $messages['error']; ?> </p>
+    <button id="reloadTextButton" onclick="reloadText(<?php echo $default_topic_id; ?>)" style="display:none;">Reload</button>
+
+    <p class="bg-default" style=""> <?php echo $messages['debug']; ?> </p>
+</div>
 
 <table width="1270" border="1" style="margin:10 30 10 30;">
     <tr>
@@ -977,9 +985,6 @@
             <div id="follow-scroll" style="position:absolute; height:680px; overflow:scroll; margin:0 5 15 5; max-width:270px">
                 <form action="javascript:void(0);">   
                     <fieldset>
-                        <button onclick="reloadText(<?php echo $default_topic_id; ?>)">Reload</button>
-                    </fieldset>
-                    <fieldset>
                         <legend><h5 class="text-success"> Config Topic: </h5></legend>
                         <div> current topic is <?php echo $topic_name; ?> 
                             <button onclick="chooseTopic()" class="btn btn-xs btn-default">Change</button>
@@ -990,14 +995,14 @@
                     <fieldset>
                         <legend><h5 class="text-success"> Replace By <i><b>Smart Regex</b></i>©: </h5></legend>
                         <div id="smartRegexShowDiv"></div><br>
-                        <button onclick="smartRegexNew()" style="height: 30px; width: 220px">Add Regex Group</button></br>
+                        <button onclick="smartRegexNew()" style="height: 35px; width: 220px">Add Regex Group</button></br>
                         Range: <input type="text" size="5" id="regexPageStart">to<input type="text" size="5" id="regexPageEnd"><br>
-                        <button onclick="replaceSmartRun()" style="height: 30px; width: 100px">Run</button>
-                        <button onclick="replaceSmartRunWithBr()" style="height: 30px; width: 100px">Run(with Br)</button></br>
-                        <button onclick="replaceSmartRunSpace()" style="height: 30px; width: 220px">Run(Allow space between Group)</button></br>
-                        <button onclick="smartRegexSave(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 70px">Save</button>
-                        <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 70px">Load</button>
-                        <button onclick="smartRegexEmpty()" style="height: 30px; width: 70px">Clear</button></br>
+                        <button onclick="replaceSmartRun()" style="height: 35px; width: 100px">Run</button>
+                        <button onclick="replaceSmartRunWithBr()" style="height: 35px; width: 100px">Run(with Br)</button></br>
+                        <button onclick="replaceSmartRunSpace()" style="height: 35px; width: 220px">Run(Allow space between Group)</button></br>
+                        <button onclick="smartRegexSave(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 70px">Save</button>
+                        <button onclick="smartRegexLoad(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 70px">Load</button>
+                        <button onclick="smartRegexEmpty()" style="height: 35px; width: 70px">Clear</button></br>
                         <!--
                         <button id="example" type="button" class="btn btn-sm btn-default" data-toggle="popover">Load</button>
                         -->
@@ -1005,17 +1010,17 @@
                     
                     <fieldset>
                         <legend><h5 class="text-success"> Tag by rule:</h5></legend>
-                        <button onclick="tagNameWithLastName()" style="height: 30px; width: 220px">Tag Word Begin With Surname</button></br>
-                        <button onclick="tagNameWithLastName2()" style="height: 30px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
+                        <button onclick="tagNameWithLastName()" style="height: 35px; width: 220px">Tag Word Begin With Surname</button></br>
+                        <button onclick="tagNameWithLastName2()" style="height: 35px; width: 170px">Tag Word Begin With</button><input type="text" size="2" id="surname"></br>
                         <!--<button onclick="tagTime()" style="height: 30px; width: 220px">Tag Time</button></br>-->
                         <!--<button onclick="tagBiogAddr()" style="height: 30px; width: 220px">Tag BiogAddr</button></br>-->
-                        <button onclick="Undo()" style="height: 30px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
+                        <button onclick="Undo()" style="height: 35px; width: 220px" id="buttonUndo" disabled="true">Undo</button>
                     </fieldset>
                 
                     <fieldset>
                         <legend><h5 class="text-success"> Edit:</h5></legend>
 
-                        <button onclick="saveTextToLGService()" id="saveTextToLGService_id" style="height: 30px; width: 220px">Save to LGService</button></br>
+                        <button onclick="saveTextToLGService()" id="saveTextToLGService_id" style="height: 35px; width: 220px">Save to LGService</button></br>
                     
                         <!--<button onclick="cleanUpTextArea()" style="height: 30px; width: 220px">Reform the text</button></br>-->
                         <!-- save text in local. replaced by saveTextToLGService, which is also saving on copy in local in development stage -->
@@ -1023,20 +1028,20 @@
                         <button onclick="saveText(<?php echo $section_id; ?>)" style="height: 30px; width: 220px">Save the text</button></br>
                         -->
 
-                        <button onclick="editText()" id="editTextId" style="height: 30px; width: 220px">Edit the text</button></br>
+                        <button onclick="editText()" id="editTextId" style="height: 35px; width: 220px">Edit the text</button></br>
                         </br>
-                        <button onclick="window.open('./EditWordlist')" style="height: 30px; width: 220px">Manage Word List</button></br>
+                        <button onclick="window.open('./EditWordlist')" style="height: 35px; width: 220px">Manage Word List</button></br>
                         <!--
                         <button onclick="window.open('./EditTaglist')" style="height: 30px; width: 220px">Manage Tag List</button></br>
                         -->
-                        <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" style="height: 30px; width: 220px">Manage Tag List</button></br>
+                        <button onclick="editTaglist(<?php echo $default_topic_id; ?>)" style="height: 35px; width: 220px">Manage Tag List</button></br>
                     </fieldset>
                     
                     <fieldset>
                         <legend><h5 class="text-success"> Export:</h5></legend>
                         Page: <input type="text" size="5" id="exportPageStart">to<input type="text" size="5" id="exportPageEnd"><br>
-                        <button onclick="exportPage(<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export</button></br>
-                        <button onclick="exportAll(<?php echo $default_topic_id;?>)" style="height: 30px; width: 220px">Export All</button></br>
+                        <button onclick="exportPage(<?php echo $default_topic_id;?>)" style="height: 35px; width: 220px">Export</button></br>
+                        <button onclick="exportAll(<?php echo $default_topic_id;?>)" style="height: 35px; width: 220px">Export All</button></br>
                     </fieldset>
                 
                     <fieldset>
--- a/views/maintemplate.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/views/maintemplate.php	Tue Mar 31 10:59:52 2015 +0200
@@ -7,18 +7,15 @@
 
 <!-- Bootstrap -->
 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
-<!--
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
-
 <link href="../css/bootstrap.min.css" rel="stylesheet">
 <script src="../js/bootstrap.min.js"></script>
+<!--
 <script src="../js/bootstrap.js"></script>
 -->
-
 </head>
 <body>
 
-
 </body>
 
 </html>
\ No newline at end of file
--- a/views/maintemplate_local.php	Mon Mar 30 17:23:47 2015 +0200
+++ b/views/maintemplate_local.php	Tue Mar 31 10:59:52 2015 +0200
@@ -1,20 +1,18 @@
 <html>
 <head>
 <title></title>
-
 <script src="../../js/jquery-1.10.2.min.js"></script>
 <script src="../../js/jquery-ui.js"></script>
 <script src="../../js/taggingtext.js"></script>
 
 <!-- Bootstrap -->
 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
-<!--
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
 <link href="../../css/bootstrap.min.css" rel="stylesheet">
 <script src="../../js/bootstrap.min.js"></script>
+<!--
 <script src="../../js/bootstrap.js"></script>
 -->
-
 </head>
 <body>