new widget structure

This commit is contained in:
denisdulici
2019-12-31 02:20:10 +03:00
parent 8c6ca5e5fb
commit 71c5caf264
44 changed files with 333 additions and 502 deletions

View File

@ -98,11 +98,6 @@ class Company extends Eloquent
return $this->hasMany('App\Models\Common\Dashboard');
}
public function dashboard_widgets()
{
return $this->hasMany('App\Models\Common\DashboardWidget');
}
public function email_templates()
{
return $this->hasMany('App\Models\Common\EmailTemplate');

View File

@ -27,7 +27,7 @@ class Dashboard extends Model
public function widgets()
{
return $this->hasMany('App\Models\Common\DashboardWidget')->orderBy('sort', 'asc');
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
}
public function user()

View File

@ -1,65 +0,0 @@
<?php
namespace App\Models\Common;
use App\Abstracts\Model;
class DashboardWidget extends Model
{
protected $table = 'dashboard_widgets';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'user_id', 'dashboard_id', 'widget_id', 'name', 'settings', 'sort'];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'settings' => 'array',
];
public function user()
{
return $this->belongsTo('App\Models\Auth\User', 'user_id', 'id');
}
public function dashboard()
{
return $this->belongsTo('App\Models\Common\Dashboard');
}
public function widget()
{
return $this->belongsTo('App\Models\Common\Widget');
}
public function getNameAttribute($value)
{
if ($value) {
return $value;
}
return $this->widget->name;
}
public function getSettingsAttribute($value)
{
if (!empty($value)) {
$value = json_decode($value, true);
$value['widget'] = $this;
} else {
$value = [
'widget' => $this,
];
}
return $value;
}
}

View File

@ -16,14 +16,7 @@ class Widget extends Model
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'alias', 'settings', 'enabled'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['name', 'alias', 'enabled'];
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'settings', 'sort'];
/**
* The attributes that should be casted to native types.
@ -31,16 +24,11 @@ class Widget extends Model
* @var array
*/
protected $casts = [
'settings' => 'array',
'settings' => 'object',
];
public function dashboard_widgets()
public function dashboard()
{
return $this->hasMany('App\Models\Common\DashboardWidget');
}
public function dashboard_widget()
{
return $this->belongsTo('App\Models\Common\DashboardWidget', 'id', 'widget_id')->where('dashboard_id', 1);
return $this->belongsTo('App\Models\Common\Dashboard');
}
}