View Issue Details

IDProjectCategoryView StatusLast Update
370RackTablesdefaultpublic2012-07-28 23:29
Reporterf0urtyfive Assigned Toadoom42  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version0.18.4 
Target Version0.20.0Fixed in Version0.20.0 
Summary370: Sort Row manually
DescriptionI'm not sure if this should go here as a previous ticket about the same thing (0000354) was closed however I've written the necessary code/sql to add a order_key value to the Racks table in order to manually sort a row with a numerical value (in ascending order). Please let me know if you'd prefer this done in a different manner as I was fumbling around the code a bit.

SQL and diff will be attached.
TagsNo tags attached.
Attached Files
racksort.diff (4,888 bytes)   
diff -rupN RackTables-0.18.4/inc/database.php rt-racksort-branch/inc/database.php
--- RackTables-0.18.4/inc/database.php	2010-09-18 19:35:58.000000000 -0400
+++ rt-racksort-branch/inc/database.php	2010-09-20 22:48:44.000000000 -0400
@@ -119,10 +119,11 @@ $SQLSchema = array
 			'height' => 'height',
 			'comment' => 'comment',
 			'row_id' => 'row_id',
+			'order_key' => 'order_key',
 			'row_name' => '(select name from RackRow where RackRow.id = row_id)',
 		),
 		'keycolumn' => 'id',
-		'ordcolumns' => array ('row_name', 'Rack.name'),
+		'ordcolumns' => array ('row_name', 'Rack.order_key', 'Rack.name'),
 		'pidcolumn' => 'row_id',
 	),
 );
@@ -644,7 +645,7 @@ function commitDeleteRack($rack_id)
 	return TRUE;
 }
 
