Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Merge branch 'feature/fix_offline_event_handling' into release/2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Oct 22, 2018
2 parents d0ce6c6 + ad9bdf8 commit ca7fe28
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
7 changes: 6 additions & 1 deletion inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function showForm($ID, array $options = []) {
'value' => $this->fields['plugin_flyvemdm_fleets_id'],
'entity' => $this->fields['entities_id']
]);
$fields['is_online'] = self::getSpecificValueToDisplay('is_online', $fields['is_online']);
if (empty($fields['last_contact'])) {
$fields['last_contact'] = __('Never seen online', 'flyvemdm');
}
Expand Down Expand Up @@ -1998,8 +1999,12 @@ public static function getSpecificValueToDisplay($field, $values, array $options
switch ($field) {
case 'is_online':
if (!isAPI()) {
$style = '';
if (isset($options['center']) && $options['center']) {
$style = 'style="text-align: center"';
}
$class = $values[$field] == 0 ? "plugin-flyvemdm-offline" : "plugin-flyvemdm-online";
$output = '<div style="text-align: center"><i class="fa fa-circle '
$output = '<div ' . $style . '><i class="fa fa-circle '
. $class
. '" aria-hidden="true" ></i></div>';
return $output;
Expand Down
4 changes: 2 additions & 2 deletions inc/mqtthandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ protected function updateOnlineStatus($topic, $message) {
if (!isset($feedback['online'])) {
return;
}
if ($feedback['online'] == 'false') {
if ($feedback['online'] == false) {
$status = '0';
} else if ($feedback['online'] == 'true') {
} else if ($feedback['online'] == true) {
$status = '1';
} else {
// Invalid value
Expand Down
22 changes: 16 additions & 6 deletions inc/mqttlog.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,23 @@ public static function showMqttLogs(PluginFlyvemdmNotifiableInterface $item) {
public static function findLogs(PluginFlyvemdmNotifiableInterface $item) {
global $DB;

$condition = [
'FIELDS' => ['id', 'date', 'topic', 'message'],
'WHERE' => ['itemtype' => $item::getType(), 'items_id' => $item->getID()],
'GROUPBY' => 'topic',
];
// Need this PR to avoid raw SQL
// https://github.com/glpi-project/glpi/pull/4812

$table = self::getTable();
$itemtype = $item->getType();
$itemId = $item->getID();
$result = $DB->request("SELECT `l1`.*
FROM `$table` AS `l1` INNER JOIN
(SELECT MAX(`date`) AS `maxdate`, `topic`
FROM `$table`
WHERE `itemtype` = '$itemtype' AND `items_id` = '$itemId'
GROUP BY `topic`
) AS `l2`
ON `l1`.`topic` = `l2`.`topic` AND `l1`.`date` = `l2`.`maxdate`
WHERE `itemtype`='$itemtype' AND `items_id` = '$itemId'
GROUP BY `topic`");

$result = $DB->request(static::getTable(), $condition);
return $result;
}
}
4 changes: 2 additions & 2 deletions tests/suite-integration/PluginFlyvemdmAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ public function testDeviceOnlineChange() {
$this->boolean($agent->isNewItem())
->isFalse(json_encode($_SESSION['MESSAGE_AFTER_REDIRECT'], JSON_PRETTY_PRINT));

$this->deviceOnlineStatus($agent, 'true', 1);
$this->deviceOnlineStatus($agent, true, 1);

$this->deviceOnlineStatus($agent, 'false', 0);
$this->deviceOnlineStatus($agent, false, 0);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions tpl/agent.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr class='tab_bg_1'>
<td>
{{ __('Name') }}{{ withTemplate }}
{{ __('Name') }}{{ withTemplate }}
</td>
<td>
{{ agent.name|raw }}
Expand Down Expand Up @@ -28,14 +28,16 @@
</tr>
<tr class='tab_bg_1'>
<td>
{{ __('Last contact', 'flyvemdm') }}
{{ __('Is online', 'flyvemdm') }}
</td>
<td>
{{ agent.last_contact }}
{{ agent.is_online|raw }}
</td>
<td>
{{ __('Last contact', 'flyvemdm') }}
</td>
<td>
{{ agent.last_contact }}
</td>
</tr>
{% if canUpdate == true %}
Expand Down

0 comments on commit ca7fe28

Please sign in to comment.