Skip to content

Commit 4cd1af7

Browse files
authored
Use new item list implementation (#315)
2 parents 81fd7d4 + b5cd11e commit 4cd1af7

67 files changed

Lines changed: 1341 additions & 2127 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

application/controllers/ChannelsController.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
namespace Icinga\Module\Notifications\Controllers;
66

77
use Icinga\Module\Notifications\Common\Database;
8+
use Icinga\Module\Notifications\Common\Links;
89
use Icinga\Module\Notifications\Forms\ChannelForm;
910
use Icinga\Module\Notifications\Model\Channel;
11+
use Icinga\Module\Notifications\View\ChannelRenderer;
1012
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
11-
use Icinga\Module\Notifications\Widget\ItemList\ChannelList;
13+
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1214
use Icinga\Web\Notification;
1315
use Icinga\Web\Widget\Tab;
1416
use Icinga\Web\Widget\Tabs;
15-
use ipl\Html\ValidHtml;
1617
use ipl\Sql\Connection;
1718
use ipl\Stdlib\Filter;
18-
use ipl\Web\Common\BaseItemList;
1919
use ipl\Web\Compat\CompatController;
2020
use ipl\Web\Compat\SearchControls;
2121
use ipl\Web\Control\LimitControl;
2222
use ipl\Web\Control\SortControl;
2323
use ipl\Web\Filter\QueryString;
24-
use ipl\Web\Url;
24+
use ipl\Web\Layout\MinimalItemLayout;
2525
use ipl\Web\Widget\ButtonLink;
2626

2727
class ChannelsController extends CompatController
@@ -85,15 +85,15 @@ public function indexAction()
8585
$this->addControl($limitControl);
8686
$this->addControl($searchBar);
8787
$this->addContent(
88-
(new ButtonLink(
89-
t('Add Channel'),
90-
Url::fromPath('notifications/channels/add'),
91-
'plus'
92-
))->setBaseTarget('_next')
93-
->addAttributes(['class' => 'add-new-component'])
88+
(new ButtonLink(t('Add Channel'), Links::channelAdd(), 'plus'))
89+
->setBaseTarget('_next')
90+
->addAttributes(['class' => 'add-new-component'])
9491
);
9592

96-
$this->addContent(new ChannelList($channels));
93+
$this->addContent(
94+
(new ObjectList($channels, new ChannelRenderer()))
95+
->setItemLayoutClass(MinimalItemLayout::class)
96+
);
9797

9898
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
9999
$this->sendMultipartUpdate();
@@ -112,29 +112,13 @@ public function addAction()
112112
$form->getValue('name')
113113
)
114114
);
115-
$this->redirectNow(Url::fromPath('notifications/channels'));
115+
$this->redirectNow(Links::channels());
116116
})
117117
->handleRequest($this->getServerRequest());
118118

119119
$this->addContent($form);
120120
}
121121

