added downloads counter and stats for reports
This commit is contained in:
parent
287c8c192c
commit
741f195a24
|
|
@ -87,4 +87,10 @@ protected static function booted(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateStatistics()
|
||||||
|
{
|
||||||
|
$this->increment('download_count');
|
||||||
|
$this->log .= "\n".Carbon::now()->toDateTimeString().' - ' . request()->ip();
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('project_reports', function (Blueprint $table) {
|
||||||
|
$table->integer('download_count')->default(0);
|
||||||
|
$table->text('log')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('project_reports', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('download_count');
|
||||||
|
$table->dropColumn('log');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $report->name }}</td>
|
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $report->name }}</td>
|
||||||
|
<td class="whitespace-nowrap py-4 pl-3 pr-4 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">
|
||||||
|
{{ $report->download_count }}
|
||||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||||
<livewire:components.badge :status="$report->status" :id="$report->id" :type="'report'"
|
<livewire:components.badge :status="$report->status" :id="$report->id" :type="'report'"
|
||||||
wire:key="{{$report->id}}"></livewire:components.badge>
|
wire:key="{{$report->id}}"></livewire:components.badge>
|
||||||
|
|
@ -159,6 +161,41 @@ class="text-center rounded-xl bg-red-500 text-white px-6 py-2 font-semibold disa
|
||||||
</div>
|
</div>
|
||||||
</x-dialog.panel>
|
</x-dialog.panel>
|
||||||
</x-dialog>
|
</x-dialog>
|
||||||
|
|
||||||
|
<x-dialog>
|
||||||
|
<x-dialog.open>
|
||||||
|
<x-menu.item>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
|
||||||
|
class="w-4 h-4">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="m20.25 7.5-.625 10.632a2.25 2.25 0 0 1-2.247 2.118H6.622a2.25 2.25 0 0 1-2.247-2.118L3.75 7.5M10 11.25h4M3.375 7.5h17.25c.621 0 1.125-.504 1.125-1.125v-1.5c0-.621-.504-1.125-1.125-1.125H3.375c-.621 0-1.125.504-1.125 1.125v1.5c0 .621.504 1.125 1.125 1.125Z"
|
||||||
|
clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
Stats / log
|
||||||
|
</x-menu.item>
|
||||||
|
</x-dialog.open>
|
||||||
|
|
||||||
|
|
||||||
|
<x-dialog.panel>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<h2 class="font-semibold text-3xl">Downloads stats / logs</h2>
|
||||||
|
<p class="text-lg text-slate-700">
|
||||||
|
<textarea class="w-full" rows="10" readonly>
|
||||||
|
{{ $report->log }}
|
||||||
|
</textarea>
|
||||||
|
</p>
|
||||||
|
<x-dialog.footer>
|
||||||
|
<x-dialog.close>
|
||||||
|
<button type="button"
|
||||||
|
class="text-center rounded-xl bg-slate-300 text-slate-800 px-6 py-2 font-semibold">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</x-dialog.close>
|
||||||
|
</x-dialog.footer>
|
||||||
|
</div>
|
||||||
|
</x-dialog.panel>
|
||||||
|
</x-dialog>
|
||||||
</x-menu.items>
|
</x-menu.items>
|
||||||
</x-menu>
|
</x-menu>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ class="flex justify-center rounded-md bg-indigo-600 px-3 py-2 text-center text-s
|
||||||
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 lg:pl-8">
|
class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 lg:pl-8">
|
||||||
Name
|
Name
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col"
|
||||||
|
class="py-3.5 pl-3 pr-4 text-left text-sm font-semibold text-gray-900 sm:pl-6 lg:pl-8">
|
||||||
|
Downloads
|
||||||
|
</th>
|
||||||
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
|
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">
|
||||||
Status
|
Status
|
||||||
</th>
|
</th>
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
$report = App\Models\ProjectReport::where('token', $token)->first();
|
$report = App\Models\ProjectReport::where('token', $token)->first();
|
||||||
if ($report) {
|
if ($report) {
|
||||||
$path = $report->project->download_path . '/' . $report->path;
|
$path = $report->project->download_path . '/' . $report->path;
|
||||||
|
$report->updateStatistics();
|
||||||
return response()->download(Storage::path($path));
|
return response()->download(Storage::path($path));
|
||||||
}
|
}
|
||||||
return abort(404);
|
return abort(404);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue