-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
336 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/** Icinga Notifications Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Notifications\Widget\TimeGrid; | ||
|
||
use DateInterval; | ||
use DateTime; | ||
use IntlDateFormatter; | ||
use ipl\Html\Attributes; | ||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\Text; | ||
use ipl\I18n\Translation; | ||
use Locale; | ||
|
||
class DaysHeader extends BaseHtmlElement | ||
{ | ||
use Translation; | ||
|
||
/** @var int The number of days to show */ | ||
protected $days; | ||
|
||
protected $tag = 'div'; | ||
|
||
protected $defaultAttributes = ['class' => 'header']; | ||
|
||
/** @var DateTime Starting day */ | ||
protected $startDay; | ||
|
||
public function __construct(DateTime $startDay, int $days) | ||
{ | ||
$this->startDay = $startDay; | ||
$this->days = $days; | ||
} | ||
|
||
public function assemble(): void | ||
{ | ||
$dayNames = [ | ||
$this->translate('Mon', 'monday'), | ||
$this->translate('Tue', 'tuesday'), | ||
$this->translate('Wed', 'wednesday'), | ||
$this->translate('Thu', 'thursday'), | ||
$this->translate('Fri', 'friday'), | ||
$this->translate('Sat', 'saturday'), | ||
$this->translate('Sun', 'sunday') | ||
]; | ||
|
||
$interval = new DateInterval('P1D'); | ||
$today = (new DateTime())->setTime(0, 0); | ||
$time = clone $this->startDay; | ||
$dateFormatter = new IntlDateFormatter( | ||
Locale::getDefault(), | ||
IntlDateFormatter::MEDIUM, | ||
IntlDateFormatter::NONE | ||
); | ||
|
||
for ($i = 0; $i < $this->days; $i++) { | ||
if ($time == $today) { | ||
$title = [new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'day-name']), | ||
Text::create($this->translate('Today')) | ||
)]; | ||
} else { | ||
$title = [ | ||
new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'date']), | ||
Text::create($time->format($this->translate('d/m', 'day-name, time'))) | ||
), | ||
Text::create(' '), | ||
new HtmlElement( | ||
'span', | ||
Attributes::create(['class' => 'day-name']), | ||
Text::create($dayNames[$time->format('N') - 1]) | ||
) | ||
]; | ||
} | ||
|
||
$this->addHtml(new HtmlElement( | ||
'div', | ||
Attributes::create(['class' => 'column-title', 'title' => $dateFormatter->format($time)]), | ||
...$title | ||
)); | ||
|
||
$time->add($interval); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** Icinga Notifications Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Notifications\Widget\TimeGrid; | ||
|
||
use ipl\Html\Attributes; | ||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\HtmlElement; | ||
use ipl\Html\HtmlString; | ||
|
||
/** | ||
* A grid without header and sidebar | ||
*/ | ||
class MinimalGrid extends DynamicGrid | ||
{ | ||
protected function sideBar(): BaseHtmlElement | ||
{ | ||
return HtmlElement::create('div', Attributes::create(['class' => 'sidebar']), new HtmlString('')); | ||
} | ||
|
||
protected function assemble(): void | ||
{ | ||
$this->style->addFor($this, [ | ||
'--primaryColumns' => $this->days, | ||
'--columnsPerStep' => 48, | ||
'--rowsPerStep' => 1 | ||
]); | ||
|
||
$overlay = $this->createGridOverlay(); | ||
if ($overlay->isEmpty()) { | ||
$this->style->addFor($this, [ | ||
'--primaryRows' => count($this->sideBar()) | ||
]); | ||
} | ||
|
||
$this->addHtml( | ||
$this->createGrid(), | ||
$overlay | ||
); | ||
} | ||
} |
Oops, something went wrong.