Skip to content

Commit

Permalink
Merge pull request #11 from philippdaun/develop
Browse files Browse the repository at this point in the history
Merge dev branch
  • Loading branch information
daun authored Jan 5, 2020
2 parents 5e6a106 + 758fa5d commit a801eda
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ body.DashboardNoHeadline #pw-content-body {

.AdminThemeUikit .Dashboard__panel .pw-table-responsive {
margin: -20px;
margin-bottom: -15px;
margin-bottom: -21px;
}

.AdminThemeUikit .Dashboard__panel .AdminDataTable th {
background-color: #fafbfc;
}

.AdminThemeUikit .Dashboard__panel .AdminDataTable tbody tr:last-child {
border-bottom-width: 0;
/* border-bottom-width: 0; */
}

.AdminThemeUikit .Dashboard__panel .AdminDataTable tr > :last-child {
Expand Down
76 changes: 40 additions & 36 deletions Dashboard.module
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Dashboard extends Process implements Module {
'PHP>=7.0',
'ProcessWire>=3.0.123',
],
'autoload' => 2, // high priority to always load base class
'singular' => true,
'autoload' => 2, // high priority to always load base class
'singular' => true,
];
}

Expand All @@ -43,17 +43,23 @@ class Dashboard extends Process implements Module {
*
*/
const panelSizes = [
'normal' => 'Normal (half)',
'mini' => 'Mini (one quarter)',
'small' => 'Small (one third)',
'large' => 'Large (two thirds)',
'full' => 'Full',
'mini', // 1/4
'small', // 1/3
'normal', // 1/2
'large', // 2/3
'full', // 1/1
];

/**
* Default panel size
*
*/
const defaultPanelSize = 'normal';

/**
* Module initialization
*
* We overwrite the parent::init() method with an empty method to
* Overwrite the parent::init() method with an empty method to
* disable auto-asset loading, which wo do manually in ready() once
* we're sure we're on the dashboard page
*/
Expand All @@ -68,13 +74,9 @@ class Dashboard extends Process implements Module {
return;
}

$this->modules->loadModuleFileAssets($this);

$this->installOnHomepage = false;

$this->moduleFolder = dirname($this->modules->getModuleFile($this));
$this->viewFolder = "{$this->moduleFolder}/views/";

$this->viewFolder = __DIR__.'/views/';
$this->panels = new DashboardPanelArray();
$this->texts = (object) [
'title' => $this->_('Dashboard'),
'headline' => $this->_('Welcome, %s'),
Expand All @@ -83,18 +85,15 @@ class Dashboard extends Process implements Module {
'empty_panel_notice' => $this->_('Your dashboard is empty'),
'setup_hint' => $this->_('Learn how to add and configure panels reading the <a href="%s">documentation</a>.'),
'get_started' => $this->_('Get started'),
'repo_url' => 'https://github.com/philippdaun/processwire-dashboard',
];

$this->links = (object) [
'repo' => 'https://github.com/philippdaun/processwire-dashboard',
];

$this->panels = new DashboardPanelArray();

// Add classname to allow styling
$this->addHookAfter('AdminTheme::getExtraMarkup', function($event) {
$event->object->addBodyClass("$this");
});

$this->modules->loadModuleFileAssets($this);
}

/**
Expand All @@ -103,7 +102,7 @@ class Dashboard extends Process implements Module {
*/

protected function isDashboardProcess() {
return $this->page && $this->page->template == 'admin' && $this->page->process == 'Dashboard';
return $this->page && $this->page->template == 'admin' && $this->page->process == $this;
}

/**
Expand All @@ -119,27 +118,25 @@ class Dashboard extends Process implements Module {
}
}

// Set title and headline
$title = $this->texts->title;
$headline = $this->getHeadline();
if (!$headline) {
// Set headline and browser title
if ($headline = $this->getHeadline()) {
$this->headline($headline);
} else {
$this->headline($this->texts->title);
// Add custom body class to hide empty headline
$headline = $this->texts->title;
$this->addHookAfter('AdminTheme::getExtraMarkup', function($event) {
$event->object->addBodyClass('DashboardNoHeadline');
});
}
$this->browserTitle($title);
$this->headline($headline);
$this->browserTitle($this->texts->title);

// Render main view
return $this->view('dashboard', [
'module' => "$this",
'settings' => $this->getSettings(),
'panels' => $this->renderPanels(),
'texts' => $this->texts,
'links' => $this->links,
'module' => "$this",
'version' => $this->modules->getModuleInfoProperty($this, 'version'),
'version' => DASHBOARD_VERSION,
]);
}

Expand Down Expand Up @@ -169,7 +166,7 @@ class Dashboard extends Process implements Module {
*/
private function renderPanel($instance) {
$className = $this->getPanelClassName($instance['panel'] ?? '');
$module = $this->modules->get($className);
$module = $this->modules->$className;
if ($this->isValidPanel($module)) {
return $module->render($instance);
} elseif ($this->config->debug) {
Expand Down Expand Up @@ -234,10 +231,17 @@ class Dashboard extends Process implements Module {
* Sanitize panel size to one of allowed values
*
*/
public function sanitizePanelSize($size) {
$allowed = array_keys(self::panelSizes);
$size = $this->sanitizer->option($size, $allowed);
return $size ?: $allowed[0];
public function sanitizePanelSize($input) {
$size = $this->sanitizer->option($input, self::panelSizes);
return $size ?: $this->getDefaultPanelSize();
}

/**
* Hook to allow overwriting the default panel size
*
*/
public function ___getDefaultPanelSize() {
return self::defaultPanelSize;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Dashboard.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.9
0.4.10
20 changes: 8 additions & 12 deletions DashboardPanel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,21 @@ abstract class DashboardPanel extends Wire implements Module {
*/
public static function getModuleInfo() {
return [
'title' => __('Dashboard Panel: Base Class', __FILE__),
'icon' => 'safari',
'requires' => 'Dashboard',
'installs' => 'Dashboard',
'autoload' => false,
'singular' => false,
'title' => __('Dashboard Panel: Base Class', __FILE__),
'icon' => 'safari',
'requires' => 'Dashboard',
'installs' => 'Dashboard',
'autoload' => false,
'singular' => false,
];
}

/**
* Constructor
*/
public function __construct() {
// Store reference to main dashboard instance
$this->dashboard = $this->modules->get('Dashboard');

// Determine module folders
$this->moduleFolder = dirname($this->modules->getModuleFile($this));
$this->viewFolder = "{$this->moduleFolder}/views/";
$this->dashboard = $this->modules->Dashboard;
$this->viewFolder = __DIR__.'/views/';
}

/**
Expand Down
6 changes: 5 additions & 1 deletion DashboardPanelCollection.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
/* Action icons */

.DashboardTableColumn__actions__ {
text-align: right;
text-align: right !important;
}

.DashboardTableColumn__actions__ .tablesorter-header-inner {
display: none;
}

.DashboardTableColumn__actions__ .fa {
Expand Down
8 changes: 7 additions & 1 deletion DashboardPanelShortcuts.module
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class DashboardPanelShortcuts extends DashboardPanel {
$rows = array_map(function ($shortcut, $key) {
$page = null;
$url = '';
$icon = '';

if (is_array($shortcut)) {
list($shortcut, $icon) = $shortcut;
}

if (is_object($shortcut) && $shortcut instanceof Page) {
$page = $shortcut;
} else if (is_int($shortcut)) {
Expand All @@ -49,7 +55,7 @@ class DashboardPanelShortcuts extends DashboardPanel {
} else {
return;
}
$icon = $this->renderPageIcon($page);
$icon = $icon ? $this->renderIcon($icon) : $this->renderPageIcon($page);

return "<li><a href='{$url}'>{$icon} {$title}</a></li>";
}, $this->shortcuts, array_keys($this->shortcuts));
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Each panel configuration is a simple associative array holding the following glo

- `panel`: The panel type (string, required)
- `size`: The width of the panel (string, default: `normal`)
- `mini`: one quarter
- `small`: one third
- `normal`: half
- `large`: two thirds
Expand Down Expand Up @@ -320,16 +321,19 @@ Display a list of shortcuts as links with icons.
- `fallbackIcon`: icon to use if page doesn't have one (string, `bookmark-o` by default)
- `icon`: force one icon for all pages (string, off by default)

To use a custom icon for a shortcut, pass an array as shortcut where the first item is the shortcut and the second item is the icon code.

#### Example

```php
[
'shortcuts' => [
1020, // Page ID
$this->pages->get(1132), // Page
'template=news-item', // Selector
'New things' => 1020, // Override title
'Backups' => "/backup/", // URL
1020, // Page ID
$this->pages->get(1132), // Page
'template=news-item', // Selector
'Backups' => '/backup/', // URL
'Updates' => 1020, // Override title
[304, 'user'], // Override icon
],
'fallbackIcon' => 'star-o',
]
Expand Down
6 changes: 3 additions & 3 deletions views/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class="Dashboard"
<?= $module ?>
<small class="uk-text-small uk-text-muted">
<?= $version ?>
<a href="<?= $links->repo ?>" target="_blank">
<a href="<?= $texts->repo_url ?>" target="_blank">
<i class="fa fa-github fa-fw"></i>
</a>
</small>
Expand All @@ -25,9 +25,9 @@ class="Dashboard"
<!-- <p><i class="fa fa-trello"></i></p> -->
<p><i class="fa fa-hand-peace-o"></i></p>
<p><?= $texts->empty_panel_notice ?></p>
<p><?= sprintf($texts->setup_hint, $links->repo) ?></p>
<p><?= sprintf($texts->setup_hint, $texts->repo_url) ?></p>
<p>
<a href="<?= $links->repo ?>" target="_blank" class="ui-button ui-priority-secondary">
<a href="<?= $texts->repo_url ?>" target="_blank" class="ui-button ui-priority-secondary">
<?= $texts->get_started ?>
</a>
</p>
Expand Down

0 comments on commit a801eda

Please sign in to comment.