Introduce some database model for the new dashboards

This commit is contained in:
Yonas Habteab 2022-03-11 16:18:08 +01:00
parent ed94660839
commit 8b9d63556d
5 changed files with 292 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Model;
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Sql\Expression;
class DashboardOverride extends Model
{
public function getTableName()
{
return 'dashboard_override';
}
public function getKeyName()
{
return 'dashboard_id';
}
public function getColumns()
{
return [
'label',
'username',
'disabled',
'priority',
'acceptance' => new Expression('COALESCE(COUNT(dashboard_subscribable_dashboard_dashboard_override.dashboard_id), 0)')
];
}
public function getMetaData()
{
return ['priority' => t('Dashboard Priority Order')];
}
public function getSearchColumns()
{
return ['name'];
}
public function getDefaultSort()
{
return 'dashboard.name';
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('dashboard', Pane::class);
}
}

View File

@ -0,0 +1,61 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Model;
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Sql\Expression;
class Dashlet extends Model
{
public function getTableName()
{
return 'dashlet';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
return [
'dashboard_id',
'name',
'label',
'url',
'priority'
];
}
public function getColumnDefinitions()
{
return [
'dashboard_id' => t('Dashboard Id'),
'name' => t('Dashlet Name'),
'label' => t('Dashlet Title'),
'url' => t('Dashlet Url'),
'priority' => t('Dashlet Priority Order'),
'description' => t('Dashlet Description')
];
}
public function getSearchColumns()
{
return ['name'];
}
public function getDefaultSort()
{
return 'priority';
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('dashboard', Pane::class);
//$relations->belongsTo('home', Home::class);
}
}

View File

@ -0,0 +1,58 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Model;
use ipl\Orm\Model;
use ipl\Orm\Relations;
class Home extends Model
{
public function getTableName()
{
return 'dashboard_home';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
return [
'name',
'label',
'username',
'type',
'priority',
];
}
public function getColumnDefinitions()
{
return [
'name' => t('Dashboard Home Name'),
'label' => t('Dashboard Home Title'),
'priority' => t('Dashboard Priority Order')
];
}
public function getSearchColumns()
{
return ['name'];
}
public function getDefaultSort()
{
return 'dashboard_home.name';
}
public function createRelations(Relations $relations)
{
$relations->hasMany('dashboard', Pane::class);
//$relations->hasMany('dashlet', Dashlet::class);
}
}

View File

@ -0,0 +1,56 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Model;
use ipl\Orm\Model;
class ModuleDashlet extends Model
{
public function getTableName()
{
return 'module_dashlet';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
return [
'name',
'label',
'module',
'pane',
'url',
'description',
'priority'
];
}
public function getColumnDefinitions()
{
return [
'name' => t('Dashlet Name'),
'label' => t('Dashlet Title'),
'module' => t('Module Name'),
'pane' => t('Pane Name'),
'url' => t('Dashlet Url'),
'description' => t('Dashlet Description'),
'priority' => t('Dashlet Priority Order')
];
}
public function getSearchColumns()
{
return ['name'];
}
public function getDefaultSort()
{
return ['module_dashlet.name', 'module_dashlet.priority'];
}
}

View File

@ -0,0 +1,64 @@
<?php
/* Icinga Web 2 | (c) 2022 Icinga GmbH | GPLv2+ */
namespace Icinga\Model;
use ipl\Orm\Model;
use ipl\Orm\Relations;
use ipl\Sql\Expression;
class Pane extends Model
{
public function getTableName()
{
return 'dashboard';
}
public function getKeyName()
{
return 'id';
}
public function getColumns()
{
return [
'home_id',
'name',
'label',
'username',
'priority'
];
}
public function getMetaData()
{
return [
'home_id' => t('Dashboard Home Id'),
'name' => t('Dashboard Name'),
'label' => t('Dashboard Title'),
'username' => t('Username'),
];
}
public function getSearchColumns()
{
return ['name'];
}
public function getDefaultSort()
{
return 'dashboard.name';
}
public function createRelations(Relations $relations)
{
$relations->belongsTo('home', Home::class)
->setCandidateKey('home_id');
$relations->hasMany('dashboard_override', DashboardOverride::class)
->setJoinType('LEFT');
$relations->hasMany('dashlet', Dashlet::class)
->setJoinType('LEFT');
}
}