# HG changeset patch # User cavaliet # Date 1319474734 -7200 # Node ID 5f038a505cd7ffa0e5393fa98d985b6ed160745f # Parent a1234ceba9127133a53a4865e9f7d0e23fcaabfe Debug Category on tag list and document. Finish pagination for tag list. diff -r a1234ceba912 -r 5f038a505cd7 Controller/WikiTagController.php --- a/Controller/WikiTagController.php Fri Oct 21 19:22:06 2011 +0200 +++ b/Controller/WikiTagController.php Mon Oct 24 18:45:34 2011 +0200 @@ -142,7 +142,7 @@ $tag_label = $this->getRequest()->request->get('value'); $id_moved_tag = $this->getRequest()->request->get('id'); $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag)); - if($tagLabel!=$movedTag->getLabel()){ + if($tag_label!=$moved_tag->getLabel()){ // We get the DocumentTags $em = $this->getDoctrine()->getEntityManager(); $tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findBy(array('document' => $id_doc)); @@ -166,7 +166,7 @@ $revision_id = $ar[1]; $created = $ar[2]; // We get the DocumentTag and change its tag - $dt = $this->getDoctrine()->getRepository('WikiTagBundle:WikiTagDocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag)); + $dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneBy(array('document' => $id_doc, 'tag' => $id_moved_tag)); $dt->setTag($tag); $dt->setWikipediaRevisionId($revision_id); // @@ -313,7 +313,16 @@ } $em->flush(); - return $this->renderDocTags($id_doc); + if($id_doc && $id_doc!=""){ + return $this->renderDocTags($id_doc); + } + 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); + } } @@ -359,10 +368,9 @@ */ public function allTagsAction() { - // We get/set all the parameters for the search and pagination. // $this->getRequest()->query->get('foo') does not work "because" we are a second controller. So we have to use $_GET. - // Searched string - $searched = ""; + // Searched string + $searched = NULL; if(array_key_exists('searched', $_GET)){ $searched = $_GET['searched']; } @@ -376,6 +384,91 @@ if(array_key_exists('num_page', $_GET)){ $num_page = intval($_GET['num_page']); } + // Sorting criteria + $sort = NULL; + if(array_key_exists('sort', $_GET)){ + $sort = $_GET['sort']; + } + + // 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]; + $num_page = $ar[1]; + $nb_by_page = $ar[2]; + $searched = $ar[3]; + $sort = $ar[4]; + $reverse_sort = $ar[5]; + $pagerfanta = $ar[6]; + + // We get the needed vars : number totals of tags, previous and next page number + $last_page = $pagerfanta->getNbPages(); + $nb_total = $pagerfanta->getNbResults(); + $prev_page = 1; + if($pagerfanta->hasPreviousPage()){ + $prev_page = $pagerfanta->getPreviousPage(); + } + $next_page = $last_page; + if($pagerfanta->hasNextPage()){ + $next_page = $pagerfanta->getNextPage(); + } + // We calculate start_index and end_index (number of tags in the whole list) + $start_index = 1 + (($num_page - 1) * $nb_by_page); + $end_index = min($nb_total, $start_index + $nb_by_page - 1); + + // We build the list of tags's first letters to make quick search. + $conn = $this->getDoctrine()->getEntityManager()->getConnection(); + $sql = "SELECT UPPER(SUBSTRING(normalized_label,1,1)) as fl FROM wikitag_tag GROUP BY fl ORDER BY fl"; + $letters = $conn->query($sql)->fetchAll(); + $search_def = array(); + foreach ($letters as $l){ + $search_def[$l[0]] = $l[0].WikiTagController::$SEARCH_STAR_CHARACTER; + } + + return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', + array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, + 'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, + 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort)); + } + + + /** + * Generic render partial template for tag list + */ + public function renderAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) + { + // 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]; + $num_page = $ar[1]; + $nb_by_page = $ar[2]; + $searched = $ar[3]; + $sort = $ar[4]; + $reverse_sort = $ar[5]; + //$pagerfanta = $ar[6]; + + return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig', + array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page, 'reverse_sort' => $reverse_sort)); + } + + + /** + * Generic to get all tags with the context (pagination number, nb by page, searched string, sort) + */ + private function getAllTags($num_page=NULL, $nb_by_page=NULL, $sort=NULL, $searched=NULL) + { + // We get/set all the parameters for the search and pagination. + // Searched string + if($searched==NULL){ + $searched = ""; + } + // Number of tags per page + if($nb_by_page==NULL){ + $nb_by_page = 50; + } + // Current page number + if($num_page==NULL){ + $num_page = 1; + } // We build the query. $qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder(); @@ -386,10 +479,9 @@ $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("*", "%", $searched)."'"))); } // We add the sorting criteria - $sort = "popd"; // sort by descendent popularity by default. - $reverse_sort = "popa"; - if(array_key_exists('sort', $_GET)){ - $sort = $_GET['sort']; + if($sort==NULL){ + $sort = "popd"; // sort by descendent popularity by default. + $reverse_sort = "popa"; } $sort_query = "t.popularity DESC t.normalizedLabel ASC t.label ASC"; switch($sort){ @@ -421,38 +513,13 @@ $adapter = new DoctrineORMAdapter($qb); $pagerfanta = new Pagerfanta($adapter); $pagerfanta->setMaxPerPage($nb_by_page); // 10 by default - $last_page = $pagerfanta->getNbPages(); + //$last_page = $pagerfanta->getNbPages(); $pagerfanta->setCurrentPage($num_page); // 1 by default $nb_total = $pagerfanta->getNbResults(); $tags = $pagerfanta->getCurrentPageResults(); $pagerfanta->haveToPaginate(); // whether the number of results if higher than the max per page - // We get the previous and next page number - $prev_page = 1; - if($pagerfanta->hasPreviousPage()){ - $prev_page = $pagerfanta->getPreviousPage(); - } - $next_page = $last_page; - if($pagerfanta->hasNextPage()){ - $next_page = $pagerfanta->getNextPage(); - } - // We calculate start_index and end_index (tag number in the whole list) - $start_index = 1 + (($num_page - 1) * $nb_by_page); - $end_index = min($nb_total, $start_index + $nb_by_page - 1); - - // We build the list of tags's first letters to make quick search. - $conn = $this->getDoctrine()->getEntityManager()->getConnection(); - $sql = "SELECT UPPER(SUBSTRING(normalized_label,1,1)) as fl FROM wikitag_tag GROUP BY fl ORDER BY fl"; - $letters = $conn->query($sql)->fetchAll(); - $search_def = array(); - foreach ($letters as $l){ - $search_def[$l[0]] = $l[0].WikiTagController::$SEARCH_STAR_CHARACTER; - } - - return $this->render('WikiTagBundle:WikiTag:TagList.html.twig', - array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort, - 'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page, - 'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort)); + return array($tags, $num_page, $nb_by_page, $searched, $sort, $reverse_sort, $pagerfanta); } diff -r a1234ceba912 -r 5f038a505cd7 Model/Tag.php --- a/Model/Tag.php Fri Oct 21 19:22:06 2011 +0200 +++ b/Model/Tag.php Mon Oct 24 18:45:34 2011 +0200 @@ -302,5 +302,14 @@ return $this->category; } + /** + * Set category to Null + * + */ + function nullCategory() + { + return $this->setCategory(NULL); + } + } \ No newline at end of file diff -r a1234ceba912 -r 5f038a505cd7 Resources/public/css/wikiTag.css --- a/Resources/public/css/wikiTag.css Fri Oct 21 19:22:06 2011 +0200 +++ b/Resources/public/css/wikiTag.css Mon Oct 24 18:45:34 2011 +0200 @@ -20,10 +20,10 @@ width: 25px; } tr.wikitag_oddline { - background: #d8d8d8; + background: white; } tr.wikitag_evenline { - background: white; + background: #d8d8d8; } tr.wikitag_oddline:hover, tr.wikitag_evenline:hover { background: lightblue; @@ -76,14 +76,18 @@ display: inline; } + +/* Styles for all tags list table */ +#wikitag_alltags_table { + min-width: 600px; + border-spacing: 0px; +} +#wikitag_alltags_table td, th { + padding: 3px; +} + /* -tr.wikitag_simpleoddline { - background: #e4e4e4; -} -tr.wikitag_simpleevenline { - background: white; -} #count_nav_top, #count_nav_bottom { @@ -96,16 +100,4 @@ } - -#all_tags_table { - min-width: 600px; - border-spacing: 0px; -} -#all_tags_table td, th { - padding: 3px; -} - - - - */ diff -r a1234ceba912 -r 5f038a505cd7 Resources/public/js/wikiTag.js --- a/Resources/public/js/wikiTag.js Fri Oct 21 19:22:06 2011 +0200 +++ b/Resources/public/js/wikiTag.js Mon Oct 24 18:45:34 2011 +0200 @@ -111,10 +111,10 @@ submitdata: { csrfmiddlewaretoken:global_csrf_token, wikitag_document_id:$('#wikitag_document_id').val(), - num_page:$('#num_page').val(), - nb_by_page:$('#nb_by_page').val(), - sort:$('#sort').val(), - searched:$('#searched_str').val() + num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined), + nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined), + sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined), + searched:(('searched' in getUrlVars()) ? getUrlVars()['searched'] : undefined) }, callback : function(value, settings) { $('#wikitag_table_container').html(value); @@ -122,6 +122,13 @@ } }); + /* + + num_page:$('#num_page').val(), + nb_by_page:$('#nb_by_page').val(), + sort:$('#sort').val(), + searched:$('#searched_str').val() + */ // Tag table drag and drop $("#wikitag_table").tableDnD({ onDragClass: "wikitag_dragged_row", @@ -212,28 +219,6 @@ reorder_tags(); } }); - /* - // Validate sheet management : the radiobutton name has is "'gr_validated' + datasheet.hda_id" - $("#validated").click(function(e){ - e.preventDefault(); - // We count the number of tags. It has to be between 5 and 25 - var nb_tags = $('#tag_table tr').length - 1; - if(nb_tags<5 || nb_tags>25){ - alert("Cette fiche n'est pas validable : elle doit contenir entre 5 et 25 tags."); - } - else{ - if(confirm("Confirmez-vous la validation de cette fiche ? Elle contient " + nb_tags + " tags.")){ - window.location = validate_datasheet_url + "/" + $('#wikitag_document_id').val() + "/true"; - } - } - }); - $("#not_validated").click(function(e){ - e.preventDefault(); - if(confirm("Confirmez-vous l'invalidation de cette fiche ?")){ - window.location = validate_datasheet_url + "/" + $('#wikitag_document_id').val() + "/false"; - } - }); - */ } function wikitag_update_tag(btn) @@ -366,3 +351,17 @@ }); } +function getUrlVars() +{ + var vars = [], hash; + if(window.location.href.indexOf('?')>=0){ + var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + for(var i = 0; i < hashes.length; i++) + { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + } + return vars; +} diff -r a1234ceba912 -r 5f038a505cd7 Resources/views/WikiTag/TagList.html.twig --- a/Resources/views/WikiTag/TagList.html.twig Fri Oct 21 19:22:06 2011 +0200 +++ b/Resources/views/WikiTag/TagList.html.twig Mon Oct 24 18:45:34 2011 +0200 @@ -25,7 +25,7 @@ #} -
+
{% include "WikiTagBundle:WikiTag:TagListTable.html.twig" %}

diff -r a1234ceba912 -r 5f038a505cd7 Resources/views/WikiTag/TagListTable.html.twig --- a/Resources/views/WikiTag/TagListTable.html.twig Fri Oct 21 19:22:06 2011 +0200 +++ b/Resources/views/WikiTag/TagListTable.html.twig Mon Oct 24 18:45:34 2011 +0200 @@ -1,5 +1,5 @@ {% block tag_table %} - +
id {% if sort != "laba" and sort != "labd" %}