new widget structure
This commit is contained in:
@ -25,12 +25,11 @@ class CreateDashboardsTable extends Migration
|
||||
$table->index(['company_id']);
|
||||
});
|
||||
|
||||
Schema::create('dashboard_widgets', function (Blueprint $table) {
|
||||
Schema::create('widgets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('company_id');
|
||||
$table->integer('user_id');
|
||||
$table->integer('dashboard_id');
|
||||
$table->integer('widget_id');
|
||||
$table->string('class');
|
||||
$table->string('name');
|
||||
$table->text('settings')->nullable();
|
||||
$table->integer('sort')->default(0);
|
||||
@ -39,19 +38,6 @@ class CreateDashboardsTable extends Migration
|
||||
|
||||
$table->index(['company_id']);
|
||||
});
|
||||
|
||||
Schema::create('widgets', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('company_id');
|
||||
$table->string('name');
|
||||
$table->string('alias');
|
||||
$table->text('settings')->nullable();
|
||||
$table->boolean('enabled')->default(1);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['company_id', 'alias']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +48,6 @@ class CreateDashboardsTable extends Migration
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('dashboards');
|
||||
Schema::drop('dashboard_widgets');
|
||||
Schema::drop('widgets');
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace Database\Seeds;
|
||||
use App\Abstracts\Model;
|
||||
use App\Models\Common\Widget;
|
||||
use App\Models\Common\Dashboard;
|
||||
use App\Models\Common\DashboardWidget;
|
||||
use App\Utilities\Widgets as WidgetUtility;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class Dashboards extends Seeder
|
||||
@ -29,35 +29,28 @@ class Dashboards extends Seeder
|
||||
$user_id = $this->command->argument('user');
|
||||
$company_id = $this->command->argument('company');
|
||||
|
||||
$rows = [
|
||||
[
|
||||
$dashboard = Dashboard::create([
|
||||
'company_id' => $company_id,
|
||||
'user_id' => $user_id,
|
||||
'name' => trans('general.dashboard'),
|
||||
'enabled' => 1,
|
||||
]);
|
||||
|
||||
$widgets = WidgetUtility::getClasses();
|
||||
|
||||
$sort = 1;
|
||||
|
||||
foreach ($widgets as $class => $name) {
|
||||
Widget::create([
|
||||
'company_id' => $company_id,
|
||||
'user_id' => $user_id,
|
||||
'name' => trans('general.dashboard'),
|
||||
'enabled' => 1,
|
||||
]
|
||||
];
|
||||
'dashboard_id' => $dashboard->id,
|
||||
'class' => $class,
|
||||
'name' => $name,
|
||||
'settings' => (new $class())->getDefaultSettings(),
|
||||
'sort' => $sort,
|
||||
]);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$dashboard = Dashboard::create($row);
|
||||
|
||||
$widgets = Widget::where('company_id', $company_id)->orderBy('created_at','desc')->get();
|
||||
|
||||
$sort = 1;
|
||||
|
||||
foreach ($widgets as $widget) {
|
||||
DashboardWidget::create([
|
||||
'company_id' => $company_id,
|
||||
'user_id' => $user_id,
|
||||
'dashboard_id' => $dashboard->id,
|
||||
'widget_id' => $widget->id,
|
||||
'name' => $widget->name,
|
||||
'settings' => $widget->settings,
|
||||
'sort' => $sort
|
||||
]);
|
||||
|
||||
$sort++;
|
||||
}
|
||||
$sort++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ class UserSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->call(Database\Seeds\Widgets::class);
|
||||
$this->call(Database\Seeds\Dashboards::class);
|
||||
}
|
||||
}
|
||||
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeds;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
use App\Models\Common\Widget;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class Widgets extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Model::unguard();
|
||||
|
||||
$this->create();
|
||||
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
private function create()
|
||||
{
|
||||
$company_id = $this->command->argument('company');
|
||||
|
||||
$rows = [
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.total_income'),
|
||||
'alias' => 'total-income',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.total_expenses'),
|
||||
'alias' => 'total-expenses',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.total_profit'),
|
||||
'alias' => 'total-profit',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.cash_flow'),
|
||||
'alias' => 'cash-flow',
|
||||
'settings' => ['width' => 'col-md-12'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.income_by_category'),
|
||||
'alias' => 'income-by-category',
|
||||
'settings' => ['width' => 'col-md-6'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.expenses_by_category'),
|
||||
'alias' => 'expenses-by-category',
|
||||
'settings' => ['width' => 'col-md-6'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.account_balance'),
|
||||
'alias' => 'account-balance',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.latest_income'),
|
||||
'alias' => 'latest-income',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'company_id' => $company_id,
|
||||
'name' => trans('dashboard.latest_expenses'),
|
||||
'alias' => 'latest-expenses',
|
||||
'settings' => ['width' => 'col-md-4'],
|
||||
'enabled' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
Widget::create($row);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user