]> 91.132.146.200 Git - insipid.git/commitdiff
adding sorting options to overview. Frontend and link building
authorBanana <banana@mirage>
Sun, 29 Dec 2019 18:42:48 +0000 (19:42 +0100)
committerBanana <banana@mirage>
Sun, 29 Dec 2019 18:42:48 +0000 (19:42 +0100)
TODO
webroot/lib/summoner.class.php
webroot/view/overview.inc.php
webroot/view/overview.php

diff --git a/TODO b/TODO
index c003439345829932b7ff3bb097c2bb86abde72a2..136593edce1e3dae29c0dad2c4b0f4bc0d3c8028 100755 (executable)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,7 @@
 TODO / Feature list
 + backup. Complete and single
 + sorting
++ sorting for tag or category selection
 + snapshots
 + bookmark js snippet
 + theme support
index ca55dec3c8b3eeab8492726bd637f362e3ff0d58..c5cd273466e0c760c1056b481108276fc41678f3 100644 (file)
@@ -111,7 +111,6 @@ class Summoner {
 
                $value = preg_replace($pattern, '', $input);
 
-               #if($input === $value) {
                if($value === "") {
                        $ret = true;
                }
@@ -560,4 +559,34 @@ class Summoner {
             return true;
         }
     }
+
+    /**
+     * http_build_query with modify array
+     * modify will add: key AND value not empty
+     * modify will remove: only key with no value
+     * 
+     * @param $array
+     * @param bool $modify
+     * @return string
+     */
+    static function createFromParameterLinkQuery($array,$modify=false) {
+        $ret = '';
+
+        if(!empty($modify)) {
+            foreach($modify as $k=>$v) {
+                if(empty($v)) {
+                    unset($array[$k]);
+                }
+                else {
+                    $array[$k] = $v;
+                }
+            }
+        }
+
+        if(!empty($array)) {
+            $ret = http_build_query($array);
+        }
+
+        return $ret;
+    }
 }
index fb90e6d8797869b347a5ddb996bff202e48c7df4..5770d4016a90cedfa090230d550109872d99baee 100644 (file)
  * along with this program.  If not, see http://www.gnu.org/licenses/gpl-3.0.
  *
  */
+$currentGetParameters['p'] = 'overview';
+
 $_requestMode = false;
 if(isset($_GET['m']) && !empty($_GET['m'])) {
        $_requestMode = trim($_GET['m']);
-       $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : "all";
+       $_requestMode = Summoner::validate($_requestMode,'nospace') ? $_requestMode : false;
 }
 
 $_id = false;
@@ -36,12 +38,25 @@ if(isset($_GET['id']) && !empty($_GET['id'])) {
        $_id = trim($_GET['id']);
        $_id = Summoner::validate($_id,'digit') ? $_id : false;
 }
+
 $_curPage = 1;
 if(isset($_GET['page']) && !empty($_GET['page'])) {
        $_curPage = trim($_GET['page']);
        $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1;
 }
 
+$_sort = false;
+if(isset($_GET['s']) && !empty($_GET['s'])) {
+    $_sort = trim($_GET['s']);
+    $_sort = Summoner::validate($_sort,'nospace') ? $_sort : false;
+}
+
+$_sortDirection = false;
+if(isset($_GET['sd']) && !empty($_GET['sd'])) {
+    $_sortDirection = trim($_GET['sd']);
+    $_sortDirection = Summoner::validate($_sortDirection,'nospace') ? $_sortDirection : false;
+}
+
 $linkCollection = array();
 $subHeadline = false;
 $tagCollection = array();
@@ -49,13 +64,27 @@ $categoryCollection = array();
 $pagination = array('pages' => 0);
 $displayEditButton = false;
 $isAwm = false;
+$sortLink = array();
 
 if(Summoner::simpleAuthCheck() === true) {
        $displayEditButton = true;
 }
 