122-
/**
123-
* Add attribute 'class' => 'full-width' if the content is an instance of BaseItemList
124-
*
125-
* @param ValidHtml $content
126-
*
127-
* @return ChannelsController
128-
*/
129-
protected function addContent(ValidHtml $content)
130-
{
131-
if ($content instanceof BaseItemList) {
132-
$this->content->getAttributes()->add('class', 'full-width');
133-
}
134-
135-
return parent::addContent($content);
136-
}
137-
138122
public function completeAction(): void
139123
{
140124
$suggestions = new ObjectSuggestions();

application/controllers/ConfigController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
use Icinga\Application\Config;
88
use Icinga\Module\Notifications\Forms\DatabaseConfigForm;
9-
use Icinga\Web\Form;
109
use Icinga\Web\Notification;
1110
use Icinga\Web\Widget\Tab;
1211
use Icinga\Web\Widget\Tabs;
13-
use ipl\Html\HtmlString;
1412
use ipl\Web\Compat\CompatController;
1513

1614
class ConfigController extends CompatController

application/controllers/ContactController.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
namespace Icinga\Module\Notifications\Controllers;
66

77
use Icinga\Module\Notifications\Common\Database;
8-
use Icinga\Module\Notifications\Model\Contact;
98
use Icinga\Module\Notifications\Web\Form\ContactForm;
109
use Icinga\Web\Notification;
11-
use ipl\Html\FormElement\FieldsetElement;
12-
use ipl\Sql\Connection;
13-
use ipl\Stdlib\Filter;
1410
use ipl\Web\Compat\CompatController;
1511

1612
class ContactController extends CompatController

application/controllers/ContactGroupController.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
use Icinga\Module\Notifications\Forms\ContactGroupForm;
1010
use Icinga\Module\Notifications\Model\Contact;
1111
use Icinga\Module\Notifications\Model\Contactgroup;
12-
use Icinga\Module\Notifications\Model\ContactgroupMember;
13-
use Icinga\Module\Notifications\Widget\ItemList\ContactList;
12+
use Icinga\Module\Notifications\View\ContactRenderer;
13+
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1414
use Icinga\Web\Notification;
1515
use ipl\Html\Attributes;
1616
use ipl\Html\Form;
1717
use ipl\Html\HtmlElement;
1818
use ipl\Html\Text;
19-
use ipl\Html\ValidHtml;
2019
use ipl\Stdlib\Filter;
21-
use ipl\Web\Common\BaseItemList;
2220
use ipl\Web\Compat\CompatController;
21+
use ipl\Web\Layout\MinimalItemLayout;
2322
use ipl\Web\Widget\ButtonLink;
2423

2524
class ContactGroupController extends CompatController
@@ -64,7 +63,10 @@ public function indexAction(): void
6463
))->openInModal()
6564
);
6665

67-
$this->addContent(new ContactList($contacts));
66+
$this->addContent(
67+
(new ObjectList($contacts, new ContactRenderer()))
68+
->setItemLayoutClass(MinimalItemLayout::class)
69+
);
6870

6971
$this->addTitleTab(t('Contact Group'));
7072
$this->setTitle(sprintf(t('Contact Group: %s'), $group->name));
@@ -111,13 +113,4 @@ public function editAction(): void
111113
$this->addContent($form);
112114
$this->setTitle(t('Edit Contact Group'));
113115
}
114-
115-
protected function addContent(ValidHtml $content): self
116-
{
117-
if ($content instanceof BaseItemList) {
118-
$this->content->getAttributes()->add('class', 'full-width');
119-
}
120-
121-
return parent::addContent($content);
122-
}
123116
}

application/controllers/ContactGroupsController.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88
use Icinga\Module\Notifications\Common\Links;
99
use Icinga\Module\Notifications\Forms\ContactGroupForm;
1010
use Icinga\Module\Notifications\Model\Contactgroup;
11+
use Icinga\Module\Notifications\View\ContactgroupRenderer;
1112
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
12-
use Icinga\Module\Notifications\Widget\ItemList\ContactGroupList;
13+
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1314
use Icinga\Module\Notifications\Widget\MemberSuggestions;
1415
use Icinga\Web\Notification;
1516
use ipl\Html\Form;
1617
use ipl\Html\Text;
17-
use ipl\Html\ValidHtml;
1818
use ipl\Stdlib\Filter;
19-
use ipl\Web\Common\BaseItemList;
2019
use ipl\Web\Compat\CompatController;
2120
use ipl\Web\Compat\SearchControls;
2221
use ipl\Web\Control\LimitControl;
2322
use ipl\Web\Control\SortControl;
2423
use ipl\Web\Filter\QueryString;
24+
use ipl\Web\Layout\MinimalItemLayout;
2525
use ipl\Web\Widget\ButtonLink;
2626
use ipl\Web\Widget\Tabs;
2727

@@ -87,7 +87,10 @@ public function indexAction(): void
8787
))->openInModal()
8888
);
8989

90-
$this->addContent(new ContactGroupList($groups));
90+
$this->addContent(
91+
(new ObjectList($groups, new ContactgroupRenderer()))
92+
->setItemLayoutClass(MinimalItemLayout::class)
93+
);
9194

9295
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
9396
$this->sendMultipartUpdate();
@@ -178,15 +181,6 @@ public function getTabs(): Tabs
178181
]);
179182
}
180183

