# HG changeset patch # User Zoe Hong # Date 1428410731 -7200 # Node ID 3ada9334ebfc7d68c4ea60cc618a035dab515307 # Parent e71a437ae49f2dba81eb64aa4f64bb19887b835e New: check taglist is deprecated or not diff -r e71a437ae49f -r 3ada9334ebfc classes/basemodel.php --- a/classes/basemodel.php Thu Apr 02 16:33:46 2015 +0200 +++ b/classes/basemodel.php Tue Apr 07 14:45:31 2015 +0200 @@ -19,6 +19,7 @@ $this->get_text_from_sectionId_url = $lgserver_url."rest/text/getSectionText?sectionId="; $this->save_to_LGService_url = $lgserver_url."rest/text/save"; $this->save_new_to_LGService_url = $lgserver_url."rest/text/saveNew"; + $this->get_section_metadata_by_sectionId_url = $lgserver_url."rest/text/getSectionMetadata?sectionId="; set_time_limit(0); ini_set('memory_limit', '-1'); diff -r e71a437ae49f -r 3ada9334ebfc controllers/extractapp.php --- a/controllers/extractapp.php Thu Apr 02 16:33:46 2015 +0200 +++ b/controllers/extractapp.php Tue Apr 07 14:45:31 2015 +0200 @@ -14,7 +14,6 @@ } protected function TaggingText() { - //$viewmodel = new ExtractappModel(); $viewmodel = $this->viewmodel; switch ($this->postdata['func']) { @@ -60,15 +59,15 @@ if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) { // --- Existing branch case --- - // get text from fileId, from LGService $viewmodel->GetInfoFromPreviousPage($this->postdata); + // get text by fileId, from LGService $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->GetBookMetaDataBySectionId(); + // get text by sectionId from LGService $viewmodel->GetTextFromSectionId(); } else if ($this->postdata['sectionId'] != 0) { @@ -94,14 +93,12 @@ } protected function ExportTable() { - //$viewmodel = new ExtractappModel(); $viewmodel = $this->viewmodel; $this->ReturnView($viewmodel->ExportTable($this->postdata), true); } protected function EditWordlist() { - // $viewmodel = new ExtractappModel(); $viewmodel = $this->viewmodel; switch ($this->postdata['func']) { case 'AddNewList': @@ -119,7 +116,6 @@ protected function EditTaglist() { - //$viewmodel = new ExtractappModel(); $viewmodel = $this->viewmodel; switch ($this->postdata['func']) { case 'NewTagElement': @@ -139,7 +135,6 @@ protected function ConfigTagsInTopic() { - //$viewmodel = new ExtractappModel(); $viewmodel = $this->viewmodel; switch ($this->postdata['func']) { case 'Update': @@ -152,7 +147,6 @@ } protected function TestAction() { - $viewmodel = new ExtractappModel(); $this->ReturnView($viewmodel->Test(), true); } diff -r e71a437ae49f -r 3ada9334ebfc models/extractapp.php --- a/models/extractapp.php Thu Apr 02 16:33:46 2015 +0200 +++ b/models/extractapp.php Tue Apr 07 14:45:31 2015 +0200 @@ -48,9 +48,15 @@ } - public function GetBookMetaData($_postdata) { - // TODO: get book_meta from $_postdata, depended on LGService - + + + + public function GetBookMetaDataBySectionId() { + + // TODO: get book_meta from $$this->get_section_metadata_by_sectionId_url ... + $section_meta_url = $this->get_section_metadata_by_sectionId_url.$this->section_id; + $section_meta = file_get_contents($section_meta_url); + // TODO: set $this->book_meta to an array(book_id,book_name,author,year,pagenumber,dynasty) $book_meta = array(); @@ -140,30 +146,44 @@ } - // TODO: comparison not correct - private function Taglist_infileUpToDate($taglistArray) { - // compare $this->taglist_infile is the same as $taglistArray - $taglist_infile = $this->taglist_infile; - if (count($taglist_infile) != count($taglistArray)) { + + + private function TaglistSubsetIn($list1, $list2) { // $l1 is a subset of $l2 or not + // l1 and l2: array( $row['id'], $row['name'], $row['tag'], $row['color'] ) + $cnt_list1 = count($list1); + $cnt_list2 = count($list2); + + if ($cnt_list1 > $cnt_list2) { return false; } - - foreach ($taglistArray as $row_indb) { + foreach ($list1 as $v1) { $cnt = 0; - foreach ($taglist_infile as $row) { - //$taglistArray: array( $row['id'], $row['name'], $row['tag'], $row['color'] ) - if ($row[0] == $row_indb[0] && $row[1] == $row_indb[1] && $row[2] == $row_indb[2] && $row[3] == $row_indb[3]) { + foreach ($list2 as $v2) { + $num_field = count($v2); + $matched = true; + for ($i=0; $i < $num_field; $i++) { + if ($v1[$i] != $v2[$i]) { + $matched = false; + break; + } + } + if (!$matched) { + // not match with this v2 + $cnt += 1; } else { - $cnt ++; + break; } + } - if ($cnt == count($row)) { - return false; + if ($cnt == $cnt_list2) { + return false; } } return true; + } + // === for tagging === public function StartTagging() { @@ -176,15 +196,13 @@ //for GetTaglistByTopicID: $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); - $data['taglist_infile'] = $this->taglist_infile; - // TODO: check if taglist_infile is up-to-date - /* - if ( !$this->Taglist_infileUpToDate($taglistArray)) { - $data['taglist_infile'] = $this->taglist_infile; - } else { - $data['taglist_infile'] = ""; - } - */ + // $this->taglist_infile is set (1) from file or (2) from _postdata['taglistArray'] which comes from frontend that user decided + // $this->taglist_infile is the most up-to-date taglist decided by user. Should be written into file. + if( $this->TaglistSubsetIn($this->taglist_infile, $taglistArray) ) { // TaglistSubsetIn($l1,$l2): $l1 is a subset of $l2 or not + $this->taglist_infile = ""; + } + $data['taglist_infile'] = $this->taglist_infile; // if taglist_infile == "" means taglist in file is up-to-date (will use taglist in db), otherwise means the taglist in file + // book_meta $data['book_meta'] = $this->book_meta; @@ -209,8 +227,6 @@ 'branch_id'=>$this->branch_id, 'section_id'=>$this->section_id, 'book_id'=>$this->book_id, 'book_name'=>$this->book_name, 'section_name'=>$this->section_name, 'current_fileId'=>$this->current_fileId); - //'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; @@ -670,7 +686,7 @@ } - private function _GetTag($_postdata) { + private function GetTag($_postdata) { if (get_magic_quotes_gpc()) { $id = stripslashes($_postdata['id']); $name = stripslashes($_postdata['name']); @@ -687,7 +703,7 @@ public function NewTagElement($postdata) { if ($postdata['id']){ - list($id, $name, $tag, $color) = $this->_GetTag($postdata); + list($id, $name, $tag, $color) = $this->GetTag($postdata); $query1 = sprintf("INSERT INTO `taglist` (`id`, `name`, `tag`, `color`, `systemName`) VALUES (%s, %s, %s, %s, %s)", $this->GetSQLValueString($id, "int"), @@ -713,7 +729,7 @@ public function SaveTagElement($postdata) { if ($postdata['id']){ - list($id, $name, $tag, $color) = $this->_GetTag($postdata); + list($id, $name, $tag, $color) = $this->GetTag($postdata); $query = sprintf("UPDATE taglist SET `name`=%s, `tag`=%s, `color`=%s WHERE `id`=%s", $this->GetSQLValueString($name, "text"), diff -r e71a437ae49f -r 3ada9334ebfc views/Extractapp/TaggingText.php --- a/views/Extractapp/TaggingText.php Thu Apr 02 16:33:46 2015 +0200 +++ b/views/Extractapp/TaggingText.php Tue Apr 07 14:45:31 2015 +0200 @@ -110,8 +110,6 @@ function handleFileVersionConflict() { var info = JSON.parse(''); - console.log("currentFileId="+info['current_fileId']); - // if (info['current_fileId'] != 0 && info['current_fileId'] != info['file_id']){ if (info['current_fileId'] != 0){ // -- there might be conflicts between different version @@ -150,6 +148,7 @@ //el.stop().animate({'top':finaldestination},500); el.stop().animate({'top':finaldestination},0); }); + // --- //--- for popups --- //run once @@ -165,11 +164,12 @@ //el.stop().animate({'top':finaldestination},500); el.stop().animate({'top':finaldestination},0); }); + // --- + // === This case only be possible for developing on local machine ==== var _GET = JSON.parse(''); if (_GET['id']) { - // === This case should only be possible for developing on local machine ==== var info = JSON.parse(''); var redirectUrl = "http://localhost:1080/localgazetteers-dev/extraction-interface/Extractapp/TaggingText"; var section_id = info['section_id']; @@ -180,7 +180,34 @@ $('body').append(form); $(form).submit(); } - + // -------- + + // --- handle file version conflict --- + var info = JSON.parse(''); + // the first time to this section. without branch_id and file_id + if (info['file_id'] == 0) { // or info['branch_id'] == 0, means new file + $( "#saveTextToLGService_id").text( "Create(Save) Branch to LGService" ); + + } + handleFileVersionConflict(); + + // --- handle taglist deprecation --- + var taglist_infile = JSON.parse(''); + var taglistArray = JSON.parse(''); + + if (taglist_infile == "") { + console.log("Debug: taglist_infile is empty which means taglist_infile is equal to taglist in db."); + } else { + console.log("Debug: taglist_infile length=" + taglist_infile.length); + console.log(taglist_infile); + console.log("Debug: taglistArray length=" + taglistArray.length); + console.log(taglistArray); + + // TOOD: ask user to modify/decide tags + // showing taglist_infile and taglistArray + alert("taglist is deprecated in the current file."); + + } // --- handle old version taglist --- // --- TODO: check if taglist in file is up-to-date --- @@ -204,16 +231,7 @@ } */ - var info = JSON.parse(''); - - // the first time to this section. without branch_id and file_id - if (info['file_id'] == 0) { // or info['branch_id'] == 0, means new file - $( "#saveTextToLGService_id").text( "Create(Save) Branch to LGService" ); - - } - - handleFileVersionConflict(); - + }); @@ -479,43 +497,6 @@ form.appendChild(hiddenField); _postForContineTagging(form); -/* - var section_id = JSON.parse(''); - console.log("section_id: "+section_id+", topic_id: "+topic_id); - - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "sectionId"); - hiddenField.setAttribute("value", section_id); - form.appendChild(hiddenField); - - var info = JSON.parse( ''); - - if (info) { - 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", "bookName"); - hiddenField.setAttribute("value", info['book_name']); - form.appendChild(hiddenField); - - var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "sectionName"); - hiddenField.setAttribute("value", info['section_name']); - 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 - } - */ } // =========== @@ -527,7 +508,6 @@ range.deleteContents(); - if ( tag==topic_tag2) { var newdiv = document.createElement(topic_tag); newdiv.innerHTML = stringSelection; @@ -541,26 +521,6 @@ range.insertNode(newdiv); } - /* - if ( tag=="person2") { - var newdiv = document.createElement("person"); - newdiv.innerHTML = stringSelection; - range.insertNode(newdiv); - var newdiv = document.createElement("br"); - range.insertNode(newdiv); - } else if (tag=="object2") { - var newdiv = document.createElement("object"); - newdiv.innerHTML = stringSelection; - range.insertNode(newdiv); - var newdiv = document.createElement("br"); - range.insertNode(newdiv); - - } else { - var newdiv = document.createElement(tag); - newdiv.innerHTML = stringSelection; - range.insertNode(newdiv); - } - */ $('.tagItemDivClass').remove(); } @@ -709,7 +669,6 @@ //Create and append the options for (var i = 0; i < t.length; i++) { - console.log(t[i]['id']+","+t[i]['name_ch']+","+t[i]['name_pinyin']+","+t[i]['name_en']); var option = document.createElement("option"); option.value = t[i]['id']; option.text = t[i]['name_en']+" ("+t[i]['name_ch']+", "+t[i]['name_pinyin']+")"; @@ -741,7 +700,10 @@ var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "taglistArray"); var taglistObj = JSON.parse(''); + // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file + if (!taglistObj) { + // TODO: should pass the user-decided taglist to post['taglistArray'] taglistObj = JSON.parse(''); } taglistArray = JSON.stringify(taglistObj); @@ -869,12 +831,12 @@
- +
- -
+
+