Showing with 63 additions and 49 deletions.
  1. +12 −8 css/testswarm.css
  2. +2 −4 inc/actions/SwarmstateAction.php
  3. +2 −2 inc/pages/ApiDebugPage.php
  4. +47 −35 inc/pages/HomePage.php
@@ -3,22 +3,26 @@
text-align: center;
}

.swarm-browseronline img {
height: 48px;
.swarm-browseronline .swarm-onlineclients {
position: absolute;
top: 5px;
right: 5px;
line-height: normal;
}

.swarm-browseronline .badge {
position: absolute;
right: 7px;
top: 7px;
.swarm-browseronline .swarm-browsericon {
height: 48px;
margin: 10px 0;
}
.swarm-browseronline .badge:hover {

.swarm-browseronline .swarm-browsername:hover {
cursor: default;
}

/* Result table */

table.swarm-results th {
table.swarm-results th,
table.swarm-results td {
text-align: center;
}

@@ -55,10 +55,8 @@ public function doAction() {
continue;
}

$data["useragents"][$uaID] = array(
"id" => $uaID,
"displaytitle" => $uaData->displaytitle,
"displayicon" => $uaData->displayicon,
$data["userAgents"][$uaID] = array(
"data" => $uaData,
"stats" => array(
"onlineClients" => intval( $clients ),
"pendingRuns" => intval( $pendingRuns ),
@@ -31,7 +31,7 @@ protected function initContent() {

ob_start();
var_dump( $_POST + $_GET );
$html .= ob_get_contents();
$html .= htmlspecialchars( ob_get_contents() );
ob_end_clean();

$html .= "</pre>";
@@ -41,7 +41,7 @@ protected function initContent() {

ob_start();
var_dump( $this->apiResponse );
$html .= ob_get_contents();
$html .= htmlspecialchars( ob_get_contents() );
ob_end_clean();

$html .= "</pre>";
@@ -13,6 +13,14 @@ class HomePage extends Page {

var $userHasKnownUA = false;

public function execute() {
$action = SwarmstateAction::newFromContext( $this->getContext() );
$action->doAction();

$this->setAction( $action );
$this->content = $this->initContent();
}

protected function initContent() {
$request = $this->getContext()->getRequest();
$browserInfo = $this->getContext()->getBrowserInfo();
@@ -76,49 +84,53 @@ protected function initContent() {


/** @return bool: Whether the current user was found in the swarm */
function getBrowsersOnlineHtml() {
$swarmUaIndex = BrowserInfo::getSwarmUAIndex();
public function getBrowsersOnlineHtml() {
$db = $this->getContext()->getDB();
$browserInfo = $this->getContext()->getBrowserInfo();

$html = "";
$data = $this->getAction()->getData();

$clientRows = $db->getRows(str_queryf(
"SELECT
COUNT(*) as total,
useragent_id
FROM clients
WHERE clients.updated > %u
GROUP BY useragent_id;",
swarmdb_dateformat( strtotime( '1 minute ago' ) )
));
$onlineStats = array();
if ( $clientRows ) {
foreach ( $clientRows as $clientRow ) {
$onlineStats[$clientRow->useragent_id] = intval( $clientRow->total );
}
}
$html = "";

$desktopHtml = '<h2>Desktop Browsers</h2><div class="row">';
$mobileHtml = '<h2>Mobile Browsers</h2><div class="row">';

foreach ( $swarmUaIndex as $swarmUaId => $swarmUaItem ) {
$isCurr = $swarmUaId == $browserInfo->getSwarmUaID();

$item = '<div class="span2">'
. '<div class="well swarm-browseronline' . ( $isCurr ? " alert-info" : "" ) . '">'
. '<img src="' . swarmpath( "img/" . $swarmUaItem->displayicon . ".sm.png" ) . '"'
. ' class="swarm-browsericon"'
. ' alt="' . htmlspecialchars( $swarmUaItem->displaytitle ) . '"'
. ' title="' . htmlspecialchars( $swarmUaItem->displaytitle ) . '"'
. '>';
if ( isset( $onlineStats[$swarmUaId] ) && $onlineStats[$swarmUaId] > 0 ) {
$item .= '<span class="badge badge-error">' . $onlineStats[$swarmUaId] . '</span>';
}
$item .= '<br><span class="label">' . htmlspecialchars( $swarmUaItem->displaytitle ) . '</span>';
$item .= '</div></div>';

if ( $swarmUaItem->mobile ) {
foreach ( $data["userAgents"] as $uaID => $userAgent ) {
$isCurr = $uaID == $browserInfo->getSwarmUaID();

$item = ""
. '<div class="span2">'
. '<div class="well well-small swarm-browseronline' . ( $isCurr ? " alert-info" : "" ) . '">'
. html_tag( "img", array(
"src" => swarmpath( "img/" . $userAgent["data"]["displayicon"] . ".sm.png" ),
"class" => "swarm-browsericon",
"alt" => "",
"title" => $userAgent["data"]["displaytitle"],
) )
. '<br>'
. html_tag( "span", array(
"class" => "badge swarm-browsername",
), $userAgent["data"]["displaytitle"] )
. '<br>'
. html_tag( "span", array(
"class" => "swarm-onlineclients " . (
$userAgent["stats"]["onlineClients"] > 0
? "badge"
: ( $userAgent["stats"]["pendingRuns"] > 0 ? "badge badge-error" : "badge" )
),
"title" => $userAgent["stats"]["onlineClients"] . ' clients online',
), $userAgent["stats"]["onlineClients"] )
. html_tag( "span", array(
"class" => "swarm-pendingruns " . (
$userAgent["stats"]["pendingRuns"] > 0
? ( $userAgent["stats"]["onlineClients"] > 0 ? "label label-info" : "label label-warning" )
: "label label-success"
)
), $userAgent["stats"]["pendingRuns"] . ' pending runs' )
. '</div>'
. '</div>';

if ( $userAgent["data"]["mobile"] ) {
$mobileHtml .= $item;
} else {
$desktopHtml .= $item;