# HG changeset patch # User ymh # Date 1323402836 -3600 # Node ID 1bc0ec8ed05b5c1d72ef15eac1fc08044db7679c # Parent 984ba20c150b0bdb63c51eb825580c6d06dfea40 add relaunch wp diff -r 984ba20c150b -r 1bc0ec8ed05b Controller/WikiTagController.php --- a/Controller/WikiTagController.php Fri Dec 09 02:27:20 2011 +0100 +++ b/Controller/WikiTagController.php Fri Dec 09 04:53:56 2011 +0100 @@ -377,11 +377,7 @@ // Here we are in the context of tag list. if($un_tag_created==true){ $em->flush(); - $num_page = $this->getRequest()->request->get('num_page'); - $nb_by_page = $this->getRequest()->request->get('nb_by_page'); - $sort = $this->getRequest()->request->get('sort'); - $searched = $this->getRequest()->request->get('searched'); - return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); + return $this->renderAllTags(); } else{ // The unsemantized version of the tag already exist, so we send an error. @@ -417,11 +413,7 @@ return $this->renderDocTags($id_doc, $this->getRequest()->request->get('wikitag_document_profile')); } else{ - $num_page = $this->getRequest()->request->get('num_page'); - $nb_by_page = $this->getRequest()->request->get('nb_by_page'); - $sort = $this->getRequest()->request->get('sort'); - $searched = $this->getRequest()->request->get('searched'); - return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); + return $this->renderAllTags(); } } @@ -461,11 +453,7 @@ } else{ // In case we changed the alias from the tag list. - $num_page = $this->getRequest()->request->get('num_page'); - $nb_by_page = $this->getRequest()->request->get('nb_by_page'); - $sort = $this->getRequest()->request->get('sort'); - $searched = $this->getRequest()->request->get('searched'); - return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); + return $this->renderAllTags(); } } @@ -555,16 +543,11 @@ return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); } // We render the tag list. - $num_page = $this->getRequest()->request->get('num_page'); - $nb_by_page = $this->getRequest()->request->get('nb_by_page'); - $sort = $this->getRequest()->request->get('sort'); - $searched = $this->getRequest()->request->get('searched'); - return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); + return $this->renderAllTags(); } /** - * * Resemantize the tag with its original label. Kind of undo if we changed the tag's label. * */ @@ -581,12 +564,29 @@ } // We render the tag list. - $num_page = $this->getRequest()->request->get('num_page'); - $nb_by_page = $this->getRequest()->request->get('nb_by_page'); - $sort = $this->getRequest()->request->get('sort'); - $searched = $this->getRequest()->request->get('searched'); - return $this->renderAllTags($num_page, $nb_by_page, $sort, $searched); + return $this->renderAllTags(); } + + /** + * Redo a Wikipedia search + * @return \Symfony\Component\HttpFoundation\Response|\Symfony\Bundle\FrameworkBundle\Controller\Response + */ + public function relaunchWpSearchAction() + { + $id_tag = $this->getRequest()->request->get('tag_id'); + $tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_tag)); + // We update the tag label and its wikipedia info with the original label. + try { + $this->updateTagWithNewLabel($tag, $tag->getLabel()); + } + catch (\Exception $e){ + return new Response(json_encode(array('error' => 'wikipedia_request_failed', 'message' => $e->getMessage())),400); + } + + // We render the tag list. + return $this->renderAllTags(); + } + /** @@ -595,16 +595,14 @@ private function updateTagWithNewLabel($tag, $label) { if($tag!=null && $label!=null){ - if($label!=$tag->getLabel()){ - // We get the Wikipedia informations for the sent label - $tag_label_normalized = WikiTagUtils::normalizeTag($label); - $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); - $tag->setWikipediaInfo($wp_response); - // Save datas. - $em = $this->getDoctrine()->getEntityManager(); - $em->persist($tag); - $em->flush(); - } + // We get the Wikipedia informations for the sent label + $tag_label_normalized = WikiTagUtils::normalizeTag($label); + $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized); + $tag->setWikipediaInfo($wp_response); + // Save datas. + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($tag); + $em->flush(); } } @@ -612,9 +610,20 @@ /** * Generic render partial template for tag list */ - public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) + public function renderAllTags($num_page=null, $nb_by_page=null, $sort=null, $searched=null) { - + if(is_null($num_page)) { + $num_page = $this->getRequest()->request->get('num_page'); + } + if(is_null($nb_by_page)) { + $nb_by_page = $this->getRequest()->request->get('nb_by_page'); + } + if(is_null($sort)) { + $sort = $this->getRequest()->request->get('sort'); + } + if(is_null($searched)) { + $searched = $this->getRequest()->request->get('searched'); + } //We get the needed datas in an array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); $ar = $this->getAllTags($num_page, $nb_by_page, $sort, $searched); $tags = $ar[0]; @@ -629,7 +638,6 @@ 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"))); } - /** * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) */ diff -r 984ba20c150b -r 1bc0ec8ed05b Resources/config/routing.yml --- a/Resources/config/routing.yml Fri Dec 09 02:27:20 2011 +0100 +++ b/Resources/config/routing.yml Fri Dec 09 04:53:56 2011 +0100 @@ -19,6 +19,9 @@ wikitag_modify_tag_in_list: pattern: /wtmtl defaults: { _controller: WikiTagBundle:WikiTag:modifyTag } +wikitag_relaunch_wp_search: + pattern: /wtrws + defaults: { _controller: WikiTagBundle:WikiTag:relaunchWpSearch } wikitag_reset_wp_info: pattern: /wtrwi defaults: { _controller: WikiTagBundle:WikiTag:resetWpInfo } diff -r 984ba20c150b -r 1bc0ec8ed05b Resources/public/css/wikiTag.css --- a/Resources/public/css/wikiTag.css Fri Dec 09 02:27:20 2011 +0100 +++ b/Resources/public/css/wikiTag.css Fri Dec 09 04:53:56 2011 +0100 @@ -75,10 +75,21 @@ .wikitag_updown_td span { display: none; } +.wikitag_indicator { + cursor: progress; + background-image: url('../images/indicator.gif'); +} + .wikitag_remove_wp_link { cursor: pointer; background-image: url('../images/red_cross.png'); } + +.wikitag_relaunch_wp_search { + cursor : pointer; + background-image: url('../images/arrow_refresh.png'); +} + .wikitag_remove_tag_from_list { cursor: pointer; background-image: url('../images/tag_remove.png'); diff -r 984ba20c150b -r 1bc0ec8ed05b Resources/public/js/wikiTag.js --- a/Resources/public/js/wikiTag.js Fri Dec 09 02:27:20 2011 +0100 +++ b/Resources/public/js/wikiTag.js Fri Dec 09 04:53:56 2011 +0100 @@ -4,17 +4,27 @@ // Tag simple operations : activate/unactivate wp link, reset wp info, remove wp link, remove tag from list $(".wikitag_reset_wp_info").click(function(e){ if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){ - wikitag_update_tag(this); + var id_tag = $(this).html(); + var btn = this; + $(this).html(""); + wikitag_update_tag(this, reset_wp_info_url, id_tag, function(){ $(btn).html(id_tag); }); + } + }); + $(".wikitag_relaunch_wp_search").click(function(e){ + if(confirm("Confirmez-vous la relance de la recherche Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?")){ + $(this).toggleClass("wikitag_relaunch_wp_search wikitag_indicator"); + var btn = this; + wikitag_update_tag(this, relaunch_wp_search_url, $(this).attr('id'), function() { $(btn).toggleClass("wikitag_relaunch_wp_search wikitag_indicator");}); } }); $(".wikitag_remove_wp_link").click(function(e){ if(confirm("Confirmez-vous le suppression du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?")){ - wikitag_update_tag(this); + wikitag_update_tag(this, remove_wp_link_url, $(this).attr('id')); } }); $(".wikitag_remove_tag_from_list").click(function(){ if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){ - wikitag_update_tag(this); + wikitag_update_tag(this,remove_tag_from_list_url,$(this).attr('id')); } }); @@ -316,23 +326,9 @@ }); } -function wikitag_update_tag(btn) +function wikitag_update_tag(btn, url, id_tag, error_callback) { new_checked = false; - if ($(btn).is(".wikitag_remove_tag_from_list")) { - var url = remove_tag_from_list_url; - var id_tag = $(btn).attr('id'); - } - else if ($(btn).is(".wikitag_reset_wp_info")) { - var url = reset_wp_info_url; - var id_tag = $(btn).html(); - $(btn).html(""); - } - else if ($(btn).is(".wikitag_remove_wp_link")) { - var url = remove_wp_link_url; - var id_tag = $(btn).attr('id'); - } - // 2 cases : // - ordered tag for one datasheet : $('#wikitag_document_id') is not null // - all tags list : $('#wikitag_document_id') is null and $('#num_page') and $('#nb_by_page') are not null @@ -358,7 +354,7 @@ error: function(jqXHR, textStatus, errorThrown) { resp = $.parseJSON(jqXHR.responseText); alert(resp.message); - $(btn).html(id_tag); + error_callback && error_callback(); } }); } diff -r 984ba20c150b -r 1bc0ec8ed05b Resources/views/WikiTag/TagListTable.html.twig --- a/Resources/views/WikiTag/TagListTable.html.twig Fri Dec 09 02:27:20 2011 +0100 +++ b/Resources/views/WikiTag/TagListTable.html.twig Fri Dec 09 04:53:56 2011 +0100 @@ -69,12 +69,14 @@   {% endif %} - {% if tag.category %}{{ tag.category.label }}{% endif %} - {% if tag.urlstatus and tag.urlstatus != 4 and tag.urlstatus != 0 %} - - {% else %} + {% if tag.category %}{{ tag.category.label }}{% endif %} + {% if not tag.urlstatus or tag.urlstatus == 0 %} + + {% elseif tag.urlstatus == 4 %} - % endif %} + {% else %} + + {% endif %} {% if tag.alias %}{{tag.alias}}{% endif %} {% if nb_docs > 0 %} diff -r 984ba20c150b -r 1bc0ec8ed05b Resources/views/WikiTag/javascript.html.twig --- a/Resources/views/WikiTag/javascript.html.twig Fri Dec 09 02:27:20 2011 +0100 +++ b/Resources/views/WikiTag/javascript.html.twig Fri Dec 09 04:53:56 2011 +0100 @@ -22,6 +22,7 @@ var modify_tag_url = "{{ url('wikitag_modify_documenttag') }}"; {% endif %} var reset_wp_info_url = "{{ url('wikitag_reset_wp_info') }}"; + var relaunch_wp_search_url = "{{ url('wikitag_relaunch_wp_search') }}"; var reorder_tag_datasheet_url = "{{ url('wikitag_reorder_tag_document') }}"; var add_tag_url = "{{ url('wikitag_add_tag') }}"; var remove_wp_link_url = "{{ url('wikitag_remove_wp_link') }}";