admin: better column sort on balances + USD one

also, keep sort and search filter on auto refresh..

sort ages columns with metadata...
This commit is contained in:
Tanguy Pruvot 2016-01-11 19:30:00 +01:00
parent 5be767009d
commit c104f6f6a0
6 changed files with 1242 additions and 42 deletions

View file

@ -1,6 +1,7 @@
<?php
//echo "<a href='/coin/create'>Add a coin</a>";
JavascriptFile("/yaamp/ui/js/jquery.metadata.js");
JavascriptFile("/yaamp/ui/js/jquery.tablesorter.widgets.js");
echo <<<end
<div align="right" style="margin-bottom: 6px;">
@ -13,7 +14,18 @@ end;
showTableSorter('maintable', "{
tableClass: 'dataGrid',
headers: { 0: { sorter: false} },
headers: {
0:{sorter:false},
1:{sorter:'text'},
2:{sorter:'text'},
3:{sorter:'text'},
4:{sorter:'text'},
5:{sorter:'text'},
6:{sorter:'metadata'},
7:{sorter:'numeric'},
8:{sorter:'text'},
9:{sorter: false }
},
widgets: ['zebra','filter'],
widgetOptions: {
filter_external: '.search',
@ -52,7 +64,7 @@ foreach($coins as $coin)
$coin->errors = substr($coin->errors, 0, 30);
$coin->version = substr($coin->version, 0, 20);
$difficulty = Itoa2($coin->difficulty, 3);
$d = datetoa2($coin->created);
$created = datetoa2($coin->created);
echo "<tr class='ssrow' title='$coin->specifications'>";
echo "<td><img src='$coin->image' width=18></td>";
@ -76,10 +88,10 @@ foreach($coins as $coin)
echo "<td></td>";
echo "<td>$coin->version</td>";
echo "<td>$d ago</td>";
echo '<td data="'.$coin->created.'">'.$created.'</td>';
// echo "<td align=right>$difficulty</td>";
echo "<td align=right>$coin->block_height</td>";
echo '<td align="center">'.$coin->block_height.'</td>';
echo "<td>$coin->errors</td>";
echo "<td>";
@ -116,12 +128,18 @@ $total = count($coins);
echo "<tr class='ssrow'>";
echo "<td></td>";
echo "<td colspan=10><b>$total coins, $total_installed installed, $total_active running</b></td>";
echo '<td colspan="6">';
echo "<b>$total coins, $total_installed installed, $total_active running</b>";
echo '<br/><br/><a href="/coin/create">Add a coin</a>';
echo '<td style="display: none;"></td>';
echo '<td style="display: none;"></td>';
echo '<td style="display: none;"></td>';
echo '<td style="display: none;"></td>';
echo '<td style="display: none;" data="0"></td>';
echo '</td>';
echo "</tr>";
echo "</table>";
echo "<br><br><br><br><br>";
echo "<br><br><br><br><br>";

View file

@ -1,5 +1,8 @@
<?php
JavascriptFile("/yaamp/ui/js/jquery.metadata.js");
JavascriptFile("/yaamp/ui/js/jquery.tablesorter.widgets.js");
echo getAdminSideBarLinks();
echo '&nbsp;<a href="/site/emptymarkets">Empty Markets</a>&nbsp;';
@ -40,28 +43,29 @@ Select Server:
$('#server_select').change(function(event)
{
var server = $('#server_select').val();
clearTimeout(main_timeout);
window.location.href = '/site/admin?server='+server;
});
//var current_hash;
$(function()
{
// current_hash = window.location.hash;
// window.location.hash = '';
main_refresh();
});
var main_delay=30000;
var main_timeout;
var lastSearch = false;
function main_ready(data)
{
$('#main_results').html(data);
$('#server_select').val('{$server}');
// window.location.hash = current_hash;
if (lastSearch !== false) {
$('input.search').val(lastSearch);
$('table.dataGrid').trigger('search');
}
main_timeout = setTimeout(main_refresh, main_delay);
}
@ -75,6 +79,7 @@ function main_refresh()
var url = "/site/admin_results?server=$server";
clearTimeout(main_timeout);
lastSearch = $('input.search').val();
$.get(url, '', main_ready).error(main_error);
}

View file

@ -11,8 +11,8 @@ end;
showTableSorter('maintable', '{
tableClass: "dataGrid",
headers: {
0:{sorter:false},
1:{sorter:false},
0:{sorter:"metadata"}, /* reset filter */
1:{sorter:"metadata"},
2:{sorter:"text"},
3:{sorter:"text"},
4:{sorter:"currency"},
@ -21,10 +21,13 @@ headers: {
7:{sorter:"currency"},
8:{sorter:"currency"},
9:{sorter:"currency"},
10:{sorter:"currency"}
10:{sorter:"currency"},
11:{sorter:"currency"}
},
widgets: ["zebra","filter"],
widgets: ["zebra","filter","Storage","saveSort"],
widgetOptions: {
saveSort: true,
filter_saveFilters: true,
filter_external: ".search",
filter_columnFilters: false,
filter_childRows : true,
@ -42,17 +45,16 @@ echo <<<end
<th align="right">Diff/Height</th>
<th align="right">Profit</th>
<th align="right">Owed/BTC</th>
<th align="right">Balance/BTC</th>
<th align="right">Mint/BTC</th>
<th align="right">Balance/Mint</th>
<th align="right">Price</th>
<th align="right">BTC</th>
<th align="right">USD</th>
<th align="right">Win/Market</th>
</tr>
</thead><tbody>
end;
$current_algo = '';
$server = getparam('server');
if(!empty($server))
{
@ -62,21 +64,17 @@ if(!empty($server))
else
$coins = getdbolist('db_coins', "installed or enable order by algo, index_avg desc");
$mining = getdbosql('db_mining');
foreach($coins as $coin)
{
if($coin->algo != $current_algo)
{
$current_algo = $coin->algo;
echo "<tr class='ssrow' id='$current_algo'>";
}
else
echo "<tr class='ssrow'>";
echo '<tr class="ssrow">';
$lowsymbol = strtolower($coin->symbol);
echo "<td><img src='$coin->image' width=24></td>";
$algo_color = getAlgoColors($coin->algo);
echo "<td style='background-color:$algo_color;'><b>";
echo '<td style="background-color:$algo_color;"><b>';
if($coin->enable)
{
@ -109,6 +107,7 @@ foreach($coins as $coin)
echo "<br><span style='font-size: .8em'>$coin->rpcencoding <span style='background-color:$algo_color;'>&nbsp; ($coin->algo) &nbsp;</span></span></td>";
$difficulty = Itoa2($coin->difficulty, 3);
if ($difficulty > 1e20) $difficulty = '&nbsp;';
if(!empty($coin->errors))
echo "<td align=right style='color: red; font-size: .9em;' title='$coin->errors'><b>$difficulty</b><br>$coin->block_height</td>";
@ -147,25 +146,29 @@ foreach($coins as $coin)
else
echo "<td align=right style='font-size: .9em'>$owed<br>$owed_btc</td>";
$btc = bitcoinvaluetoa($coin->balance*$coin->price);
echo "<td align=right style='font-size: .9em'>$coin->balance<br>$btc</td>";
$btc = bitcoinvaluetoa($coin->mint*$coin->price);
echo "<td align=right style='font-size: .9em'>$coin->mint<br>$btc</td>";
echo '<td align="right" style="font-size: .9em;">'.$coin->balance.'<br/>'.$coin->mint.'</td>';
$price = bitcoinvaluetoa($coin->price);
$price2 = bitcoinvaluetoa($coin->price2);
// $marketcount = getdbocount('db_markets', "coinid=$coin->id");
$marketname = '';
$bestmarket = getBestMarket($coin);
if($bestmarket) $marketname = $bestmarket->name;
if($coin->dontsell)
echo "<td align=right style='font-size: .9em; background-color: #ffaaaa'>$price<br>$price2</td>";
else
echo "<td align=right style='font-size: .9em'>$price<br>$price2</td>";
$btc = bitcoinvaluetoa($coin->balance * $coin->price);
$mint = bitcoinvaluetoa($coin->mint * $coin->price);
echo '<td align="right" style="font-size: .9em;">'.$btc.'<br/>'.$mint.'</td>';
$fiat = round($coin->balance * $coin->price * $mining->usdbtc, 2). ' $';
$mint = round($coin->mint * $coin->price * $mining->usdbtc, 2). ' $';
echo '<td align="right" style="font-size: .9em;">'.$fiat.'<br/>'.$mint.'</td>';
$marketname = '';
$bestmarket = getBestMarket($coin);
if($bestmarket) $marketname = $bestmarket->name;
echo "<td align=right style='font-size: .9em'>$coin->reward<br>$marketname</td>";
echo "</tr>";

View file

@ -1,5 +1,8 @@
<?php
JavascriptFile("/yaamp/ui/js/jquery.metadata.js");
JavascriptFile("/yaamp/ui/js/jquery.tablesorter.widgets.js");
echo <<<end
<div align="right" style="margin-top: -14px; margin-bottom: 6px;">
<input class="search" type="search" data-column="all" style="width: 140px;" placeholder="Search..." />
@ -11,7 +14,18 @@ end;
showTableSorter('maintable', "{
tableClass: 'dataGrid',
headers: { 0: { sorter: false} },
headers: {
0:{sorter:false},
1:{sorter:'text'},
2:{sorter:'text'},
3:{sorter:'currency'},
4:{sorter:'numeric'},
5:{sorter:false},
6:{sorter:'metadata'},
7:{sorter:false},
8:{sorter:false},
9:{sorter:false}
},
widgets: ['zebra','filter'],
widgetOptions: {
filter_external: '.search',
@ -51,7 +65,8 @@ foreach($earnings as $earning)
if(!$block) continue;
$t1 = datetoa2($earning->create_time). ' ago';
$t2 = datetoa2($earning->mature_time). ' ago';
$t2 = datetoa2($earning->mature_time);
if ($t2) $t2 = '+'.$t2;
$coinimg = CHtml::image($coin->image, $coin->symbol, array('width'=>'16'));
$coinlink = CHtml::link($coin->name, '/site/coin?id='.$coin->id);
@ -63,7 +78,7 @@ foreach($earnings as $earning)
echo '<td>'.bitcoinvaluetoa($earning->amount).'</td>';
echo "<td>$block->height</td>";
echo "<td>$block->category ($block->confirmations)</td>";
echo "<td>$t1 $t2</td>";
echo '<td data="'.$earning->create_time.'">'."$t1 $t2</td>";
echo "<td>
<a href='/site/clearearning?id=$earning->id'>[clear]</a>

View file

@ -0,0 +1,122 @@
/*
* Metadata - jQuery plugin for parsing metadata from elements
*
* Copyright (c) 2006 John Resig, Yehuda Katz, J<EFBFBD>örn Zaefferer, Paul McLanahan
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.metadata.js 4187 2007-12-16 17:15:27Z joern.zaefferer $
*
*/
/**
* Sets the type of metadata to use. Metadata is encoded in JSON, and each property
* in the JSON will become a property of the element itself.
*
* There are three supported types of metadata storage:
*
* attr: Inside an attribute. The name parameter indicates *which* attribute.
*
* class: Inside the class attribute, wrapped in curly braces: { }
*
* elem: Inside a child element (e.g. a script tag). The
* name parameter indicates *which* element.
*
* The metadata for an element is loaded the first time the element is accessed via jQuery.
*
* As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
* matched by expr, then redefine the metadata type and run another $(expr) for other elements.
*
* @name $.metadata.setType
*
* @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
* @before $.metadata.setType("class")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from the class attribute
*
* @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
* @before $.metadata.setType("attr", "data")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a "data" attribute
*
* @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
* @before $.metadata.setType("elem", "script")
* @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
* @desc Reads metadata from a nested script element
*
* @param String type The encoding type
* @param String name The name of the attribute to be used to get metadata (optional)
* @cat Plugins/Metadata
* @descr Sets the type of encoding to be used when loading metadata for the first time
* @type undefined
* @see metadata()
*/
(function($) {
$.extend({
metadata : {
defaults : {
type: 'class',
name: 'metadata',
cre: /({.*})/,
single: 'metadata'
},
setType: function( type, name ){
this.defaults.type = type;
this.defaults.name = name;
},
get: function( elem, opts ){
var settings = $.extend({},this.defaults,opts);
// check for empty string in single property
if ( !settings.single.length ) settings.single = 'metadata';
var data = $.data(elem, settings.single);
// returned cached data if it already exists
if ( data ) return data;
data = "{}";
if ( settings.type == "class" ) {
var m = settings.cre.exec( elem.className );
if ( m )
data = m[1];
} else if ( settings.type == "elem" ) {
if( !elem.getElementsByTagName )
return undefined;
var e = elem.getElementsByTagName(settings.name);
if ( e.length )
data = $.trim(e[0].innerHTML);
} else if ( elem.getAttribute != undefined ) {
var attr = elem.getAttribute( settings.name );
if ( attr )
data = attr;
}
if ( data.indexOf( '{' ) <0 )
data = "{" + data + "}";
data = eval("(" + data + ")");
$.data( elem, settings.single, data );
return data;
}
}
});
/**
* Returns the metadata object for the first member of the jQuery object.
*
* @name metadata
* @descr Returns element's metadata object
* @param Object opts An object contianing settings to override the defaults
* @type jQuery
* @cat Plugins/Metadata
*/
$.fn.metadata = function( opts ){
return $.metadata.get( this[0], opts );
};
})(jQuery);

File diff suppressed because it is too large Load diff