Skip to content

Commit 93c444f

Browse files
committedFeb 12, 2019
Add packet index sorting
* Reverts 54d9fa2 * Removes pagination, which was disliked by users
1 parent 95a384f commit 93c444f

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed
 

‎src/controllers/Packet/Index.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,43 @@ public function &run( Router &$router, View &$view, array &$args ) {
2323

2424
$model = new PacketIndexModel();
2525

26-
$model->packets = Packet::getAllPackets(
27-
['packet_application_layer_id,packet_id', 'ASC']
26+
$query = $router->getRequestQueryArray();
27+
28+
$model->order = (
29+
isset( $query['order'] ) ? $query['order'] : 'packet-id-asc'
2830
);
2931

32+
switch ( $model->order ) {
33+
case 'created-datetime-asc':
34+
$order = [ 'created_datetime','ASC' ]; break;
35+
36+
case 'created-datetime-desc':
37+
$order = [ 'created_datetime','DESC' ]; break;
38+
39+
case 'id-asc':
40+
$order = [ 'id','ASC' ]; break;
41+
42+
case 'id-desc':
43+
$order = [ 'id','DESC' ]; break;
44+
45+
case 'packet-id-asc':
46+
$order = [ 'packet_application_layer_id,packet_id','ASC' ]; break;
47+
48+
case 'packet-id-desc':
49+
$order = [ 'packet_application_layer_id,packet_id','DESC' ]; break;
50+
51+
case 'user-id-asc':
52+
$order = [ 'user_id','ASC' ]; break;
53+
54+
case 'user-id-desc':
55+
$order = [ 'user_id','DESC' ]; break;
56+
57+
default:
58+
$order = null;
59+
}
60+
61+
$model->packets = Packet::getAllPackets( $order );
62+
3063
if ( !( $view instanceof PacketIndexHtmlView
3164
|| $view instanceof PacketIndexJSONView )) {
3265

‎src/libraries/Packet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public static function &getAllPackets(
126126

127127
if ( empty( $limit_clause )) {
128128

129-
$ckey = 'bnetdocs-packets';
129+
$ckey = 'bnetdocs-packets-' . hash('md5', $order[0] . $order[1]);
130130
$cval = Common::$cache->get( $ckey );
131131

132132
if ( $cval !== false && !empty( $cval )) {

‎src/models/Packet/Index.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Index extends Model {
88

9+
public $order;
910
public $packets;
1011
public $timestamp;
1112
public $user;

‎src/templates/Packet/Index.phtml

+33
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,45 @@ $title = 'Packet Index';
1111
$description = 'The index for packets on BNETDocs';
1212
$this->opengraph->attach(new Pair('url', '/packet/index'));
1313

14+
$order = $this->getContext()->order;
15+
1416
$this->additional_css[] = '/a/forms.css';
1517
require('./header.inc.phtml');
1618
?>
1719
<article>
1820
<header>Packet Index</header>
1921
<section>
22+
<form method="GET">
23+
<label for="order">Order by:</label>
24+
<select name="order" id="order" onchange="form.submit();"
25+
style="display:inline-block;width:200px;">
26+
<option value="created-datetime-asc"<?php
27+
if ($order === 'created-datetime-asc') { echo ' selected="selected"';
28+
} ?>>Created Timestamp (Ascending)</option>
29+
<option value="created-datetime-desc"<?php
30+
if ($order === 'created-datetime-desc') { echo ' selected="selected"';
31+
} ?>>Created Timestamp (Descending)</option>
32+
<option value="id-asc"<?php
33+
if ($order === 'id-asc') { echo ' selected="selected"';
34+
} ?>>Database Id (Ascending)</option>
35+
<option value="id-desc"<?php
36+
if ($order === 'id-desc') { echo ' selected="selected"';
37+
} ?>>Database Id (Descending)</option>
38+
<option value="packet-id-asc"<?php
39+
if ($order === 'packet-id-asc') { echo ' selected="selected"';
40+
} ?>>Packet Id (Ascending)</option>
41+
<option value="packet-id-desc"<?php
42+
if ($order === 'packet-id-desc') { echo ' selected="selected"';
43+
} ?>>Packet Id (Descending)</option>
44+
<option value="user-id-asc"<?php
45+
if ($order === 'user-id-asc') { echo ' selected="selected"';
46+
} ?>>User Id (Ascending)</option>
47+
<option value="user-id-desc"<?php
48+
if ($order === 'user-id-desc') { echo ' selected="selected"';
49+
} ?>>User Id (Descending)</option>
50+
</select>
51+
<input type="submit" value="Reorder"/>
52+
</form>
2053
<table>
2154
<thead>
2255
<tr>

0 commit comments

Comments
 (0)