Report page cache own widget..

This commit is contained in:
Cüneyt Şentürk 2021-06-15 12:37:13 +03:00
parent c005e21738
commit 0bbc31bec4
6 changed files with 49 additions and 14 deletions

View File

@ -142,7 +142,7 @@ abstract class Report
$sum += is_array($total) ? array_sum($total) : $total;
}
$total = money($sum, setting('default.currency'), true);
$total = money($sum, setting('default.currency'), true)->format();
} else {
$total = trans('general.na');
}

View File

@ -67,6 +67,8 @@ class ReportReminder extends Command
$ttl = 3600 * 6; // 6 hours
Cache::forget('reports.totals.' . $report->id);
Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
return $class->getGrandTotal();
});

View File

@ -24,6 +24,7 @@ class Reports extends Controller
$this->middleware('permission:update-common-reports')->only('edit', 'update', 'enable', 'disable');
$this->middleware('permission:delete-common-reports')->only('destroy');
}
/**
* Display a listing of the resource.
*
@ -271,16 +272,17 @@ class Reports extends Controller
*
* @return Response
*/
public function clear()
public function clear(Report $report)
{
Report::all()->each(function ($report) {
if (!Utility::canShow($report->class)) {
return;
}
$data = Utility::getClassInstance($report)->getGrandTotal();
Cache::put('reports.totals.' . $report->id, Utility::getClassInstance($report)->getGrandTotal());
});
Cache::put('reports.totals.' . $report->id, $data);
return redirect()->back();
return response()->json([
'success' => true,
'error' => false,
'data' => $data,
'message' => '',
]);
}
}

View File

@ -30,9 +30,14 @@ const app = new Vue({
form: new Form('report'),
bulk_action: new BulkAction('reports'),
report_fields: '',
reports_total: [],
}
},
created() {
this.reports_total = reports_total;
},
methods: {
onChangeClass(class_name) {
axios.get(url + '/common/reports/fields', {
@ -76,6 +81,15 @@ const app = new Vue({
onChangeReportFields(event) {
this.form = event;
}
},
onRefreshTotal(report_id) {
axios.get(url + '/common/reports/' + report_id + '/clear')
.then(response => {
this.reports_total[report_id] = response.data.data;
})
.catch(error => {
});
},
}
});

View File

@ -6,7 +6,6 @@
@can('create-common-reports')
<a href="{{ route('reports.create') }}" class="btn btn-success btn-sm">{{ trans('general.add_new') }}</a>
@endcan
<a href="{{ route('reports.clear') }}" class="btn btn-warning btn-sm">{{ trans('general.clear_cache') }}</a>
@endsection
@section('content')
@ -25,14 +24,17 @@
<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-primary"></i>
</a>
<div class="dropdown-menu dropdown-menu-right dropdown-menu-arrow">
@can('update-common-reports')
<a class="dropdown-item" href="{{ route('reports.edit', $report->id) }}">{{ trans('general.edit') }}</a>
@endcan
@can('create-common-reports')
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ route('reports.duplicate', $report->id) }}">{{ trans('general.duplicate') }}</a>
@endcan
@can('delete-common-reports')
<div class="dropdown-divider"></div>
{!! Form::deleteLink($report, 'reports.destroy') !!}
@ -47,9 +49,20 @@
<div class="col">
<a href="{{ route('reports.show', $report->id) }}">
<h5 class="card-title text-uppercase text-muted mb-0">{{ $report->name }}</h5>
<h2 class="font-weight-bold mb-0">{{ $totals[$report->id] }}</h2>
</a>
<div class="d-flex align-items-center">
<a href="{{ route('reports.show', $report->id) }}">
<h2 class="font-weight-bold mb-0" v-if="reports_total[{{ $report->id }}]" v-html="reports_total[{{ $report->id }}]"></h2>
<h2 class="font-weight-bold mb-0" v-else>{{ $totals[$report->id] }}</h2>
</a>
<button type="button" @click="onRefreshTotal('{{ $report->id }}')" class="btn btn-otline-primary btn-sm ml-2">
<i class="fas fa-redo"></i>
</button>
</div>
</div>
<div class="col-auto">
<a href="{{ route('reports.show', $report->id) }}">
<div class="icon icon-shape bg-orange text-white rounded-circle shadow">
@ -58,6 +71,7 @@
</a>
</div>
</div>
<p class="mt-3 mb-0 text-sm">
<a class="text-default" href="{{ route('reports.show', $report->id) }}">
<span class="pre">{{ $report->description }}</span>
@ -73,6 +87,9 @@
@endsection
@push('scripts_start')
<script type="text/javascript">
var reports_total = {!! json_encode($totals) !!};
</script>
<script src="{{ asset('public/js/common/reports.js?v=' . version('short')) }}"></script>
@endpush

View File

@ -46,7 +46,7 @@ Route::group(['prefix' => 'common'], function () {
Route::get('reports/{report}/print', 'Common\Reports@print')->name('reports.print');
Route::get('reports/{report}/export', 'Common\Reports@export')->name('reports.export');
Route::get('reports/{report}/duplicate', 'Common\Reports@duplicate')->name('reports.duplicate');
Route::get('reports/clear', 'Common\Reports@clear')->name('reports.clear');
Route::get('reports/{report}/clear', 'Common\Reports@clear')->name('reports.clear');
Route::get('reports/fields', 'Common\Reports@fields')->name('reports.fields');
Route::resource('reports', 'Common\Reports');
});