Dashboard now supports reset and make default
Added the new widgets to the add widget screen System Parameters can now be reset
This commit is contained in:
parent
b171407382
commit
bb769db223
|
|
@ -29,6 +29,7 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
*/
|
||||
if (App::runningInBackend()) {
|
||||
$this->registerBackendNavigation();
|
||||
$this->registerBackendReportWidgets();
|
||||
$this->registerBackendWidgets();
|
||||
$this->registerBackendPermissions();
|
||||
$this->registerBackendSettings();
|
||||
|
|
@ -100,6 +101,19 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Register report widgets
|
||||
*/
|
||||
protected function registerBackendReportWidgets()
|
||||
{
|
||||
WidgetManager::instance()->registerReportWidgets(function ($manager) {
|
||||
$manager->registerReportWidget('Backend\ReportWidgets\Welcome', [
|
||||
'label' => 'backend::lang.dashboard.welcome.widget_title_default',
|
||||
'context' => 'dashboard'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Register permissions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ return [
|
|||
'widget_label' => 'Widget',
|
||||
'widget_width' => 'Width',
|
||||
'full_width' => 'full width',
|
||||
'manage_widgets' => 'Manage widgets',
|
||||
'add_widget' => 'Add widget',
|
||||
'widget_inspector_title' => 'Widget configuration',
|
||||
'widget_inspector_description' => 'Configure the report widget',
|
||||
|
|
@ -65,6 +66,12 @@ return [
|
|||
'widget_new_row_description' => 'Put the widget in a new row.',
|
||||
'widget_title_label' => 'Widget title',
|
||||
'widget_title_error' => 'The Widget Title is required.',
|
||||
'reset_layout' => 'Reset layout',
|
||||
'reset_layout_confirm' => 'Reset layout back to default?',
|
||||
'reset_layout_success' => 'Layout has been reset',
|
||||
'make_default' => 'Make default',
|
||||
'make_default_confirm' => 'Set the current layout as the default?',
|
||||
'make_default_success' => 'Current layout is now the default',
|
||||
'status' => [
|
||||
'widget_title_default' => 'System status',
|
||||
'update_available' => '{0} updates available!|{1} update available!|[2,Inf] updates available!',
|
||||
|
|
@ -89,7 +96,6 @@ return [
|
|||
'nice_message' => 'Have a great day!',
|
||||
]
|
||||
],
|
||||
|
||||
'user' => [
|
||||
'name' => 'Administrator',
|
||||
'menu_label' => 'Administrators',
|
||||
|
|
|
|||
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
use File;
|
||||
use Lang;
|
||||
use Flash;
|
||||
use Request;
|
||||
use Backend\Classes\WidgetBase;
|
||||
use Backend\Classes\WidgetManager;
|
||||
use Backend\Models\UserPreference;
|
||||
use System\Models\Parameters as SystemParameters;
|
||||
use ApplicationException;
|
||||
|
||||
/**
|
||||
|
|
@ -130,6 +132,26 @@ class ReportContainer extends WidgetBase
|
|||
// Event handlers
|
||||
//
|
||||
|
||||
public function onResetWidgets()
|
||||
{
|
||||
$this->resetWidgets();
|
||||
|
||||
$this->vars['widgets'] = $this->reportWidgets;
|
||||
|
||||
Flash::success(Lang::get('backend::lang.dashboard.reset_layout_success'));
|
||||
|
||||
return ['#'.$this->getId('container-list') => $this->makePartial('widget_list')];
|
||||
}
|
||||
|
||||
public function onMakeLayoutDefault()
|
||||
{
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
SystemParameters::set($this->getSystemParametersKey(), $widgets);
|
||||
|
||||
Flash::success(Lang::get('backend::lang.dashboard.make_default_success'));
|
||||
}
|
||||
|
||||
public function onUpdateWidget()
|
||||
{
|
||||
$alias = Request::input('alias');
|
||||
|
|
@ -196,6 +218,10 @@ class ReportContainer extends WidgetBase
|
|||
|
||||
public function addWidget($widget, $size)
|
||||
{
|
||||
if (!$this->canAddAndDelete) {
|
||||
throw new ApplicationException('Access denied.');
|
||||
}
|
||||
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
$num = count($widgets);
|
||||
|
|
@ -259,7 +285,7 @@ class ReportContainer extends WidgetBase
|
|||
}
|
||||
|
||||
//
|
||||
// Methods for the internal use
|
||||
// Methods for internal use
|
||||
//
|
||||
|
||||
/**
|
||||
|
|
@ -315,35 +341,21 @@ class ReportContainer extends WidgetBase
|
|||
return ['widget' => $widget, 'sortOrder' => $widgetInfo['sortOrder']];
|
||||
}
|
||||
|
||||
protected function getWidgetsFromUserPreferences()
|
||||
protected function resetWidgets()
|
||||
{
|
||||
$widgets = UserPreference::forUser()
|
||||
->get($this->getUserPreferencesKey(), $this->defaultWidgets);
|
||||
$this->resetWidgetsUserPreferences();
|
||||
|
||||
if (!is_array($widgets)) {
|
||||
return [];
|
||||
}
|
||||
return $widgets;
|
||||
}
|
||||
$this->reportsDefined = false;
|
||||
|
||||
protected function setWidgetsToUserPreferences($widgets)
|
||||
{
|
||||
UserPreference::forUser()->set($this->getUserPreferencesKey(), $widgets);
|
||||
}
|
||||
|
||||
protected function saveWidgetProperties($alias, $properties)
|
||||
{
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
if (isset($widgets[$alias])) {
|
||||
$widgets[$alias]['configuration'] = $properties;
|
||||
|
||||
$this->setWidgetsToUserPreferences($widgets);
|
||||
}
|
||||
$this->defineReportWidgets();
|
||||
}
|
||||
|
||||
protected function removeWidget($alias)
|
||||
{
|
||||
if (!$this->canAddAndDelete) {
|
||||
throw new ApplicationException('Access denied.');
|
||||
}
|
||||
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
if (isset($widgets[$alias])) {
|
||||
|
|
@ -436,8 +448,52 @@ class ReportContainer extends WidgetBase
|
|||
return json_encode($result);
|
||||
}
|
||||
|
||||
//
|
||||
// User and system value storage
|
||||
//
|
||||
|
||||
protected function getWidgetsFromUserPreferences()
|
||||
{
|
||||
$defaultWidgets = SystemParameters::get($this->getSystemParametersKey(), $this->defaultWidgets);
|
||||
|
||||
$widgets = UserPreference::forUser()
|
||||
->get($this->getUserPreferencesKey(), $defaultWidgets);
|
||||
|
||||
if (!is_array($widgets)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
protected function setWidgetsToUserPreferences($widgets)
|
||||
{
|
||||
UserPreference::forUser()->set($this->getUserPreferencesKey(), $widgets);
|
||||
}
|
||||
|
||||
protected function resetWidgetsUserPreferences()
|
||||
{
|
||||
UserPreference::forUser()->reset($this->getUserPreferencesKey());
|
||||
}
|
||||
|
||||
protected function saveWidgetProperties($alias, $properties)
|
||||
{
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
if (isset($widgets[$alias])) {
|
||||
$widgets[$alias]['configuration'] = $properties;
|
||||
|
||||
$this->setWidgetsToUserPreferences($widgets);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getUserPreferencesKey()
|
||||
{
|
||||
return 'backend::reportwidgets.'.$this->context;
|
||||
}
|
||||
|
||||
protected function getSystemParametersKey()
|
||||
{
|
||||
return 'backend::reportwidgets.default.'.$this->context;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
.report-container {
|
||||
/**** Isotope CSS3 transitions ****/
|
||||
}
|
||||
.report-container > ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
|
|
@ -142,25 +139,31 @@
|
|||
right: 30px;
|
||||
}
|
||||
.report-container > ul.wrapped .item {
|
||||
width: 100%!important;
|
||||
width: 100% !important;
|
||||
}
|
||||
.report-container .add-widget {
|
||||
.report-container .manage-widgets {
|
||||
display: inline-block;
|
||||
color: #bcc3c7;
|
||||
padding: 10px 15px;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
border: 1px dashed #bcc3c7;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
margin-left: 5px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.report-container .add-widget i {
|
||||
.report-container .manage-widgets i {
|
||||
margin-right: 5px;
|
||||
}
|
||||
.report-container .add-widget:hover {
|
||||
.report-container .manage-widgets:hover {
|
||||
text-decoration: none;
|
||||
background-color: #0181b9;
|
||||
color: white;
|
||||
border: 1px solid #0181b9;
|
||||
}
|
||||
.report-container .dropdown.open .manage-widgets {
|
||||
text-decoration: none;
|
||||
background-color: #0181b9;
|
||||
color: white;
|
||||
|
|
|
|||
|
|
@ -92,15 +92,20 @@
|
|||
})
|
||||
})
|
||||
|
||||
$(window).on('oc.report-widget-added', function(){
|
||||
$(window).on('oc.reportWidgetAdded', function(){
|
||||
self.redraw()
|
||||
self.setSortOrders()
|
||||
})
|
||||
|
||||
$(window).on('oc.reportWidgetRefresh', function(){
|
||||
self.redraw()
|
||||
})
|
||||
|
||||
window.setTimeout(function(){
|
||||
self.updateWidth()
|
||||
self.redraw()
|
||||
}, 200)
|
||||
|
||||
this.setSortOrders()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@
|
|||
}
|
||||
|
||||
&.separator {
|
||||
width: 100%!important;
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,12 +132,12 @@
|
|||
|
||||
&.wrapped {
|
||||
.item {
|
||||
width: 100%!important;
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.add-widget {
|
||||
.manage-widgets {
|
||||
display: inline-block;
|
||||
color: #bcc3c7;
|
||||
padding: 10px 15px;
|
||||
|
|
@ -160,7 +160,16 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**** Isotope CSS3 transitions ****/
|
||||
.dropdown.open .manage-widgets {
|
||||
text-decoration: none;
|
||||
background-color: @link-color;
|
||||
color: white;
|
||||
border: 1px solid @link-color;
|
||||
}
|
||||
|
||||
//
|
||||
// Isotope CSS3 transitions
|
||||
//
|
||||
|
||||
&.isotope,
|
||||
&.isotope .isotope-item {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,14 @@
|
|||
<div class="report-container">
|
||||
<input type="hidden" value="<?= $this->alias ?>" data-container-alias />
|
||||
|
||||
<ul
|
||||
id="<?= $this->getId('container-list') ?>"
|
||||
class="<?= $this->canAddAndDelete ? 'add-delete' : null ?>"
|
||||
data-control="report-container">
|
||||
|
||||
<?php foreach ($widgets as $widgetAlias=>$widgetInfo): ?>
|
||||
<?= $this->makePartial('widget', [
|
||||
'widgetAlias' => $widgetAlias,
|
||||
'widget' => $widgetInfo['widget'],
|
||||
'sortOrder' => $widgetInfo['sortOrder']
|
||||
]) ?>
|
||||
<?php endforeach ?>
|
||||
|
||||
<?= $this->makePartial('widget_list') ?>
|
||||
</ul>
|
||||
<input type="hidden" value="<?= $this->alias ?>" data-container-alias />
|
||||
|
||||
<?php if ($this->canAddAndDelete): ?>
|
||||
<a
|
||||
href="javascript:;"
|
||||
class="add-widget"
|
||||
data-control="popup"
|
||||
data-handler="<?= $this->getEventHandler('onLoadAddPopup') ?>">
|
||||
<i class="icon-plus"></i> <?= e(trans('backend::lang.dashboard.add_widget')) ?>
|
||||
</a>
|
||||
<?= $this->makePartial('widget_toolbar') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?= Form::open([
|
||||
'data-request' => $this->getEventHandler('onAddWidget'),
|
||||
'data-request-success' => "\$(this).trigger('close.oc.popup'); \$(window).trigger('oc.report-widget-added')",
|
||||
'data-request-success' => "\$(this).trigger('close.oc.popup'); \$(window).trigger('oc.reportWidgetAdded')",
|
||||
'data-popup-load-indicator' => 1
|
||||
]) ?>
|
||||
<div class="modal-header">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?php foreach ($widgets as $widgetAlias => $widgetInfo): ?>
|
||||
<?= $this->makePartial('widget', [
|
||||
'widgetAlias' => $widgetAlias,
|
||||
'widget' => $widgetInfo['widget'],
|
||||
'sortOrder' => $widgetInfo['sortOrder']
|
||||
]) ?>
|
||||
<?php endforeach ?>
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<div class="dropdown dropup">
|
||||
<a
|
||||
href="javascript:;"
|
||||
class="manage-widgets"
|
||||
data-toggle="dropdown">
|
||||
<i class="icon-cogs"></i> <?= e(trans('backend::lang.dashboard.manage_widgets')) ?>
|
||||
</a>
|
||||
|
||||
<ul class="dropdown-menu" role="menu" data-dropdown-title="Manage dashboard">
|
||||
<li role="presentation">
|
||||
<a
|
||||
role="menuitem"
|
||||
href="javascript:;"
|
||||
data-control="popup"
|
||||
data-handler="<?= $this->getEventHandler('onLoadAddPopup') ?>"
|
||||
class="oc-icon-plus"
|
||||
tabindex="-1">
|
||||
<?= e(trans('backend::lang.dashboard.add_widget')) ?>
|
||||
</a>
|
||||
</li>
|
||||
<li role="separator" class="divider"></li>
|
||||
<li role="presentation">
|
||||
<a
|
||||
role="menuitem"
|
||||
href="javascript:;"
|
||||
class="oc-icon-floppy-o"
|
||||
data-request="<?= $this->getEventHandler('onMakeLayoutDefault') ?>"
|
||||
data-request-confirm="<?= e(trans('backend::lang.dashboard.make_default_confirm')) ?>"
|
||||
tabindex="-1">
|
||||
<?= e(trans('backend::lang.dashboard.make_default')) ?>
|
||||
</a>
|
||||
</li>
|
||||
<li role="presentation">
|
||||
<a
|
||||
role="menuitem"
|
||||
href="javascript:;"
|
||||
data-request-success="$(window).trigger('oc.reportWidgetRefresh')"
|
||||
data-request="<?= $this->getEventHandler('onResetWidgets') ?>"
|
||||
data-request-confirm="<?= e(trans('backend::lang.dashboard.reset_layout_confirm')) ?>"
|
||||
class="oc-icon-repeat"
|
||||
tabindex="-1">
|
||||
<?= e(trans('backend::lang.dashboard.reset_layout')) ?>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -33,6 +33,7 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
*/
|
||||
if (App::runningInBackend()) {
|
||||
$this->registerBackendNavigation();
|
||||
$this->registerBackendReportWidgets();
|
||||
$this->registerBackendPermissions();
|
||||
$this->registerBackendWidgets();
|
||||
$this->registerBackendSettings();
|
||||
|
|
@ -153,6 +154,19 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Register report widgets
|
||||
*/
|
||||
protected function registerBackendReportWidgets()
|
||||
{
|
||||
WidgetManager::instance()->registerReportWidgets(function ($manager) {
|
||||
$manager->registerReportWidget('Cms\ReportWidgets\ActiveTheme', [
|
||||
'label' => 'cms::lang.dashboard.active_theme.widget_title_default',
|
||||
'context' => 'dashboard'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Register permissions
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -337,7 +337,6 @@ class ServiceProvider extends ModuleServiceProvider
|
|||
'context' => 'dashboard'
|
||||
]);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -88,6 +88,24 @@ class Parameters extends Model
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a setting value by deleting the record.
|
||||
* @param string $key Specifies the setting key value.
|
||||
* @return bool
|
||||
*/
|
||||
public function reset($key)
|
||||
{
|
||||
$record = static::findRecord($key);
|
||||
if (!$record) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$record->delete();
|
||||
|
||||
unset(static::$cache[$key]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a record (cached)
|
||||
* @return self
|
||||
|
|
|
|||
Loading…
Reference in New Issue