Changeset 1745

Show
Ignore:
Timestamp:
05/18/08 20:44:40 (8 months ago)
Author:
dmondark
Message:

Committing patch supplied to #262. Thanks bjohnson.

Location:
trunk/htdocs/system
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/admin/comments.php

    r1722 r1745  
    1111        <div class="years"> 
    1212            <div class="months"> 
    13                 <?php foreach($monthcomments as $cdata): ?> 
    14                 <div><span style="width: <?php echo $cdata->ct; ?>px"><?php echo date('M', mktime(0, 0, 0, $cdata->month)) ?></span></div> 
    15                 <?php endforeach; ?> 
     13                <?php $theme->display( 'timeline_items' )?> 
    1614            </div> 
    1715        </div> 
     
    8381    $.post( 
    8482        '<?php echo URL::get('admin_ajax', array('context' => 'comments')) ?>', 
    85         'do_search=1&search=' + liveSearch.input.val() + 
    86         <?php 
    87                 $vars= Controller::get_handler_vars(); 
    88                 $out= ''; 
    89                 $keys= array_keys($vars); 
    90                 foreach($keys as $key) { 
    91                     $out .= "&$key=$vars[$key]"; 
    92                 } 
    93                 echo '"' . $out . '"'; 
    94             ?>, 
     83        '&search=' + liveSearch.input.val() + '&limit=20', 
    9584        function(json) { 
    9685            $('#comments').html(json.items); 
     86            $('.years .months').html(json.timeline); 
    9787            spinner.stop(); 
    9888            itemManage.initItems(); 
     89            timeline.reset(); 
    9990            $('.modulecore .item:first-child, ul li:first-child').addClass('first-child').show(); 
    10091            $('.modulecore .item:last-child, ul li:last-child').addClass('last-child'); 
     
    10798    spinner.start(); 
    10899 
     100    var search_args= $('.search input').val(); 
     101 
    109102    $.ajax({ 
    110         type: "POST", 
     103        type: 'POST', 
    111104        url: "<?php echo URL::get('admin_ajax', array('context' => 'comments')); ?>", 
    112         data: "offset=" + (parseInt(c) - parseInt(b)) + "&limit=" + (1 + parseInt(b) - parseInt(a)) + 
    113             <?php 
    114                 $vars= Controller::get_handler_vars(); 
    115                 $out= ''; 
    116                 $keys= array_keys($vars); 
    117                 foreach($keys as $key) { 
    118                     $out .= "&$key=$vars[$key]"; 
    119                 } 
    120                 echo '"' . $out . '"'; 
    121             ?>, 
     105        data: 'offset=' + (parseInt(c) - parseInt(b)) + '&limit=' + (1 + parseInt(b) - parseInt(a)) + '&search=' + search_args, 
    122106        dataType: 'json', 
    123107        success: function(json){ 
  • trunk/htdocs/system/admin/entries.php

    r1722 r1745  
    1212        <div class="years"> 
    1313            <div class="months"> 
    14                 <?php foreach($monthposts as $pdata): ?> 
    15                 <div><span style="width: <?php echo $pdata->ct; ?>px"><?php echo date('M', mktime(0, 0, 0, $pdata->month)) ?></span></div> 
    16                 <?php endforeach; ?> 
     14                <?php $theme->display( 'timeline_items' )?> 
    1715            </div> 
    1816        </div> 
     
    6159    $.post( 
    6260        '<?php echo URL::get('admin_ajax', array('context' => 'entries')) ?>', 
    63         'do_search=1&search=' + liveSearch.input.val() + 
    64         <?php 
    65                 $vars= Controller::get_handler_vars(); 
    66                 $out= ''; 
    67                 $keys= array_keys($vars); 
    68                 foreach($keys as $key) { 
    69                     $out .= "&$key=$vars[$key]"; 
    70                 } 
    71                 echo '"' . $out . '"'; 
    72             ?>, 
     61        '&search=' + liveSearch.input.val() + '&limit=20', 
    7362        function(json) { 
    7463            $('.entries').html(json.items); 
     64            $('.years .months').html(json.timeline); 
    7565            spinner.stop(); 
    7666            itemManage.initItems(); 
     67            timeline.reset(); 
    7768            $('.modulecore .item:first-child, ul li:first-child').addClass('first-child').show(); 
    7869            $('.modulecore .item:last-child, ul li:last-child').addClass('last-child'); 
     
    8475timelineHandle.loupeUpdate = function(a,b,c) { 
    8576    spinner.start(); 
     77     
     78    var search_args= $('.search input').val(); 
    8679 
    8780    $.ajax({ 
    88         type: "POST", 
     81        type: 'POST', 
    8982        url: "<?php echo URL::get('admin_ajax', array('context' => 'entries')); ?>", 
    90         data: "offset=" + (parseInt(c) - parseInt(b)) + "&limit=" + (1 + parseInt(b) - parseInt(a)) + 
    91             <?php 
    92                 $vars= Controller::get_handler_vars(); 
    93                 $out= ''; 
    94                 $keys= array_keys($vars); 
    95                 foreach($keys as $key) { 
    96                     $out .= "&$key=$vars[$key]"; 
    97                 } 
    98                 echo '"' . $out . '"'; 
    99             ?>, 
     83        data: 'offset=' + (parseInt(c) - parseInt(b)) + '&limit=' + (1 + parseInt(b) - parseInt(a)) + '&search=' + search_args, 
    10084        dataType: 'json', 
    10185        success: function(json){ 
  • trunk/htdocs/system/admin/js/admin.js

    r1722 r1745  
    191191        }); 
    192192 
    193         // if there are fewer than 20 things, set the handle width to the timelineWidth 
    194         var minWidth= ( timelineWidth < 20 ) ? timelineWidth : 20; 
     193        // find the width which makes the loupe select 20 items 
     194        var minWidth= timelineWidth - timeline.positionFromIndex( timeline.totalCount - 20 ); 
     195 
     196        /* Initialize the timeline handle. We need to do this before we create the slider because 
     197         * at the end of the slider initializer, it calls slider('moveTo', startValue) which will 
     198         * trigger the 'stop' event. We also don't need to do a search on initial page load, so 
     199         * set do_search to false until after slider initialization */ 
     200        timelineHandle.init( minWidth ); 
     201        timeline.do_search= false; 
    195202 
    196203        $('.track') 
     
    198205        .slider({ 
    199206            handle: '.handle', 
    200             maxValue: timelineWidth - minWidth, 
     207            maxValue: Math.max( 1, timelineWidth - minWidth ), 
    201208            startValue: timelineWidth - minWidth, 
    202209            axis: 'horizontal', 
     
    224231            else 
    225232                timeline.t1 = setTimeout('timeline.skipLoupeRight()', 300); 
    226         }); 
    227          
    228         // update current position text 
    229         loupeStartPosition = timeline.indexFromPosition( parseInt($('.handle').css('left')) ); 
    230         $('.currentposition').text( loupeStartPosition +'-'+ timeline.totalCount +' of '+ timeline.totalCount ); 
    231          
    232         // Spool the timeline handle 
    233         timelineHandle.init( ( timelineWidth < 20 ) ? timelineWidth : 20 ); 
     233        }) 
     234        .slider( 'moveTo', timelineWidth - minWidth ); // a bug in the jQuery code requires us to explicitly do this in the case that startValue == 0 
     235 
     236        // update the do_search state variable 
     237        timeline.do_search= true; 
    234238    }, 
    235239    skipLoupeLeft: function(e) { 
     
    274278        padding= padding ? padding : 0; 
    275279        return monthIndex + Math.min( 
    276                                     Math.max( pos - ( monthBoundary + padding ), 0 ), 
    277                                     timeline.monthData[month] - 1 ); 
     280                        Math.max( pos - ( monthBoundary + padding ), 0 ), 
     281                        timeline.monthData[month] - 1 ); 
     282    }, 
     283    /* the reverse of the above function */ 
     284    positionFromIndex: function(index) { 
     285        var month= 0; 
     286        var position= 0; 
     287        var positionIndex= 1; 
     288 
     289        if ( index < 1 ) return 0; 
     290 
     291        for ( i = 0; i < timeline.monthWidths.length && positionIndex + timeline.monthData[i] < index; i++ ) { 
     292            position+= timeline.monthWidths[i]; 
     293            positionIndex+= timeline.monthData[i]; 
     294            month= i + 1; 
     295        } 
     296 
     297        var padding= parseInt( $('.years .months span').css('margin-left') ); 
     298        padding= padding ? padding : 0; 
     299        return position + padding + ( index - positionIndex ); 
     300    }, 
     301    reset: function () { 
     302        var timelineWidth = $('.years').width(); 
     303 
     304        // update the arrays of posts per month 
     305        timeline.monthData= [0]; 
     306        timeline.monthWidths= [0]; 
     307        timeline.totalCount= 0; 
     308        $('.years span').each(function(i) { 
     309            timeline.monthData[i] = $(this).width(); 
     310            timeline.monthWidths[i] = $(this).parent().width() + 1; // 1px border 
     311            timeline.totalCount += timeline.monthData[i]; 
     312        }); 
     313 
     314        // find the width which makes the loupe select 20 items 
     315        var minWidth= timelineWidth - timeline.positionFromIndex( timeline.totalCount - 20 ); 
     316 
     317        // reset the widths 
     318        $('.track').width( $('.years').width() ); 
     319        $('.handle').width( minWidth + 'px' ); 
     320 
     321        // reset the slider maxValue 
     322        $('.track').data('ui-slider').size= timelineWidth; 
     323        $('.track').data('ui-slider').options['realMaxValue']= Math.max( 1, timelineWidth - minWidth ); 
     324 
     325        // move the handle without triggering a search 
     326        timeline.do_search= false; 
     327        $('.track').slider( 'moveTo', timelineWidth - minWidth ); 
     328        timeline.do_search= true; 
    278329    } 
    279330} 
     
    335386 
    336387        /* AJAX call to fetch needed info goes here. */ 
    337         if(jQuery.isFunction(this.loupeUpdate)) { 
     388        if( timeline.do_search && jQuery.isFunction(this.loupeUpdate) ) { 
    338389            return this.loupeUpdate(loupeStartPosition, loupeEndPosition, timeline.totalCount); 
    339390        } 
  • trunk/htdocs/system/classes/adminhandler.php

    r1741 r1745  
    752752 
    753753        $this->theme->comments= Comments::get( $arguments ); 
    754  
    755         $this->theme->monthcomments= DB::get_results( 'SELECT MONTH(date) AS month, YEAR(date) AS year, COUNT(id) AS ct FROM {comments} GROUP BY year, month ORDER BY year, month', array() ); 
     754        $this->theme->monthcts= Comments::get( array_merge( $arguments, array( 'month_cts' => 1 ) ) ); 
    756755    } 
    757756 
     
    913912        } 
    914913 
    915         $this->theme->monthposts= DB::get_results( 'SELECT MONTH(pubdate) AS month, YEAR(pubdate) AS year, COUNT(id) AS ct FROM {posts} WHERE content_type = ? GROUP BY year, month ORDER BY year, month', array( $type ) ); 
     914        $this->theme->monthcts= Posts::get( array_merge( $arguments, array( 'month_cts' => 1 ) ) ); 
    916915    } 
    917916 
     
    948947        $this->fetch_entries( $params ); 
    949948        $items= $this->theme->fetch( 'entries_items' ); 
     949        $timeline= $this->theme->fetch( 'timeline_items' ); 
    950950 
    951951        $output= array( 
    952952            'items' => $items, 
     953            'timeline' => $timeline, 
    953954        ); 
    954955        echo json_encode($output); 
     
    956957 
    957958    /** 
    958      * Handles ajax requests from the manage commens page 
     959     * Handles ajax requests from the manage comments page 
    959960     */ 
    960961    public function ajax_comments() 
     
    967968        $this->fetch_comments( $params ); 
    968969        $items= $this->theme->fetch( 'comments_items' ); 
     970        $timeline= $this->theme->fetch( 'timeline_items' ); 
    969971 
    970972        $output= array( 
    971973            'items' => $items, 
     974            'timeline' => $timeline, 
    972975        ); 
    973976        echo json_encode($output); 
  • trunk/htdocs/system/classes/comments.php

    r1720 r1745  
    174174            $orderby= ''; 
    175175        } 
     176        // is a count of comments by month being requested? 
     177        $groupby= ''; 
     178        if ( isset ( $month_cts ) ) { 
     179            $select= 'MONTH(date) AS month, YEAR(date) AS year, COUNT(id) AS ct'; 
     180            $groupby= 'year, month'; 
     181            $orderby= 'year, month'; 
     182        } 
    176183        if ( isset( $limit ) ) { 
    177184            $limit= " LIMIT $limit"; 
     
    180187            } 
    181188        } 
    182         if ( isset( $nolimit ) ) { 
     189        if ( isset( $nolimit ) || isset( $month_cts )) { 
    183190            $limit= ''; 
    184191        } 
     
    192199            $query.= ' WHERE ' . implode( " \nOR\n ", $wheres ); 
    193200        } 
     201        $query.= ( $groupby == '' ) ? '' : ' GROUP BY ' . $groupby; 
    194202        $query.= ( ( $orderby == '' ) ? '' : ' ORDER BY ' . $orderby ) . $limit; 
    195203        //Utils::debug( $paramarray, $fetch_fn, $query, $params ); 
  • trunk/htdocs/system/classes/posts.php

    r1720 r1745  
    374374            $orderby= ''; 
    375375        } 
     376         
     377        // If the month counts are requested, replaced the select clause 
     378        $groupby= ''; 
     379        if( isset( $paramset['month_cts'] ) ) { 
     380            $select= 'MONTH(pubdate) AS month, YEAR(pubdate) AS year, COUNT(id) AS ct'; 
     381            $groupby= 'year, month'; 
     382            $orderby= 'year, month'; 
     383        } 
     384         
    376385 
    377386        // Define the LIMIT and add the OFFSET if it exists 
     
    383392        } 
    384393 
    385         // Remove the LIMIT if 'nolimit' is set 
    386         if ( isset( $nolimit ) ) { 
     394        // Remove the LIMIT if 'nolimit' or 'month_cts' is set 
     395        if ( isset( $nolimit ) || isset( $paramset['month_cts'] ) ) { 
    387396            $limit= ''; 
    388397        } 
     
    400409            $query.= ' WHERE ' . implode( " \nOR\n ", $wheres ); 
    401410        } 
     411        $query.= ( $groupby == '' ) ? '' : ' GROUP BY ' . $groupby; 
    402412        $query.= ( ( $orderby == '' ) ? '' : ' ORDER BY ' . $orderby ) . $limit; 
    403413