-function commitUpdateRack ($rack_id, $new_name, $new_height, $new_row_id, $new_comment)
+function commitUpdateRack ($rack_id, $new_name, $new_height, $new_row_id, $new_comment, $new_order_key)
 {
 	// Can't shrink a rack if rows being deleted contain mounted objects
 	$check_result = usePreparedSelectBlade ('SELECT COUNT(*) AS count FROM RackSpace WHERE rack_id = ? AND unit_no > ?', array ($rack_id, $new_height));
@@ -655,13 +656,14 @@ function commitUpdateRack ($rack_id, $ne
 
 	usePreparedExecuteBlade
 	(
-		'UPDATE Rack SET name=?, height=?, comment=?, row_id=? WHERE id=?',
+		'UPDATE Rack SET name=?, height=?, comment=?, row_id=?, order_key=? WHERE id=?',
 		array
 		(
 			$new_name,
 			$new_height,
 			$new_comment,
 			$new_row_id,
+			$new_order_key,
 			$rack_id,
 		)
 	);
diff -rupN RackTables-0.18.4/inc/interface.php rt-racksort-branch/inc/interface.php
--- RackTables-0.18.4/inc/interface.php	2010-07-09 11:07:24.000000000 -0400
+++ rt-racksort-branch/inc/interface.php	2010-09-20 22:56:42.000000000 -0400
@@ -717,6 +717,7 @@ function renderEditRackForm ($rack_id)
 	echo "<tr><th class=tdright>Name (required):</th><td class=tdleft><input type=text name=rack_name value='${rack['name']}'></td></tr>\n";
 	echo "<tr><th class=tdright>Height (required):</th><td class=tdleft><input type=text name=rack_height value='${rack['height']}'></td></tr>\n";
 	echo "<tr><th class=tdright>Comment:</th><td class=tdleft><input type=text name=rack_comment value='${rack['comment']}'></td></tr>\n";
+	echo "<tr><th class=tdright>Order Key:</th><td class=tdleft><input type=text name=rack_order_key value='${rack['order_key']}'></td></tr>\n";
 	if (count ($rack['mountedObjects']) == 0)
 	{
 		echo "<tr><th class=tdright>Actions:</th><td class=tdleft><a href='".
@@ -1928,11 +1929,11 @@ function renderHistory ($object_type, $o
 			break;
 		case 'rack':
 			$query =
-				"select ctime, user_name, rh.name, rr.name as name, rh.height, rh.comment " .
+				"select ctime, user_name, rh.name, rr.name as name, rh.height, rh.comment, rh.order_key " .
 				"from RackHistory as rh left join RackRow as rr on rh.row_id = rr.id " .
 				"where rh.id = ? order by ctime";
-			$header = '<tr><th>change time</th><th>author</th><th>rack name</th><th>rack row name</th><th>rack height</th><th>rack comment</th></tr>';
-			$extra = 5;
+			$header = '<tr><th>change time</th><th>author</th><th>rack name</th><th>rack row name</th><th>rack height</th><th>rack comment</th><th>rack orderkey</th></tr>';
+			$extra = 6;
 			break;
 		case 'object':
 			$query =
diff -rupN RackTables-0.18.4/inc/ophandlers.php rt-racksort-branch/inc/ophandlers.php
--- RackTables-0.18.4/inc/ophandlers.php	2010-09-18 19:35:26.000000000 -0400
+++ rt-racksort-branch/inc/ophandlers.php	2010-09-20 23:03:53.000000000 -0400
@@ -1700,7 +1700,7 @@ function addRack ()
 		assertUIntArg ('rack_height1');
 		assertStringArg ('rack_comment', TRUE);
 
-		if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
+		if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], 1, $taglist) === TRUE)
 			return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
 		else
 			return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name']));
@@ -1757,11 +1757,12 @@ function updateRack ()
 	assertUIntArg ('rack_id');
 	assertUIntArg ('rack_row_id');
 	assertUIntArg ('rack_height');
+	assertUIntArg ('rack_order_key');
 	assertStringArg ('rack_name');
 	assertStringArg ('rack_comment', TRUE);
 
 	resetThumbCache ($_REQUEST['rack_id']);
-	if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
+	if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment'], $_REQUEST['rack_order_key']))
 		return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
 	else
 		return buildRedirectURL (__FUNCTION__, 'ERR');
racksort.diff (4,888 bytes)   
racksort.sql (148 bytes)

Relationships

has duplicate 587 closedadoom42 Unable to change rack numbering order 

Activities

infrastation

infrastation

2010-11-20 18:15

administrator   ~0000183

Please consider this:

https://sourceforge.net/apps/mediawiki/racktables/index.php?title=FAQ#how_do_I_reoder_racks_in_a_row.3F
infrastation

infrastation

2011-02-15 09:07

administrator   ~0000249

I will consider this again.
infrastation

infrastation

2011-03-16 12:27

administrator   ~0000303

There are some points in the submitted patch, which should be fixed against current trunk codebase:

1. "order key" column must accept NULL values (and this must be its default value)
2. user form must not enforce a default value for order key
3. there should be a KEY for the column, as soon as it's used in the ORDER BY clause
4. ALTER TABLE statements should be placed in inc/upgrade.php, and inc/install.php should list Rack and RackHistory tables updated.
adoom42

adoom42

2012-01-30 01:34

administrator   ~0000555

Starting with version 0.20, rows are stored in the DB in a different way. Work on this issue should only apply to >= 0.20.
adoom42

adoom42

2012-07-28 23:29

administrator   ~0000717

I added the ability to manually sort racks to 0.20.

Issue History

Date Modified Username Field Change
2010-09-21 03:09 f0urtyfive New Issue
2010-09-21 03:10 f0urtyfive File Added: racksort.diff
2010-09-21 03:11 f0urtyfive File Added: racksort.sql
2010-11-20 18:15 infrastation Note Added: 0000183
2010-11-20 18:15 infrastation Assigned To => infrastation
2010-11-20 18:15 infrastation Status new => closed
2010-11-20 18:15 infrastation Resolution open => won't fix
2011-02-15 09:07 infrastation Note Added: 0000249
2011-02-15 09:07 infrastation Status closed => new
2011-02-21 15:55 infrastation Status new => acknowledged
2011-03-16 12:27 infrastation Note Added: 0000303
2012-01-07 11:59 infrastation Assigned To infrastation =>
2012-01-07 11:59 infrastation Resolution won't fix => open
2012-01-07 11:59 infrastation Target Version => 0.19.12
2012-01-30 01:34 adoom42 Note Added: 0000555
2012-01-30 01:34 adoom42 Target Version 0.19.12 => 0.20.0
2012-07-27 19:00 adoom42 Relationship added has duplicate 587
2012-07-28 23:29 adoom42 Note Added: 0000717
2012-07-28 23:29 adoom42 Assigned To => adoom42
2012-07-28 23:29 adoom42 Status acknowledged => closed
2012-07-28 23:29 adoom42 Resolution open => fixed
2012-07-28 23:29 adoom42 Fixed in Version => 0.20.0