181-
protected function addContent(ValidHtml $content): self
182-
{
183-
if ($content instanceof BaseItemList) {
184-
$this->content->getAttributes()->add('class', 'full-width');
185-
}
186-
187-
return parent::addContent($content);
188-
}
189-
190184
/**
191185
* Get the filter created from query string parameters
192186
*

application/controllers/ContactsController.php

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
namespace Icinga\Module\Notifications\Controllers;
66

77
use Icinga\Module\Notifications\Common\Links;
8+
use Icinga\Module\Notifications\View\ContactRenderer;
89
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
910
use Icinga\Module\Notifications\Common\Database;
1011
use Icinga\Module\Notifications\Model\Contact;
1112
use Icinga\Module\Notifications\Web\Form\ContactForm;
12-
use Icinga\Module\Notifications\Widget\ItemList\ContactList;
13+
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1314
use Icinga\Web\Notification;
1415
use ipl\Sql\Connection;
1516
use ipl\Stdlib\Filter;
16-
use ipl\Web\Common\BaseItemList;
1717
use ipl\Web\Compat\CompatController;
1818
use ipl\Web\Compat\SearchControls;
1919
use ipl\Web\Control\LimitControl;
2020
use ipl\Web\Control\SortControl;
2121
use ipl\Web\Filter\QueryString;
22+
use ipl\Web\Layout\MinimalItemLayout;
2223
use ipl\Web\Widget\ButtonLink;
23-
use ipl\Html\ValidHtml;
2424

2525
class ContactsController extends CompatController
2626
{
@@ -80,15 +80,15 @@ public function indexAction()
8080
$this->addControl($limitControl);
8181
$this->addControl($searchBar);
8282
$this->addContent(
83-
(new ButtonLink(
84-
t('Add Contact'),
85-
'notifications/contacts/add',
86-
'plus'
87-
))->setBaseTarget('_next')
88-
->addAttributes(['class' => 'add-new-component'])
83+
(new ButtonLink(t('Add Contact'), Links::contactAdd(), 'plus'))
84+
->setBaseTarget('_next')
85+
->addAttributes(['class' => 'add-new-component'])
8986
);
9087

91-
$this->addContent(new ContactList($contacts));
88+
$this->addContent(
89+
(new ObjectList($contacts, new ContactRenderer()))
90+
->setItemLayoutClass(MinimalItemLayout::class)
91+
);
9292

9393
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
9494
$this->sendMultipartUpdate();
@@ -114,22 +114,6 @@ public function addAction(): void
114114
$this->addContent($form);
115115
}
116116

117-
/**
118-
* Add attribute 'class' => 'full-width' if the content is an instance of BaseItemList
119-
*
120-
* @param ValidHtml $content
121-
*
122-
* @return ContactsController
123-
*/
124-
protected function addContent(ValidHtml $content)
125-
{
126-
if ($content instanceof BaseItemList) {
127-
$this->content->getAttributes()->add('class', 'full-width');
128-
}
129-
130-
return parent::addContent($content);
131-
}
132-
133117
public function completeAction(): void
134118
{
135119
$suggestions = new ObjectSuggestions();

application/controllers/EventController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
namespace Icinga\Module\Notifications\Controllers;
66

7-
use ArrayObject;
87
use Icinga\Module\Notifications\Common\Auth;
98
use Icinga\Module\Notifications\Common\Database;
109
use Icinga\Module\Notifications\Model\Event;
1110
use Icinga\Module\Notifications\Widget\Detail\EventDetail;
12-
use Icinga\Module\Notifications\Widget\ItemList\EventList;
13-
use ipl\Orm\ResultSet;
11+
use Icinga\Module\Notifications\Widget\Detail\ObjectHeader;
1412
use ipl\Stdlib\Filter;
1513
use ipl\Web\Compat\CompatController;
1614

@@ -40,11 +38,7 @@ public function indexAction(): void
4038
$this->httpNotFound(t('Event not found'));
4139
}
4240

43-
$this->addControl(
44-
(new EventList(new ResultSet(new ArrayObject([$event]))))
45-
->setPageSize(1)
46-
->setNoSubjectLink()
47-
);
41+
$this->addControl(new ObjectHeader($event));
4842

4943
$this->controls->addAttributes(['class' => 'event-detail']);
5044

