From 7783f4dc18d781adc06fa0fe4190be06ba4491ab Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 23 Oct 2024 21:17:38 +1100 Subject: [PATCH] Add filearea stats --- app/Models/Domain.php | 19 ++++++++++++ app/Models/Filearea.php | 5 ++++ resources/views/domain/view.blade.php | 43 ++++++++++++++++++++------- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 4fff481..20ba0f4 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -124,6 +124,25 @@ class Domain extends Model }); } + public function filearea_stats() + { + $dt = Carbon::now()->startOfday(); + $case = CaseBuilder::whenRaw("datetime >= '?'",$dt->subDays(7)->format('Y-m-d'))->thenRaw("'week'") + ->whenRaw("datetime >= '?'",$dt->subMonth()->format('Y-m-d'))->thenRaw("'month'") + ->elseRaw("'all'"); + + return Filearea::select(['fileareas.id','fileareas.name','description','active',DB::raw('count(files.id) AS count'),DB::raw('min(datetime) as first_file'),DB::raw('max(datetime) as last_file')]) + ->selectRaw($case->toRaw().' AS stats') + ->join('files',['files.filearea_id'=>'fileareas.id'],NULL,NULL,'left outer') + ->where('domain_id',$this->id) + ->groupBy('fileareas.id') + ->groupBy('fileareas.name') + ->groupBy('stats') + ->orderBy('fileareas.name') + ->orderBy('last_file','DESC') + ->get(); + } + /** * Determine if this zone is managed by this host * diff --git a/app/Models/Filearea.php b/app/Models/Filearea.php index 1736a1d..68bac9d 100644 --- a/app/Models/Filearea.php +++ b/app/Models/Filearea.php @@ -11,6 +11,11 @@ class Filearea extends Model { use SoftDeletes,ScopeActive,AreaSecurity; + protected $casts = [ + 'first_file' => 'datetime:Y-m-d H:i:s', + 'last_file' => 'datetime:Y-m-d H:i:s', + ]; + protected $fillable = [ 'name', ]; diff --git a/resources/views/domain/view.blade.php b/resources/views/domain/view.blade.php index db1fbc0..3983d09 100644 --- a/resources/views/domain/view.blade.php +++ b/resources/views/domain/view.blade.php @@ -58,10 +58,10 @@ @foreach ($o->echoarea_stats()->groupBy('id') as $oo) - {{ $x->name }} + {{ $x->name }} {{ $x->description }} - {{ ($xx=$oo->min('first_message')) ? $xx->format('Y-m-d H:i') : '-' }} - {{ $x->last_message ? $x->last_message->format('Y-m-d H:i') : '-' }} + {{ ($xx=$oo->min('first_message')) ? $xx->format('Y-m-d H:i') : '-' }} + {{ $x->last_message ? $x->last_message->format('Y-m-d H:i') : '-' }} {{ $x->active ? 'Active' : 'Archive' }} {{ number_format($oo->where('stats','day')->pop()?->count) }} {{ number_format($oo->where('stats','week')->pop()?->count) }} @@ -88,21 +88,35 @@
@if($o->fileareas->count())

This network provides the following File areas:

- +
+ + + + - + + + + + + - @foreach ($o->fileareas->sortBy('name') as $oo) + @foreach ($o->filearea_stats()->groupBy('id') as $oo) - - - + + + + + + + + @endforeach @@ -247,7 +261,16 @@ conditionalPaging: { style: 'fade', speed: 500 // optional - } + }, + rowGroup: { + dataSrc: [4], + }, + columnDefs: [ + { + targets: [4], + visible: false, + }, + ], }); $('#system').DataTable({
Files
Filearea DescriptionLast File SentFirst FileLast FileArea ActiveWeekMonthTotal
{{ $oo->name }}{{ $oo->description }}-{{ $x->name }}{{ $x->description }}{{ ($xx=$oo->min('first_file')) ? $xx->format('Y-m-d H:i') : '-' }}{{ $x->last_file ? $x->last_file->format('Y-m-d H:i') : '-' }}{{ $x->active ? 'Active' : 'Archive' }}{{ number_format($oo->where('stats','week')->pop()?->count) }}{{ number_format($oo->where('stats','month')->pop()?->count) }}{{ number_format($oo->sum('count')) }}