Browse Source

Bugfix: miner.php: Display devices with aligned columns instead of assuming they come out of the RPC aligned

Luke Dashjr 13 years ago
parent
commit
393fff9861
2 changed files with 53 additions and 17 deletions
  1. 1 1
      libblkmaker
  2. 52 16
      miner.php

+ 1 - 1
libblkmaker

@@ -1 +1 @@
-Subproject commit ca3cf0173806d39d2b3a1400de3fa4bec7ab772a
+Subproject commit 19847fbab02450fb0db2ae519a35808cdc091991

+ 52 - 16
miner.php

@@ -955,35 +955,71 @@ function details($cmd, $list, $rig)
 	$dototal = $singlerigsum[$cmd];
  else
 	$dototal = array();
-
  $total = array();
 
  $section = '';
  $oldvalues = null;
+
+ // Build a common row column for all entries
+ $columns = array();
+ $columnsByIndex = array();
  foreach ($list as $item => $values)
  {
 	if ($item == 'STATUS')
 		continue;
-
-	$sectionname = preg_replace('/\d/', '', $item);
-
-	// Handle 'devs' possibly containing >1 table
-	if ($sectionname != $section)
+	$ikey = array_keys($values)[0];
+	$list[$item] = $values = array('Dev' => $values[$ikey]) + array_slice($values, 1);
+	$namesByIndex = array_keys($values);
+	$nameCount = count($namesByIndex);
+	for ($i = 0; $i < $nameCount; ++$i)
 	{
-		if ($oldvalues != null && count($total) > 0
-		&&  ($rownum > 2 || $forcerigtotals === true))
-			showtotal($total, $when, $oldvalues);
-
-		endtable();
-		newtable();
-		showhead($cmd, $values);
-		$section = $sectionname;
+		$name = $namesByIndex[$i];
+		if (isset($columns[$name]))
+			continue;
+		$value = $values[$name];
+		$before = null;
+		for ($j = $i + 1; $j < $nameCount; ++$j)
+		{
+			$maybebefore = $namesByIndex[$j];
+			if (isset($columns[$maybebefore]))
+			{
+				$before = $columns[$maybebefore];
+				break;
+			}
+		}
+		if (!$before)
+		{
+			$columns[$name] = array_push($columnsByIndex, $name) - 1;
+			continue;
+		}
+		array_splice($columnsByIndex, $before, 0, $name);
+		$columns[$name] = $before;
+		$columnCount = count($columnsByIndex);
+		for ($j = $before + 1; $j < $columnCount; ++$j)
+			$columns[$columnsByIndex[$j]] = $j;
 	}
+ }
+ asort($columns);
+ endtable();
+ newtable();
+ showhead($cmd, $columns);
+
+ foreach ($list as $item => $values)
+ {
+	if ($item == 'STATUS')
+		continue;
 
 	newrow();
 
-	foreach ($values as $name => $value)
+	foreach ($columns as $name => $columnidx)
 	{
+		if (!isset($values[$name]))
+		{
+			echo '<td></td>';
+			continue;
+		}
+		$value = $values[$name];
+
 		list($showvalue, $class) = fmt($section, $name, $value, $when, $values);
 		echo "<td$class";
 		if ($rigtotals === true)
@@ -1025,7 +1061,7 @@ function details($cmd, $list, $rig)
 
  if ($oldvalues != null && count($total) > 0
  &&  ($rownum > 2 || $forcerigtotals === true))
-	showtotal($total, $when, $oldvalues);
+	showtotal($total, $when, $columns);
 
  endtable();
 }