dashboard: Differentiate between `name` and `title`
The former is the original name while title may be changed by the user. This change is strictly necessary for the references bug and should also be introduced when rewriting this mess. refs #3542
This commit is contained in:
parent
813efde1b6
commit
37a972cf75
|
@ -106,29 +106,22 @@ class DashboardController extends ActionController
|
|||
$action = $this;
|
||||
$form->setOnSuccess(function (Form $form) use ($dashboard, $action) {
|
||||
try {
|
||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||
$pane = $dashboard->getPane($form->getValue('org_pane'));
|
||||
$pane->setTitle($form->getValue('pane'));
|
||||
} catch (ProgrammingError $e) {
|
||||
$pane = new Dashboard\Pane($form->getValue('pane'));
|
||||
$pane->setUserWidget();
|
||||
$dashboard->addPane($pane);
|
||||
}
|
||||
try {
|
||||
$dashlet = $pane->getDashlet($form->getValue('dashlet'));
|
||||
$dashlet = $pane->getDashlet($form->getValue('org_dashlet'));
|
||||
$dashlet->setTitle($form->getValue('dashlet'));
|
||||
$dashlet->setUrl($form->getValue('url'));
|
||||
} catch (ProgrammingError $e) {
|
||||
$dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
|
||||
$pane->addDashlet($dashlet);
|
||||
}
|
||||
$dashlet->setUserWidget();
|
||||
// Rename dashlet
|
||||
if ($form->getValue('org_dashlet') && $form->getValue('org_dashlet') !== $dashlet->getTitle()) {
|
||||
$pane->removeDashlet($form->getValue('org_dashlet'));
|
||||
}
|
||||
// Move
|
||||
if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) {
|
||||
$oldPane = $dashboard->getPane($form->getValue('org_pane'));
|
||||
$oldPane->removeDashlet($dashlet->getTitle());
|
||||
}
|
||||
$dashboardConfig = $dashboard->getConfig();
|
||||
try {
|
||||
$dashboardConfig->saveIni();
|
||||
|
@ -269,7 +262,7 @@ class DashboardController extends ActionController
|
|||
$action = $this;
|
||||
$form->setOnSuccess(function (Form $form) use ($dashboard, $pane, $action) {
|
||||
$pane = $dashboard->getPane($pane);
|
||||
$dashboard->removePane($pane->getTitle());
|
||||
$dashboard->removePane($pane->getName());
|
||||
$dashboardConfig = $dashboard->getConfig();
|
||||
try {
|
||||
$dashboardConfig->saveIni();
|
||||
|
|
|
@ -161,10 +161,10 @@ class DashletForm extends Form
|
|||
public function load(Dashlet $dashlet)
|
||||
{
|
||||
$this->populate(array(
|
||||
'pane' => $dashlet->getPane()->getName(),
|
||||
'pane' => $dashlet->getPane()->getTitle(),
|
||||
'org_pane' => $dashlet->getPane()->getName(),
|
||||
'dashlet' => $dashlet->getTitle(),
|
||||
'org_dashlet' => $dashlet->getTitle(),
|
||||
'org_dashlet' => $dashlet->getName(),
|
||||
'url' => $dashlet->getUrl()->getRelativeUrl()
|
||||
));
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<?= $this->qlink(
|
||||
$dashlet->getTitle(),
|
||||
'dashboard/update-dashlet',
|
||||
array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle()),
|
||||
array('pane' => $pane->getName(), 'dashlet' => $dashlet->getName()),
|
||||
array('title' => sprintf($this->translate('Edit dashlet %s'), $dashlet->getTitle()))
|
||||
); ?>
|
||||
</td>
|
||||
|
@ -75,10 +75,10 @@
|
|||
<?= $this->qlink(
|
||||
'',
|
||||
'dashboard/remove-dashlet',
|
||||
array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle()),
|
||||
array('pane' => $pane->getName(), 'dashlet' => $dashlet->getName()),
|
||||
array(
|
||||
'icon' => 'trash',
|
||||
'title' => sprintf($this->translate('Remove dashlet %s from pane %s'), $dashlet->getTitle(), $pane->getName())
|
||||
'title' => sprintf($this->translate('Remove dashlet %s from pane %s'), $dashlet->getTitle(), $pane->getTitle())
|
||||
)
|
||||
); ?>
|
||||
</td>
|
||||
|
|
|
@ -103,7 +103,7 @@ class Dashboard extends AbstractWidget
|
|||
}
|
||||
foreach ($pane->getDashlets() as $dashlet) {
|
||||
if ($dashlet->isUserWidget()) {
|
||||
$output[$pane->getName() . '.' . $dashlet->getTitle()] = $dashlet->toArray();
|
||||
$output[$pane->getName() . '.' . $dashlet->getName()] = $dashlet->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -175,6 +175,7 @@ class Dashboard extends AbstractWidget
|
|||
$dashletData->url,
|
||||
$pane
|
||||
);
|
||||
$dashlet->setName($dashletData->dashlet);
|
||||
|
||||
if ((bool) $dashletData->get('disabled', false) === true) {
|
||||
$dashlet->setDisabled(true);
|
||||
|
@ -200,7 +201,7 @@ class Dashboard extends AbstractWidget
|
|||
{
|
||||
/** @var $pane Pane */
|
||||
foreach ($panes as $pane) {
|
||||
if ($this->hasPane($pane->getTitle()) === true) {
|
||||
if ($this->hasPane($pane->getName()) === true) {
|
||||
/** @var $current Pane */
|
||||
$current = $this->panes[$pane->getName()];
|
||||
$current->addDashlets($pane->getDashlets());
|
||||
|
|
|
@ -22,6 +22,8 @@ class Dashlet extends UserWidget
|
|||
*/
|
||||
private $url;
|
||||
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The title being displayed on top of the dashlet
|
||||
* @var
|
||||
|
@ -91,11 +93,23 @@ EOD;
|
|||
*/
|
||||
public function __construct($title, $url, Pane $pane)
|
||||
{
|
||||
$this->name = $title;
|
||||
$this->title = $title;
|
||||
$this->pane = $pane;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the dashlets title
|
||||
*
|
||||
|
|
|
@ -22,7 +22,6 @@ class Pane extends UserWidget
|
|||
|
||||
/**
|
||||
* The title of this pane, as displayed in the dashboard tabs
|
||||
* @TODO: Currently the same as $name, evaluate if distinguishing is needed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
@ -229,7 +228,7 @@ class Pane extends UserWidget
|
|||
public function addDashlet($dashlet, $url = null)
|
||||
{
|
||||
if ($dashlet instanceof Dashlet) {
|
||||
$this->dashlets[$dashlet->getTitle()] = $dashlet;
|
||||
$this->dashlets[$dashlet->getName()] = $dashlet;
|
||||
} elseif (is_string($dashlet) && $url !== null) {
|
||||
$this->createDashlet($dashlet, $url);
|
||||
} else {
|
||||
|
@ -248,15 +247,15 @@ class Pane extends UserWidget
|
|||
{
|
||||
/* @var $dashlet Dashlet */
|
||||
foreach ($dashlets as $dashlet) {
|
||||
if (array_key_exists($dashlet->getTitle(), $this->dashlets)) {
|
||||
if (preg_match('/_(\d+)$/', $dashlet->getTitle(), $m)) {
|
||||
$name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getTitle());
|
||||
if (array_key_exists($dashlet->getName(), $this->dashlets)) {
|
||||
if (preg_match('/_(\d+)$/', $dashlet->getName(), $m)) {
|
||||
$name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getName());
|
||||
} else {
|
||||
$name = $dashlet->getTitle() . '_2';
|
||||
$name = $dashlet->getName() . '_2';
|
||||
}
|
||||
$this->dashlets[$name] = $dashlet;
|
||||
} else {
|
||||
$this->dashlets[$dashlet->getTitle()] = $dashlet;
|
||||
$this->dashlets[$dashlet->getName()] = $dashlet;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue