feature/multiplayer-game-interface #94
@@ -17,15 +17,12 @@ class GameController extends Controller
|
||||
$user = Auth::user();
|
||||
$query = Game::query()->with(["winner", "player1", "player2"]);
|
||||
|
||||
// Filter games based on user type
|
||||
if ($user->type !== 'A') {
|
||||
// Players can only see games they participate in
|
||||
$query->where(function ($q) use ($user) {
|
||||
$q->where('player1_user_id', $user->id)
|
||||
->orWhere('player2_user_id', $user->id);
|
||||
});
|
||||
}
|
||||
// Admins see all games (no filter needed)
|
||||
|
||||
if ($request->has("type") && in_array($request->type, ["3", "9"])) {
|
||||
$query->where("type", $request->type);
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\CoinTransaction;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$this->authorize('viewAny', CoinTransaction::class);
|
||||
|
||||
$query = CoinTransaction::with('user:id,nickname,email', 'type:id,name');
|
||||
|
||||
if ($request->has('sort_coins')) {
|
||||
$direction = $request->get('sort_coins') === 'asc' ? 'asc' : 'desc';
|
||||
$query->orderBy('coins', $direction);
|
||||
}
|
||||
|
||||
$dateDirection = $request->get('sort_datetime') === 'asc' ? 'asc' : 'desc';
|
||||
$query->orderBy('transaction_datetime', $dateDirection);
|
||||
|
||||
|
||||
$transactions = $query->paginate(15);
|
||||
|
||||
return response()->json($transactions);
|
||||
}
|
||||
}
|
||||
@@ -21,11 +21,14 @@ class UserController extends Controller
|
||||
|
||||
$query = User::query();
|
||||
|
||||
// Filtros úteis para o Backoffice
|
||||
if ($request->has('type')) {
|
||||
$query->where('type', $request->type);
|
||||
}
|
||||
|
||||
if ($request->has('blocked')) {
|
||||
$query->where('blocked', $request->type);
|
||||
}
|
||||
|
||||
if ($request->has('search')) {
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'like', '%'.$request->search.'%')
|
||||
@@ -47,7 +50,6 @@ class UserController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'nickname' => 'required|string|max:20|unique:users,nickname',
|
||||
'email' => 'required|email|unique:users,email',
|
||||
'password' => 'required|string|min:3',
|
||||
'type' => 'required|in:A,U',
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\CoinTransaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CoinTransactionPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->type === 'A' ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class GamePolicy
|
||||
*/
|
||||
public function view(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ class GamePolicy
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($game->status === "Pending") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -39,7 +43,7 @@ class GamePolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,28 +52,32 @@ class GamePolicy
|
||||
|
||||
public function join(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'waiting' ||
|
||||
$game->status !== "Pending" ||
|
||||
$game->player1_user_id === $user->id
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($game->player2_user_id !== null && $game->player2_user_id !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resign(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'ongoing' ||
|
||||
$game->status !== "Playing" ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -84,12 +92,12 @@ class GamePolicy
|
||||
*/
|
||||
public function update(User $user, Game $game): bool
|
||||
{
|
||||
if ($user->type === 'A') {
|
||||
if ($user->type === "A") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
$game->status !== 'ongoing' ||
|
||||
$game->status !== "Playing" ||
|
||||
($game->player1_user_id !== $user->id &&
|
||||
$game->player2_user_id !== $user->id)
|
||||
) {
|
||||
@@ -105,7 +113,7 @@ class GamePolicy
|
||||
public function delete(User $user, Game $game): bool
|
||||
{
|
||||
// Only admins can delete games
|
||||
return $user->type === 'A';
|
||||
return $user->type === "A";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\StatisticsController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\CoinPurchaseController;
|
||||
use App\Http\Controllers\TransactionController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::prefix('v1')->group(function () {
|
||||
@@ -97,6 +98,7 @@ Route::prefix('v1')->group(function () {
|
||||
->prefix('admin')
|
||||
->group(function () {
|
||||
Route::get('/statistics', [StatisticsController::class, 'getAdminStats']);
|
||||
Route::get('/transactions', [TransactionController::class, 'index']);
|
||||
Route::prefix('users')->group(function () {
|
||||
Route::get('/', [UserController::class, 'index']);
|
||||
Route::post('/', [UserController::class, 'store']);
|
||||
|
||||
@@ -5,7 +5,7 @@ Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"email": "p[email protected]",
|
||||
"email": "a1@mail.pt",
|
||||
"password": "123"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ Accept: application/json
|
||||
@id = {{login.response.body.user.id}}
|
||||
|
||||
### Get All matches
|
||||
GET http://localhost:8000/api/v1/matches
|
||||
GET http://localhost:8000/api/v1/games
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
@@ -55,7 +55,7 @@ Authorization: Bearer {{token}}
|
||||
"payment_reference": "912345678"
|
||||
}
|
||||
|
||||
### Get public stats
|
||||
### Get leaderboard
|
||||
GET http://localhost:8000/api/v1/leaderboard
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
@@ -65,3 +65,20 @@ GET http://localhost:8000/api/v1/statistics/me
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Get public stats
|
||||
GET http://localhost:8000/api/v1/statistics/public
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
### Get admin stats
|
||||
GET http://localhost:8000/api/v1/admin/statistics
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
|
||||
### Get admin stats
|
||||
GET http://localhost:8000/api/v1/admin/users
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
@@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: Create Game
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{api_url}}/games
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
}
|
||||
@@ -3,8 +3,7 @@
|
||||
<nav class="max-w-full p-5 flex flex-row justify-between align-middle">
|
||||
<div class="align-middle text-xl">
|
||||
<RouterLink to="/"> {{ pageTitle }} </RouterLink>
|
||||
<span class="text-xs" v-if="authStore.currentUser"
|
||||
> ({{ authStore.currentUser?.name }})
|
||||
<span class="text-xs" v-if="authStore.currentUser"> ({{ authStore.currentUser?.name }})
|
||||
</span>
|
||||
</div>
|
||||
<NavBar @logout="logout" :userLoggedIn="authStore.isLoggedIn" />
|
||||
@@ -29,8 +28,7 @@ import { useSocketStore } from './stores/socket'
|
||||
const authStore = useAuthStore()
|
||||
const socketStore = useSocketStore()
|
||||
|
||||
const year = new Date().getFullYear()
|
||||
const pageTitle = ref(`DAD ${year}/${String(year + 1).slice(-2)}`)
|
||||
const pageTitle = ref(`DAD 2025/26`)
|
||||
|
||||
const logout = () => {
|
||||
toast.promise(authStore.logout(), {
|
||||
|
||||
@@ -0,0 +1,752 @@
|
||||
<template>
|
||||
<div class="min-h-screen p-4 md:p-8 flex flex-col items-center font-sans text-black">
|
||||
|
||||
<div class="max-w-7xl w-full mb-8">
|
||||
<div class="flex flex-col md:flex-row md:justify-between md:items-end gap-6 mb-8">
|
||||
<div>
|
||||
<h1 class="text-4xl font-black uppercase tracking-tighter">Admin Panel</h1>
|
||||
<p class="text-gray-500 text-xs mt-1 uppercase tracking-[0.2em] font-bold">Platform Oversight</p>
|
||||
</div>
|
||||
<button @click="showCreateModal = true"
|
||||
class="px-6 py-3 bg-black text-white text-xs font-bold uppercase tracking-widest hover:bg-gray-800 transition-all active:scale-95 border border-black">
|
||||
+ Create Admin
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
||||
<div class="bg-white border border-gray-300 p-6 shadow-sm">
|
||||
<span class="text-[10px] font-bold uppercase tracking-widest text-gray-400 block mb-1">Total
|
||||
Players</span>
|
||||
<span class="text-3xl font-black">{{ stats.global_counters?.total_players ?? 'Loading' }}</span>
|
||||
</div>
|
||||
|
||||
<div class="bg-white border border-gray-300 p-6 shadow-sm">
|
||||
<span class="text-[10px] font-bold uppercase tracking-widest text-gray-400 block mb-1">Active
|
||||
Games</span>
|
||||
<span class="text-3xl font-black">{{ stats.global_counters?.active_games ?? 'Loading' }}</span>
|
||||
</div>
|
||||
|
||||
<div @click="openChart('games')"
|
||||
class="bg-white border border-gray-300 p-6 shadow-sm cursor-pointer hover:border-black transition-colors group">
|
||||
<div class="flex justify-between items-start">
|
||||
<span class="text-[10px] font-bold uppercase tracking-widest text-gray-400 mb-1">Total
|
||||
Games</span>
|
||||
<svg class="w-4 h-4 text-gray-300 group-hover:text-black" fill="none" stroke="currentColor"
|
||||
viewBox="0 0 24 24">
|
||||
<path d="M7 12l5 5L22 7"></path>
|
||||
</svg>
|
||||
</div>
|
||||
<span class="text-3xl font-black">{{ stats.global_counters?.total_games ?? 'Loading' }}</span>
|
||||
<span
|
||||
class="block text-[10px] mt-2 underline opacity-0 group-hover:opacity-100 transition-opacity">View
|
||||
Volume Chart</span>
|
||||
</div>
|
||||
|
||||
<div @click="openChart('revenue')"
|
||||
class="bg-black text-white p-6 shadow-lg cursor-pointer hover:bg-gray-900 transition-colors group">
|
||||
<div class="flex justify-between items-start">
|
||||
<span class="text-[10px] font-bold uppercase tracking-widest opacity-60 mb-1">Estimated
|
||||
Revenue</span>
|
||||
<svg class="w-4 h-4 opacity-40 group-hover:opacity-100" fill="none" stroke="currentColor"
|
||||
viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z">
|
||||
</path>
|
||||
</svg>
|
||||
</div>
|
||||
<span class="text-3xl font-black">€ {{ (stats.global_counters?.total_coins_purchased /
|
||||
10).toLocaleString() ?? 'Loading' }}</span>
|
||||
<span
|
||||
class="block text-[10px] mt-2 underline opacity-60 group-hover:opacity-100 transition-opacity">View
|
||||
Purchase History</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="activeChart"
|
||||
class="fixed inset-0 bg-black/80 backdrop-blur-md z-[60] flex items-center justify-center p-4"
|
||||
@click.self="activeChart = null">
|
||||
<div class="bg-white border border-gray-300 w-full max-w-5xl overflow-hidden shadow-2xl">
|
||||
|
||||
<div class="p-6 border-b border-gray-300 flex justify-between items-center bg-white">
|
||||
<div>
|
||||
<h3 class="text-2xl font-black uppercase tracking-tighter">
|
||||
{{ activeChart === 'games' ? 'Games Volume' : 'Purchases History' }}
|
||||
</h3>
|
||||
<p class="text-[10px] font-bold text-gray-400 uppercase tracking-[0.2em]">Last 12 Months
|
||||
Activity</p>
|
||||
</div>
|
||||
<button @click="activeChart = null"
|
||||
class="w-12 h-12 flex items-center justify-center border border-black hover:bg-black hover:text-white transition-all group">
|
||||
<span class="text-xl group-hover:rotate-90 transition-transform">✕</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="p-12 min-h-[400px] flex flex-col justify-end">
|
||||
|
||||
<div v-if="chartData.length > 0" class="flex items-end gap-3 h-64 w-full">
|
||||
<div v-for="(data, index) in chartData" :key="data.month"
|
||||
class="flex-1 flex flex-col items-center group relative h-full justify-end">
|
||||
|
||||
<div
|
||||
class="absolute -top-12 bg-black text-white text-[10px] py-2 px-3 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10 font-bold">
|
||||
{{ data.total || data.total_coins }}
|
||||
<div class="absolute -bottom-1 left-1/2 -translate-x-1/2 w-2 h-2 bg-black rotate-45">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full bg-black hover:bg-gray-700 transition-all ease-out" :style="{
|
||||
height: showBars ? `${calculateHeight(data.total || data.total_coins)}%` : '0%',
|
||||
transitionDelay: `${index * 50}ms`,
|
||||
transitionDuration: '800ms'
|
||||
}"></div>
|
||||
|
||||
<div class="h-8 flex items-center">
|
||||
<span class="text-[9px] font-black uppercase text-gray-400">
|
||||
{{ formatMonth(data.month) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else
|
||||
class="h-64 flex flex-col items-center justify-center text-gray-400 border-2 border-dashed border-gray-100">
|
||||
<p class="text-xs font-bold uppercase tracking-widest">No data available for this period</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-gray-50 p-8 border-t border-gray-300 flex justify-between items-center">
|
||||
<div class="flex gap-12">
|
||||
<div v-if="activeChart === 'games'" v-for="gt in stats.charts.games_by_type" :key="gt.type">
|
||||
<span class="text-[10px] font-bold uppercase text-gray-400 block tracking-widest">Bisca {{
|
||||
gt.type }}</span>
|
||||
<span class="text-2xl font-black">{{ gt.total.toLocaleString() }}</span>
|
||||
</div>
|
||||
<div v-if="activeChart === 'revenue'">
|
||||
<span class="text-[10px] font-bold uppercase text-gray-400 block tracking-widest">Total
|
||||
Period Volume</span>
|
||||
<span class="text-2xl font-black">{{
|
||||
stats.global_counters.total_coins_purchased.toLocaleString() }} Coins</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-[10px] font-bold text-gray-400 uppercase italic">
|
||||
* Admin Full-Access View
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bg-white border border-gray-300 shadow-2xl max-w-7xl w-full overflow-hidden">
|
||||
<div class="flex border-b border-gray-300 bg-gray-50 overflow-x-auto scrollbar-hide">
|
||||
<button v-for="tab in tabs" :key="tab.id" @click="activeTab = tab.id" :class="[
|
||||
'flex-1 min-w-[150px] p-5 text-xs font-bold uppercase tracking-widest transition-all outline-none',
|
||||
activeTab === tab.id
|
||||
? 'bg-white border-b-2 border-black text-black'
|
||||
: 'text-gray-400 hover:text-black hover:bg-gray-100 border-b-2 border-transparent'
|
||||
]">
|
||||
{{ tab.name }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="min-h-[400px]">
|
||||
<div v-if="activeTab === 'users'" class="animate-in fade-in slide-in-from-bottom-2 duration-300">
|
||||
<div class="overflow-x-auto">
|
||||
<div id="table-scroll-container"
|
||||
class="overflow-y-auto h-[500px] scrollbar-thin scrollbar-thumb-black">
|
||||
<table class="w-full text-left border-collapse sticky-header">
|
||||
<thead class="bg-gray-50 border-b border-gray-300">
|
||||
<tr>
|
||||
<th
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Name</th>
|
||||
<th
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Coins</th>
|
||||
<th @click="handleSort('type')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Role
|
||||
<span class="ml-1">
|
||||
<template v-if="filters.type === 'A'"> (Admins)</template>
|
||||
<template v-else-if="filters.type === 'P'"> (Players)</template>
|
||||
<template v-else> ↕</template>
|
||||
</span>
|
||||
</th>
|
||||
|
||||
<th @click="handleSort('blocked')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Status
|
||||
<span class="ml-1">
|
||||
<template v-if="filters.blocked === true"> (Blocked)</template>
|
||||
<template v-else-if="filters.blocked === false"> (Active)</template>
|
||||
<template v-else> ↕</template>
|
||||
</span>
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
<template v-if="filteredUsers.length > 0">
|
||||
<tr v-for="user in filteredUsers" :key="user.id"
|
||||
class="hover:bg-gray-50/80 transition-colors">
|
||||
<td class="p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
class="w-10 h-10 bg-black text-white flex items-center justify-center font-bold text-sm border-2 border-black">
|
||||
{{ user.name.charAt(0) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-sm font-bold">{{ user.name }}</div>
|
||||
<div v-if="user.nickname"
|
||||
class="text-xs text-gray-500 font-mono">@{{ user.nickname
|
||||
}}</div>
|
||||
<div class="text-xs text-gray-500 font-mono">{{ user.email }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<div v-if="user.coins_balance" class="flex items-center gap-2">
|
||||
<div
|
||||
class="flex items-center justify-center w-5 h-5 bg-purple-400 rounded-full shadow-sm">
|
||||
<span class="text-[10px] font-bold text-purple-900">$</span>
|
||||
</div>
|
||||
<span class="text-[10px] uppercase font-bold tracking-tight">{{
|
||||
user.coins_balance }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<span :class="[
|
||||
'px-2 py-1 text-[10px] font-bold border',
|
||||
user.type === 'A' ? 'bg-black text-white border-black' : 'bg-white text-gray-600 border-gray-300'
|
||||
]">
|
||||
{{ user.type === 'A' ? 'ADMIN' : 'PLAYER' }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<div
|
||||
:class="['w-2 h-2 rounded-full', user.blocked ? 'bg-red-600' : 'bg-green-500']">
|
||||
</div>
|
||||
<span class="text-[10px] uppercase font-bold tracking-tight">{{
|
||||
user.blocked
|
||||
? 'Blocked' : 'Active' }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4 text-right">
|
||||
<div v-if="user.type != 'A'" class="space-x-2 flex justify-end">
|
||||
<button @click="toggleBlock(user)"
|
||||
class="text-[10px] font-bold uppercase tracking-tighter border-2 border-black px-3 py-1 hover:bg-black hover:text-white transition-all">{{
|
||||
user.blocked ? 'Unblock' : 'Block' }}</button>
|
||||
<button @click=" confirmDelete(user)"
|
||||
class="text-[10px] font-bold uppercase tracking-tighter bg-red-600 text-white border-2 border-red-600 px-3 py-1 hover:bg-red-700 transition-all">Remove</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="!isLoading">
|
||||
<td colspan="3"
|
||||
class="p-12 text-center text-gray-400 uppercase text-xs font-bold tracking-widest">
|
||||
No users found
|
||||
</td>
|
||||
</tr>
|
||||
<tr ref="loadMoreTrigger">
|
||||
<td colspan="4" class="p-4 text-center">
|
||||
<span v-if="isLoading"
|
||||
class="text-[10px] font-bold uppercase animate-pulse">Loading
|
||||
more...</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="activeTab === 'transactions'"
|
||||
class="animate-in fade-in slide-in-from-bottom-2 duration-300">
|
||||
<div class="overflow-x-auto">
|
||||
<div id="table-scroll-container"
|
||||
class="overflow-y-auto h-[500px] scrollbar-thin scrollbar-thumb-black">
|
||||
<table class="w-full text-left border-collapse sticky-header">
|
||||
<thead class="bg-gray-50 border-b border-gray-300">
|
||||
<tr>
|
||||
<th @click="handleSort('datetime')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Date Time
|
||||
<span>{{ filters.sort_datetime === 'desc' ? ' ↓' : ' ↑' }}</span>
|
||||
</th>
|
||||
<th class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500">
|
||||
User
|
||||
</th>
|
||||
<th class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500">
|
||||
Transaction type
|
||||
</th>
|
||||
<th @click="handleSort('coins')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Coins
|
||||
<span v-if="filters.sort_coins">
|
||||
{{ filters.sort_coins === 'desc' ? ' ↓' : '↑' }}</span>
|
||||
<span v-else> ↕</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
<template v-if="transactions.length > 0">
|
||||
<tr v-for="tx in transactions" :key="tx.id"
|
||||
class="hover:bg-gray-50/80 transition-colors">
|
||||
<td class="p-4 text-xs font-mono text-gray-600">
|
||||
{{ new Date(tx.transaction_datetime).toLocaleDateString() }} •
|
||||
{{ new Date(tx.transaction_datetime).toLocaleTimeString([], {
|
||||
hour:
|
||||
'2-digit', minute: '2-digit'
|
||||
}) }}
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<div class="text-sm font-bold">{{ tx.user?.nickname || 'Guest' }}</div>
|
||||
<div class="text-[10px] text-gray-500 font-mono">{{ tx.user?.email }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<div class="flex items-center gap-4">
|
||||
<div
|
||||
class="px-2 py-1 bg-gray-100 border border-gray-300 text-[9px] font-black uppercase tracking-tighter text-gray-500 min-w-[80px] text-center">
|
||||
{{ tx.type?.name || 'Manual' }}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-4">
|
||||
<div class="inline-flex items-center gap-2">
|
||||
<span :class="[
|
||||
'text-sm font-black tracking-tighter',
|
||||
tx.coins >= 0 ? 'text-green-400' : 'text-red-400'
|
||||
]">
|
||||
{{ tx.coins > 0 ? '+' : '' }}{{ tx.coins.toLocaleString() }}
|
||||
</span>
|
||||
|
||||
<span
|
||||
class="text-[10px] font-bold text-gray-400 uppercase tracking-widest">Coins</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="!isLoading">
|
||||
<td colspan="3"
|
||||
class="w-1 p-12 text-center text-gray-400 uppercase text-xs font-bold tracking-widest">
|
||||
No transactions found
|
||||
</td>
|
||||
</tr>
|
||||
<tr ref="loadMoreTrigger">
|
||||
<td colspan="4" class="p-4 text-center">
|
||||
<span v-if="isLoading"
|
||||
class="text-[10px] font-bold uppercase animate-pulse">Loading
|
||||
more...</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else-if="activeTab === 'games'" class="animate-in fade-in slide-in-from-bottom-2 duration-300">
|
||||
<div class="overflow-x-auto">
|
||||
<div id="table-scroll-container"
|
||||
class="overflow-y-auto h-[500px] scrollbar-thin scrollbar-thumb-black">
|
||||
<table class="w-full text-left border-collapse sticky-header">
|
||||
<thead class="bg-gray-50 border-b border-gray-300">
|
||||
<tr>
|
||||
<th @click="handleSort('date')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Timeline
|
||||
<span>{{ filters.game_sort_date === 'desc' ? ' ↓' : ' ↑' }}</span>
|
||||
</th>
|
||||
<th class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500">
|
||||
Player 1</th>
|
||||
<th class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500">
|
||||
Player 2</th>
|
||||
<th class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500">
|
||||
Result</th>
|
||||
<th @click="handleSort('type')"
|
||||
class="p-4 text-[10px] font-bold uppercase tracking-widest text-gray-500 cursor-pointer hover:text-black transition-colors">
|
||||
Variant
|
||||
<span v-if="filters.game_filter_type"> (Bisca {{ filters.game_filter_type
|
||||
}})</span>
|
||||
<span v-else> ↕</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-100">
|
||||
<template v-if="games.length > 0">
|
||||
<tr v-for="game in games" :key="game.id"
|
||||
class="hover:bg-gray-50/80 transition-colors">
|
||||
<td class="p-4">
|
||||
<div class="text-[10px] font-mono text-black font-bold">
|
||||
{{ new Date(game.began_at).toLocaleDateString() }}</div>
|
||||
<div class="text-[10px] font-mono text-gray-400 italic">
|
||||
{{ new Date(game.began_at).toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}) }} •
|
||||
{{ new Date(game.ended_at).toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
}) }}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<div class="text-sm font-bold text-black">{{ game.player1?.nickname }}
|
||||
</div>
|
||||
<div
|
||||
class="text-[10px] font-black text-gray-400 uppercase tracking-tighter">
|
||||
{{ game.player1_points }} Points
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<div class="text-sm font-bold text-black">{{ game.player2?.nickname }}
|
||||
</div>
|
||||
<div
|
||||
class="text-[10px] font-black text-gray-400 uppercase tracking-tighter">
|
||||
{{ game.player2_points }} Points
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<div v-if="game.is_draw" class="text-xs font-bold text-gray-400">— Draw
|
||||
—</div>
|
||||
<div v-else class="flex flex-col">
|
||||
<span
|
||||
class="text-[9px] font-bold uppercase text-gray-400 tracking-widest mb-0.5">Winner</span>
|
||||
<span
|
||||
class="text-xs font-black bg-black text-white px-2 py-0.5 w-fit uppercase tracking-tighter">
|
||||
{{ game.winner_user_id === game.player1_user_id ?
|
||||
game.player1?.nickname : game.player2?.nickname }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="p-4">
|
||||
<div
|
||||
class="px-2 py-1 bg-gray-100 border border-gray-300 text-[10px] font-black text-center w-20">
|
||||
BISCA {{ game.type }}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr ref="loadMoreTrigger">
|
||||
<td colspan="5" class="p-8 text-center border-none">
|
||||
<div v-if="isLoading" class="flex flex-col items-center gap-2">
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-black border-t-transparent rounded-full animate-spin">
|
||||
</div>
|
||||
<span
|
||||
class="text-[10px] font-black uppercase tracking-[0.2em]">Retrieving
|
||||
match data...</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="!isLoading">
|
||||
<td colspan="5"
|
||||
class="p-12 text-center text-gray-400 uppercase text-xs font-bold tracking-widest border-none">
|
||||
No match history found
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="p-12 text-center animate-in fade-in duration-500">
|
||||
<svg class="w-12 h-12 mx-auto mb-4 text-gray-300" fill="none" stroke="currentColor"
|
||||
viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1"
|
||||
d="M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
<h2 class="text-sm font-bold uppercase tracking-widest text-gray-400">Detailed logs for {{ activeTab
|
||||
}} pending API</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showCreateModal"
|
||||
class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 flex items-center justify-center p-4">
|
||||
<div class="bg-white border border-gray-300 w-full max-w-md shadow-2xl animate-in zoom-in-95 duration-200">
|
||||
<div class="p-6 border-b border-gray-300 bg-black text-white">
|
||||
<h3 class="text-xl font-black uppercase tracking-tighter">New Admin</h3>
|
||||
</div>
|
||||
<form @submit.prevent="handleSubmitAdmin" class="p-6 space-y-4">
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold uppercase text-gray-500 mb-1">Full Name</label>
|
||||
<input v-model="adminForm.name" type="text" required
|
||||
class="w-full border border-gray-300 p-3 text-sm focus:border-black outline-none transition-colors" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-[10px] font-bold uppercase text-gray-500 mb-1">Email Address</label>
|
||||
<input v-model="adminForm.email" type="email" required
|
||||
class="w-full border border-gray-300 p-3 text-sm focus:border-black outline-none transition-colors" />
|
||||
</div>
|
||||
<div class="flex gap-3 pt-4">
|
||||
<button type="button" @click="showCreateModal = false"
|
||||
class="flex-1 px-4 py-3 border border-gray-300 font-bold uppercase text-xs hover:bg-gray-50 transition-all">Cancel</button>
|
||||
<button type="submit"
|
||||
class="flex-1 px-4 py-3 bg-black text-white font-bold uppercase text-xs hover:bg-gray-800 transition-all">Create
|
||||
Account</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted, watch, nextTick } from 'vue'
|
||||
import { useAPIStore } from '@/stores/api'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
const activeTab = ref('users')
|
||||
const showCreateModal = ref(false)
|
||||
const activeChart = ref(null)
|
||||
const showBars = ref(false)
|
||||
const stats = ref({})
|
||||
const users = ref([])
|
||||
const transactions = ref([])
|
||||
const games = ref([])
|
||||
const isLoading = ref(false)
|
||||
const loadMoreTrigger = ref(null)
|
||||
|
||||
const apiStore = useAPIStore()
|
||||
|
||||
const pagination = reactive({
|
||||
users: { page: 1, lastPage: 1 },
|
||||
transactions: { page: 1, lastPage: 1 },
|
||||
games: { page: 1, lastPage: 1 }
|
||||
})
|
||||
|
||||
const filters = reactive({
|
||||
type: null,
|
||||
blocked: null,
|
||||
sort_datetime: 'desc',
|
||||
sort_coins: null,
|
||||
game_sort_direction: 'desc',
|
||||
game_type: null
|
||||
})
|
||||
|
||||
watch(activeTab, async () => {
|
||||
resetPagination();
|
||||
await fetchData();
|
||||
await nextTick();
|
||||
setupObserver();
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
{ id: 'users', name: 'User Management' },
|
||||
{ id: 'transactions', name: 'Transactions' },
|
||||
{ id: 'games', name: 'Games History' }
|
||||
]
|
||||
|
||||
const chartData = computed(() => {
|
||||
if (!stats.value) return []
|
||||
if (activeChart.value === 'games') return [...stats.value.charts.games_per_month].reverse()
|
||||
if (activeChart.value === 'revenue') return [...stats.value.charts.purchases_per_month].reverse()
|
||||
return []
|
||||
})
|
||||
|
||||
const openChart = (type) => {
|
||||
activeChart.value = type
|
||||
showBars.value = false
|
||||
|
||||
setTimeout(() => {
|
||||
showBars.value = true
|
||||
}, 50);
|
||||
}
|
||||
|
||||
const calculateHeight = (value) => {
|
||||
const max = Math.max(...chartData.value.map(d => d.total || d.total_coins))
|
||||
return (value / max) * 100
|
||||
}
|
||||
|
||||
const formatMonth = (monthStr) => {
|
||||
const [_, month] = monthStr.split('-')
|
||||
const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
||||
return months[parseInt(month) - 1]
|
||||
}
|
||||
|
||||
const adminForm = reactive({ name: '', nickname: '', email: '' })
|
||||
|
||||
const toggleBlock = (user) => {
|
||||
user.blocked == false ? apiStore.blockUser(user) : apiStore.unblockUser(user)
|
||||
user.blocked = !user.blocked
|
||||
}
|
||||
|
||||
const confirmDelete = (user) => {
|
||||
if (confirm(`Remove ${user.name}? This action follows platform rules for ${user.type === 'P' ? 'soft-deletion' : 'permanent removal'}.`)) {
|
||||
apiStore.deleteUser(user)
|
||||
users.value = users.value.filter(u => u.id !== user.id)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmitAdmin = () => {
|
||||
adminForm.type = 'A'
|
||||
adminForm.password = '123'
|
||||
adminForm.blocked = false
|
||||
|
||||
const promise = apiStore.postAdmin(adminForm)
|
||||
toast.promise(promise, {
|
||||
loading: 'Calling API',
|
||||
success: () => {
|
||||
return `Admin created with success`
|
||||
},
|
||||
error: (error) =>
|
||||
error.response?.data?.message
|
||||
})
|
||||
|
||||
showCreateModal.value = false
|
||||
adminForm.name = ''; adminForm.email = '';
|
||||
}
|
||||
|
||||
const resetPagination = () => {
|
||||
pagination[activeTab.value].page = 1
|
||||
if (activeTab.value === 'users') users.value = []
|
||||
if (activeTab.value === 'transactions') transactions.value = []
|
||||
if (activeTab.value === 'games') games.value = []
|
||||
}
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
return users.value.filter(user => user.id !== useAuthStore().currentUserID);
|
||||
});
|
||||
|
||||
const fetchData = async () => {
|
||||
if (isLoading.value) return
|
||||
const currentTab = activeTab.value
|
||||
if (pagination[currentTab].page > pagination[currentTab].lastPage && pagination[currentTab].page !== 1) return
|
||||
|
||||
isLoading.value = true
|
||||
try {
|
||||
let response
|
||||
if (currentTab === 'users') {
|
||||
const params = { page: pagination[currentTab].page, type: filters.type, blocked: filters.blocked };
|
||||
response = await apiStore.getAdminUsers(params);
|
||||
users.value.push(...response.data.data);
|
||||
}
|
||||
else if (currentTab === 'transactions') {
|
||||
const params = {
|
||||
page: pagination[currentTab].page,
|
||||
sort_datetime: filters.sort_datetime,
|
||||
sort_coins: filters.sort_coins
|
||||
};
|
||||
response = await apiStore.getAdminTransactions(params);
|
||||
transactions.value.push(...response.data.data);
|
||||
}
|
||||
else if (currentTab === 'games') {
|
||||
const params = {
|
||||
page: pagination[currentTab].page,
|
||||
sort_direction: filters.game_sort_direction,
|
||||
type: filters.game_type
|
||||
};
|
||||
response = await apiStore.getAdminGames(params);
|
||||
games.value.push(...response.data.data);
|
||||
}
|
||||
|
||||
|
||||
pagination[currentTab].lastPage = response.data.last_page
|
||||
pagination[currentTab].page++
|
||||
} catch (error) {
|
||||
console.error("Fetch failed", error)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSort = async (column) => {
|
||||
if (activeTab.value === 'users') {
|
||||
if (column === 'type') {
|
||||
filters.type = filters.type === null ? 'A' : (filters.type === 'A' ? 'P' : null);
|
||||
} else if (column === 'blocked') {
|
||||
filters.blocked = filters.blocked === null ? true : (filters.blocked === true ? false : null);
|
||||
}
|
||||
}
|
||||
|
||||
else if (activeTab.value === 'transactions') {
|
||||
if (column === 'datetime') {
|
||||
filters.sort_datetime = filters.sort_datetime === 'desc' ? 'asc' : 'desc';
|
||||
} else if (column === 'coins') {
|
||||
if (filters.sort_coins === null) filters.sort_coins = 'desc';
|
||||
else if (filters.sort_coins === 'desc') filters.sort_coins = 'asc';
|
||||
else filters.sort_coins = null;
|
||||
}
|
||||
}
|
||||
|
||||
else if (activeTab.value === 'games') {
|
||||
if (column === 'date') {
|
||||
filters.game_sort_direction = filters.game_sort_direction === 'desc' ? 'asc' : 'desc';
|
||||
} else if (column === 'type') {
|
||||
if (filters.game_type === null) filters.game_type = '9';
|
||||
else if (filters.game_type === '9') filters.game_type = '3';
|
||||
else filters.game_type = null;
|
||||
}
|
||||
}
|
||||
|
||||
resetPagination();
|
||||
await fetchData();
|
||||
await nextTick();
|
||||
setupObserver();
|
||||
};
|
||||
|
||||
const setupObserver = () => {
|
||||
if (window.adminTableObserver) window.adminTableObserver.disconnect();
|
||||
|
||||
const container = document.querySelector('#table-scroll-container');
|
||||
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
const currentTab = activeTab.value;
|
||||
const hasMore = pagination[currentTab].page <= pagination[currentTab].lastPage;
|
||||
|
||||
if (entries[0].isIntersecting && !isLoading.value && hasMore) {
|
||||
fetchData();
|
||||
}
|
||||
}, {
|
||||
root: container,
|
||||
threshold: 0.1,
|
||||
rootMargin: '100px'
|
||||
});
|
||||
|
||||
if (loadMoreTrigger.value) {
|
||||
observer.observe(loadMoreTrigger.value);
|
||||
window.adminTableObserver = observer;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const statsResponse = await apiStore.getAdminStats()
|
||||
const globalResponse = await apiStore.getPublicStats()
|
||||
stats.value = statsResponse.data
|
||||
stats.value.global_counters.active_games = globalResponse.data.active_games
|
||||
|
||||
await fetchData()
|
||||
await nextTick()
|
||||
setupObserver()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.sticky-header thead th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background-color: #f9fafb;
|
||||
box-shadow: inset 0 -1px 0 #d1d5db;
|
||||
}
|
||||
|
||||
#table-scroll-container::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
#table-scroll-container::-webkit-scrollbar-thumb {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
#table-scroll-container::-webkit-scrollbar-track {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
</style>
|
||||
@@ -37,6 +37,7 @@ const lbPage = ref(1)
|
||||
const lbObserverTarget = ref(null)
|
||||
const lbObserver = ref(null)
|
||||
const lbMorePages = ref(true)
|
||||
const publicStats = ref(null)
|
||||
|
||||
const setupGamesObserver = () => {
|
||||
if (gObserver.value) gObserver.value.disconnect();
|
||||
@@ -74,6 +75,15 @@ const getPendingGames = async (mode = selectedMode.value) => {
|
||||
}
|
||||
}
|
||||
|
||||
const fetchPublicStats = async () => {
|
||||
try {
|
||||
const response = await apiStore.getPublicStats()
|
||||
publicStats.value = response.data
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch public stats", error)
|
||||
}
|
||||
}
|
||||
|
||||
const openStats = async () => {
|
||||
showStatsModal.value = true
|
||||
statsLoading.value = true
|
||||
@@ -161,6 +171,7 @@ const toggleReady = () => {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchPublicStats();
|
||||
await getPendingGames();
|
||||
await nextTick();
|
||||
setupGamesObserver();
|
||||
@@ -218,6 +229,27 @@ const joinGame = async (game) => {
|
||||
|
||||
<div class="flex flex-col justify-center items-center gap-5 pt-10 px-4">
|
||||
|
||||
<Card v-if="publicStats" class="w-full max-w-2xl border-[#a855f7] bg-[#f8f0ff] shadow-sm">
|
||||
<CardContent class="p-4">
|
||||
<div class="flex justify-around items-center">
|
||||
<div class="text-center">
|
||||
<p class="text-xs uppercase font-bold opacity-70">Players</p>
|
||||
<p class="text-xl font-black">{{ publicStats.total_players }}</p>
|
||||
</div>
|
||||
<div class="h-8 w-[1px] bg-[#a855f7]/20"></div>
|
||||
<div class="text-center">
|
||||
<p class="text-xs uppercase font-bold opacity-70">Total Games</p>
|
||||
<p class="text-xl font-black">{{ publicStats.total_games }}</p>
|
||||
</div>
|
||||
<div class="h-8 w-[1px] bg-[#a855f7]/20"></div>
|
||||
<div class="text-center">
|
||||
<p class="text-xs uppercase font-bold opacity-70">Active</p>
|
||||
<p class="text-xl font-black">{{ publicStats.active_games }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div class="relative w-full max-w-md bg-card rounded-lg border shadow-sm overflow-hidden">
|
||||
<div class="relative h-14 flex items-center">
|
||||
|
||||
|
||||
@@ -77,12 +77,12 @@
|
||||
@click="activeTab = 'edit'">
|
||||
Edit Profile
|
||||
</button>
|
||||
<button
|
||||
<button v-if="!authStore.isAdmin"
|
||||
:class="['flex-1 p-4 bg-transparent border-none border-b-2 border-transparent cursor-pointer text-sm font-medium text-gray-600 transition-all hover:bg-gray-100 hover:text-black', { 'border-b-black text-black bg-white': activeTab === 'transaction-history' }]"
|
||||
@click="activeTab = 'transaction-history'">
|
||||
Transaction History
|
||||
</button>
|
||||
<button
|
||||
<button v-if="!authStore.isAdmin"
|
||||
:class="['flex-1 p-4 bg-transparent border-none border-b-2 border-transparent cursor-pointer text-sm font-medium text-gray-600 transition-all hover:bg-gray-100 hover:text-black', { 'border-b-black text-black bg-white': activeTab === 'game-history' }]"
|
||||
@click="activeTab = 'game-history'">
|
||||
Game History
|
||||
@@ -92,7 +92,7 @@
|
||||
@click="activeTab = 'password'">
|
||||
Change Password
|
||||
</button>
|
||||
<button
|
||||
<button v-if="!authStore.isAdmin"
|
||||
:class="['flex-1 p-4 bg-transparent border-none border-b-2 border-transparent cursor-pointer text-sm font-medium text-gray-600 transition-all hover:bg-gray-100 hover:text-black', { 'border-b-black text-black bg-white': activeTab === 'delete' }]"
|
||||
@click="activeTab = 'delete'">
|
||||
Delete Account
|
||||
@@ -228,7 +228,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Transaction History Tab -->
|
||||
<div v-if="activeTab === 'transaction-history'" class="p-8">
|
||||
<div v-if="activeTab === 'transaction-history' && !authStore.isAdmin" class="p-8">
|
||||
|
||||
<div class="flex flex-wrap gap-4 mb-6 items-end">
|
||||
<div class="flex flex-col gap-1">
|
||||
@@ -280,8 +280,7 @@
|
||||
{{ transaction.category }} </div>
|
||||
<div class="text-xs text-muted-foreground">
|
||||
{{ new Date(transaction.began_at).toLocaleDateString() }} •
|
||||
{{ new Date(transaction.began_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||
}}
|
||||
{{ new Date(transaction.began_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -305,7 +304,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Game History Tab -->
|
||||
<div v-if="activeTab === 'game-history'" class="p-8">
|
||||
<div v-if="activeTab === 'game-history' && !authStore.isAdmin" class="p-8">
|
||||
<div class="flex flex-wrap gap-4 mb-6 items-end">
|
||||
<div class="flex flex-col gap-1">
|
||||
<label class="text-xs font-medium text-muted-foreground">Variant</label>
|
||||
@@ -457,7 +456,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Delete Account Tab -->
|
||||
<div v-if="activeTab === 'delete'" class="p-8 flex flex-col items-center">
|
||||
<div v-if="activeTab === 'delete' && !authStore.isAdmin" class="p-8 flex flex-col items-center">
|
||||
<div class="max-w-lg">
|
||||
<div class="border border-red-600 bg-red-50 p-6 mb-6">
|
||||
<div class="flex items-start gap-3">
|
||||
|
||||
@@ -12,6 +12,8 @@ import SinglePlayerGamePage from '@/pages/game/SinglePlayerGamePage.vue'
|
||||
import MultiplayerGamePage from '@/pages/game/MultiplayerGamePage.vue'
|
||||
import RegisterPage from '@/pages/register/RegisterPage.vue'
|
||||
import CoinsPurchasePage from '@/pages/purchase/CoinPurchasePage.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import AdminPage from '@/pages/admin/AdminPage.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -20,6 +22,7 @@ const router = createRouter({
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomePage,
|
||||
meta: { requiresAdmin: false }
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
@@ -36,7 +39,7 @@ const router = createRouter({
|
||||
name: 'bisca3',
|
||||
component: SinglePlayerGamePage,
|
||||
props: { gameType: 3 },
|
||||
meta: { requiresAuth: true },
|
||||
meta: { requiresAuth: true, requiresAdmin: false },
|
||||
},
|
||||
{
|
||||
path: '/game/9',
|
||||
@@ -61,6 +64,12 @@ const router = createRouter({
|
||||
component: CoinsPurchasePage,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'admin',
|
||||
component: AdminPage,
|
||||
meta: { requiresAuth: true, requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/testing',
|
||||
children: [
|
||||
@@ -95,6 +104,7 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const requiresAuth = to.matched.some((record) => record.meta.requiresAuth)
|
||||
const requiresAdmin = to.matched.some((record) => record.meta.requiresAdmin)
|
||||
|
||||
if (requiresAuth) {
|
||||
const token = localStorage.getItem('token')
|
||||
@@ -103,6 +113,10 @@ router.beforeEach((to, from, next) => {
|
||||
return next({ name: 'login' })
|
||||
}
|
||||
}
|
||||
|
||||
if (useAuthStore().isAdmin && to.name === 'home') return next({ name: 'admin' })
|
||||
if (requiresAdmin && !useAuthStore().isAdmin) return next({ name: 'home' })
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ export const useAPIStore = defineStore('api', () => {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: params.page || 1,
|
||||
...(params.type && { type: params.type }),
|
||||
...(params.date_from && { date_from: params.date_from }),
|
||||
...(params.date_to && { date_to: params.date_to }),
|
||||
...(params.blocked && { blocked: params.blocked }),
|
||||
}).toString()
|
||||
|
||||
return axios.get(`${API_BASE_URL}/users/${authStore.currentUserID}/transactions?${queryParams}`)
|
||||
@@ -114,6 +113,58 @@ export const useAPIStore = defineStore('api', () => {
|
||||
return axios.get(`${API_BASE_URL}/statistics/me`)
|
||||
}
|
||||
|
||||
const getPublicStats = () => {
|
||||
return axios.get(`${API_BASE_URL}/statistics/public`)
|
||||
}
|
||||
|
||||
const getAdminStats = () => {
|
||||
return axios.get(`${API_BASE_URL}/admin/statistics`)
|
||||
}
|
||||
|
||||
const getAdminUsers = (params) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: params.page || 1,
|
||||
...(params.type && { type: params.type }),
|
||||
...(params.blocked && { blocked: params.blocked }),
|
||||
}).toString()
|
||||
return axios.get(`${API_BASE_URL}/admin/users?${queryParams}`)
|
||||
}
|
||||
|
||||
const blockUser = (user) => {
|
||||
return axios.post(`${API_BASE_URL}/admin/users/${user.id}/block`)
|
||||
}
|
||||
|
||||
const unblockUser = (user) => {
|
||||
return axios.post(`${API_BASE_URL}/admin/users/${user.id}/unblock`)
|
||||
}
|
||||
|
||||
const deleteUser = (user) => {
|
||||
return axios.delete(`${API_BASE_URL}/admin/users/${user.id}`)
|
||||
}
|
||||
|
||||
const getAdminTransactions = (params) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: params.page || 1,
|
||||
...(params.sort_datetime == 'asc' && { sort_datetime: 'asc' }),
|
||||
...(params.sort_coins && { sort_coins: params.sort_coins }),
|
||||
}).toString()
|
||||
return axios.get(`${API_BASE_URL}/admin/transactions?${queryParams}`)
|
||||
}
|
||||
|
||||
const getAdminGames = (params) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: params.page || 1,
|
||||
...(params.sort_direction == 'asc' && { sort_direction: 'asc' }),
|
||||
...(params.type && { type: params.type }),
|
||||
}).toString()
|
||||
return axios.get(`${API_BASE_URL}/games?${queryParams}`)
|
||||
}
|
||||
|
||||
const postAdmin = async (credentials) => {
|
||||
return axios.post(`${API_BASE_URL}/admin/users`, credentials)
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
postLogin,
|
||||
postLogout,
|
||||
@@ -123,6 +174,15 @@ export const useAPIStore = defineStore('api', () => {
|
||||
getCurrentUserTransactions,
|
||||
getCurrentUserStats,
|
||||
getLeaderboard,
|
||||
getPublicStats,
|
||||
getAdminStats,
|
||||
getAdminUsers,
|
||||
blockUser,
|
||||
unblockUser,
|
||||
deleteUser,
|
||||
getAdminTransactions,
|
||||
getAdminGames,
|
||||
postAdmin,
|
||||
gameQueryParameters,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useAPIStore } from './api'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
const DEFAULT_TIMEOUT = 5 * 60 * 1000
|
||||
const DEFAULT_TIMEOUT = 30 * 60 * 1000
|
||||
const REMEMBER_ME_TIMEOUT = 365 * 24 * 60 * 60 * 1000
|
||||
|
||||
const currentUser = ref(undefined)
|
||||
@@ -20,6 +20,10 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
return currentUser.value?.id
|
||||
})
|
||||
|
||||
const isAdmin = computed(() => {
|
||||
return currentUser.value?.type === 'A'
|
||||
})
|
||||
|
||||
const isTokenAlmostExpired = () => {
|
||||
if (!tokenExpiry.value) return false;
|
||||
return Date.now() > (tokenExpiry.value - 60 * 1000);
|
||||
@@ -112,10 +116,16 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
return true
|
||||
}
|
||||
|
||||
const updateCurrentUserCoins = (coins) => {
|
||||
if (!currentUser.value) return;
|
||||
currentUser.value.coins_balance = coins
|
||||
}
|
||||
|
||||
return {
|
||||
currentUser,
|
||||
isLoggedIn,
|
||||
currentUserID,
|
||||
isAdmin,
|
||||
token,
|
||||
rememberMe,
|
||||
getToken,
|
||||
@@ -124,5 +134,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
resetTokenExpiry,
|
||||
isTokenAlmostExpired,
|
||||
restoreSession,
|
||||
updateCurrentUserCoins,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import axios from 'axios'
|
||||
import { inject, ref } from 'vue'
|
||||
import { useAuthStore } from './auth'
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const API_BASE_URL = inject('apiBaseURL')
|
||||
@@ -10,6 +11,7 @@ export const useUserStore = defineStore('user', () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/users/me/coins`)
|
||||
coins.value = response.data?.coins || 0
|
||||
useAuthStore().updateCurrentUserCoins(coins.value)
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error('Error fetching coins', error)
|
||||
|
||||
@@ -17,7 +17,7 @@ class BiscaGame {
|
||||
};
|
||||
|
||||
this.currentTurn = null;
|
||||
this.status = "pending";
|
||||
this.status = 'pending';
|
||||
this.startTime = null;
|
||||
|
||||
this.players = {
|
||||
@@ -50,7 +50,7 @@ class BiscaGame {
|
||||
this.currentTurn = playerIds.find((id) => id != 1) || playerIds[0];
|
||||
|
||||
this.startTime = Date.now();
|
||||
this.status = "playing";
|
||||
this.status = 'playing';
|
||||
}
|
||||
|
||||
startTurnTimer(callback) {
|
||||
@@ -74,7 +74,9 @@ class BiscaGame {
|
||||
}
|
||||
|
||||
handleTimeout() {
|
||||
console.log(`[Game ${this.id}] Timeout! Auto-playing for ${this.currentTurn}`);
|
||||
console.log(
|
||||
`[Game ${this.id}] Timeout! Auto-playing for ${this.currentTurn}`,
|
||||
);
|
||||
|
||||
const lowestCard = this.getLowestCard(this.currentTurn);
|
||||
|
||||
@@ -92,7 +94,7 @@ class BiscaGame {
|
||||
}
|
||||
|
||||
createDeck() {
|
||||
const suits = ["c", "e", "o", "p"];
|
||||
const suits = ['c', 'e', 'o', 'p'];
|
||||
const ranks = [1, 2, 3, 4, 5, 6, 7, 11, 12, 13];
|
||||
let deck = [];
|
||||
|
||||
@@ -128,7 +130,7 @@ class BiscaGame {
|
||||
}
|
||||
|
||||
playCard(userId, cardId) {
|
||||
if (this.currentTurn != userId) return { error: "Not your turn!" };
|
||||
if (this.currentTurn != userId) return { error: 'Not your turn!' };
|
||||
|
||||
const player = this.players[userId];
|
||||
const cardIndex = player.hand.findIndex((c) => c.id === cardId);
|
||||
@@ -142,7 +144,7 @@ class BiscaGame {
|
||||
const suitToFollow = this.table.playerCard.suit;
|
||||
const hasSuit = player.hand.some((c) => c.suit === suitToFollow);
|
||||
if (hasSuit && card.suit !== suitToFollow) {
|
||||
return { error: "You must follow the suit!" };
|
||||
return { error: 'You must follow the suit!' };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@ class BiscaGame {
|
||||
this.table.playerCard = card;
|
||||
this.table.firstPlayerId = userId;
|
||||
this.currentTurn = this.getOpponentId(userId);
|
||||
return { action: "next_turn" };
|
||||
return { action: 'next_turn' };
|
||||
} else {
|
||||
this.table.opponentCard = card;
|
||||
return this.resolveTrick();
|
||||
@@ -194,7 +196,7 @@ class BiscaGame {
|
||||
this.table = { playerCard: null, opponentCard: null, firstPlayerId: null };
|
||||
|
||||
if (this.players[winnerId].hand.length === 0) {
|
||||
this.status = "finished";
|
||||
this.status = 'finished';
|
||||
this.stopTimer();
|
||||
|
||||
const pIds = Object.keys(this.players);
|
||||
@@ -218,7 +220,7 @@ class BiscaGame {
|
||||
: p1Obj.id;
|
||||
|
||||
return {
|
||||
action: "game_ended",
|
||||
action: 'game_ended',
|
||||
trickResult,
|
||||
winnerId: finalWinner,
|
||||
loserId: finalLoser,
|
||||
@@ -231,7 +233,7 @@ class BiscaGame {
|
||||
};
|
||||
}
|
||||
|
||||
return { action: "trick_resolved", trickResult };
|
||||
return { action: 'trick_resolved', trickResult };
|
||||
}
|
||||
|
||||
getStateForPlayer(userId) {
|
||||
@@ -277,4 +279,4 @@ class BiscaGame {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BiscaGame;
|
||||
export default BiscaGame;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { addUser, removeUser } from "../state/connection.js";
|
||||
|
||||
|
||||
const HEARTBEAT_INTERVAL = 30000; // 30 seconds
|
||||
const HEARTBEAT_TIMEOUT = 10000; // 10 seconds
|
||||
|
||||
@@ -8,36 +9,36 @@ export const handleConnectionEvents = (io, socket) => {
|
||||
let heartbeatTimeout;
|
||||
const startHeartbeat = () => {
|
||||
heartbeatInterval = setInterval(() => {
|
||||
socket.emit("heartbeat");
|
||||
socket.emit('heartbeat');
|
||||
|
||||
heartbeatTimeout = setTimeout(() => {
|
||||
console.log(
|
||||
`[Heartbeat] No response from ${socket.id}, disconnecting...`
|
||||
`[Heartbeat] No response from ${socket.id}, disconnecting...`,
|
||||
);
|
||||
socket.disconnect(true);
|
||||
}, HEARTBEAT_TIMEOUT);
|
||||
}, HEARTBEAT_INTERVAL);
|
||||
};
|
||||
|
||||
socket.on("heartbeat_ack", () => {
|
||||
socket.on('heartbeat_ack', () => {
|
||||
clearTimeout(heartbeatTimeout);
|
||||
console.log(`[Heartbeat] Received pong from ${socket.id}`);
|
||||
});
|
||||
|
||||
socket.on("join", (user) => {
|
||||
socket.on('join', (user) => {
|
||||
addUser(socket, user);
|
||||
console.log(`[Connection] User ${user.name} has joined the server`);
|
||||
});
|
||||
|
||||
socket.on("leave", () => {
|
||||
socket.on('leave', () => {
|
||||
const user = removeUser(socket.id);
|
||||
if (user) {
|
||||
console.log(`[Connection] User ${user.name} has left the server`);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log("Connection Lost:", socket.id);
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Connection Lost:', socket.id);
|
||||
removeUser(socket.id);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "websockets",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "nodemon index.js",
|
||||
"start": "bun index.js "
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const BiscaGame = require("../classes/BiscaGame");
|
||||
import BiscaGame from '../classes/BiscaGame.js';
|
||||
|
||||
const activeGames = new Map();
|
||||
|
||||
@@ -38,3 +38,4 @@ module.exports = {
|
||||
getGame,
|
||||
removeGame,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user