application/controllers/EventRuleController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Icinga\Module\Notifications\Common\Links;
1010
use Icinga\Module\Notifications\Forms\EventRuleForm;
1111
use Icinga\Module\Notifications\Forms\SaveEventRuleForm;
12-
use Icinga\Module\Notifications\Model\Incident;
1312
use Icinga\Module\Notifications\Model\Rule;
1413
use Icinga\Module\Notifications\Web\Control\SearchBar\ExtraTagSuggestions;
1514
use Icinga\Module\Notifications\Widget\EventRuleConfig;

application/controllers/EventRulesController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use Icinga\Module\Notifications\Common\Links;
99
use Icinga\Module\Notifications\Forms\SaveEventRuleForm;
1010
use Icinga\Module\Notifications\Model\Rule;
11+
use Icinga\Module\Notifications\View\EventRuleRenderer;
1112
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
1213
use Icinga\Module\Notifications\Widget\EventRuleConfig;
13-
use Icinga\Module\Notifications\Widget\ItemList\EventRuleList;
14+
use Icinga\Module\Notifications\Widget\ItemList\ObjectList;
1415
use Icinga\Web\Notification;
1516
use Icinga\Web\Session;
1617
use ipl\Html\Html;
@@ -21,6 +22,7 @@
2122
use ipl\Web\Control\SearchEditor;
2223
use ipl\Web\Control\SortControl;
2324
use ipl\Web\Filter\QueryString;
25+
use ipl\Web\Layout\DetailedItemLayout;
2426
use ipl\Web\Url;
2527
use ipl\Web\Widget\ButtonLink;
2628
use ipl\Web\Widget\Icon;
@@ -88,10 +90,13 @@ public function indexAction(): void
8890
Url::fromPath('notifications/event-rule/edit', ['id' => -1, 'clearCache' => true]),
8991
'plus'
9092
))->openInModal()
91-
->addAttributes(['class' => 'new-event-rule'])
93+
->addAttributes(['class' => 'add-new-component'])
9294
);
9395

94-
$this->addContent(new EventRuleList($eventRules));
96+
$this->addContent(
97+
(new ObjectList($eventRules, new EventRuleRenderer()))
98+
->setItemLayoutClass(DetailedItemLayout::class)
99+
);
95100

96101
if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
97102
$this->sendMultipartUpdate();

application/controllers/EventsController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66

77
use Icinga\Module\Notifications\Common\Auth;
88
use Icinga\Module\Notifications\Common\Database;
9+
use Icinga\Module\Notifications\Hook\ObjectsRendererHook;
910
use Icinga\Module\Notifications\Web\Control\SearchBar\ObjectSuggestions;
10-
use Icinga\Module\Notifications\Widget\ItemList\EventList;
1111
use Icinga\Module\Notifications\Model\Event;
12+
use Icinga\Module\Notifications\Widget\ItemList\LoadMoreObjectList;
1213
use ipl\Stdlib\Filter;
1314
use ipl\Web\Compat\CompatController;
1415
use ipl\Web\Compat\SearchControls;
1516
use ipl\Web\Control\LimitControl;
1617
use ipl\Web\Control\SortControl;
1718
use ipl\Web\Filter\QueryString;
1819
use ipl\Web\Url;
20+
use ipl\Web\Widget\ItemList;
21+
use ipl\Web\Widget\ListItem;
1922

2023
class EventsController extends CompatController
2124
{
@@ -83,9 +86,15 @@ public function indexAction(): void
8386
$url = Url::fromRequest()->onlyWith($preserveParams);
8487
$url->setQueryString(QueryString::render($filter) . '&' . $url->getParams()->toString());
8588

86-
$eventList = (new EventList($events->execute()))
89+
$eventList = (new LoadMoreObjectList($events->execute()))
8790
->setPageSize($limitControl->getLimit())
88-
->setLoadMoreUrl($url->setParam('before', $before));
91+
->setLoadMoreUrl($url->setParam('before', $before))
92+
->on(ItemList::ON_ITEM_ADD, function (ListItem $item, Event $data) {
93+
ObjectsRendererHook::register($data->object);
94+
})
95+
->on(ItemList::ON_ASSEMBLED, function () {
96+
ObjectsRendererHook::load();
97+
});
8998

9099
if ($compact) {
91100
$eventList->setPageNumber($page);

0 commit comments

Comments
 (0)