widget refactoring
This commit is contained in:
parent
ad2b69b9b6
commit
27cb3d001e
@ -28,9 +28,7 @@ class Dashboard extends Controller
|
||||
session(['dashboard_id' => $dashboard_id]);
|
||||
}
|
||||
|
||||
$user_id = user()->id;
|
||||
|
||||
$dashboards = Model::where('user_id', $user_id)->enabled()->get();
|
||||
$dashboards = Model::where('user_id', user()->id)->enabled()->get();
|
||||
|
||||
if (!$dashboard_id) {
|
||||
$dashboard_id = $dashboards->first()->id;
|
||||
|
@ -25,16 +25,16 @@ class Dashboard extends Model
|
||||
*/
|
||||
public $sortable = ['name', 'enabled'];
|
||||
|
||||
public function widgets()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function widgets()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
|
||||
}
|
||||
|
||||
public function scopeOfUser($query, $user_id)
|
||||
{
|
||||
return $query->where('user_id', $user_id);
|
||||
|
@ -31,4 +31,9 @@ class Widget extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Dashboard');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOneThrough('App\Models\Auth\User', 'App\Models\Common\Dashboard');
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
<div id="@yield('widget-id', 'widget-' . Str::random())" class="@yield('widget-class', 'col-md-12')">
|
||||
|
||||
<div class="card @yield('widget-card-class', 'col-md-12')">
|
||||
|
||||
@include('partials.widget.head')
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
@include('partials.widget.content')
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
@ -1,3 +0,0 @@
|
||||
@stack('content_start')
|
||||
@yield('widget-content')
|
||||
@stack('content_end')
|
@ -1,41 +0,0 @@
|
||||
@if (trim($__env->yieldContent('widget-title')))
|
||||
<div class="card-header">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-4 text-nowrap">
|
||||
<h4 class="mb-0">@yield('widget-title')</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-8 text-right d-none d-sm-block">
|
||||
@yield('button')
|
||||
|
||||
<span>
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
<a class="dropdown-item" href="#" @click.prevent="onAction('edit')">{{ trans('general.edit') }}</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($config->widget, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<span>
|
||||
<div class="dropdown card-action-button">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-white"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
<a class="dropdown-item" href="#" @click.prevent="onAction('edit')">{{ trans('general.edit') }}</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($config->widget, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
@endif
|
29
resources/views/partials/widgets/standard_header.blade.php
Normal file
29
resources/views/partials/widgets/standard_header.blade.php
Normal file
@ -0,0 +1,29 @@
|
||||
<div class="card-header border-bottom-0">
|
||||
<div class="row align-items-center">
|
||||
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), [
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
]) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
18
resources/views/partials/widgets/stats_header.blade.php
Normal file
18
resources/views/partials/widgets/stats_header.blade.php
Normal file
@ -0,0 +1,18 @@
|
||||
<span>
|
||||
<div class="dropdown card-action-button">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-white"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), [
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
]) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
@ -1,34 +1,6 @@
|
||||
<div id="widgets-account-balance" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom-0">
|
||||
<div class="row align-items-center">
|
||||
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table align-items-center table-flush">
|
||||
|
@ -1,33 +1,6 @@
|
||||
<div id="widgets-cash-flow" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-4 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-8 text-right hidden-sm">
|
||||
<span>
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="card-body pt-0" id="cashflow">
|
||||
<div class="chart">
|
||||
|
@ -1,37 +1,8 @@
|
||||
<div id="widgets-expenses-by-category" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row align-items-center">
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body" id="expense-category-doughnut">
|
||||
<div class="card-body" id="expenses-category-doughnut">
|
||||
<div class="dashboard-categories">
|
||||
{!! $chart->container() !!}
|
||||
</div>
|
||||
@ -41,8 +12,8 @@
|
||||
|
||||
@push('charts')
|
||||
<script>
|
||||
var expense_category_doughnut = new Vue({
|
||||
el: '#expense-category-doughnut',
|
||||
var expenses_category_doughnut = new Vue({
|
||||
el: '#expenses-category-doughnut',
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
@ -1,35 +1,6 @@
|
||||
<div id="widgets-incomes-by-category" class="{{ $model->settings->width }}">
|
||||
<div id="widgets-income-by-category" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<div class="row align-items-center">
|
||||
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="card-body" id="income-category-doughnut">
|
||||
<div class="dashboard-categories">
|
||||
|
@ -1,33 +1,6 @@
|
||||
<div id="widgets-latest-expenses" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom-0">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table align-items-center table-flush">
|
||||
|
@ -1,33 +1,6 @@
|
||||
<div id="widgets-latest-incomes" class="{{ $model->settings->width }}">
|
||||
<div id="widgets-latest-income" class="{{ $model->settings->width }}">
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom-0">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-6 text-nowrap">
|
||||
<h4 class="mb-0">{{ $model->name }}</h4>
|
||||
</div>
|
||||
|
||||
<div class="col-6 hidden-sm">
|
||||
<span class="float-right">
|
||||
<div class="dropdown">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-muted"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('partials.widgets.standard_header')
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table align-items-center table-flush">
|
||||
|
@ -1,23 +1,6 @@
|
||||
<div id="widgets-total-expenses" class="{{ $model->settings->width }}">
|
||||
<div class="card bg-gradient-danger card-stats">
|
||||
<span>
|
||||
<div class="dropdown card-action-button">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-white"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
@include('partials.widgets.stats_header')
|
||||
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
|
@ -1,23 +1,6 @@
|
||||
<div id="widgets-total-incomes" class="{{ $model->settings->width }}">
|
||||
<div id="widgets-total-income" class="{{ $model->settings->width }}">
|
||||
<div class="card bg-gradient-info card-stats">
|
||||
<span>
|
||||
<div class="dropdown card-action-button">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-white"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
@include('partials.widgets.stats_header')
|
||||
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
|
@ -1,23 +1,6 @@
|
||||
<div id="widgets-total-profit" class="{{ $model->settings->width }}">
|
||||
<div class="card bg-gradient-success card-stats">
|
||||
<span>
|
||||
<div class="dropdown card-action-button">
|
||||
<a class="btn btn-sm items-align-center py-2 mr-0 shadow-none--hover" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fa fa-ellipsis-v text-white"></i>
|
||||
</a>
|
||||
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
|
||||
{!! Form::button(trans('general.edit'), array(
|
||||
'type' => 'button',
|
||||
'class' => 'dropdown-item',
|
||||
'title' => trans('general.edit'),
|
||||
'@click' => 'onEditWidget(' . $model->id . ')'
|
||||
)) !!}
|
||||
<div class="dropdown-divider"></div>
|
||||
{!! Form::deleteLink($model, 'common/widgets') !!}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
@include('partials.widgets.stats_header')
|
||||
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
|
Loading…
x
Reference in New Issue
Block a user