Changeset 29053


Ignore:
Timestamp:
Jul 17, 2014, 9:06:05 PM (10 years ago)
Author:
rvelices
Message:

rating user improvements: faster javascript, by default sorted by last rate date, better tooltips ...

Location:
trunk/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/rating_user.php

    r26900 r29053  
    9494    $rating['uid'] = (int)$row['user_id'];
    9595    $rating['aid'] = $usr['anon'] ? $row['anonymous_id'] : '';
    96     $rating['last_date'] = $row['date'];
    97   }
     96    $rating['last_date'] = $rating['first_date'] = $row['date'];
     97  }
     98  else
     99    $rating['first_date'] = $row['date'];
     100
    98101  $rating['rates'][$row['rate']][] = array(
    99102    'id' => $row['element_id'],
     
    108111if (count($image_ids) > 0 )
    109112{
    110   $query = 'SELECT id, name, file, path, representative_ext
     113  $query = 'SELECT id, name, file, path, representative_ext, level
    111114  FROM '.IMAGES_TABLE.'
    112115  WHERE id IN ('.implode(',', array_keys($image_ids)).')';
    113116  $result = pwg_query($query);
     117  $params = ImageStdParams::get_by_type(IMG_SQUARE);
    114118  while ($row = pwg_db_fetch_assoc($result))
    115119  {
    116120    $image_urls[ $row['id'] ] = array(
    117       'tn' => DerivativeImage::thumb_url($row),
     121      'tn' => DerivativeImage::url($params, $row),
    118122      'page' => make_picture_url( array('image_id'=>$row['id'], 'image_file'=>$row['file']) ),
    119123    );
     
    172176    'cv'  => $s==0 ? -1 : sqrt($var)/($s/$c), // http://en.wikipedia.org/wiki/Coefficient_of_variation
    173177    'cd'  => $consensus_dev,
    174     'cdtop'  => $consensus_dev_top_count ? $consensus_dev_top : ''
     178    'cdtop'  => $consensus_dev_top_count ? $consensus_dev_top : '',
    175179  );
    176180}
     
    211215}
    212216
    213 $order_by_index=3;
     217function last_rate_compare($a, $b)
     218{
     219  return -strcmp( $a['last_date'], $b['last_date']);
     220}
     221
     222$order_by_index=4;
    214223if (isset($_GET['order_by']) and is_numeric($_GET['order_by']))
    215224{
     
    222231    array(l10n('Variation'), 'cv_compare'),
    223232    array(l10n('Consensus deviation'), 'consensus_dev_compare'),
     233    array(l10n('Last'), 'last_rate_compare'),
    224234  );
    225235
     
    242252  'ratings' => $by_user_ratings,
    243253  'image_urls' => $image_urls,
    244   'TN_WIDTH' => 28+2*ImageStdParams::get_by_type(IMG_THUMB)->sizing->ideal_size[0],
     254  'TN_WIDTH' => ImageStdParams::get_by_type(IMG_SQUARE)->sizing->ideal_size[0],
    245255  ) );
    246256$template->set_filename('rating', 'rating_user.tpl');
  • trunk/admin/themes/default/template/rating_user.tpl

    r26941 r29053  
    1313.dtBar {
    1414        text-align:left;
    15         padding-left: 20px;
    16 }
     15        padding: 10px 0 10px 20px
     16}
     17.dtBar DIV{
     18        display:inline;
     19        padding-right: 5px;
     20}
     21
     22.dataTables_paginate A {
     23        padding-left: 3px;
     24}
     25
     26.ui-tooltip {
     27        padding: 8px;
     28        position: absolute;
     29        z-index: 9999;
     30        max-width: {3*$TN_WIDTH}px;
     31        -webkit-box-shadow: 0 0 5px #aaa;
     32        box-shadow: 0 0 5px #aaa;
     33}
     34body .ui-tooltip {
     35        border-width: 2px;
     36}
     37
    1738{/html_style}
    1839
     
    4364
    4465{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'}
     66{combine_script id='jquery.geoip' load='async' path='admin/themes/default/js/jquery.geoip.js'}
    4567{footer_script}
    4668var oTable = jQuery('#rateTable').dataTable({
    47         sDom : '<"dtBar"f>rt',
    48         bPaginate: false,
    49         aaSorting: [[5,'desc']],
     69        sDom : '<"dtBar"filp>rt<"dtBar"ilp>',
     70        iDisplayLength: 100,
     71        aLengthMenu: [ [25, 50, 100, 500, -1], [25, 50, 100, 500, "All"]],
     72        aaSorting: [], //[[1,'desc']],
     73        bAutoWidth: false,
     74        bSortClasses: false,
    5075        aoColumnDefs: [
    51                 /*{
    52                         aTargets: ["dtc_user"]
    53                 },*/
     76                {
     77                        aTargets: ["dtc_user"],
     78                        sType: "string",
     79                        sClass: null
     80                },
    5481                {
    5582                        aTargets: ["dtc_date"],
    56                         asSorting: ["desc","asc"]
     83                        asSorting: ["desc","asc"],
     84                        sType: "string",
     85                        sClass: null
    5786                },
    5887                {
    5988                        aTargets: ["dtc_stat"],
    6089                        asSorting: ["desc","asc"],
    61                         bSearchable: false
     90                        bSearchable: false,
     91                        sType: "numeric",
     92                        sClass: null
    6293                },
    6394                {
    6495                        aTargets: ["dtc_rate"],
    6596                        asSorting: ["desc","asc"],
    66                         bSearchable: false
     97                        bSearchable: false,
     98                        sType: "html",
     99                        sClass: null
    67100                },
    68101                {
    69102                        aTargets: ["dtc_del"],
    70103                        bSortable: false,
    71                         bSearchable: false
     104                        bSearchable: false,
     105                        sType: "string",
     106                        sClass: null
    72107                }
    73108        ]
    74109});
    75110
    76 function del(elt,uid,aid){
    77         if (!confirm('{'Are you sure?'|@translate|@escape:'javascript'}'))
    78                 return false;
    79         var tr = elt;
     111
     112function uidFromCell(cell){
     113        var tr = cell;
    80114        while ( tr.nodeName != "TR") tr = tr.parentNode;
    81         tr = jQuery(tr).fadeTo(1000, 0.4);
    82 
    83         (new PwgWS('{$ROOT_URL|@escape:javascript}')).callService(
    84                 'pwg.rates.delete', { user_id:uid, anonymous_id:aid},
    85                 {
    86                         method: 'POST',
    87                         onFailure: function(num, text) { tr.stop(); tr.fadeTo(0,1); alert(num + " " + text); },
    88                         onSuccess: function(result){
    89                                 if (result)
    90                                         oTable.fnDeleteRow(tr[0]);
    91                                 else
    92                                         alert(result);
     115        return $(tr).data("usr");
     116}
     117
     118{* -----DELETE----- *}
     119$(document).ready( function(){
     120        $("#rateTable").on( "click", ".del", function(e) {
     121                e.preventDefault();
     122                if (!confirm('{'Are you sure?'|@translate|@escape:'javascript'}'))
     123                        return;
     124                var cell = e.target.parentNode,
     125                        tr = cell;
     126                while ( tr.nodeName != "TR") tr = tr.parentNode;
     127                tr = jQuery(tr).fadeTo(1000, 0.4);
     128
     129                var data=uidFromCell(cell);
     130               
     131                (new PwgWS('{$ROOT_URL|@escape:javascript}')).callService(
     132                        'pwg.rates.delete', { user_id:data.uid, anonymous_id:data.aid},
     133                        {
     134                                method: 'POST',
     135                                onFailure: function(num, text) { tr.stop(); tr.fadeTo(0,1); alert(num + " " + text); },
     136                                onSuccess: function(result){
     137                                        if (result)
     138                                                oTable.fnDeleteRow(tr[0]);
     139                                        else
     140                                                alert(result);
     141                                }
    93142                        }
    94                 }
    95         );
    96        
    97         return false;
    98 }
     143                );
     144
     145        });
     146});
     147
    99148{/footer_script}
    100149<table id="rateTable">
    101150<thead>
    102151<tr class="throw">
    103         <td class="dtc_user">{'Username'|@translate}</td>
    104         <td class="dtc_date">{'Last'|@translate}</td>
    105         <td class="dtc_stat">{'Number of rates'|@translate}</td>
    106         <td class="dtc_stat">{'Average rate'|@translate}</td>
    107         <td class="dtc_stat">{'Variation'|@translate}</td>
    108         <td class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'}</td>
    109         <td class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'} {$CONSENSUS_TOP_NUMBER}</td>
     152        <th class="dtc_user">{'Username'|@translate}</th>
     153        <th class="dtc_date">{'Last'|@translate}</th>
     154        <th class="dtc_stat">{'Number of rates'|@translate}</th>
     155        <th class="dtc_stat">{'Average rate'|@translate}</th>
     156        <th class="dtc_stat">{'Variation'|@translate}</th>
     157        <th class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'}</th>
     158        <th class="dtc_stat">{'Consensus deviation'|@translate|@replace:' ':'<br>'} {$CONSENSUS_TOP_NUMBER}</th>
    110159{foreach from=$available_rates item=rate}
    111         <td class="dtc_rate">{$rate}</td>
     160        <th class="dtc_rate">{$rate}</th>
    112161{/foreach}
    113         <td class="dtc_del"></td>
     162        <th class="dtc_del"></th>
    114163</tr>
    115164</thead>
    116165{foreach from=$ratings item=rating key=user}
    117 <tr>
    118         <td>{$user}</td>
    119         <td>{$rating.last_date}</td>
    120         <td>{$rating.count}</td>
    121         <td>{$rating.avg|@number_format:2}</td>
    122         <td>{$rating.cv|@number_format:3}</td>
    123         <td>{$rating.cd|@number_format:3}</td>
    124         <td>{if !empty($rating.cdtop)}{$rating.cdtop|@number_format:3}{/if}</td>
    125         {foreach from=$rating.rates item=rates key=rate}
    126         <td>{if !empty($rates)}
    127                 {capture assign=rate_over}{foreach from=$rates item=rate_arr}<img src="{$image_urls[$rate_arr.id].tn}" alt="thumb-{$rate_arr.id}" title="{$rate_arr.date}"></img>
    128                 {/foreach}{/capture}
    129                 <a class="cluetip" title="|{$rate_over|@htmlspecialchars}">{$rates|@count}</a>
    130                 {/if}</td>
    131         {/foreach}
    132         <td><a onclick="return del(this,{$rating.uid},'{$rating.aid}');" class="icon-trash"></a></td>
     166<tr data-usr='{ldelim}"uid":{$rating.uid},"aid":"{$rating.aid}"}'>
     167{strip}
     168<td class=usr>{$user}</td><td title="First: {$rating.first_date}">{$rating.last_date}</td>
     169<td>{$rating.count}</td><td>{$rating.avg|@number_format:2}</td>
     170<td>{$rating.cv|@number_format:3}</td><td>{$rating.cd|@number_format:3}</td><td>{if !empty($rating.cdtop)}{$rating.cdtop|@number_format:3}{/if}</td>
     171{foreach from=$rating.rates item=rates key=rate}
     172<td>{if !empty($rates)}
     173{capture assign=rate_over}{foreach $rates as $rate_arr}{if $rate_arr@index>29}{break}{/if}<img src="{$image_urls[$rate_arr.id].tn}" alt="thumb-{$rate_arr.id}" width="{$TN_WIDTH}" height="{$TN_WIDTH}">{/foreach}{/capture}
     174<a title="{$rate_over|@htmlspecialchars}">{$rates|@count}</a>
     175{/if}</td>
     176{/foreach}
     177<td><a class="del icon-trash"></a></td>
    133178</tr>
     179{/strip}
    134180{/foreach}
    135181</table>
    136182
    137 {combine_script id='jquery.cluetip' load='footer' require='jquery' path='themes/default/js/plugins/jquery.cluetip.js'}
    138 {footer_script require='jquery.cluetip'}
    139 jQuery(document).ready(function(){ldelim}
    140         jQuery('.cluetip').cluetip({ldelim}
    141                 width: {$TN_WIDTH}, showTitle:false, splitTitle: '|'
     183{combine_script id='jquery.ui.tooltip' load='footer'}
     184{footer_script require='jquery.ui.tooltip'}
     185jQuery(document).ready(function(){
     186        jQuery("#rateTable").tooltip({
     187                items: ".usr,[title]",
     188                content: function(callback) {
     189                        var t = $(this).attr("title");
     190                        if (t)
     191                                return t;
     192                        var that = $(this),
     193                                udata = uidFromCell(this);
     194                        if (!udata.aid)
     195                                return;
     196                        that
     197                                .data("isOver", true)
     198                                .one("mouseleave", function() {
     199                                        that.removeData("isOver");
     200                                });
     201
     202                        GeoIp.get( udata.aid + ".1", function(data) {
     203                                if (!data.fullName) return;
     204                                var content = data.fullName;
     205                                if (data.latitude && data.region_name) {
     206                                        content += "<br><img width=300 height=220 src=\"http://maps.googleapis.com/maps/api/staticmap?sensor=false&size=300x220&zoom=6"
     207                                                + "&markers=size:tiny%7C" + data.latitude + "," + data.longitude
     208                                                + "\">";
     209                                }
     210                                if (that.data("isOver"))
     211                                        callback(content);
     212                        });
     213                }
    142214        });
    143215})
Note: See TracChangeset for help on using the changeset viewer.