@@ -13,7 +13,7 @@ use function ProcessWire\wireIconMarkup;
1313 * @author Philipp Daun <post@philippdaun.net>
1414 * @license GPL-3.0
1515 *
16- * @version 1.4.2
16+ * @version 1.5.0
1717 */
1818
1919// Include abstract panel base class
@@ -31,7 +31,7 @@ class Dashboard extends Process implements Module
3131 'summary' => __('Configurable dashboard page', __FILE__),
3232 'href' => 'https://github.com/daun/processwire-dashboard',
3333 'author' => 'Philipp Daun',
34- 'version' => '1.4.2 ',
34+ 'version' => '1.5.0 ',
3535 'icon' => 'compass',
3636 'permission' => 'dashboard-view',
3737 'permissions' => [
@@ -70,6 +70,7 @@ class Dashboard extends Process implements Module
7070 * Supported panel sizes.
7171 */
7272 const panelSizes = [
73+ 'micro', // 1/6
7374 'mini', // 1/4
7475 'small', // 1/3
7576 'normal', // 1/2
@@ -116,7 +117,7 @@ class Dashboard extends Process implements Module
116117 'headline_without_user' => $this->_('Welcome'),
117118 'panel_not_found' => $this->_('Dashboard panel not found: %s'),
118119 'empty_panel_notice' => $this->_('Your dashboard is empty'),
119- 'setup_hint' => $this->sanitizer->entitiesMarkdown(
120+ 'setup_hint' => $this->wire()-> sanitizer->entitiesMarkdown(
120121 $this->_('Learn how to add and configure panels reading the [documentation](%s).')
121122 ),
122123 'get_started' => $this->_('Get started'),
@@ -174,19 +175,17 @@ class Dashboard extends Process implements Module
174175 protected function addUserNavItem()
175176 {
176177 $this->addHookAfter('AdminThemeFramework::getUserNavArray', function ($event) {
177- $navArray = $event->return;
178-
179178 $page = $this->getDashboardPageInNav() ?: $this->getDashboardPage();
180179 if ($page && $page->viewable) {
181180 $icon = $this->modules->getModuleInfoProperty($this, 'icon');
182- array_unshift($navArray, [
181+ $nav = $event->return;
182+ array_unshift($nav, [
183183 'url' => $page->url,
184184 'title' => $this->texts->usernav,
185185 'icon' => $icon,
186186 ]);
187+ $event->return = $nav;
187188 }
188-
189- $event->return = $navArray;
190189 });
191190 }
192191
@@ -195,7 +194,7 @@ class Dashboard extends Process implements Module
195194 */
196195 protected function getDashboardPage()
197196 {
198- $admin = $this->pages->get(2 );
197+ $admin = $this->wire()-> pages->get($this->wire()->config->adminRootPageID );
199198 $children = $admin->children('include=hidden, check_access=0');
200199
201200 return $admin->and($children)->get("process={$this}");
@@ -206,7 +205,7 @@ class Dashboard extends Process implements Module
206205 */
207206 protected function getDashboardPageInNav()
208207 {
209- $admin = $this->pages->get(2 );
208+ $admin = $this->wire()-> pages->get($this->wire()->config->adminRootPageID );
210209 $pages = $admin->children('check_access=0');
211210
212211 return $pages->get("process={$this}");
@@ -218,10 +217,11 @@ class Dashboard extends Process implements Module
218217 public function ___execute()
219218 {
220219 // Redirect admin homepage to process page if in navigation
221- if ($this->page->id === 2 ) {
220+ if ($this->page->id === $this->wire()->config->adminRootPageID ) {
222221 $page = $this->getDashboardPageInNav();
223222 if ($page) {
224223 $this->session->redirect($page->url);
224+ return;
225225 }
226226 }
227227
@@ -231,11 +231,16 @@ class Dashboard extends Process implements Module
231231 // Load panel instances from hook
232232 $this->panels = $this->getPanels();
233233
234- // Ajax request? Render requested panel directly
235- if ($this->config->ajax && $this->input->post->dashboard) {
236- $key = $this->input->post->key;
237- $panel = $this->input->post->panel;
238- return $this->renderInstanceByKey($key, $panel);
234+ if ($this->config->ajax) {
235+ if ($this->input->post->dashboard) {
236+ // Ajax request? (Re)render a single requested panel
237+ $key = $this->input->post->key;
238+ $panel = $this->input->post->panel;
239+ return $this->renderInstanceByKey($key, $panel);
240+ } else {
241+ // Disregard all other ajax requests
242+ return;
243+ }
239244 }
240245
241246 // Set browser title
@@ -399,7 +404,7 @@ class Dashboard extends Process implements Module
399404 */
400405 private function getPanelClassName($name)
401406 {
402- $panelName = $this->sanitizer() ->pascalCase($name);
407+ $panelName = $this->wire()->sanitizer ->pascalCase($name);
403408
404409 return self::panelModulePrefix.$panelName;
405410 }
@@ -409,10 +414,10 @@ class Dashboard extends Process implements Module
409414 */
410415 public function sanitizePanelSize($input)
411416 {
412- $size = $this->sanitizer->option($input, self::panelSizes);
417+ $size = $this->wire()-> sanitizer->option($input, self::panelSizes);
413418 if (!$size) {
414419 $default = $this->settings->defaultPanelSize;
415- $size = $this->sanitizer->option($default, self::panelSizes);
420+ $size = $this->wire()-> sanitizer->option($default, self::panelSizes);
416421 }
417422
418423 return $size ?: self::fallbackPanelSize;
@@ -554,7 +559,7 @@ class Dashboard extends Process implements Module
554559 parent::___install();
555560 if ($this->installOnHomepage) {
556561 // Set the admin process to use this module
557- $admin = $this->pages->get(2 );
562+ $admin = $this->wire()-> pages->get($this->wire()->config->adminRootPageID );
558563 $admin->process = $this;
559564 $admin->save();
560565 }
@@ -572,7 +577,7 @@ class Dashboard extends Process implements Module
572577 parent::___uninstall();
573578 if ($this->installOnHomepage) {
574579 // Restore the admin process to use ProcessHome again
575- $admin = $this->pages->get(2 );
580+ $admin = $this->wire()-> pages->get($this->wire()->config->adminRootPageID );
576581 $admin->process = 'ProcessHome';
577582 $admin->save();
578583 }
0 commit comments