+$sortLink['active'] = 'default';
+$sortLink['activeDirection'] = false;
+
+if(!empty($_sort) && $_sort === 'name') {
+    $currentGetParameters['s'] = 'name';
+    $sortLink['active'] = 'name';
+}
+if(!empty($_sortDirection) && $_sortDirection === 'asc') {
+    $currentGetParameters['sd'] = 'asc';
+    $sortLink['activeDirection'] = true;
+}
+
 switch($_requestMode) {
        case 'tag':
+        $currentGetParameters['m'] = 'tag';
                if(!empty($_id)) {
             $tagObj = new Tag($DB);
             $tagObj->initbyid($_id);
@@ -63,6 +92,8 @@ switch($_requestMode) {
             $subHeadline = $tagname.' <i class="ion-md-pricetag"></i>';
 
                        $linkCollection = $Management->linksByTag($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+
+            $currentGetParameters['id'] = $_id;
                }
                else {
                        # show all the tags we have
@@ -71,12 +102,16 @@ switch($_requestMode) {
                }
        break;
        case 'category':
+        $currentGetParameters['m'] = 'category';
                if(!empty($_id)) {
             $catObj = new Category($DB);
             $catObj->initbyid($_id);
             $catname = $catObj->getData('name');
             $subHeadline = $catname.' <i class="ion-md-filing"></i>';
+
                        $linkCollection = $Management->linksByCategory($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
+
+            $currentGetParameters['id'] = $_id;
                }
                else {
                        # show all the categories we have
@@ -85,10 +120,12 @@ switch($_requestMode) {
                }
        break;
        case 'awm':
+        $currentGetParameters['m'] = 'awm';
                Summoner::simpleAuth();
                $isAwm = true;
                $subHeadline = 'Awaiting moderation';
                $Management->setShowAwm(true);
+
                $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
        break;
        case 'all':
@@ -96,13 +133,12 @@ switch($_requestMode) {
                # show all
                $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1)));
 }
+
 if(!empty($linkCollection['amount'])) {
        $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE);
        $pagination['curPage'] = $_curPage;
-       $pagination['linkadd'] = '&m='.$_requestMode;
-       if(!empty($_id)) {
-               $pagination['linkadd'] .= '&id='.$_id;
-       }
+
+    $currentGetParameters['page'] = $_curPage;
 }
 
 if($pagination['pages'] > 11) {
@@ -123,3 +159,7 @@ if($pagination['pages'] > 11) {
 else {
        $pagination['visibleRange'] = range(1,$pagination['pages']);
 }
+
+$sortLink['default'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>false,'sd'=>false));
+$sortLink['name'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('s'=>'name','sd'=>false));
+$sortLink['direction'] = Summoner::createFromParameterLinkQuery($currentGetParameters,array('sd'=>'asc'));
\ No newline at end of file
index 4fa3504afc87a8082fc2da76ababd4bccd8414fc..b0335c394688a3c3890c35a42b6067474b8d8495 100644 (file)
                </div>
        </div>
 
-       <?php if($pagination['pages'] > 1) { ?>
-               <nav class="pagination is-centered" role="navigation" aria-label="pagination">
-                       <?php if($pagination['curPage'] > 1) {
-                               echo '<a href="index.php?p=overview'.$pagination['linkadd'].'&page='.($pagination['curPage']-1).'" 
-                                       class="pagination-previous">Previous</a>';
-                       }
-                       if($pagination['curPage'] < $pagination['pages']) {
-                               echo '<a href="index.php?p=overview'.$pagination['linkadd'].'&page='.($pagination['curPage']+1).'" 
-                                       class="pagination-next">Next</a>';
-                       }
-                       ?>
-                       <ul class="pagination-list">
-                               <?php
-                               $ellipsisShown = 0;
-                               for($i=1;$i<=$pagination['pages'];$i++) {
-                                       $active = '';
-                                       if($i == $pagination['curPage']) $active = 'is-current';
+    <div class="columns">
+        <div class="column is-half">
+        <?php if($pagination['pages'] > 1) { ?>
+            <nav class="pagination is-small" role="navigation" aria-label="pagination">
+                <?php if($pagination['curPage'] > 1) {
+                    echo '<a href="index.php?'.Summoner::createFromParameterLinkQuery($currentGetParameters,array('page'=>($pagination['curPage']-1))).'" 
+                        class="pagination-previous">Previous</a>';
+                }
+                if($pagination['curPage'] < $pagination['pages']) {
+                    echo '<a href="index.php?'.Summoner::createFromParameterLinkQuery($currentGetParameters,array('page'=>($pagination['curPage']+1))).'" 
+                        class="pagination-next">Next</a>';
+                }
+                ?>
+                <ul class="pagination-list">
+                    <?php
+                    $ellipsisShown = 0;
+                    for($i=1;$i<=$pagination['pages'];$i++) {
+                        $active = '';
+                        if($i == $pagination['curPage']) $active = 'is-current';
 
-                                       if(in_array($i,$pagination['visibleRange'])) {
-                                               echo '<li><a href="index.php?p=overview' . $pagination['linkadd'] . '&page=' . $i . '"
-                                               class="pagination-link ' . $active . '"
-                                               aria-label="Goto page ' . $i . '">' . $i . '</a></li>';
-                                       }
-                                       else {
-                                               if($i < $pagination['currentRangeStart'] && $ellipsisShown == 0) {
-                                                       echo '<li><span class="pagination-ellipsis">&hellip;</span></li>';
-                                                       $ellipsisShown = 1;
-                                               }
-                                               if($i > $pagination['currentRangeEnd'] && ($ellipsisShown == 0 || $ellipsisShown == 1)) {
-                                                       echo '<li><span class="pagination-ellipsis">&hellip;</span></li>';
-                                                       $ellipsisShown = 2;
-                                               }
-                                       }
-                               }
-                               ?>
-                       </ul>
-               </nav>
-       <?php } ?>
+                        if(in_array($i,$pagination['visibleRange'])) {
+                            echo '<li><a href="index.php?'.Summoner::createFromParameterLinkQuery($currentGetParameters,array('page'=>$i)).'"
+                            class="pagination-link ' . $active . '"
+                            aria-label="Goto page ' . $i . '">' . $i . '</a></li>';
+                        }
+                        else {
+                            if($i < $pagination['currentRangeStart'] && $ellipsisShown == 0) {
+                                echo '<li><span class="pagination-ellipsis">&hellip;</span></li>';
+                                $ellipsisShown = 1;
+                            }
+                            if($i > $pagination['currentRangeEnd'] && ($ellipsisShown == 0 || $ellipsisShown == 1)) {
+                                echo '<li><span class="pagination-ellipsis">&hellip;</span></li>';
+                                $ellipsisShown = 2;
+                            }
+                        }
+                    }
+                    ?>
+                </ul>
+            </nav>
+        <?php } ?>
+        </div>
+        <div class="column is-half">
+            <div class="is-pulled-right">
+                <a href="index.php?<?php echo $sortLink['default']; ?>"
+                   class="button is-small <?php if($sortLink['active'] === 'default') { ?>is-link<?php } ?>">default</a>
+                <a href="index.php?<?php echo $sortLink['name']; ?>"
+                   class="button is-small <?php if($sortLink['active'] === 'name') { ?>is-link<?php } ?>">name</a>
+                <a href="index.php?<?php echo $sortLink['direction']; ?>"
+                   class="button is-small <?php if($sortLink['activeDirection'] === true) { ?>is-link<?php } ?>"><span class="icon"><i class="ion-md-arrow-dropup"></i></span></a>
+            </div>
+        </div>
+    </div>
 </section>
 
 <section class="section">