Mercurial > hg > extraction-interface
changeset 95:9a29e9d28ece extractapp
new: create new topic
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Wed, 11 Nov 2015 14:12:55 +0100 |
parents | b0cecc104639 |
children | ce7e933b18b0 |
files | controllers/extractapp.php css/taggingtext.css js/taggingtext.js models/extractapp.php views/Extractapp/ConfigTagsInTopic.php views/Extractapp/EditTaglist.php views/Extractapp/TaggingText.php |
diffstat | 7 files changed, 171 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/controllers/extractapp.php Mon Nov 09 12:00:24 2015 +0100 +++ b/controllers/extractapp.php Wed Nov 11 14:12:55 2015 +0100 @@ -101,13 +101,28 @@ case 'ContinueTagging': $viewmodel->messages['info'] .= "(Countinue tagging) "; - if ($this->postdata['topic']) { - $viewmodel->SetTopic($this->postdata['topic']); - } - $viewmodel->SetInfoFromPreviousPage($this->postdata); + $viewmodel->SetInfoFromPreviousPage($this->postdata); + $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService + $viewmodel->SetTopic($this->postdata['topic']); + $this->ReturnView($viewmodel->StartTagging(), true); break; + case 'CreateNewTopic': + $result = $viewmodel->CreateNewTopic($this->postdata); + if ($result == "error") { + $viewmodel->messages['error'] .= "Fail to create the new topic <br> "; + } else { + // then act like ContinueTagging + $viewmodel->messages['info'] .= "Created a new topic <br>"; + $viewmodel->SetInfoFromPreviousPage($result); + $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService + $viewmodel->SetTopic($result['topic']); + + } + $this->ReturnView($viewmodel->StartTagging(), true); + + break; default: // This is where the first time user visit extraction interface from LGService @@ -280,13 +295,20 @@ case 'Update': $viewmodel->UpdateTagsInTopic($this->postdata); break; + /* case 'CreateNewTopic': - $this->ReturnView($viewmodel->CreateNewTopic($this->postdata), true); + $result = $viewmodel->CreateNewTopic($this->postdata); + if ($result == "error") { + echo "Fail to create the new topic. Please contact us."; + } else { + $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true); + } break; + */ default: $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true); break; - } + } }
--- a/css/taggingtext.css Mon Nov 09 12:00:24 2015 +0100 +++ b/css/taggingtext.css Wed Nov 11 14:12:55 2015 +0100 @@ -114,8 +114,8 @@ z-index: 2; } .popup-newtopic { - left: -340px; - width: 340px; + left: -360px; + width: 360px; height: 340px; top: 100px; z-index: 2;
--- a/js/taggingtext.js Mon Nov 09 12:00:24 2015 +0100 +++ b/js/taggingtext.js Wed Nov 11 14:12:55 2015 +0100 @@ -29,7 +29,7 @@ var regex_element_index = 0; window.onbeforeunload = function() { - return "Are you sure?"; + return "Unsaved data will be lost."; }; @@ -558,11 +558,22 @@ replaceSmartClose(); } +$(document).keyup(function(e) { + if (e.keyCode == 27) { // escape key maps to keycode `27` + // close popups + $('#load_topic_div').css("display", "none"); + $('#new_topic_div').css("display", "none"); + $('#load_regex_div').css("display", "none"); + $('#regex_generator').css("display", "none"); + $('#smartRegexPopUpDiv').css("display", "none"); + $('.questionMarkClass').css("display", "none"); + $('.tagItemDivClass').css("display", "none"); + } +}); + $(document).on("click", '#smartRegexShowDiv > span', function (e) { - - $('#smartRegexPopUpDiv').css("display", "block"); $('#smartRegexPopUpDiv').attr("editID", $(this).attr("id"));
--- a/models/extractapp.php Mon Nov 09 12:00:24 2015 +0100 +++ b/models/extractapp.php Wed Nov 11 14:12:55 2015 +0100 @@ -188,9 +188,10 @@ if (isset($_postdata['userId'])) { $this->user_id = $_postdata['userId']; } - if (isset($_postdata['topic_id'])) { - $this->topic = $_postdata['topic_id']; + if (isset($_postdata['topic'])) { + $this->topic = $_postdata['topic']; } + if (isset($_postdata['sectionName'])) { $this->section_name = $_postdata['sectionName']; } @@ -954,12 +955,87 @@ } // === for config topic === - public function ConfigTagsInTopic($postdata) { + public function CreateNewTopic($_postdata) { + $new_topic_id = "2"; // default topic_id=1 for 'person' topic + + // get user input data from postdata + $new_topic_name_en = $_postdata['new_topic_name_en']; + $new_topic_name_ch = $_postdata['new_topic_name_ch']; + $new_topic_name_pi = $_postdata['new_topic_name_pi']; + $new_topic_tag = $_postdata['new_topic_tag']; + $new_topic_tag_name = $_postdata['new_topic_tag_name']; + + // -- Start Transaction -- + mysql_query("BEGIN"); + + // create records for the new topic in database + /* In table: + taglist: name, tag, color (default, user can change later in the editing page) + topics: tag, name_en, name_ch, name_pinyin + topic_tag_relation: topic_id (new), tag_id (new) + + - need transaction for the following actions: + taglist.name: topic_tag name in chinese + taglist.tag: topic_tag name in eng + topics.tag: (the same a taglist.tag) + topics.name_en: + topics.name_ch: + topics.name_pinyin: + + + topic_tag_relation.topic_id = new_topic_id + topic_tag_relation.tag_id = new_tag_id + which are the new record that just been created in the 'taglist' and 'topics' table + */ + + // new record in topics table + $query="INSERT INTO topics (tag, name_en, name_ch, name_pinyin) VALUES ('".$new_topic_tag."','".$new_topic_name_en."','".$new_topic_name_ch."','".$new_topic_name_pi."')"; + $result_topics=mysql_query($query); + if($result_topics){ + $new_topic_id = mysql_insert_id(); + } else { + //echo mysql_error(); + } + + // new record in taglist table + $query="INSERT INTO taglist (name, tag, color, systemName) VALUES ('".$new_topic_tag_name."','".$new_topic_tag."','rgb(255, 0, 174)','interface')"; + $result_taglist=mysql_query($query); + if($result_taglist){ + $new_tag_id = mysql_insert_id(); + } else { + //echo mysql_error(); + } + + // new record in topic_tag_relation + $query="INSERT INTO topic_tag_relation (topic_id, tag_id) VALUES ('".$new_topic_id."','".$new_tag_id."')"; + $result_topic_tag_relation=mysql_query($query); + if($result_topic_tag_relation){ + + } else { + //echo mysql_error(); + } + + + // --- End Transaction --- + if ($result_taglist && $result_topics && $result_topic_tag_relation) { + mysql_query("COMMIT"); + + } else { + mysql_query("ROLLBACK"); + return "error"; + } + + + $_postdata['topic'] = $new_topic_id; + return $_postdata; + } + + public function ConfigTagsInTopic($_postdata) { /** * */ - $topic = $postdata['topic']; + $topic = $_postdata['topic']; $result = $this->GetTopicById($topic); $row = mysql_fetch_assoc($result); $topic_name_en = $row['name_en']; @@ -1046,10 +1122,7 @@ return $data; } - public function CreateNewTopic($_postdata) { - - } public function UpdateTagsInTopic($_postdata) { $topic_id = $_postdata['topic_id'];
--- a/views/Extractapp/ConfigTagsInTopic.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/ConfigTagsInTopic.php Wed Nov 11 14:12:55 2015 +0100 @@ -149,12 +149,17 @@ </tr> <tr> <td></td> - <td><input type="submit" value="Submit" class="btn btn-lg btn-success"></td> + <td align="center" valign="middle"> + <input type="submit" value="Submit" class="btn btn-success"> + </td> <td></td> </tr> </tbody> </table> </form> + <!-- + <input type="button" id="contTagging" value="Continue Tagging" class="btn btn-default"> + --> </div> </body>
--- a/views/Extractapp/EditTaglist.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/EditTaglist.php Wed Nov 11 14:12:55 2015 +0100 @@ -212,7 +212,9 @@ newcolumn.setAttribute("width","50"); if ( color=="Color") { row.appendChild(newcolumn).innerHTML="Delete"; - } else { + } else if (id == topic_tag_id) { + row.appendChild(newcolumn).innerHTML="-"; + } else { row.appendChild(newcolumn).innerHTML="<button onclick=\"DeleteTag("+id+")\">Delete</button>"; }
--- a/views/Extractapp/TaggingText.php Mon Nov 09 12:00:24 2015 +0100 +++ b/views/Extractapp/TaggingText.php Wed Nov 11 14:12:55 2015 +0100 @@ -690,7 +690,7 @@ form.appendChild(hiddenField); var hiddenField = document.createElement("input"); - hiddenField.setAttribute("name", "topic_id"); + hiddenField.setAttribute("name", "topic"); hiddenField.setAttribute("value", topic_id); form.appendChild(hiddenField); @@ -708,40 +708,26 @@ $('#new_topic_div').css("display", "block"); } - - - - // TODO input new topic - /* In table: - taglist: name, tag, color (default, user can change later in the editing page) - topics: tag, name_en, name_ch, name_pinyin - - need transaction for the following actions: - taglist.name: topic_tag name in chinese - taglist.tag: topic_tag name in eng - topics.tag: (the same a taglist.tag) - topics.name_en: - topics.name_ch: - topics.name_pinyin: - add a new record in topic_tag_relation: topic_id, tag_id - */ - - - var newtopic = document.getElementById("newTopicSubmit"); newtopic.onclick = function(){ + // check if all fields are filled in + if ($("#newTopicNameEn").val()==""|| $("#newTopicNameCh").val()=="" || $("#newTopicNamePi").val()=="" || + $("#newTopicTag").val()=="" || $("#newTopicTagName").val()=="") { + alert("Please fill in all the fields for the new topic."); + return; + } + + var form = document.createElement("form"); form.setAttribute("method", "post"); - form.setAttribute("action", "./ConfigTagsInTopic"); // hand to controller - form.setAttribute("target", "_self"); // TODO self here? + form.setAttribute("action", "./TaggingText"); // hand to controller + form.setAttribute("target", "_self"); - // TODO var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "func"); hiddenField.setAttribute("value", "CreateNewTopic"); form.appendChild(hiddenField); - var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "new_topic_name_en"); @@ -764,7 +750,6 @@ hiddenField.setAttribute("value", $("#newTopicTagName").val()); form.appendChild(hiddenField); - _postForContineTagging(form); @@ -845,6 +830,7 @@ } + function _postForContineTagging(form) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "text"); @@ -856,6 +842,10 @@ // pass taglist var hiddenField = document.createElement("input"); hiddenField.setAttribute("name", "taglistArray"); + + // use json_encode($taglistArray), which is the up-to-date taglist (in db) instead, + // so replace the follwoing code + /* var taglistObj = JSON.parse('<?php echo json_encode($taglist_infile) ?>'); // if taglist_infile == "" means the taglist in db is up-to-date, will use taglistArray to save to file @@ -864,6 +854,10 @@ taglistObj = JSON.parse('<?php echo json_encode($taglistArray) ?>'); } taglistArray = JSON.stringify(taglistObj); + */ + + + var taglistArray = JSON.parse('<?php echo json_encode($taglistArray) ?>'); hiddenField.setAttribute("value", taglistArray); form.appendChild(hiddenField); @@ -1018,43 +1012,43 @@ <div class="form-horizontal"> <h4 class="text-info">New topic name:</h4> <div class="form-group form-group-sm"> - <label for="newTopicNameEn" class="col-sm-4 control-label">name (en)</label> - <div class="col-sm-8"> - <input type="text" class="form-control" id="newTopicNameEn" placeholder="name in English"> + <label for="newTopicNameEn" class="col-sm-5 control-label">name (eng)</label> + <div class="col-sm-7"> + <input type="text" class="form-control" id="newTopicNameEn" placeholder="e.g. Local Product"> </div> </div> <div class="form-group form-group-sm"> - <label for="newTopicNameCh" class="col-sm-4 control-label">name (ch)</label> - <div class="col-sm-8"> - <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Chinese"> + <label for="newTopicNameCh" class="col-sm-5 control-label">name (中文)</label> + <div class="col-sm-7"> + <input type="text" class="form-control" id="newTopicNameCh" placeholder="e.g. 物產"> </div> </div> <div class="form-group form-group-sm"> - <label for="newTopicNamePi" class="col-sm-4 control-label">name (pi)</label> - <div class="col-sm-8"> - <input type="text" class="form-control" id="newTopicNameCh" placeholder="name in Pinyin"> + <label for="newTopicNamePi" class="col-sm-5 control-label">name (pinyin)</label> + <div class="col-sm-7"> + <input type="text" class="form-control" id="newTopicNamePi" placeholder="e.g. wu chan"> </div> </div> - <h4 class="text-info">New topic tag:</h4> + <h4 class="text-info">Define the topic tag for the new topic:</h4> <div class="form-group form-group-sm"> - <label for="newTopicTag" class="col-sm-4 control-label">tag (en)</label> - <div class="col-sm-8"> - <input type="text" class="form-control" id="newTopicTag" placeholder="tag in English"> + <label for="newTopicTag" class="col-sm-5 control-label">topic tag (eng)</label> + <div class="col-sm-7"> + <input type="text" class="form-control" id="newTopicTag" placeholder="e.g. product_name"> </div> </div> <div class="form-group form-group-sm"> - <label for="newTopicTagName" class="col-sm-4 control-label">tag (ch)</label> - <div class="col-sm-8"> - <input type="text" class="form-control" id="newTopicTag" placeholder="tag in Chinese"> + <label for="newTopicTagName" class="col-sm-5 control-label">topic tag (中文)</label> + <div class="col-sm-7"> + <input type="text" class="form-control" id="newTopicTagName" placeholder="e.g. 物產名稱"> </div> </div> <div class="form-group form-group-sm"> - <div class="col-sm-offset-4 col-sm-8"> + <div class="col-sm-offset-5 col-sm-7"> <button type="submit" id="newTopicSubmit" class="btn btn-primary btn-xs">Submit</button> <button id="newTopicCancel" class="btn btn-default btn-xs">Cancel</button> </div> @@ -1119,7 +1113,7 @@ <div> Current topic is: <?php echo $topic_name['name_en']; ?> (<?php echo $topic_name['name_ch']; ?>, <?php echo $topic_name['name_pinyin']; ?>) <button onclick="chooseTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Change Topic</button> - <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic (TODO)</button> + <button onclick="createTopic(<?php echo $default_topic_id;?>)" class="btn btn-default btn-block">Create a New Topic</button> </div> </div> </fieldset>