Mercurial > hg > extraction-interface
changeset 10:54a235d43694
add topic choosing in the TaggingText page
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 10 Feb 2015 16:20:29 +0100 |
parents | 584b1623e9ef |
children | 3d6fba07bfbd |
files | develop/classes/basemodel.php develop/controllers/extractapp.php develop/index.php develop/models/_extractapp_func.php develop/models/extractapp.php develop/views/Extractapp/taggingtext.php |
diffstat | 6 files changed, 143 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/develop/classes/basemodel.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/classes/basemodel.php Tue Feb 10 16:20:29 2015 +0100 @@ -2,7 +2,7 @@ abstract class BaseModel { // protected $database; - protected $systemNAME; + protected $systemNAME, $topic; public function __construct() { global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME; @@ -23,6 +23,7 @@ die ('Can\'t use foo : ' . mysql_error()); } + $this->topic = 1; // set the default topic to person (人物) } protected function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { @@ -88,6 +89,15 @@ return $result; } + protected function GetTopiclist() { + $query = sprintf("SELECT * FROM `topics`"); + $result = mysql_query($query); + if (!$result) { + return json_encode("Failed during selecting topics table."); + } + return $result; + } + }
--- a/develop/controllers/extractapp.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/controllers/extractapp.php Tue Feb 10 16:20:29 2015 +0100 @@ -12,9 +12,12 @@ case 'SaveFullText': $viewmodel->SaveFullText($this->postdata); $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); - break; - + break; + default: + if ($this->postdata['topic']) { + $viewmodel->SetTopic($this->postdata['topic']); + } $this->ReturnView($viewmodel->StartTagging($this->urlvalues), false); break; } @@ -62,6 +65,8 @@ } } + + protected function TestAction() { $viewmodel = new ExtractappModel();
--- a/develop/index.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/index.php Tue Feb 10 16:20:29 2015 +0100 @@ -15,8 +15,9 @@ </head> <body> <?php +header("Content-Type: text/html;charset=utf-8"); -// configiration +// system configiration include_once('config/Lib_mb_utf8.php'); include_once('config/config.php');
--- a/develop/models/_extractapp_func.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/models/_extractapp_func.php Tue Feb 10 16:20:29 2015 +0100 @@ -10,7 +10,7 @@ case 'SmartRegexSave': SmartRegexSave(); break; - + default: SmartRegexLoad(); break; @@ -45,7 +45,7 @@ } else { $require = $_POST['text']; } - + file_put_contents( $data_path."regex_files/".$_POST['filename'].".txt", $require); } }
--- a/develop/models/extractapp.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/models/extractapp.php Tue Feb 10 16:20:29 2015 +0100 @@ -24,9 +24,13 @@ $stringInput = $this->GetSectionContent(); - $taglistArray = $this->GetTaglistArray(); - // test for GetTaglistByTopicID: - // $taglistArray = $this->GetTaglistByTopicID(1); + //$taglistArray = $this->GetTaglistArray(); + //for GetTaglistByTopicID: + + $taglistArray = $this->GetTaglistByTopicID($this->GetTopic()); + + // topic list? + $topiclistArray = $this->GetTopiclistArray(); $wordlistArray = $this->GetWordlistArray(); @@ -36,8 +40,9 @@ $data['taglistArray'] = $taglistArray; $data['wordlistArray'] = $wordlistArray; $data['section_id'] = $section_id; - - + $data['topiclistArray'] = $topiclistArray; + $data['default_topic_id'] = $this->GetTopic(); + return $data; } @@ -66,8 +71,7 @@ } - - + // === for export table === public function ExportTable($urlvalues, $postdata) { $this->Initialize($urlvalues); @@ -235,37 +239,56 @@ } + // === for config topic === + - // TODO: get taglist by choosen topic private function GetTaglistByTopicID($topic_id) { - $taglistArray = ""; - - $query = "SELECT * FROM topic_tag_relation WHERE topic_id=".$topic_id; + $taglistArray = array(); + // select taglist ids from topic_tag_relation table + $query = sprintf("SELECT * FROM `topic_tag_relation` WHERE `topic_id`='%s'", $topic_id); $result = mysql_query($query); if (!$result) { - return json_encode("Failed during selecting topics table."); + return json_encode("Failed during selecting topic_tag_relation table."); } + $taglist_ids = array(); while ($row = mysql_fetch_assoc($result)) { - $tag_id = $row['tag_id']; - $query = "SELECT * FROM taglist WHERE id=".$tag_id; - $tag_result = mysql_query($query); - if ($tag_result) { + array_push($taglist_ids, $row['tag_id']); + } + + // select taglist by tag ids + foreach ($taglist_ids as $tag_id) { + $query = sprintf("SELECT * FROM `taglist` WHERE `id`='%s'", $tag_id); + $result = mysql_query($query); + if (!$result) { + echo mysql_error(); return json_encode("Failed during selecting taglist table."); } - $row = mysql_fetch_assoc($tag_result)); - $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); - // array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); + + $row = mysql_fetch_assoc($result); + array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); + } - - return $taglistArray; + } + public function SetTopic($topic) { + $this->topic = $topic; + } + public function GetTopic() { + return $this->topic; + } - + private function GetTopiclistArray() { + $topiclistArray = array(); + $result = $this->GetTopiclist(); + while ($row = mysql_fetch_assoc($result)) { + array_push($topiclistArray, array('id'=>$row['id'],'name'=>$row['name'])); + } + return $topiclistArray; + } - } // =========================== // === for manage wordlist === @@ -439,11 +462,10 @@ } private function GetTaglistArray() { - $taglistArray=""; + $taglistArray = array(); $result = $this->GetTaglist(); while ($row = mysql_fetch_assoc($result)) { - $taglistArray[] = array( $row['id'], $row['name'], $row['tag'], $row['color'] ); - + array_push($taglistArray, array( $row['id'], $row['name'], $row['tag'], $row['color'] )); } return $taglistArray;
--- a/develop/views/Extractapp/taggingtext.php Mon Feb 09 18:59:24 2015 +0100 +++ b/develop/views/Extractapp/taggingtext.php Tue Feb 10 16:20:29 2015 +0100 @@ -4,9 +4,8 @@ $wordlistArray = $viewmodel['wordlistArray']; $taglistArray = $viewmodel['taglistArray']; $section_id = $viewmodel['section_id']; - - -var_dump($taglistArray); +$topiclistArray = $viewmodel['topiclistArray']; +$default_topic_id = $viewmodel['default_topic_id']; ?> @@ -226,6 +225,73 @@ } +function chooseTopic(section_id, default_topic_id) { + var t = JSON.parse( '<?php echo json_encode($topiclistArray) ?>' ); + + $('#load_topic_div').html(""); + $('#load_topic_div').css("display", "block"); + $('#load_topic_div').css("border", "1px solid black"); + $('#load_topic_div').css("background-color", "White"); + $('#load_topic_div').css("width", "200px"); + $('#load_topic_div').css("height", "50px"); + $('#load_topic_div').css("top", "20px"); + $('#load_topic_div').css("left", "-200px"); + + var topic_select = document.createElement("select"); + topic_select.id = "loadTopiclist"; + var selected_topic = t[0]; + topic_select.onchange = function(){ + + selected_topic = topic_select.options[topic_select.selectedIndex]; + console.log(selected_topic.text); + + var topic_id = selected_topic.value; + var topic_name = selected_topic.text; + + var form = document.createElement("form"); + form.setAttribute("method", "post"); + form.setAttribute("action", "./"+section_id); // hand to controller + form.setAttribute("target", "_self"); + + var hiddenField = document.createElement("input"); + hiddenField.setAttribute("name", "topic"); + hiddenField.setAttribute("value", topic_id); + 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 + } + + + + }; + + + //Create and append the options + for (var i = 0; i < t.length; i++) { + console.log(t[i]['id']+","+t[i]['name']); + var option = document.createElement("option"); + option.value = t[i]['id']; + option.text = t[i]['name']; + if (option.value == default_topic_id) { + option.selected = true; + }; + topic_select.appendChild(option); + } + + $('#load_topic_div').append(topic_select); + + var newbutton = document.createElement("button"); + $(newbutton).html("Close"); + $(newbutton).attr("onclick", "$('#load_topic_div').css(\"display\", \"none\");"); + $('#load_topic_div').append(newbutton); + +} + + $(document).on("change", '#smartRegexPopUpSelectWord', function (e) { <?php @@ -248,6 +314,7 @@ <td width="270" valign="top"> <div id="follow-scroll" style="position:absolute; width: 220" width="220"> <div id="load_regex_div" style="position: absolute; display: none"></div> + <div id="load_topic_div" style="position: absolute; display: none"></div> <div id="smartRegexPopUpDiv" style="position: absolute; display: none"> Name: <input id="smartRegexPopUpName"></input><br><br> Word List: @@ -280,6 +347,8 @@ <button onclick="replaceSmartClose()" style="height: 30px; width: 50px">Close</button> </div> <form action="javascript:void(0);"> + <button onclick="chooseTopic(<?php echo $section_id;?>, <?php echo $default_topic_id; ?>)">Choose Topic</button> + <fieldset> <legend>Replace By <i><b>Smart Regex</b></i>©:</legend> <div id="smartRegexShowDiv"></div><br> @@ -331,4 +400,5 @@ </tr> </table> </body> + </html>