Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CronTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
if ($item instanceof GlpiCronTask) {
/** @var GlpiCronTask $item */
$cron_task = new self();
$cron_task->showForCronTask($item);
$cron_task->showForCronTask($item, $tabnum);
}
return true;
}

public function showForCronTask(CommonDBTM $item)
public function showForCronTask(CommonDBTM $item, int $tabnum)
{
$itemtype = $item->fields['itemtype'];
if (!in_array($itemtype, CronTaskProvider::getCronTaskTypes())) {
return;
}
$crontask = new $itemtype();
$crontask->showForCronTask($item);
$crontask->showForCronTask($item, $tabnum);
}

/**
Expand Down
37 changes: 25 additions & 12 deletions src/DataSource/CarbonIntensity/ElectricityMaps/CronTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@

class CronTask extends AbstractCronTask implements CronTaskInterface
{
private const TAB_DIAGNOSIS = 0;
private const TAB_CACHE = 1;

public static function getIcon()
{
return 'fa-solid fa-gears';
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
return self::createTabEntry(__('Resource diagnosis', 'carbon'), 0);
return [
self::TAB_DIAGNOSIS => self::createTabEntry(__('Resource diagnosis', 'carbon'), 0),
// self::TAB_CACHE => self::createTabEntry(__('Cache', 'carbon'), 0),
];
}

public static function enumerateTasks(): array
Expand Down Expand Up @@ -103,19 +109,26 @@ public static function cronDownloadElectricityMap(GlpiCronTask $task): int
return CarbonCronTask::downloadCarbonIntensityFromSource($task, $client, new CarbonIntensity());
}

public function showForCronTask(CommonDBTM $item)
public function showForCronTask(CommonDBTM $item, int $tabnum)
{
switch ($item->fields['name']) {
case 'DownloadElectricityMap':
$client = new Client(new RestApiClient());
$source_name = ($client)->getSourceName();
foreach ($client->getSupportedZones() as $zone_name) {
$source_zone = new Source_Zone();
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
continue;
if ($tabnum === self::TAB_DIAGNOSIS) {
switch ($item->fields['name']) {
case 'DownloadElectricityMap':
$client = new Client(new RestApiClient());
$source_name = ($client)->getSourceName();
foreach ($client->getSupportedZones() as $zone_name) {
$source_zone = new Source_Zone();
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
continue;
}
$source_zone->showGaps();
}
$source_zone->showGaps();
}
}
} elseif ($tabnum === self::TAB_CACHE) {
switch ($item->fields['name']) {
case 'DownloadElectricityMap':
// TODO: implement tab to clear cached data in files/ folder
}
}
}
}
37 changes: 25 additions & 12 deletions src/DataSource/CarbonIntensity/Rte/CronTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,42 @@

class CronTask extends AbstractCronTask implements CronTaskInterface
{
private const TAB_DIAGNOSIS = 0;
private const TAB_CACHE = 1;

public static function getIcon()
{
return 'fa-solid fa-gears';
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
return self::createTabEntry(__('Resource diagnosis', 'carbon'), 0);
return [
self::TAB_DIAGNOSIS => self::createTabEntry(__('Resource diagnosis', 'carbon'), 0),
// self::TAB_CACHE => self::createTabEntry(__('Cache', 'carbon'), 0),
];
}

public function showForCronTask(CommonDBTM $item)
public function showForCronTask(CommonDBTM $item, int $tabnum)
{
switch ($item->fields['name']) {
case 'DownloadRte':
$client = new Client(new RestApiClient());
$source_name = ($client)->getSourceName();
foreach ($client->getSupportedZones() as $zone_name) {
$source_zone = new Source_Zone();
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
continue;
if ($tabnum === self::TAB_DIAGNOSIS) {
switch ($item->fields['name']) {
case 'DownloadRte':
$client = new Client(new RestApiClient());
$source_name = ($client)->getSourceName();
foreach ($client->getSupportedZones() as $zone_name) {
$source_zone = new Source_Zone();
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
continue;
}
$source_zone->showGaps();
}
$source_zone->showGaps();
}
}
} elseif ($tabnum === self::TAB_CACHE) {
switch ($item->fields['name']) {
case 'DownloadElectricityMap':
// TODO: implement tab to clear cached data in files/ folder
}
}
}

Expand Down