Compare commits
32
Commits
4ce510402c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64d771e34c | ||
|
|
2ab1acf040 | ||
|
|
3d6a5362e6 | ||
|
|
dc94c2252c | ||
|
|
1be49133a0 | ||
|
|
b2a7e2557e | ||
|
|
ccb3598da0 | ||
|
|
371b75193a | ||
|
|
57be9168e5 | ||
|
|
800cb7a819 | ||
|
|
89a48fae16 | ||
|
|
806d17842f | ||
|
|
d0b173fe76 | ||
|
|
8d95e4ee53 | ||
|
|
ae925c7173 | ||
|
|
e7481eac95 | ||
|
|
0c6bab4a04 | ||
|
|
a35b50bec6 | ||
|
|
1e33bfb50b | ||
|
|
d751cd4fdd | ||
|
|
807a260cf6 | ||
|
|
a7159c4527 | ||
|
|
cca5952470 | ||
|
|
5aced64669 | ||
|
|
af1eabfa01 | ||
|
|
682da3dea8 | ||
|
|
d68fc33bcb | ||
|
|
9c270973ed | ||
|
|
de88658a48 | ||
|
|
0f8edfb827 | ||
|
|
188c4435cb | ||
|
|
c60033b365 |
@@ -29,3 +29,7 @@ yarn-error.log
|
|||||||
/.zed
|
/.zed
|
||||||
/public/sw.js
|
/public/sw.js
|
||||||
/public/workbox-*.js
|
/public/workbox-*.js
|
||||||
|
/tests/Browser/console
|
||||||
|
/tests/Browser/screenshots
|
||||||
|
/tests/Browser/source
|
||||||
|
/storage/debugbar/
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ This application is a Laravel application and its main Laravel ecosystems packag
|
|||||||
- tightenco/ziggy (ZIGGY) - v2
|
- tightenco/ziggy (ZIGGY) - v2
|
||||||
- larastan/larastan (LARASTAN) - v3
|
- larastan/larastan (LARASTAN) - v3
|
||||||
- laravel/boost (BOOST) - v2
|
- laravel/boost (BOOST) - v2
|
||||||
|
- laravel/dusk (DUSK) - v8
|
||||||
- laravel/mcp (MCP) - v0
|
- laravel/mcp (MCP) - v0
|
||||||
- laravel/pail (PAIL) - v1
|
- laravel/pail (PAIL) - v1
|
||||||
- laravel/pint (PINT) - v1
|
- laravel/pint (PINT) - v1
|
||||||
|
|||||||
@@ -59,6 +59,27 @@ We created `app/Services/ActivityService.php` to centralize the creation of syst
|
|||||||
* **Polymorphic Subject Linking**: System messages are linked to relevant entities (e.g., a `User` who joined a dynamic, a `Ledger` that was created) via a polymorphic `subject` relationship on the `messages` table. This allows system messages on the dashboard to link directly to the relevant entity.
|
* **Polymorphic Subject Linking**: System messages are linked to relevant entities (e.g., a `User` who joined a dynamic, a `Ledger` that was created) via a polymorphic `subject` relationship on the `messages` table. This allows system messages on the dashboard to link directly to the relevant entity.
|
||||||
* **Seeder Refactoring**: The `DatabaseSeeder` was refactored to use the `ActivityService` to generate all system messages, ensuring consistency.
|
* **Seeder Refactoring**: The `DatabaseSeeder` was refactored to use the `ActivityService` to generate all system messages, ensuring consistency.
|
||||||
|
|
||||||
|
### 8. Event-Driven Automated System Logging
|
||||||
|
We relocated the dynamic system activity message generation out of individual controller endpoints and into the **Eloquent `Mutation` Model's `booted` -> `created` event hook**.
|
||||||
|
* **Unified generation:** Any mutation creation (whether occurring via a controller submission, an automated Pest test factory, or seeders during `php artisan db:seed`) now automatically and reliably generates correct system log messages.
|
||||||
|
* **Database Seeder fixed:** Reverted the database seeder (`DatabaseSeeder.php`) back to using standard clean Eloquent creations. Since model events automatically trigger, `php artisan db:seed` executes cleanly and builds a rich, fully populated database history with system messages out-of-the-box.
|
||||||
|
|
||||||
|
### 9. Standardized Policy-Driven UI Capabilities (`can` prop)
|
||||||
|
To maintain strict data security and clean up front-end markup, we eliminated unstandardized, hardcoded client-side role checks (like `isOwner` properties or manual `pivot.role === 'owner'` checks) and replaced them completely with dynamic **policy-driven capabilities** returned directly from Laravel policies as `can` objects.
|
||||||
|
* **Centralized checks:** Both the dynamic and ledger show routes return a standard `can` prop to the frontend (e.g., `can: { update: boolean, close: boolean }`).
|
||||||
|
* **Polymorphic Resource Capabilities:** Each mutation model is wrapped in `MutationResource` which appends its own localized policy checks (`update` for approving suggestions, `void` for voiding) at the individual record level.
|
||||||
|
* **State-based policies:** The `MutationPolicy` methods enforce both ownership authorization and state-based business constraints simultaneously (e.g., a mutation can be approved/updated *only* if its status is currently `'pending'`; and can be voided *only* if its status is not `'voided'`). This keeps the Vue templates purely declarative (e.g., `v-if="mutation.can.update"`) and automatically protects the backend controllers against illegal state transitions.
|
||||||
|
|
||||||
|
### 10. Ledger-Scoped Predefined Mutation Templates ("Rewards")
|
||||||
|
Predefined mutations act as point-based templates ("purchases" or reusable chores) and belong strictly to specific **Ledgers** instead of broad Dynamics.
|
||||||
|
* **Domain Alignment:** Moving the resource nesting under ledgers (`dynamics.ledgers.predefined-mutations`) aligns perfectly with the mental model of spending points on a ledger.
|
||||||
|
* **Type-Less Rewards:** To simplify both the database schema and UI/UX, we eliminated the explicit `type` column ('reward' vs. 'penalty') from predefined mutations. They act as generic point-carrying "Rewards" whose amount can naturellement be positive (earning points) or negative (making a purchase / deducting points) without requiring restrictive explicit categorization.
|
||||||
|
|
||||||
|
### 11. Silent XHR Chat Pagination & Smooth Scrolling UX
|
||||||
|
To optimize chat-feed performance and improve overall user experience:
|
||||||
|
* **Silent pagination (No URL pollution):** Rather than using Inertia `router.get` visits which push `?page=x` into the browser URL and break history during page reloads, we implemented a **silent background fetch** (using native browser `fetch()`) that queries our dedicated messages JSON API endpoints and prepends older messages silently to the feed.
|
||||||
|
* **Scroll Preservation:** Added `preserveScroll: true` to the Inertia `form.post` call in `Chat.vue` to prevent the active page scroll position from jumping or shifting when a new message is successfully submitted.
|
||||||
|
|
||||||
## Initial Database Schema
|
## Initial Database Schema
|
||||||
|
|
||||||
I will start with a basic schema and evolve it as I build features.
|
I will start with a basic schema and evolve it as I build features.
|
||||||
|
|||||||
@@ -14,4 +14,28 @@ Welcome to the Ledgerrz codebase! This file defines the persistent guidelines, a
|
|||||||
* **PHP/Laravel:** PHP 8.4 & Laravel 13. Adhere to typed parameters and return values. Ensure controllers extend properly and use required authorization traits (e.g., `AuthorizesRequests`).
|
* **PHP/Laravel:** PHP 8.4 & Laravel 13. Adhere to typed parameters and return values. Ensure controllers extend properly and use required authorization traits (e.g., `AuthorizesRequests`).
|
||||||
* **Frontend Styling (BEM):** Replaced direct Tailwind inline utility-class markup with **BEM (Block, Element, Modifier)**. All custom component styles must live inside `<style scoped>` blocks with a relative `@reference "../../css/app.css"` directive to pull variables without duplications.
|
* **Frontend Styling (BEM):** Replaced direct Tailwind inline utility-class markup with **BEM (Block, Element, Modifier)**. All custom component styles must live inside `<style scoped>` blocks with a relative `@reference "../../css/app.css"` directive to pull variables without duplications.
|
||||||
* **Real-time Broadcasting:** Powered by `@laravel/echo-vue` with fallback configurations and Vite deduplication rules configured in `vite.config.ts`.
|
* **Real-time Broadcasting:** Powered by `@laravel/echo-vue` with fallback configurations and Vite deduplication rules configured in `vite.config.ts`.
|
||||||
* **Testing:** Powered by Pest PHP (v4). Every backend controller, event, or model change must be validated by running `vendor/bin/pest`.
|
* **Testing & Isolation:** Powered by Pest PHP (v4). Every backend controller, event, or model change must be validated by running tests. To prevent local `.env` variables from polluting the CLI test execution (causing CSRF/session 419 errors), **always** run tests in an isolated environment using:
|
||||||
|
```bash
|
||||||
|
env -i PATH="$PATH" php artisan test
|
||||||
|
```
|
||||||
|
* **Standardized Authorization (`can` prop):** Never write manual role checks (such as `pivot.role === 'owner'`) or hardcoded boolean flags (such as `isOwner`) inside Vue pages or components. Instead, always leverage Laravel policies on the backend and pass permissions reactively to the frontend as structured `can` objects (e.g., `can: { update: boolean, close: boolean }`).
|
||||||
|
* **Vue-Defined Breadcrumbs Layout:** All page-specific breadcrumbs should be declared locally inside the page's `.vue` file rather than returned from controllers. For dynamic, prop-dependent paths, always use the Inertia v3 layout callback function inside `defineOptions`:
|
||||||
|
```typescript
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{ title: 'Dynamics', href: route('dynamics.index') },
|
||||||
|
{ title: props.dynamic.name, href: route('dynamics.show', props.dynamic.id) }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Advanced Browser Testing & Architectural Guidelines (Laravel Dusk)
|
||||||
|
* **Dusk Database Locks on SQLite:** Never use the `DatabaseTransactions` trait in Laravel Dusk tests if the project is backed by a SQLite database file. Since Dusk runs in concurrent, separate processes (the CLI runner and the web server), an active uncommitted database transaction in the CLI will hold a SQLite write lock. This causes the web server to fail with `SQLSTATE[HY000]: General error: 5 database is locked`. Instead, dynamically create and clean up models during test execution or use sequential DB seeds.
|
||||||
|
* **Inertia/Vue SPA Testing:** Browser tests targeting asynchronously rendered Single Page Applications must **always** use explicit `waitForText()` or `waitFor()` selectors before executing assertions. Direct assertions like `assertSee()` are immediate and will fail if the JavaScript has not finished compiling and mounting the DOM.
|
||||||
|
* **Synchronous Queue for WebSockets:** Running real-time WebSocket / Echo Dusk tests locally requires setting `QUEUE_CONNECTION=sync` and `BROADCAST_CONNECTION=reverb` in your `.env` file. This ensures broadcast jobs execute immediately on the web server rather than buffering in the database (which fails without a running background queue worker).
|
||||||
|
* **Automatic ID-to-UUID Serialization:** All models carrying a `uuid` column (such as `User`, `Dynamic`, `Ledger`, `Mutation`, and `PredefinedMutation`) must use the `App\Concerns\SerializesIdToUuid` trait. This guarantees that any raw model or relationship array/JSON conversion automatically replaces the integer `id` with the secure `uuid` under the `'id'` key.
|
||||||
|
* **UUID Controller Inputs:** When the frontend submits relationship parameters (such as `predefined_mutation_id` in requests), it only knows and passes the secure UUID. The receiving backend controller must explicitly resolve this UUID to its internal database integer ID before inserting the record (e.g. `PredefinedMutation::where('uuid', $uuid)->value('id')`), maintaining column type safety and foreign key constraints without exposing integer IDs to the client.
|
||||||
|
|||||||
@@ -41,3 +41,27 @@ During this session, we successfully built out and verified several core archite
|
|||||||
* Configured real-time notifications utilizing Laravel Reverb.
|
* Configured real-time notifications utilizing Laravel Reverb.
|
||||||
* Documented CLI environment test pollution learnings inside `AGENTS.md` to prevent future CSRF `419` errors.
|
* Documented CLI environment test pollution learnings inside `AGENTS.md` to prevent future CSRF `419` errors.
|
||||||
* Ensured full production assets compilation (`npm run build`) and achieved **45/45 passing Pest PHP tests with 206 assertions**.
|
* Ensured full production assets compilation (`npm run build`) and achieved **45/45 passing Pest PHP tests with 206 assertions**.
|
||||||
|
|
||||||
|
6. **Ledger-Scoped Predefined Mutation Templates ("Rewards")**:
|
||||||
|
* Associated reusable point-based predefined mutation templates under specific Ledgers rather than broad Dynamics, mapping perfectly to the mental model of spending points on a ledger.
|
||||||
|
* Designed them purely as "Rewards" with positive or negative point amounts (handling both demerit-purchases and chores), removing the obsolete `type` categorization for a simpler, type-less, and sleeker UI/UX.
|
||||||
|
|
||||||
|
7. **User Activity Profiling & Detail Pages**:
|
||||||
|
* Created a dynamic user detail page (`dynamics.users.show`) scoped to each dynamic. It displays a participant's role, custom display name, fallback real name, and a clean chronological listing of their 10 most recent mutations (activities) in that dynamic.
|
||||||
|
|
||||||
|
8. **Polymorphic System Message placeholders & Dynamic Client-Side Linking**:
|
||||||
|
* Refactored system log activity messages to use native `<user:userUuid>` placeholders and associated them with polymorphic `subject_id` and `subject_type` objects.
|
||||||
|
* On the client-side, the chat component parses these placeholders into rich, clickable links to User Profiles, and dynamically matches and wraps referenced ledger names into links pointing directly to the ledger show page.
|
||||||
|
* Added backend-side placeholder resolution inside `ActivityService` for the dashboard, ensuring unread system logs translate cleanly to real names across multiple dynamics.
|
||||||
|
|
||||||
|
9. **Vite/Inertia v3 Layout Callback Breadcrumbs**:
|
||||||
|
* Utilized Inertia v3's powerful new layout callback API inside Vue page `defineOptions` to reactively resolve page-specific dynamic breadcrumbs at runtime using parsed page props, making the pages self-contained and keeping PHP controllers beautifully slim.
|
||||||
|
|
||||||
|
10. **Silent background Chat Pagination & Smooth Scrolling UX**:
|
||||||
|
* Implemented silent background XHR queries (using native browser `fetch()`) on our dedicated message JSON API routes to load older chat pages, completely bypassing browser history/URL pollution and preserving page state on refreshes.
|
||||||
|
* Integrated `preserveScroll: true` inside chat form submissions to completely prevent scroll jumps when sending messages.
|
||||||
|
|
||||||
|
11. **Standardized Policy-Driven UI Capabilities**:
|
||||||
|
* Eliminated unstandardized client-side role checks and boolean flags, replacing them with structured `can` capability objects returned directly from Laravel policies.
|
||||||
|
* Combined permission validation with state-based business constraints in `MutationPolicy` (e.g., suggestions can be approved/rejected only if `'pending'`; and voided only if not `'voided'`), securing both the frontend action buttons and backend controllers simultaneously.
|
||||||
|
* Achieved **65/65 passing Pest PHP tests with 333 assertions**.
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Concerns;
|
||||||
|
|
||||||
|
trait SerializesIdToUuid
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Convert the model's attributes to an array.
|
||||||
|
* Overrides the default model toArray method to replace 'id' with 'uuid'.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
$array = parent::toArray();
|
||||||
|
|
||||||
|
if (isset($this->uuid)) {
|
||||||
|
$array['id'] = $this->uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ class DashboardController extends Controller
|
|||||||
public function index(Request $request, ActivityService $activityService)
|
public function index(Request $request, ActivityService $activityService)
|
||||||
{
|
{
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$unreadDynamics = $activityService->getUnreadDynamicsGrouped($user);
|
$unreadDynamics = $activityService->getUnreadEntitiesGrouped($user);
|
||||||
|
|
||||||
return Inertia::render('Dashboard', [
|
return Inertia::render('Dashboard', [
|
||||||
'unreadDynamics' => $unreadDynamics,
|
'unreadDynamics' => $unreadDynamics,
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\UpdateDynamicRequest;
|
use App\Http\Requests\UpdateDynamicRequest;
|
||||||
use App\Http\Resources\DynamicResource;
|
|
||||||
use App\Http\Resources\LedgerResource;
|
|
||||||
use App\Http\Resources\MessageResource;
|
|
||||||
use App\Http\Resources\UserResource;
|
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Services\ActivityService;
|
use App\Services\ActivityService;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
@@ -23,7 +19,7 @@ class DynamicController extends Controller
|
|||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
return Inertia::render('Dynamics/Index', [
|
return Inertia::render('Dynamics/Index', [
|
||||||
'dynamics' => DynamicResource::collection($request->user()->dynamics()->get()),
|
'dynamics' => $request->user()->dynamics()->get(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,10 +55,10 @@ class DynamicController extends Controller
|
|||||||
$dynamic->load(['ledgers.media', 'participants', 'chat']);
|
$dynamic->load(['ledgers.media', 'participants', 'chat']);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/Show', [
|
return Inertia::render('Dynamics/Show', [
|
||||||
'dynamic' => new DynamicResource($dynamic),
|
'dynamic' => $dynamic,
|
||||||
'ledgers' => LedgerResource::collection($dynamic->ledgers),
|
'ledgers' => $dynamic->ledgers,
|
||||||
'participants' => UserResource::collection($dynamic->participants),
|
'participants' => $dynamic->participants,
|
||||||
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(10)),
|
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
||||||
'can' => [
|
'can' => [
|
||||||
'update' => $request->user()->can('update', $dynamic),
|
'update' => $request->user()->can('update', $dynamic),
|
||||||
],
|
],
|
||||||
@@ -73,7 +69,7 @@ class DynamicController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('view', $dynamic);
|
$this->authorize('view', $dynamic);
|
||||||
|
|
||||||
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(10));
|
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +80,7 @@ class DynamicController extends Controller
|
|||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/Settings', [
|
return Inertia::render('Dynamics/Settings', [
|
||||||
'dynamic' => new DynamicResource($dynamic),
|
'dynamic' => $dynamic,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class DynamicInvitationController extends Controller
|
|||||||
// Log to Dynamic chat activity log!
|
// Log to Dynamic chat activity log!
|
||||||
$dynamic->chat->messages()->create([
|
$dynamic->chat->messages()->create([
|
||||||
'user_id' => null,
|
'user_id' => null,
|
||||||
'content' => "<user:{$request->user()->id}> joined the Dynamic as a ".strtoupper($invitation->role),
|
'content' => "<user:{$request->user()->uuid}> joined the Dynamic as a ".strtoupper($invitation->role),
|
||||||
'subject_id' => $request->user()->id,
|
'subject_id' => $request->user()->id,
|
||||||
'subject_type' => User::class,
|
'subject_type' => User::class,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -3,11 +3,6 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\StoreLedgerRequest;
|
use App\Http\Requests\StoreLedgerRequest;
|
||||||
use App\Http\Resources\DynamicResource;
|
|
||||||
use App\Http\Resources\LedgerResource;
|
|
||||||
use App\Http\Resources\MessageResource;
|
|
||||||
use App\Http\Resources\MutationResource;
|
|
||||||
use App\Http\Resources\UserResource;
|
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\Ledger;
|
use App\Models\Ledger;
|
||||||
use App\Services\ActivityService;
|
use App\Services\ActivityService;
|
||||||
@@ -35,7 +30,7 @@ class LedgerController extends Controller
|
|||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Create', [
|
return Inertia::render('Ledgers/Create', [
|
||||||
'dynamic' => new DynamicResource($dynamic),
|
'dynamic' => $dynamic,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +69,7 @@ class LedgerController extends Controller
|
|||||||
|
|
||||||
$ledger->load([
|
$ledger->load([
|
||||||
'media',
|
'media',
|
||||||
|
'predefinedMutations',
|
||||||
'mutations' => function ($query) {
|
'mutations' => function ($query) {
|
||||||
$query->latest();
|
$query->latest();
|
||||||
},
|
},
|
||||||
@@ -83,11 +79,9 @@ class LedgerController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Show', [
|
return Inertia::render('Ledgers/Show', [
|
||||||
'dynamic' => new DynamicResource($dynamic),
|
'dynamic' => $dynamic,
|
||||||
'ledger' => new LedgerResource($ledger),
|
'ledger' => $ledger,
|
||||||
'mutations' => MutationResource::collection($ledger->mutations),
|
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
||||||
'participants' => UserResource::collection($dynamic->participants),
|
|
||||||
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(10)),
|
|
||||||
'can' => [
|
'can' => [
|
||||||
'update' => $request->user()->can('update', $ledger),
|
'update' => $request->user()->can('update', $ledger),
|
||||||
'close' => $request->user()->can('close', $ledger),
|
'close' => $request->user()->can('close', $ledger),
|
||||||
@@ -99,7 +93,7 @@ class LedgerController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('view', $ledger);
|
$this->authorize('view', $ledger);
|
||||||
|
|
||||||
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(10));
|
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,8 +104,8 @@ class LedgerController extends Controller
|
|||||||
$this->authorize('update', $ledger);
|
$this->authorize('update', $ledger);
|
||||||
|
|
||||||
return Inertia::render('Ledgers/Edit', [
|
return Inertia::render('Ledgers/Edit', [
|
||||||
'dynamic' => new DynamicResource($dynamic),
|
'dynamic' => $dynamic,
|
||||||
'ledger' => new LedgerResource($ledger),
|
'ledger' => $ledger,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,47 +6,34 @@ use App\Events\MessageSent;
|
|||||||
use App\Events\MutationCreated;
|
use App\Events\MutationCreated;
|
||||||
use App\Events\MutationUpdated;
|
use App\Events\MutationUpdated;
|
||||||
use App\Http\Requests\StoreMutationRequest;
|
use App\Http\Requests\StoreMutationRequest;
|
||||||
use App\Http\Resources\MutationResource;
|
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\Ledger;
|
use App\Models\Ledger;
|
||||||
use App\Models\Mutation;
|
use App\Models\Mutation;
|
||||||
|
use App\Notifications\NewActivityNotification;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
class MutationController extends Controller
|
class MutationController extends Controller
|
||||||
{
|
{
|
||||||
use AuthorizesRequests;
|
use AuthorizesRequests;
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*/
|
|
||||||
public function store(StoreMutationRequest $request, Dynamic $dynamic, Ledger $ledger)
|
public function store(StoreMutationRequest $request, Dynamic $dynamic, Ledger $ledger)
|
||||||
{
|
{
|
||||||
$this->authorize('create', [Mutation::class, $ledger]);
|
$this->authorize('create', [Mutation::class, $ledger]);
|
||||||
|
|
||||||
// If the user is an owner, default status to 'approved'. Otherwise default to 'pending'.
|
|
||||||
$status = $request->user()->can('update', $ledger) ? 'approved' : 'pending';
|
$status = $request->user()->can('update', $ledger) ? 'approved' : 'pending';
|
||||||
|
|
||||||
$mutation = DB::transaction(function () use ($request, $ledger, $status) {
|
$mutation = DB::transaction(function () use ($request, $ledger, $status) {
|
||||||
|
$predefinedId = null;
|
||||||
|
if ($request->filled('predefined_mutation_id')) {
|
||||||
|
$predefinedId = \App\Models\PredefinedMutation::where('uuid', $request->input('predefined_mutation_id'))->value('id');
|
||||||
|
}
|
||||||
|
|
||||||
$mutation = $ledger->mutations()->create([
|
$mutation = $ledger->mutations()->create([
|
||||||
...$request->except(['media', 'type', 'status']),
|
...$request->except(['media', 'type', 'status', 'predefined_mutation_id']),
|
||||||
|
'predefined_mutation_id' => $predefinedId,
|
||||||
'user_id' => $request->user()->id,
|
'user_id' => $request->user()->id,
|
||||||
'type' => $request->input('type', $request->input('amount') >= 0 ? 'addition' : 'subtraction'),
|
'type' => $request->input('type', $request->input('amount') >= 0 ? 'addition' : 'subtraction'),
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
@@ -63,7 +50,6 @@ class MutationController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only increment score if the status is approved!
|
|
||||||
if ($status === 'approved') {
|
if ($status === 'approved') {
|
||||||
$ledger->increment('score', $request->validated('amount'));
|
$ledger->increment('score', $request->validated('amount'));
|
||||||
}
|
}
|
||||||
@@ -71,40 +57,46 @@ class MutationController extends Controller
|
|||||||
return $mutation;
|
return $mutation;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Broadcast the real-time creation event!
|
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
|
||||||
broadcast(new MutationCreated($mutation));
|
$message = $status === 'approved'
|
||||||
|
? "{$request->user()->name} added a new entry: \"{$mutation->description}\"."
|
||||||
|
: "{$request->user()->name} suggested a new entry: \"{$mutation->description}\".";
|
||||||
|
|
||||||
|
if ($recipients->isNotEmpty()) {
|
||||||
|
Notification::send($recipients, new NewActivityNotification([
|
||||||
|
'content' => $message,
|
||||||
|
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function show(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
||||||
* Display the specified resource.
|
|
||||||
*/
|
|
||||||
public function show(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
|
||||||
{
|
{
|
||||||
$this->authorize('view', $mutation);
|
$this->authorize('view', $mutation);
|
||||||
|
|
||||||
return new MutationResource($mutation);
|
$mutation->load('user', 'ledger', 'media', 'chat.messages.user');
|
||||||
|
$dynamic = $mutation->ledger->dynamic;
|
||||||
|
|
||||||
|
$dynamic->load('participants');
|
||||||
|
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
return inertia('Mutations/Show', [
|
||||||
|
'mutation' => $mutation,
|
||||||
|
'dynamic' => $dynamic,
|
||||||
|
'can' => [
|
||||||
|
'update' => $user->can('update', $dynamic),
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for editing the specified resource.
|
|
||||||
*/
|
|
||||||
public function edit(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
|
||||||
*/
|
|
||||||
public function update(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
public function update(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $mutation);
|
$this->authorize('update', $mutation);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate(['status' => ['required', 'string', 'in:approved,rejected']]);
|
||||||
'status' => ['required', 'string', 'in:approved,rejected'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$oldStatus = $mutation->status;
|
$oldStatus = $mutation->status;
|
||||||
$newStatus = $request->input('status');
|
$newStatus = $request->input('status');
|
||||||
@@ -112,7 +104,6 @@ class MutationController extends Controller
|
|||||||
DB::transaction(function () use ($mutation, $ledger, $oldStatus, $newStatus) {
|
DB::transaction(function () use ($mutation, $ledger, $oldStatus, $newStatus) {
|
||||||
$mutation->update(['status' => $newStatus]);
|
$mutation->update(['status' => $newStatus]);
|
||||||
|
|
||||||
// Adjust the ledger score if status transitions to approved or from approved!
|
|
||||||
if ($oldStatus !== 'approved' && $newStatus === 'approved') {
|
if ($oldStatus !== 'approved' && $newStatus === 'approved') {
|
||||||
$ledger->increment('score', $mutation->amount);
|
$ledger->increment('score', $mutation->amount);
|
||||||
} elseif ($oldStatus === 'approved' && $newStatus !== 'approved') {
|
} elseif ($oldStatus === 'approved' && $newStatus !== 'approved') {
|
||||||
@@ -120,37 +111,17 @@ class MutationController extends Controller
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log to Mutation and Dynamic chats
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
$statusText = strtoupper($newStatus);
|
$statusText = strtoupper($newStatus);
|
||||||
|
|
||||||
$mutationMsg = $mutation->chat->messages()->create([
|
// Notify the suggester
|
||||||
'user_id' => null,
|
$suggester = $mutation->user;
|
||||||
'content' => "Suggestion was {$statusText} by <user:{$user->id}>.",
|
if ($suggester && $suggester->id !== $user->id) {
|
||||||
'subject_id' => $mutation->id,
|
Notification::send($suggester, new NewActivityNotification([
|
||||||
'subject_type' => Mutation::class,
|
'content' => "Your suggestion \"{$mutation->description}\" was {$statusText} by {$user->name}.",
|
||||||
]);
|
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
|
||||||
broadcast(new MessageSent($mutationMsg));
|
]));
|
||||||
|
|
||||||
if ($newStatus === 'approved') {
|
|
||||||
$dynamicMsg = $dynamic->chat->messages()->create([
|
|
||||||
'user_id' => null,
|
|
||||||
'content' => "<user:{$user->id}> APPROVED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
|
||||||
'subject_id' => $mutation->id,
|
|
||||||
'subject_type' => Mutation::class,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$dynamicMsg = $dynamic->chat->messages()->create([
|
|
||||||
'user_id' => null,
|
|
||||||
'content' => "<user:{$user->id}> REJECTED the suggestion \"{$mutation->description}\" on \"{$ledger->name}\" ledger.",
|
|
||||||
'subject_id' => $mutation->id,
|
|
||||||
'subject_type' => Mutation::class,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
broadcast(new MessageSent($dynamicMsg));
|
|
||||||
|
|
||||||
// Broadcast the real-time update event!
|
|
||||||
broadcast(new MutationUpdated($mutation));
|
|
||||||
|
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
@@ -159,16 +130,21 @@ class MutationController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('void', $mutation);
|
$this->authorize('void', $mutation);
|
||||||
|
|
||||||
|
DB::transaction(function() use ($mutation, $ledger) {
|
||||||
|
if ($mutation->status === 'approved') {
|
||||||
|
$ledger->decrement('score', $mutation->amount);
|
||||||
|
}
|
||||||
$mutation->update(['status' => 'voided']);
|
$mutation->update(['status' => 'voided']);
|
||||||
|
});
|
||||||
|
|
||||||
|
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
|
||||||
|
if ($recipients->isNotEmpty()) {
|
||||||
|
Notification::send($recipients, new NewActivityNotification([
|
||||||
|
'content' => "{$request->user()->name} voided an entry: \"{$mutation->description}\".",
|
||||||
|
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the specified resource from storage.
|
|
||||||
*/
|
|
||||||
public function destroy(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class ParticipantController extends Controller
|
|||||||
return Inertia::render('Dynamics/Participants/Show', [
|
return Inertia::render('Dynamics/Participants/Show', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => $dynamic,
|
||||||
'participant' => [
|
'participant' => [
|
||||||
'id' => $user->id,
|
'id' => $user->uuid,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'display_name' => $participant->pivot->display_name,
|
'display_name' => $participant->pivot->display_name,
|
||||||
'role' => $participant->pivot->role,
|
'role' => $participant->pivot->role,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
|
use App\Models\Ledger;
|
||||||
use App\Models\PredefinedMutation;
|
use App\Models\PredefinedMutation;
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -15,44 +16,45 @@ class PredefinedMutationController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*/
|
*/
|
||||||
public function index(Dynamic $dynamic)
|
public function index(Dynamic $dynamic, Ledger $ledger)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/PredefinedMutations/Index', [
|
return Inertia::render('Ledgers/PredefinedMutations/Index', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => $dynamic,
|
||||||
'predefined_mutations' => $dynamic->predefinedMutations()->latest()->get(),
|
'ledger' => $ledger,
|
||||||
|
'predefined_mutations' => $ledger->predefinedMutations()->latest()->get(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*/
|
*/
|
||||||
public function store(Request $request, Dynamic $dynamic)
|
public function store(Request $request, Dynamic $dynamic, Ledger $ledger)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'amount' => ['required', 'integer'],
|
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
||||||
'type' => ['required', 'string', 'in:reward,penalty'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$dynamic->predefinedMutations()->create($request->all());
|
$ledger->predefinedMutations()->create($request->all());
|
||||||
|
|
||||||
return redirect()->route('dynamics.predefined-mutations.index', $dynamic);
|
return redirect()->route('dynamics.ledgers.predefined-mutations.index', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*/
|
*/
|
||||||
public function edit(Dynamic $dynamic, PredefinedMutation $predefinedMutation)
|
public function edit(Dynamic $dynamic, Ledger $ledger, PredefinedMutation $predefinedMutation)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
return Inertia::render('Dynamics/PredefinedMutations/Edit', [
|
return Inertia::render('Ledgers/PredefinedMutations/Edit', [
|
||||||
'dynamic' => $dynamic,
|
'dynamic' => $dynamic,
|
||||||
|
'ledger' => $ledger,
|
||||||
'predefined_mutation' => $predefinedMutation,
|
'predefined_mutation' => $predefinedMutation,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -60,31 +62,30 @@ class PredefinedMutationController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, Dynamic $dynamic, PredefinedMutation $predefinedMutation)
|
public function update(Request $request, Dynamic $dynamic, Ledger $ledger, PredefinedMutation $predefinedMutation)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'amount' => ['required', 'integer'],
|
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
||||||
'type' => ['required', 'string', 'in:reward,penalty'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$predefinedMutation->update($request->all());
|
$predefinedMutation->update($request->all());
|
||||||
|
|
||||||
return redirect()->route('dynamics.predefined-mutations.index', $dynamic);
|
return redirect()->route('dynamics.ledgers.predefined-mutations.index', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*/
|
*/
|
||||||
public function destroy(Dynamic $dynamic, PredefinedMutation $predefinedMutation)
|
public function destroy(Dynamic $dynamic, Ledger $ledger, PredefinedMutation $predefinedMutation)
|
||||||
{
|
{
|
||||||
$this->authorize('update', $dynamic);
|
$this->authorize('update', $dynamic);
|
||||||
|
|
||||||
$predefinedMutation->delete();
|
$predefinedMutation->delete();
|
||||||
|
|
||||||
return redirect()->route('dynamics.predefined-mutations.index', $dynamic);
|
return redirect()->route('dynamics.ledgers.predefined-mutations.index', [$dynamic, $ledger]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class HandleInertiaRequests extends Middleware
|
|||||||
|
|
||||||
$service = app(ActivityService::class);
|
$service = app(ActivityService::class);
|
||||||
|
|
||||||
return count($service->getUnreadDynamicsGrouped($request->user()));
|
return count($service->getUnreadEntitiesGrouped($request->user()));
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ class StoreMutationRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'amount' => ['required', 'integer'],
|
'amount' => ['required', 'integer', 'not_in:0', 'min:-1000', 'max:1000'],
|
||||||
'description' => ['required', 'string'],
|
'description' => ['required', 'string'],
|
||||||
'type' => ['nullable', 'string'],
|
'type' => ['nullable', 'string'],
|
||||||
'status' => ['nullable', 'string'],
|
'status' => ['nullable', 'string'],
|
||||||
|
'predefined_mutation_id' => ['nullable', 'exists:predefined_mutations,uuid'],
|
||||||
'media' => ['nullable', 'array'],
|
'media' => ['nullable', 'array'],
|
||||||
'media.*' => ['file', 'mimes:jpg,jpeg,png,gif,mp4,mov,avi,webm', 'max:20480'],
|
'media.*' => ['file', 'mimes:jpg,jpeg,png,gif,mp4,mov,avi,webm', 'max:20480'],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
|
||||||
|
|
||||||
class BaseResource extends JsonResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
$data = parent::toArray($request);
|
|
||||||
|
|
||||||
if (isset($data['id']) && isset($this->uuid)) {
|
|
||||||
$data['id'] = $this->uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class DynamicResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
$result = parent::toArray($request);
|
|
||||||
if ($this->ledgers) {
|
|
||||||
$result['ledgers'] = LedgerResource::collection($this->ledgers);
|
|
||||||
}
|
|
||||||
if ($this->participants) {
|
|
||||||
$result['participants'] = ParticipantResource::collection($this->participants);
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class LedgerResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class MessageResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class MutationResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class ParticipantResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class PredefinedMutationResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Resources;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class UserResource extends BaseResource
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Transform the resource into an array.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(Request $request): array
|
|
||||||
{
|
|
||||||
return parent::toArray($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+12
-1
@@ -9,11 +9,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use App\Models\Chat;
|
||||||
|
use App\Concerns\SerializesIdToUuid;
|
||||||
|
|
||||||
class Dynamic extends Model
|
class Dynamic extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<DynamicFactory> */
|
/** @use HasFactory<DynamicFactory> */
|
||||||
use HasFactory;
|
use HasFactory, SerializesIdToUuid;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
@@ -64,4 +66,13 @@ class Dynamic extends Model
|
|||||||
public function getUrlAttribute(): string {
|
public function getUrlAttribute(): string {
|
||||||
return route('dynamics.show', $this);
|
return route('dynamics.show', $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOrCreateChat(): Chat
|
||||||
|
{
|
||||||
|
if ($this->chat) {
|
||||||
|
return $this->chat;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->chat()->create([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use App\Concerns\SerializesIdToUuid;
|
||||||
|
|
||||||
class Ledger extends Model
|
class Ledger extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<LedgerFactory> */
|
/** @use HasFactory<LedgerFactory> */
|
||||||
use HasFactory;
|
use HasFactory, SerializesIdToUuid;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'dynamic_id',
|
'dynamic_id',
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class Message extends Model
|
|||||||
/** @use HasFactory<MessageFactory> */
|
/** @use HasFactory<MessageFactory> */
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
const PAGINATION_COUNT = 6;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'chat_id',
|
'chat_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
|
|||||||
+46
-5
@@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use App\Concerns\SerializesIdToUuid;
|
||||||
|
|
||||||
class Mutation extends Model
|
class Mutation extends Model
|
||||||
{
|
{
|
||||||
/** @use HasFactory<MutationFactory> */
|
/** @use HasFactory<MutationFactory> */
|
||||||
use HasFactory;
|
use HasFactory, SerializesIdToUuid;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'ledger_id',
|
'ledger_id',
|
||||||
@@ -69,8 +70,8 @@ class Mutation extends Model
|
|||||||
$mutationMsg = $mutation->chat->messages()->create([
|
$mutationMsg = $mutation->chat->messages()->create([
|
||||||
'user_id' => null,
|
'user_id' => null,
|
||||||
'content' => $status === 'approved'
|
'content' => $status === 'approved'
|
||||||
? "Entry was created by <user:{$user->id}>."
|
? "Entry was created by <user:{$user->uuid}>."
|
||||||
: "Suggestion was created by <user:{$user->id}>.",
|
: "Suggestion was created by <user:{$user->uuid}>.",
|
||||||
'subject_id' => $mutation->id,
|
'subject_id' => $mutation->id,
|
||||||
'subject_type' => Mutation::class,
|
'subject_type' => Mutation::class,
|
||||||
]);
|
]);
|
||||||
@@ -79,20 +80,60 @@ class Mutation extends Model
|
|||||||
if ($status === 'approved') {
|
if ($status === 'approved') {
|
||||||
$dynamicMsg = $dynamic->chat->messages()->create([
|
$dynamicMsg = $dynamic->chat->messages()->create([
|
||||||
'user_id' => null,
|
'user_id' => null,
|
||||||
'content' => "<user:{$user->id}> added entry \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
'content' => "<user:{$user->uuid}> added entry \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
||||||
'subject_id' => $mutation->id,
|
'subject_id' => $mutation->id,
|
||||||
'subject_type' => Mutation::class,
|
'subject_type' => Mutation::class,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$dynamicMsg = $dynamic->chat->messages()->create([
|
$dynamicMsg = $dynamic->chat->messages()->create([
|
||||||
'user_id' => null,
|
'user_id' => null,
|
||||||
'content' => "<user:{$user->id}> suggested \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
'content' => "<user:{$user->uuid}> suggested \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
||||||
'subject_id' => $mutation->id,
|
'subject_id' => $mutation->id,
|
||||||
'subject_type' => Mutation::class,
|
'subject_type' => Mutation::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
broadcast(new MessageSent($dynamicMsg));
|
broadcast(new MessageSent($dynamicMsg));
|
||||||
|
|
||||||
|
// Trigger the real-time creation broadcast dynamically
|
||||||
|
broadcast(new \App\Events\MutationCreated($mutation));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static::updated(function (Mutation $mutation) {
|
||||||
|
if ($mutation->wasChanged('status')) {
|
||||||
|
|
||||||
|
$status = $mutation->getAttribute('status');
|
||||||
|
$user = request()->user();
|
||||||
|
$ledger = $mutation->ledger;
|
||||||
|
$mutationMsg = $mutation->chat->messages()->create([
|
||||||
|
'user_id' => null,
|
||||||
|
'content' => $status === 'approved'
|
||||||
|
? "<user:{$user->uuid}> APPROVED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger."
|
||||||
|
: "<user:{$user->uuid}> DENIED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
|
||||||
|
'subject_id' => $mutation->id,
|
||||||
|
'subject_type' => Mutation::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dynamic = $ledger->dynamic;
|
||||||
|
$dynamic->chat->messages()->create([
|
||||||
|
'user_id' => null,
|
||||||
|
'content' => $mutationMsg->content,
|
||||||
|
'subject_id' => $mutation->id,
|
||||||
|
'subject_type' => Mutation::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
broadcast(new \App\Events\MutationUpdated($mutation));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $appends = ['can'];
|
||||||
|
|
||||||
|
public function getCanAttribute(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'update' => auth()->user()?->can('update', $this) ?? false,
|
||||||
|
'void' => auth()->user()?->can('void', $this) ?? false,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRouteKeyName()
|
public function getRouteKeyName()
|
||||||
|
|||||||
@@ -6,22 +6,22 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use App\Concerns\SerializesIdToUuid;
|
||||||
|
|
||||||
class PredefinedMutation extends Model
|
class PredefinedMutation extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory, SerializesIdToUuid;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'dynamic_id',
|
'ledger_id',
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'amount',
|
'amount',
|
||||||
'type',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function dynamic(): BelongsTo
|
public function ledger(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Dynamic::class);
|
return $this->belongsTo(Ledger::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function booted(): void
|
protected static function booted(): void
|
||||||
|
|||||||
+2
-1
@@ -15,6 +15,7 @@ use Laravel\Fortify\Contracts\PasskeyUser;
|
|||||||
use Laravel\Fortify\PasskeyAuthenticatable;
|
use Laravel\Fortify\PasskeyAuthenticatable;
|
||||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||||
use NotificationChannels\WebPush\HasPushSubscriptions;
|
use NotificationChannels\WebPush\HasPushSubscriptions;
|
||||||
|
use App\Concerns\SerializesIdToUuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $id
|
* @property int $id
|
||||||
@@ -34,7 +35,7 @@ use NotificationChannels\WebPush\HasPushSubscriptions;
|
|||||||
class User extends Authenticatable implements PasskeyUser
|
class User extends Authenticatable implements PasskeyUser
|
||||||
{
|
{
|
||||||
/** @use HasFactory<UserFactory> */
|
/** @use HasFactory<UserFactory> */
|
||||||
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
|
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
|
||||||
|
|
||||||
public function dynamics()
|
public function dynamics()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Notifications;
|
namespace App\Notifications;
|
||||||
|
|
||||||
use App\Models\Chat;
|
|
||||||
use App\Models\Message;
|
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
use NotificationChannels\WebPush\WebPushChannel;
|
use NotificationChannels\WebPush\WebPushChannel;
|
||||||
@@ -13,60 +11,33 @@ class NewActivityNotification extends Notification
|
|||||||
{
|
{
|
||||||
use Queueable;
|
use Queueable;
|
||||||
|
|
||||||
public $activity;
|
public array $activity;
|
||||||
|
|
||||||
/**
|
public function __construct(array $activity)
|
||||||
* Create a new notification instance.
|
|
||||||
*/
|
|
||||||
public function __construct($activity)
|
|
||||||
{
|
{
|
||||||
$this->activity = $activity;
|
$this->activity = $activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the notification's delivery channels.
|
|
||||||
*
|
|
||||||
* @return array<int, string>
|
|
||||||
*/
|
|
||||||
public function via(object $notifiable): array
|
public function via(object $notifiable): array
|
||||||
{
|
{
|
||||||
return [WebPushChannel::class];
|
return [WebPushChannel::class, 'database'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the web push representation of the notification.
|
|
||||||
*/
|
|
||||||
public function toWebPush(object $notifiable): WebPushMessage
|
public function toWebPush(object $notifiable): WebPushMessage
|
||||||
{
|
{
|
||||||
|
return (new WebPushMessage)
|
||||||
$result = (new WebPushMessage)
|
|
||||||
->title('New Activity')
|
->title('New Activity')
|
||||||
->icon('/apple-touch-icon.png')
|
->icon('/apple-touch-icon.png')
|
||||||
->body($this->activity['content'])
|
->body($this->activity['content'])
|
||||||
->action('View', 'view')
|
->action('View', 'view')
|
||||||
->data(['url' => $this->activity['url']]);
|
->data(['url' => $this->activity['url']]);
|
||||||
|
|
||||||
switch (get_class($this->activity)) {
|
|
||||||
case Message::class:
|
|
||||||
/** @var Chat $chat */
|
|
||||||
$chat = $this->activity->chat;
|
|
||||||
|
|
||||||
$result->data(['url' => $chat->subjectUrl]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the array representation of the notification.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function toArray(object $notifiable): array
|
public function toArray(object $notifiable): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//
|
'content' => $this->activity['content'],
|
||||||
|
'url' => $this->activity['url'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Chat;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Auth\Access\Response;
|
||||||
|
|
||||||
|
class ChatPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, Chat $chat): bool
|
||||||
|
{
|
||||||
|
$chatable = $chat->chatable;
|
||||||
|
return $user->can('view', $chatable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, Chat $chat): bool
|
||||||
|
{
|
||||||
|
return $this->view($user, $chat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, Chat $chat): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, Chat $chat): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, Chat $chat): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,14 @@ use App\Models\User;
|
|||||||
|
|
||||||
class MutationPolicy
|
class MutationPolicy
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the mutation.
|
||||||
|
*/
|
||||||
|
public function view(User $user, Mutation $mutation): bool
|
||||||
|
{
|
||||||
|
return $user->can('view', $mutation->ledger);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the user can create mutations.
|
* Determine whether the user can create mutations.
|
||||||
*/
|
*/
|
||||||
@@ -24,8 +32,9 @@ class MutationPolicy
|
|||||||
public function update(User $user, Mutation $mutation): bool
|
public function update(User $user, Mutation $mutation): bool
|
||||||
{
|
{
|
||||||
$dynamic = $mutation->ledger->dynamic;
|
$dynamic = $mutation->ledger->dynamic;
|
||||||
|
$isOwner = $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
||||||
|
|
||||||
return $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
return $isOwner && $mutation->status === 'pending';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +43,8 @@ class MutationPolicy
|
|||||||
public function void(User $user, Mutation $mutation): bool
|
public function void(User $user, Mutation $mutation): bool
|
||||||
{
|
{
|
||||||
$dynamic = $mutation->ledger->dynamic;
|
$dynamic = $mutation->ledger->dynamic;
|
||||||
|
$isOwner = $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
||||||
|
|
||||||
return $dynamic->participants()->where('user_id', $user->id)->where('role', 'owner')->exists();
|
return $isOwner && $mutation->status !== 'voided';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@@ -26,6 +27,13 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
JsonResource::withoutWrapping();
|
JsonResource::withoutWrapping();
|
||||||
$this->configureDefaults();
|
$this->configureDefaults();
|
||||||
|
|
||||||
|
Relation::morphMap([
|
||||||
|
'user' => \App\Models\User::class,
|
||||||
|
'dynamic' => \App\Models\Dynamic::class,
|
||||||
|
'ledger' => \App\Models\Ledger::class,
|
||||||
|
'mutation' => \App\Models\Mutation::class,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,8 +45,9 @@ class ActivityService
|
|||||||
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createMessage($chat, $user, $content, $subject = null)
|
public function createMessage($dynamic, $user, $content, $subject = null)
|
||||||
{
|
{
|
||||||
|
$chat = $dynamic->getOrCreateChat();
|
||||||
$message = $chat->messages()->create([
|
$message = $chat->messages()->create([
|
||||||
'user_id' => $user ? $user->id : null,
|
'user_id' => $user ? $user->id : null,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
@@ -92,14 +93,19 @@ class ActivityService
|
|||||||
*/
|
*/
|
||||||
public function getActivitiesForDynamic(Dynamic $dynamic): array
|
public function getActivitiesForDynamic(Dynamic $dynamic): array
|
||||||
{
|
{
|
||||||
|
$chat = $dynamic->getOrCreateChat();
|
||||||
|
if (!$chat) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$participants = $dynamic->participants()->withPivot('display_name')->get();
|
$participants = $dynamic->participants()->withPivot('display_name')->get();
|
||||||
$participantsMap = $participants->reduce(function ($acc, $p) {
|
$participantsMap = $participants->reduce(function ($acc, $p) {
|
||||||
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
|
$acc[$p->uuid] = $p->pivot->display_name ?? $p->name;
|
||||||
|
|
||||||
return $acc;
|
return $acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
$messages = Message::where('chat_id', $dynamic->chat->id)
|
$messages = Message::where('chat_id', $chat->id)
|
||||||
->with(['user', 'subject'])
|
->with(['user', 'subject'])
|
||||||
->latest()
|
->latest()
|
||||||
->get();
|
->get();
|
||||||
@@ -109,7 +115,7 @@ class ActivityService
|
|||||||
$messageData['url'] = $this->getUrlForMessage($message);
|
$messageData['url'] = $this->getUrlForMessage($message);
|
||||||
|
|
||||||
// Resolve <user:id> placeholders to actual names/display names
|
// Resolve <user:id> placeholders to actual names/display names
|
||||||
$messageData['content'] = preg_replace_callback('/<user:(\d+)>/', function ($matches) use ($participantsMap) {
|
$messageData['content'] = preg_replace_callback('/<user:([0-9a-f-]+)>/', function ($matches) use ($participantsMap) {
|
||||||
$userId = $matches[1];
|
$userId = $matches[1];
|
||||||
|
|
||||||
return $participantsMap[$userId] ?? "User #{$userId}";
|
return $participantsMap[$userId] ?? "User #{$userId}";
|
||||||
@@ -122,10 +128,10 @@ class ActivityService
|
|||||||
/**
|
/**
|
||||||
* Get unread activities grouped by active entities (Dynamics, Ledgers) for the given user.
|
* Get unread activities grouped by active entities (Dynamics, Ledgers) for the given user.
|
||||||
*/
|
*/
|
||||||
public function getUnreadDynamicsGrouped(User $user): array
|
public function getUnreadEntitiesGrouped(User $user): array
|
||||||
{
|
{
|
||||||
$groupedDynamics = [];
|
$groupedDynamics = [];
|
||||||
$participatingDynamics = $user->dynamics()->with('ledgers')->get();
|
$participatingDynamics = $user->dynamics()->with(['chat', 'ledgers'])->get();
|
||||||
|
|
||||||
foreach ($participatingDynamics as $dynamic) {
|
foreach ($participatingDynamics as $dynamic) {
|
||||||
$readAt = $this->getCursorReadAt($user, $dynamic);
|
$readAt = $this->getCursorReadAt($user, $dynamic);
|
||||||
|
|||||||
@@ -22,8 +22,10 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.24",
|
"fakerphp/faker": "^1.24",
|
||||||
|
"fruitcake/laravel-debugbar": "^4.4",
|
||||||
"larastan/larastan": "^3.9",
|
"larastan/larastan": "^3.9",
|
||||||
"laravel/boost": "^2.2",
|
"laravel/boost": "^2.2",
|
||||||
|
"laravel/dusk": "^8.6",
|
||||||
"laravel/pail": "^1.2.5",
|
"laravel/pail": "^1.2.5",
|
||||||
"laravel/pao": "^1.0.6",
|
"laravel/pao": "^1.0.6",
|
||||||
"laravel/pint": "^1.27",
|
"laravel/pint": "^1.27",
|
||||||
|
|||||||
Generated
+412
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "f4c79dcf0b7f9f54487404715d1085c1",
|
"content-hash": "349232eb2e405a447b06a60c3c01fe4c",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bacon/bacon-qr-code",
|
"name": "bacon/bacon-qr-code",
|
||||||
@@ -9344,6 +9344,109 @@
|
|||||||
],
|
],
|
||||||
"time": "2025-08-08T12:00:00+00:00"
|
"time": "2025-08-08T12:00:00+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "fruitcake/laravel-debugbar",
|
||||||
|
"version": "v4.4.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/fruitcake/laravel-debugbar.git",
|
||||||
|
"reference": "80ef956bda9e1a5824037d6f2cd06e73092e5634"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/fruitcake/laravel-debugbar/zipball/80ef956bda9e1a5824037d6f2cd06e73092e5634",
|
||||||
|
"reference": "80ef956bda9e1a5824037d6f2cd06e73092e5634",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/routing": "^11|^12|^13.0",
|
||||||
|
"illuminate/session": "^11|^12|^13.0",
|
||||||
|
"illuminate/support": "^11|^12|^13.0",
|
||||||
|
"php": "^8.2",
|
||||||
|
"php-debugbar/php-debugbar": "^3.8.0",
|
||||||
|
"php-debugbar/symfony-bridge": "^1.1"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"barryvdh/laravel-debugbar": "self.version"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"larastan/larastan": "^3",
|
||||||
|
"laravel/ai": "^0.8",
|
||||||
|
"laravel/octane": "^2",
|
||||||
|
"laravel/pennant": "^1",
|
||||||
|
"laravel/pint": "^1",
|
||||||
|
"laravel/telescope": "^5.16",
|
||||||
|
"livewire/livewire": "^3.7|^4",
|
||||||
|
"mockery/mockery": "^1.3.3",
|
||||||
|
"orchestra/testbench-dusk": "^9|^10|^11",
|
||||||
|
"php-debugbar/twig-bridge": "^2.0",
|
||||||
|
"phpstan/phpstan-phpunit": "^2",
|
||||||
|
"phpstan/phpstan-strict-rules": "^2.0",
|
||||||
|
"phpunit/phpunit": "^11",
|
||||||
|
"shipmonk/phpstan-rules": "^4.3"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"aliases": {
|
||||||
|
"Debugbar": "Fruitcake\\LaravelDebugbar\\Facades\\Debugbar"
|
||||||
|
},
|
||||||
|
"providers": [
|
||||||
|
"Fruitcake\\LaravelDebugbar\\ServiceProvider"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "4.2-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"src/helpers.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Fruitcake\\LaravelDebugbar\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fruitcake",
|
||||||
|
"homepage": "https://fruitcake.nl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Barry vd. Heuvel",
|
||||||
|
"email": "barryvdh@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Debugbar integration for Laravel",
|
||||||
|
"keywords": [
|
||||||
|
"barryvdh",
|
||||||
|
"debug",
|
||||||
|
"debugbar",
|
||||||
|
"dev",
|
||||||
|
"laravel",
|
||||||
|
"profiler",
|
||||||
|
"webprofiler"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/fruitcake/laravel-debugbar/issues",
|
||||||
|
"source": "https://github.com/fruitcake/laravel-debugbar/tree/v4.4.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://fruitcake.nl",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/barryvdh",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-07-04T08:30:57+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "hamcrest/hamcrest-php",
|
"name": "hamcrest/hamcrest-php",
|
||||||
"version": "v2.1.1",
|
"version": "v2.1.1",
|
||||||
@@ -9714,6 +9817,80 @@
|
|||||||
},
|
},
|
||||||
"time": "2026-06-09T10:21:08+00:00"
|
"time": "2026-06-09T10:21:08+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "laravel/dusk",
|
||||||
|
"version": "v8.6.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/laravel/dusk.git",
|
||||||
|
"reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/laravel/dusk/zipball/e7fd48762c6a82ad2cd311db07587aa2a97ce143",
|
||||||
|
"reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"guzzlehttp/guzzle": "^7.5",
|
||||||
|
"illuminate/console": "^10.0|^11.0|^12.0|^13.0",
|
||||||
|
"illuminate/support": "^10.0|^11.0|^12.0|^13.0",
|
||||||
|
"php": "^8.1",
|
||||||
|
"php-webdriver/webdriver": "^1.15.2",
|
||||||
|
"symfony/console": "^6.2|^7.0|^8.0",
|
||||||
|
"symfony/finder": "^6.2|^7.0|^8.0",
|
||||||
|
"symfony/process": "^6.2|^7.0|^8.0",
|
||||||
|
"vlucas/phpdotenv": "^5.2"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/framework": "^10.0|^11.0|^12.0|^13.0",
|
||||||
|
"mockery/mockery": "^1.6",
|
||||||
|
"orchestra/testbench-core": "^8.19|^9.17|^10.8|^11.0",
|
||||||
|
"phpstan/phpstan": "^1.10",
|
||||||
|
"phpunit/phpunit": "^10.1|^11.0|^12.0.1",
|
||||||
|
"psy/psysh": "^0.11.12|^0.12",
|
||||||
|
"symfony/yaml": "^6.2|^7.0|^8.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-pcntl": "Used to gracefully terminate Dusk when tests are running."
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Laravel\\Dusk\\DuskServiceProvider"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Laravel\\Dusk\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Taylor Otwell",
|
||||||
|
"email": "taylor@laravel.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Laravel Dusk provides simple end-to-end testing and browser automation.",
|
||||||
|
"keywords": [
|
||||||
|
"laravel",
|
||||||
|
"testing",
|
||||||
|
"webdriver"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/laravel/dusk/issues",
|
||||||
|
"source": "https://github.com/laravel/dusk/tree/v8.6.0"
|
||||||
|
},
|
||||||
|
"time": "2026-04-15T14:50:40+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "laravel/mcp",
|
"name": "laravel/mcp",
|
||||||
"version": "v0.8.1",
|
"version": "v0.8.1",
|
||||||
@@ -10967,6 +11144,240 @@
|
|||||||
},
|
},
|
||||||
"time": "2022-02-21T01:04:05+00:00"
|
"time": "2022-02-21T01:04:05+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "php-debugbar/php-debugbar",
|
||||||
|
"version": "v3.8.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-debugbar/php-debugbar.git",
|
||||||
|
"reference": "18ced90d4b882ed449b2278fea8692f8f7d1c13c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-debugbar/php-debugbar/zipball/18ced90d4b882ed449b2278fea8692f8f7d1c13c",
|
||||||
|
"reference": "18ced90d4b882ed449b2278fea8692f8f7d1c13c",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.2",
|
||||||
|
"psr/log": "^1|^2|^3",
|
||||||
|
"symfony/var-dumper": "^5.4|^6|^7|^8"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"maximebf/debugbar": "self.version"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dbrekelmans/bdi": "^1.4",
|
||||||
|
"friendsofphp/php-cs-fixer": "^3.92",
|
||||||
|
"monolog/monolog": "^3.9",
|
||||||
|
"php-debugbar/doctrine-bridge": "^3@dev",
|
||||||
|
"php-debugbar/monolog-bridge": "^1@dev",
|
||||||
|
"php-debugbar/symfony-bridge": "^1@dev",
|
||||||
|
"php-debugbar/twig-bridge": "^2@dev",
|
||||||
|
"phpstan/phpstan": "^2.1",
|
||||||
|
"phpstan/phpstan-phpunit": "^2.0",
|
||||||
|
"phpstan/phpstan-strict-rules": "^2.0",
|
||||||
|
"phpunit/phpunit": "^10",
|
||||||
|
"predis/predis": "^3.3",
|
||||||
|
"shipmonk/phpstan-rules": "^4.3",
|
||||||
|
"symfony/browser-kit": "^6.4|7.0",
|
||||||
|
"symfony/dom-crawler": "^6.4|^7",
|
||||||
|
"symfony/event-dispatcher": "^5.4|^6.4|^7.3|^8.0",
|
||||||
|
"symfony/http-foundation": "^5.4|^6.4|^7.3|^8.0",
|
||||||
|
"symfony/mailer": "^5.4|^6.4|^7.3|^8.0",
|
||||||
|
"symfony/panther": "^1|^2.1",
|
||||||
|
"twig/twig": "^3.11.2"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"php-debugbar/doctrine-bridge": "To integrate Doctrine with php-debugbar.",
|
||||||
|
"php-debugbar/monolog-bridge": "To integrate Monolog with php-debugbar.",
|
||||||
|
"php-debugbar/symfony-bridge": "To integrate Symfony with php-debugbar.",
|
||||||
|
"php-debugbar/twig-bridge": "To integrate Twig with php-debugbar."
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.8-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DebugBar\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Maxime Bouroumeau-Fuseau",
|
||||||
|
"email": "maxime.bouroumeau@gmail.com",
|
||||||
|
"homepage": "http://maximebf.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Barry vd. Heuvel",
|
||||||
|
"email": "barryvdh@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Debug bar in the browser for php application",
|
||||||
|
"homepage": "https://github.com/php-debugbar/php-debugbar",
|
||||||
|
"keywords": [
|
||||||
|
"debug",
|
||||||
|
"debug bar",
|
||||||
|
"debugbar",
|
||||||
|
"dev",
|
||||||
|
"profiler",
|
||||||
|
"toolbar"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-debugbar/php-debugbar/issues",
|
||||||
|
"source": "https://github.com/php-debugbar/php-debugbar/tree/v3.8.0"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://fruitcake.nl",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/barryvdh",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2026-07-02T12:38:20+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-debugbar/symfony-bridge",
|
||||||
|
"version": "v1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-debugbar/symfony-bridge.git",
|
||||||
|
"reference": "e37d2debe5d316408b00d0ab2688d9c2cf59b5ad"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-debugbar/symfony-bridge/zipball/e37d2debe5d316408b00d0ab2688d9c2cf59b5ad",
|
||||||
|
"reference": "e37d2debe5d316408b00d0ab2688d9c2cf59b5ad",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^8.2",
|
||||||
|
"php-debugbar/php-debugbar": "^3.1",
|
||||||
|
"symfony/http-foundation": "^5.4|^6.4|^7.3|^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"dbrekelmans/bdi": "^1.4",
|
||||||
|
"phpunit/phpunit": "^10",
|
||||||
|
"symfony/browser-kit": "^6|^7",
|
||||||
|
"symfony/dom-crawler": "^6|^7",
|
||||||
|
"symfony/mailer": "^5.4|^6.4|^7.3|^8.0",
|
||||||
|
"symfony/panther": "^1|^2.1"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.0-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DebugBar\\Bridge\\Symfony\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Maxime Bouroumeau-Fuseau",
|
||||||
|
"email": "maxime.bouroumeau@gmail.com",
|
||||||
|
"homepage": "http://maximebf.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Barry vd. Heuvel",
|
||||||
|
"email": "barryvdh@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony bridge for PHP Debugbar",
|
||||||
|
"homepage": "https://github.com/php-debugbar/php-debugbar",
|
||||||
|
"keywords": [
|
||||||
|
"debugbar",
|
||||||
|
"dev",
|
||||||
|
"symfony"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-debugbar/symfony-bridge/issues",
|
||||||
|
"source": "https://github.com/php-debugbar/symfony-bridge/tree/v1.1.0"
|
||||||
|
},
|
||||||
|
"time": "2026-01-15T14:47:34+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "php-webdriver/webdriver",
|
||||||
|
"version": "1.16.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/php-webdriver/php-webdriver.git",
|
||||||
|
"reference": "ac0662863aa120b4f645869f584013e4c4dba46a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/ac0662863aa120b4f645869f584013e4c4dba46a",
|
||||||
|
"reference": "ac0662863aa120b4f645869f584013e4c4dba46a",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-curl": "*",
|
||||||
|
"ext-json": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"php": "^7.3 || ^8.0",
|
||||||
|
"symfony/polyfill-mbstring": "^1.12",
|
||||||
|
"symfony/process": "^5.0 || ^6.0 || ^7.0 || ^8.0"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"facebook/webdriver": "*"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"ergebnis/composer-normalize": "^2.20.0",
|
||||||
|
"ondram/ci-detector": "^4.0",
|
||||||
|
"php-coveralls/php-coveralls": "^2.4",
|
||||||
|
"php-mock/php-mock-phpunit": "^2.0",
|
||||||
|
"php-parallel-lint/php-parallel-lint": "^1.2",
|
||||||
|
"phpunit/phpunit": "^9.3",
|
||||||
|
"squizlabs/php_codesniffer": "^3.5",
|
||||||
|
"symfony/var-dumper": "^5.0 || ^6.0 || ^7.0 || ^8.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-simplexml": "For Firefox profile creation"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"lib/Exception/TimeoutException.php"
|
||||||
|
],
|
||||||
|
"psr-4": {
|
||||||
|
"Facebook\\WebDriver\\": "lib/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.",
|
||||||
|
"homepage": "https://github.com/php-webdriver/php-webdriver",
|
||||||
|
"keywords": [
|
||||||
|
"Chromedriver",
|
||||||
|
"geckodriver",
|
||||||
|
"php",
|
||||||
|
"selenium",
|
||||||
|
"webdriver"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/php-webdriver/php-webdriver/issues",
|
||||||
|
"source": "https://github.com/php-webdriver/php-webdriver/tree/1.16.0"
|
||||||
|
},
|
||||||
|
"time": "2025-12-28T23:57:40+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpstan/phpstan",
|
"name": "phpstan/phpstan",
|
||||||
"version": "2.2.2",
|
"version": "2.2.2",
|
||||||
|
|||||||
@@ -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('messages', function (Blueprint $table) {
|
||||||
|
DB::table('messages')->where('subject_type', 'App\\Models\\User')->update(['subject_type' => 'user']);
|
||||||
|
DB::table('messages')->where('subject_type', 'App\\Models\\Mutation')->update(['subject_type' => 'mutation']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('messages', function (Blueprint $table) {
|
||||||
|
DB::table('messages')->where('subject_type', 'user')->update(['subject_type' => 'App\\Models\\User']);
|
||||||
|
DB::table('messages')->where('subject_type', 'mutation')->update(['subject_type' => 'App\\Models\\Mutation']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?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('users', function (Blueprint $table) {
|
||||||
|
$table->dropUnique('users_uuid_unique');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->unique('uuid');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
<?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('predefined_mutations', function (Blueprint $table) {
|
||||||
|
// Drop old foreign key constraint first
|
||||||
|
$table->dropForeign(['dynamic_id']);
|
||||||
|
|
||||||
|
// Drop old columns
|
||||||
|
$table->dropColumn(['dynamic_id', 'type']);
|
||||||
|
|
||||||
|
// Add new ledger relationship (nullable to support pre-existing entries gracefully)
|
||||||
|
$table->foreignId('ledger_id')
|
||||||
|
->after('id')
|
||||||
|
->nullable()
|
||||||
|
->constrained()
|
||||||
|
->cascadeOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('predefined_mutations', function (Blueprint $table) {
|
||||||
|
$table->dropConstrainedForeignId('ledger_id');
|
||||||
|
$table->foreignId('dynamic_id')->after('id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('type')->default('reward');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Chat;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
Chat::unguard();
|
||||||
|
\App\Models\Chat::all()->each(function (Chat $chat) {
|
||||||
|
$newType = match($chat->chatable_type) {
|
||||||
|
\App\Models\Mutation::class => 'mutation',
|
||||||
|
\App\Models\Ledger::class => 'ledger',
|
||||||
|
\App\Models\Dynamic::class => 'dynamic',
|
||||||
|
default => $chat->chatable_type,
|
||||||
|
};
|
||||||
|
$chat->update(['chatable_type' => $newType]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?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::create('notifications', function (Blueprint $table) {
|
||||||
|
$table->uuid('id')->primary();
|
||||||
|
$table->string('type');
|
||||||
|
$table->morphs('notifiable');
|
||||||
|
$table->text('data');
|
||||||
|
$table->timestamp('read_at')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('notifications');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Message;
|
||||||
|
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
|
||||||
|
{
|
||||||
|
\App\Models\Message::all()->each(function (Message $message) {
|
||||||
|
$msg = $message->content;
|
||||||
|
|
||||||
|
$msg = preg_replace_callback('/<user:([0-9]+)>/', function ($matches) {
|
||||||
|
$userId = $matches[1];
|
||||||
|
$user = \App\Models\User::find($userId);
|
||||||
|
if($user){
|
||||||
|
$userId = $user->uuid;
|
||||||
|
}
|
||||||
|
return "<user:$userId>";
|
||||||
|
}, $msg);
|
||||||
|
|
||||||
|
if($msg != $message->content) {
|
||||||
|
$message->update(['content' => $msg]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('uuid_base', function (Blueprint $table) {
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
beStrictAboutTestsThatDoNotTestAnything="false"
|
||||||
|
colors="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnError="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
cacheDirectory=".phpunit.cache"
|
||||||
|
backupStaticProperties="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Browser Test Suite">
|
||||||
|
<directory suffix="Test.php">./tests/Browser</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c-chat__message {
|
.c-chat__message {
|
||||||
@apply overflow-hidden p-4 shadow-sm sm:rounded-lg;
|
@apply p-4 shadow-sm sm:rounded-lg;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
|
|
||||||
&.c-chat__message--system {
|
&.c-chat__message--system {
|
||||||
|
|||||||
@@ -2,17 +2,46 @@
|
|||||||
import { useForm } from '@inertiajs/vue3';
|
import { useForm } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = withDefaults(
|
||||||
dynamicId: number;
|
defineProps<{
|
||||||
ledgerId: number;
|
dynamicId: string;
|
||||||
}>();
|
ledgerId: string;
|
||||||
|
predefinedMutations?: Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
amount: number;
|
||||||
|
}>;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
predefinedMutations: () => [],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
amount: 0,
|
amount: 0,
|
||||||
description: '',
|
description: '',
|
||||||
|
predefined_mutation_id: null as string | null,
|
||||||
media: [] as File[],
|
media: [] as File[],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function selectPredefinedMutation(event: Event) {
|
||||||
|
const select = event.target as HTMLSelectElement;
|
||||||
|
const selectedId = select.value;
|
||||||
|
if (!selectedId) {
|
||||||
|
form.predefined_mutation_id = null;
|
||||||
|
form.amount = 0;
|
||||||
|
form.description = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mutation = props.predefinedMutations.find(m => m.id === selectedId);
|
||||||
|
if (mutation) {
|
||||||
|
form.predefined_mutation_id = mutation.id;
|
||||||
|
form.amount = mutation.amount;
|
||||||
|
form.description = mutation.description || mutation.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleMutationFileChange(event: Event) {
|
function handleMutationFileChange(event: Event) {
|
||||||
const files = (event.target as HTMLInputElement).files;
|
const files = (event.target as HTMLInputElement).files;
|
||||||
|
|
||||||
@@ -44,6 +73,28 @@ function submit() {
|
|||||||
<div class="c-add-mutation-form">
|
<div class="c-add-mutation-form">
|
||||||
<h4 class="c-add-mutation-form__title">Add Mutation</h4>
|
<h4 class="c-add-mutation-form__title">Add Mutation</h4>
|
||||||
<form @submit.prevent="submit" class="c-add-mutation-form__form">
|
<form @submit.prevent="submit" class="c-add-mutation-form__form">
|
||||||
|
|
||||||
|
<!-- Predefined Templates Selection -->
|
||||||
|
<div v-if="predefinedMutations && predefinedMutations.length > 0" class="c-add-mutation-form__field">
|
||||||
|
<label for="predefined_mutation" class="c-add-mutation-form__label"
|
||||||
|
>Apply Predefined Template</label
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
id="predefined_mutation"
|
||||||
|
class="c-add-mutation-form__select"
|
||||||
|
@change="selectPredefinedMutation"
|
||||||
|
>
|
||||||
|
<option value="">-- Choose a predefined template (optional) --</option>
|
||||||
|
<option
|
||||||
|
v-for="item in predefinedMutations"
|
||||||
|
:key="item.id"
|
||||||
|
:value="item.id"
|
||||||
|
>
|
||||||
|
{{ item.name }} ({{ item.amount >= 0 ? '+' : '' }}{{ item.amount }} points)
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="c-add-mutation-form__field">
|
<div class="c-add-mutation-form__field">
|
||||||
<label for="amount" class="c-add-mutation-form__label"
|
<label for="amount" class="c-add-mutation-form__label"
|
||||||
>Amount</label
|
>Amount</label
|
||||||
@@ -53,6 +104,7 @@ function submit() {
|
|||||||
id="amount"
|
id="amount"
|
||||||
type="number"
|
type="number"
|
||||||
class="c-add-mutation-form__input"
|
class="c-add-mutation-form__input"
|
||||||
|
data-test="amount-input"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
v-if="form.errors.amount"
|
v-if="form.errors.amount"
|
||||||
@@ -71,6 +123,7 @@ function submit() {
|
|||||||
id="description"
|
id="description"
|
||||||
rows="4"
|
rows="4"
|
||||||
class="c-add-mutation-form__textarea"
|
class="c-add-mutation-form__textarea"
|
||||||
|
data-test="description-input"
|
||||||
></textarea>
|
></textarea>
|
||||||
<div
|
<div
|
||||||
v-if="form.errors.description"
|
v-if="form.errors.description"
|
||||||
@@ -120,6 +173,7 @@ function submit() {
|
|||||||
type="submit"
|
type="submit"
|
||||||
:disabled="form.processing"
|
:disabled="form.processing"
|
||||||
class="c-add-mutation-form__submit-btn"
|
class="c-add-mutation-form__submit-btn"
|
||||||
|
data-test="add-mutation-button"
|
||||||
>
|
>
|
||||||
Add Mutation
|
Add Mutation
|
||||||
</button>
|
</button>
|
||||||
@@ -151,6 +205,10 @@ function submit() {
|
|||||||
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
|
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.c-add-mutation-form__select {
|
||||||
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
|
}
|
||||||
|
|
||||||
.c-add-mutation-form__input {
|
.c-add-mutation-form__input {
|
||||||
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
}
|
}
|
||||||
|
|||||||
+266
-250
@@ -1,9 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useForm, usePage, router } from '@inertiajs/vue3';
|
import { usePage } from '@inertiajs/vue3';
|
||||||
import { useEcho, echoIsConfigured, configureEcho } from '@laravel/echo-vue';
|
import { useEcho, echoIsConfigured, configureEcho } from '@laravel/echo-vue';
|
||||||
import { Paperclip, Info } from '@lucide/vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
import { ref, computed } from 'vue';
|
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
import ChatInput from './chat/ChatInput.vue';
|
||||||
|
import ChatSystemMessage from './chat/ChatSystemMessage.vue';
|
||||||
|
import ChatUserMessage from './chat/ChatUserMessage.vue';
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
@@ -33,33 +35,85 @@ const props = withDefaults(
|
|||||||
} | null;
|
} | null;
|
||||||
}>;
|
}>;
|
||||||
dynamicId: string;
|
dynamicId: string;
|
||||||
initialMessages: {
|
ledgerId?: string | null;
|
||||||
|
initialMessages?: {
|
||||||
data: Array<any>;
|
data: Array<any>;
|
||||||
next_page_url: string | null;
|
next_page_url?: string | null;
|
||||||
};
|
links?: {
|
||||||
|
next: string | null;
|
||||||
|
} | null;
|
||||||
|
current_page?: number;
|
||||||
|
meta?: {
|
||||||
|
current_page: number;
|
||||||
|
} | null;
|
||||||
|
} | null;
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
participants: () => [],
|
participants: () => [],
|
||||||
|
initialMessages: null,
|
||||||
|
ledgerId: null,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const messages = ref(props.initialMessages.data.reverse());
|
const getNextPageUrl = (paginator: any) => {
|
||||||
const nextPageUrl = ref(props.initialMessages.next_page_url);
|
return paginator?.links?.next ?? paginator?.next_page_url ?? null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCurrentPage = (paginator: any) => {
|
||||||
|
return paginator?.meta?.current_page ?? paginator?.current_page ?? 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
const messages = ref(
|
||||||
|
props.initialMessages
|
||||||
|
? props.initialMessages.data.slice().reverse()
|
||||||
|
: (props.chat.messages || []).slice()
|
||||||
|
);
|
||||||
|
const nextPageUrl = ref(getNextPageUrl(props.initialMessages));
|
||||||
|
const currentPageNum = ref(1);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.initialMessages,
|
||||||
|
(newVal) => {
|
||||||
|
if (newVal && getCurrentPage(newVal) === 1) {
|
||||||
|
messages.value = newVal.data.slice().reverse();
|
||||||
|
nextPageUrl.value = getNextPageUrl(newVal);
|
||||||
|
currentPageNum.value = 1;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.chat.messages,
|
||||||
|
(newVal) => {
|
||||||
|
if (!props.initialMessages && newVal) {
|
||||||
|
messages.value = newVal.slice();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ deep: true }
|
||||||
|
);
|
||||||
|
|
||||||
function loadMoreMessages() {
|
function loadMoreMessages() {
|
||||||
if (!nextPageUrl.value) {
|
if (!nextPageUrl.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
router.get(nextPageUrl.value, {}, {
|
currentPageNum.value++;
|
||||||
preserveState: true,
|
|
||||||
preserveScroll: true,
|
const apiRouteName = props.ledgerId ? 'dynamics.ledgers.messages' : 'dynamics.messages';
|
||||||
only: ['messages'],
|
const apiParams = props.ledgerId ? [props.dynamicId, props.ledgerId] : [props.dynamicId];
|
||||||
onSuccess: (page) => {
|
const url = route(apiRouteName, [...apiParams, { page: currentPageNum.value }]);
|
||||||
const newMessages = page.props.messages as { data: Array<any>; next_page_url: string | null };
|
|
||||||
messages.value = [...newMessages.data.reverse(), ...messages.value];
|
fetch(url)
|
||||||
nextPageUrl.value = newMessages.next_page_url;
|
.then((res) => res.json())
|
||||||
},
|
.then((json) => {
|
||||||
|
const data = json?.data || [];
|
||||||
|
messages.value = [...data.slice().reverse(), ...messages.value];
|
||||||
|
nextPageUrl.value = getNextPageUrl(json);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Failed to load older messages:', err);
|
||||||
|
currentPageNum.value--;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,30 +133,10 @@ if (!echoIsConfigured()) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileInput = ref<HTMLInputElement | null>(null);
|
|
||||||
|
|
||||||
const form = useForm({
|
|
||||||
content: '',
|
|
||||||
media: [] as File[],
|
|
||||||
});
|
|
||||||
|
|
||||||
useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
|
useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
|
||||||
messages.value.push(e.message);
|
messages.value.push(e.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatTimestamp(isoString: string): { full: string; time: string } {
|
|
||||||
const date = new Date(isoString);
|
|
||||||
|
|
||||||
return {
|
|
||||||
full: date.toLocaleString(),
|
|
||||||
time: date.toLocaleTimeString([], {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const participantsById = computed(() => {
|
const participantsById = computed(() => {
|
||||||
const list = props.participants || [];
|
const list = props.participants || [];
|
||||||
|
|
||||||
@@ -115,7 +149,7 @@ const participantsById = computed(() => {
|
|||||||
{} as Record<
|
{} as Record<
|
||||||
number,
|
number,
|
||||||
{
|
{
|
||||||
id: number;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
pivot?: { display_name: string | null } | null;
|
pivot?: { display_name: string | null } | null;
|
||||||
}
|
}
|
||||||
@@ -123,83 +157,6 @@ const participantsById = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function parseMessageContent(message: {
|
|
||||||
content: string;
|
|
||||||
subject_id?: number | null;
|
|
||||||
subject_type?: string | null;
|
|
||||||
subject?: any;
|
|
||||||
}) {
|
|
||||||
let content = message.content;
|
|
||||||
|
|
||||||
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
|
||||||
const userRegex = /<user:(\d+)>/g;
|
|
||||||
content = content.replace(userRegex, (match, userId) => {
|
|
||||||
const user = participantsById.value[Number(userId)];
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
|
|
||||||
|
|
||||||
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
|
||||||
user.pivot?.display_name ?? user.name
|
|
||||||
}</a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `User #${userId}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 2. Link subjects if found in the text
|
|
||||||
if (message.subject_id && message.subject_type) {
|
|
||||||
if (
|
|
||||||
message.subject_type === 'App\\Models\\Mutation' ||
|
|
||||||
message.subject_type === 'App\\Models\\Ledger'
|
|
||||||
) {
|
|
||||||
const ledgerId =
|
|
||||||
message.subject_type === 'App\\Models\\Mutation'
|
|
||||||
? message.subject?.ledger_id
|
|
||||||
: message.subject?.id;
|
|
||||||
|
|
||||||
const ledgerName =
|
|
||||||
message.subject_type === 'App\\Models\\Mutation'
|
|
||||||
? message.subject?.ledger?.name
|
|
||||||
: message.subject?.name;
|
|
||||||
|
|
||||||
if (ledgerId && ledgerName) {
|
|
||||||
const ledgerUrl = route('dynamics.ledgers.show', [
|
|
||||||
props.dynamicId,
|
|
||||||
ledgerId,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const escapedName = ledgerName.replace(
|
|
||||||
/[-\/\\^$*+?.()|[\]{}]/g,
|
|
||||||
'\\$&',
|
|
||||||
);
|
|
||||||
|
|
||||||
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
|
||||||
content = content.replace(
|
|
||||||
nameRegex,
|
|
||||||
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleFileChange(event: Event) {
|
|
||||||
const files = (event.target as HTMLInputElement).files;
|
|
||||||
|
|
||||||
if (files) {
|
|
||||||
for (let i = 0; i < files.length; i++) {
|
|
||||||
form.media.push(files[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeFile(index: number) {
|
|
||||||
form.media.splice(index, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentUser = computed(() => usePage().props.auth?.user);
|
const currentUser = computed(() => usePage().props.auth?.user);
|
||||||
|
|
||||||
function isOwnMessage(messageUserId: number | null): boolean {
|
function isOwnMessage(messageUserId: number | null): boolean {
|
||||||
@@ -210,18 +167,6 @@ function isOwnMessage(messageUserId: number | null): boolean {
|
|||||||
return currentUser.value && currentUser.value.id === messageUserId;
|
return currentUser.value && currentUser.value.id === messageUserId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function submit() {
|
|
||||||
form.post(route('chats.messages.store', props.chat.id), {
|
|
||||||
onSuccess: () => {
|
|
||||||
form.reset();
|
|
||||||
|
|
||||||
if (fileInput.value) {
|
|
||||||
fileInput.value.value = '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lightbox Modal state
|
// Lightbox Modal state
|
||||||
const activeLightboxUrl = ref<string | null>(null);
|
const activeLightboxUrl = ref<string | null>(null);
|
||||||
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
||||||
@@ -261,138 +206,29 @@ function closeLightbox() {
|
|||||||
]"
|
]"
|
||||||
>
|
>
|
||||||
<!-- Standard User Chat Message -->
|
<!-- Standard User Chat Message -->
|
||||||
<template v-if="message.user">
|
<ChatUserMessage
|
||||||
<div class="c-chat__message-header">
|
v-if="message.user"
|
||||||
<span class="c-chat__message-author">{{
|
:message="message"
|
||||||
message.user.name
|
:participants-by-id="participantsById"
|
||||||
}}</span>
|
:dynamic-id="dynamicId"
|
||||||
<span
|
@open-lightbox="openLightbox"
|
||||||
class="c-chat__message-time"
|
|
||||||
:title="formatTimestamp(message.created_at).full"
|
|
||||||
>
|
|
||||||
{{ formatTimestamp(message.created_at).time }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<p class="c-chat__message-text" v-html="parseMessageContent(message)"></p>
|
|
||||||
|
|
||||||
<!-- Attached Media Display -->
|
|
||||||
<div
|
|
||||||
v-if="message.media && message.media.length > 0"
|
|
||||||
class="c-chat__message-media"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
v-for="item in message.media"
|
|
||||||
:key="item.id"
|
|
||||||
class="c-chat__media-item"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-if="item.mime_type.startsWith('image/')"
|
|
||||||
:src="item.url"
|
|
||||||
:alt="item.file_name"
|
|
||||||
class="c-chat__image cursor-pointer transition-opacity hover:opacity-90"
|
|
||||||
@click="openLightbox(item.url, item.mime_type)"
|
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
v-else-if="item.mime_type.startsWith('video/')"
|
|
||||||
class="relative cursor-pointer transition-opacity hover:opacity-90"
|
|
||||||
@click="openLightbox(item.url, item.mime_type)"
|
|
||||||
>
|
|
||||||
<video
|
|
||||||
:src="item.url"
|
|
||||||
class="c-chat__video"
|
|
||||||
></video>
|
|
||||||
<div class="c-chat__play-overlay">▶</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Subtle Activity Log System Message -->
|
<!-- Subtle Activity Log System Message -->
|
||||||
<template v-else>
|
<ChatSystemMessage
|
||||||
<div class="c-chat__system-inner">
|
v-else
|
||||||
<Info class="c-chat__system-icon" />
|
:message="message"
|
||||||
<span
|
:participants-by-id="participantsById"
|
||||||
class="c-chat__system-text"
|
:dynamic-id="dynamicId"
|
||||||
v-html="parseMessageContent(message)"
|
/>
|
||||||
></span>
|
|
||||||
<span
|
|
||||||
class="c-chat__system-time"
|
|
||||||
:title="formatTimestamp(message.created_at).full"
|
|
||||||
>
|
|
||||||
{{ formatTimestamp(message.created_at).time }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
</div>
|
||||||
<div v-if="messages.length === 0" class="c-chat__empty">
|
<div v-if="messages.length === 0" class="c-chat__empty">
|
||||||
No messages yet.
|
No messages yet.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form @submit.prevent="submit" class="c-chat__form">
|
|
||||||
<div class="c-chat__form-group">
|
|
||||||
<label for="content" class="c-chat__label">Message</label>
|
|
||||||
<textarea
|
|
||||||
v-model="form.content"
|
|
||||||
id="content"
|
|
||||||
rows="3"
|
|
||||||
class="c-chat__textarea"
|
|
||||||
placeholder="Type a message... (Press Enter to send, Shift+Enter for newline)"
|
|
||||||
@keydown.enter.exact.prevent="submit"
|
|
||||||
></textarea>
|
|
||||||
<div v-if="form.errors.content" class="c-chat__error">
|
|
||||||
{{ form.errors.content }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Attachment Button & Hidden Input -->
|
<!-- Cohesive Chat input Form -->
|
||||||
<div class="c-chat__attachment-container">
|
<ChatInput :chat-id="chat.id" />
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
@click="fileInput?.click()"
|
|
||||||
class="c-chat__attach-btn"
|
|
||||||
>
|
|
||||||
<Paperclip class="c-chat__attach-icon" />
|
|
||||||
Attach Photos/Videos
|
|
||||||
</button>
|
|
||||||
<input
|
|
||||||
ref="fileInput"
|
|
||||||
type="file"
|
|
||||||
multiple
|
|
||||||
accept="image/*,video/*"
|
|
||||||
class="hidden"
|
|
||||||
@change="handleFileChange"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Previews List -->
|
|
||||||
<div v-if="form.media.length > 0" class="c-chat__preview-list">
|
|
||||||
<div
|
|
||||||
v-for="(file, index) in form.media"
|
|
||||||
:key="index"
|
|
||||||
class="c-chat__preview-item"
|
|
||||||
>
|
|
||||||
<span class="c-chat__preview-name">{{
|
|
||||||
file.name
|
|
||||||
}}</span>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
@click="removeFile(index)"
|
|
||||||
class="c-chat__preview-remove"
|
|
||||||
>
|
|
||||||
✕
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="c-chat__submit-box">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
:disabled="form.processing"
|
|
||||||
class="c-chat__button"
|
|
||||||
>
|
|
||||||
Send
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- Gorgeous Dark Lightbox Modal -->
|
<!-- Gorgeous Dark Lightbox Modal -->
|
||||||
<div v-if="activeLightboxUrl" class="c-lightbox" @click="closeLightbox">
|
<div v-if="activeLightboxUrl" class="c-lightbox" @click="closeLightbox">
|
||||||
@@ -414,3 +250,183 @@ function closeLightbox() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
@reference "../../css/app.css";
|
||||||
|
|
||||||
|
.c-chat {
|
||||||
|
@apply flex flex-col h-[500px];
|
||||||
|
background-color: var(--card);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__title {
|
||||||
|
@apply p-4 font-bold border-b text-sm;
|
||||||
|
border-color: var(--border);
|
||||||
|
color: var(--foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__list {
|
||||||
|
@apply flex-1 overflow-y-auto p-4 space-y-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__load-more {
|
||||||
|
@apply flex justify-center py-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__load-more-btn {
|
||||||
|
@apply text-xs font-semibold text-blue-500 hover:underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message {
|
||||||
|
@apply max-w-[75%] p-3 rounded-lg flex flex-col gap-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message--own {
|
||||||
|
@apply self-end;
|
||||||
|
background-color: var(--primary);
|
||||||
|
color: var(--primary-foreground);
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
|
||||||
|
.c-chat__message-author {
|
||||||
|
@apply hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-time {
|
||||||
|
@apply text-blue-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-text {
|
||||||
|
color: var(--primary-foreground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message--other {
|
||||||
|
@apply self-start;
|
||||||
|
background-color: var(--muted);
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message--system {
|
||||||
|
@apply self-center max-w-full w-full bg-transparent border-0 p-0 text-center gap-0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-header {
|
||||||
|
@apply flex items-baseline gap-2 mb-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-author {
|
||||||
|
@apply font-semibold text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-time {
|
||||||
|
@apply text-[10px];
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-text {
|
||||||
|
@apply text-sm break-words whitespace-pre-wrap leading-relaxed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__message-media {
|
||||||
|
@apply mt-2 flex flex-wrap gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__media-item {
|
||||||
|
@apply max-w-[120px] overflow-hidden rounded border border-black dark:border-gray-600 bg-black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__image {
|
||||||
|
@apply h-auto max-h-[80px] w-full object-cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__video {
|
||||||
|
@apply h-auto max-h-[80px] w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__play-overlay {
|
||||||
|
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-lg font-bold text-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__system-inner {
|
||||||
|
@apply inline-flex items-center gap-2 bg-neutral-100 dark:bg-neutral-900/30 px-3 py-1 rounded-full text-xs text-neutral-500 dark:text-neutral-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__system-icon {
|
||||||
|
@apply size-3.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__system-text {
|
||||||
|
@apply font-medium leading-relaxed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__system-time {
|
||||||
|
@apply text-[10px] opacity-75 ml-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__empty {
|
||||||
|
@apply text-center text-xs py-8;
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__form {
|
||||||
|
@apply p-4 border-t flex flex-col gap-2 bg-neutral-50 dark:bg-neutral-900/10;
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__form-group {
|
||||||
|
@apply relative flex flex-col gap-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__label {
|
||||||
|
@apply sr-only;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__textarea {
|
||||||
|
@apply w-full rounded border p-2 text-sm resize-none focus:outline-none focus:ring-1 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-800;
|
||||||
|
color: var(--foreground);
|
||||||
|
border-color: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__error {
|
||||||
|
@apply text-xs text-red-500 mt-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__attachment-container {
|
||||||
|
@apply flex items-center mt-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__attach-btn {
|
||||||
|
@apply inline-flex items-center gap-1.5 text-xs text-neutral-500 hover:text-neutral-900 dark:hover:text-neutral-100 transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__attach-icon {
|
||||||
|
@apply size-3.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__preview-list {
|
||||||
|
@apply mt-2 flex flex-wrap gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__preview-item {
|
||||||
|
@apply inline-flex items-center gap-2 bg-neutral-100 dark:bg-neutral-900/50 px-2 py-1 rounded text-xs;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__preview-name {
|
||||||
|
@apply max-w-[150px] truncate text-neutral-600 dark:text-neutral-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__preview-remove {
|
||||||
|
@apply text-neutral-400 hover:text-red-500 transition-colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__submit-box {
|
||||||
|
@apply flex justify-end mt-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-chat__button {
|
||||||
|
@apply inline-flex items-center justify-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ const props = defineProps<{
|
|||||||
}>();
|
}>();
|
||||||
|
|
||||||
const processedContent = computed(() => {
|
const processedContent = computed(() => {
|
||||||
return props.message.content.replace(/<user:(\d+)>/g, (match, userId) => {
|
return props.message.content.replace(
|
||||||
|
/<user:([0-9a-f-]+)>/g,
|
||||||
|
(match, userId) => {
|
||||||
// This is a placeholder for a more robust user lookup
|
// This is a placeholder for a more robust user lookup
|
||||||
return `<a href="${route('users.show', userId)}" class="text-blue-500 hover:underline">@user${userId}</a>`;
|
return `<a href="${route('users.show', userId)}" class="text-blue-500 hover:underline">@user${userId}</a>`;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useForm } from '@inertiajs/vue3';
|
import { Link } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import Chat from '@/components/Chat.vue';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamicId: number;
|
dynamicId: string;
|
||||||
ledgerId: number;
|
ledgerId: string;
|
||||||
ledgerAlignment?: string;
|
ledgerAlignment?: string;
|
||||||
mutations: Array<{
|
mutations: Array<{
|
||||||
id: number;
|
id: string; // Now a UUID
|
||||||
user_id: number;
|
user_id: number;
|
||||||
user: { name: string };
|
user: { name: string };
|
||||||
amount: number;
|
amount: number;
|
||||||
description: string;
|
description: string;
|
||||||
status: string;
|
status: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
chat: any;
|
|
||||||
media?: Array<{ id: number; url: string; mime_type: string }>;
|
|
||||||
}>;
|
}>;
|
||||||
participants?: Array<{
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
pivot?: { role: string };
|
|
||||||
}>;
|
|
||||||
isOwner: boolean;
|
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
(e: 'open-lightbox', url: string, mimeType: string): void;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
function updateStatus(mutationId: number, status: 'approved' | 'rejected') {
|
|
||||||
useForm({ status }).put(
|
|
||||||
route('dynamics.ledgers.mutations.update', {
|
|
||||||
dynamic: props.dynamicId,
|
|
||||||
ledger: props.ledgerId,
|
|
||||||
mutation: mutationId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function voidMutation(mutationId: number) {
|
|
||||||
useForm({}).put(
|
|
||||||
route('dynamics.ledgers.mutations.void', {
|
|
||||||
dynamic: props.dynamicId,
|
|
||||||
ledger: props.ledgerId,
|
|
||||||
mutation: mutationId,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isOwnerUser(userId: number): boolean {
|
|
||||||
const participant = props.participants?.find((p) => p.id === userId);
|
|
||||||
|
|
||||||
return participant?.pivot?.role === 'owner';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAmountClass(amount: number): string {
|
function getAmountClass(amount: number): string {
|
||||||
const alignment = props.ledgerAlignment || 'neutral';
|
const alignment = props.ledgerAlignment || 'neutral';
|
||||||
|
|
||||||
@@ -84,18 +45,15 @@ function getAmountClass(amount: number): string {
|
|||||||
<li
|
<li
|
||||||
v-for="mutation in mutations"
|
v-for="mutation in mutations"
|
||||||
:key="mutation.id"
|
:key="mutation.id"
|
||||||
class="c-mutation-list__item"
|
|
||||||
>
|
>
|
||||||
<div class="c-mutation-list__item-header">
|
<Link
|
||||||
<div>
|
:href="route('dynamics.ledgers.mutations.show', { dynamic: dynamicId, ledger: ledgerId, mutation: mutation.id })"
|
||||||
<span class="c-mutation-list__item-author">
|
class="c-mutation-list__item-link"
|
||||||
{{
|
>
|
||||||
isOwnerUser(mutation.user_id)
|
<div class="c-mutation-list__item-content">
|
||||||
? 'Added by'
|
<p class="c-mutation-list__item-desc">
|
||||||
: 'Suggested by'
|
{{ mutation.description }}
|
||||||
}}
|
</p>
|
||||||
{{ mutation.user.name }}
|
|
||||||
</span>
|
|
||||||
<div class="c-mutation-list__item-meta">
|
<div class="c-mutation-list__item-meta">
|
||||||
<span
|
<span
|
||||||
:class="getAmountClass(mutation.amount)"
|
:class="getAmountClass(mutation.amount)"
|
||||||
@@ -104,9 +62,7 @@ function getAmountClass(amount: number): string {
|
|||||||
{{ mutation.amount > 0 ? '+' : ''
|
{{ mutation.amount > 0 ? '+' : ''
|
||||||
}}{{ mutation.amount }}
|
}}{{ mutation.amount }}
|
||||||
</span>
|
</span>
|
||||||
<!-- Only show status badge if mutation was NOT auto-approved by an owner -->
|
|
||||||
<span
|
<span
|
||||||
v-if="!isOwnerUser(mutation.user_id)"
|
|
||||||
:class="{
|
:class="{
|
||||||
'c-mutation-list__item-status--pending':
|
'c-mutation-list__item-status--pending':
|
||||||
mutation.status === 'pending',
|
mutation.status === 'pending',
|
||||||
@@ -121,79 +77,7 @@ function getAmountClass(amount: number): string {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="c-mutation-list__item-time">
|
</Link>
|
||||||
{{ new Date(mutation.created_at).toLocaleString() }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<p class="c-mutation-list__item-desc">
|
|
||||||
{{ mutation.description }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<!-- Attached Mutation Proof Media -->
|
|
||||||
<div
|
|
||||||
v-if="mutation.media && mutation.media.length > 0"
|
|
||||||
class="c-mutation-list__media-list"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
v-for="item in mutation.media"
|
|
||||||
:key="item.id"
|
|
||||||
class="c-mutation-list__media-item"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
v-if="item.mime_type.startsWith('image/')"
|
|
||||||
:src="item.url"
|
|
||||||
class="c-mutation-list__media-img"
|
|
||||||
@click="
|
|
||||||
emit('open-lightbox', item.url, item.mime_type)
|
|
||||||
"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
v-else-if="item.mime_type.startsWith('video/')"
|
|
||||||
class="c-mutation-list__media-video-wrapper"
|
|
||||||
@click="
|
|
||||||
emit('open-lightbox', item.url, item.mime_type)
|
|
||||||
"
|
|
||||||
>
|
|
||||||
<video
|
|
||||||
:src="item.url"
|
|
||||||
class="c-mutation-list__media-video"
|
|
||||||
></video>
|
|
||||||
<div class="c-mutation-list__media-video-overlay">
|
|
||||||
▶
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Owner Approve/Reject Actions -->
|
|
||||||
<div
|
|
||||||
v-if="isOwner && (mutation.status === 'pending' || mutation.status === 'approved')"
|
|
||||||
class="c-mutation-list__actions"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
v-if="mutation.status === 'pending'"
|
|
||||||
@click="updateStatus(mutation.id, 'approved')"
|
|
||||||
class="c-mutation-list__approve-btn"
|
|
||||||
>
|
|
||||||
Approve
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="mutation.status === 'pending'"
|
|
||||||
@click="updateStatus(mutation.id, 'rejected')"
|
|
||||||
class="c-mutation-list__reject-btn"
|
|
||||||
>
|
|
||||||
Reject
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="mutation.status !== 'voided'"
|
|
||||||
@click="voidMutation(mutation.id)"
|
|
||||||
class="c-mutation-list__void-btn"
|
|
||||||
>
|
|
||||||
Void
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Chat :chat="mutation.chat" :dynamic-id="dynamicId" :participants="participants" />
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="mutations.length === 0" class="c-mutation-list__empty">
|
<div v-if="mutations.length === 0" class="c-mutation-list__empty">
|
||||||
@@ -214,23 +98,23 @@ function getAmountClass(amount: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__list {
|
.c-mutation-list__list {
|
||||||
@apply mt-4 space-y-4;
|
@apply mt-4 space-y-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item {
|
.c-mutation-list__item-link {
|
||||||
@apply overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800;
|
@apply block overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800 transition-all duration-200 hover:shadow-md hover:bg-gray-50 dark:hover:bg-gray-700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item-header {
|
.c-mutation-list__item-content {
|
||||||
@apply flex items-start justify-between;
|
@apply flex items-center justify-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item-author {
|
.c-mutation-list__item-desc {
|
||||||
@apply font-semibold;
|
@apply text-sm text-gray-600 dark:text-gray-400;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item-meta {
|
.c-mutation-list__item-meta {
|
||||||
@apply mt-1 flex items-center gap-2;
|
@apply flex items-center gap-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item-amount {
|
.c-mutation-list__item-amount {
|
||||||
@@ -265,54 +149,6 @@ function getAmountClass(amount: number): string {
|
|||||||
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
|
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-mutation-list__item-time {
|
|
||||||
@apply text-xs text-gray-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__item-desc {
|
|
||||||
@apply mt-3 text-sm text-gray-600 dark:text-gray-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-list {
|
|
||||||
@apply mt-3 flex flex-wrap gap-2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-item {
|
|
||||||
@apply max-w-[200px] overflow-hidden rounded-md border border-neutral-200 bg-black dark:border-neutral-700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-img {
|
|
||||||
@apply h-auto max-h-[150px] w-full cursor-pointer object-cover transition-opacity hover:opacity-90;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-video-wrapper {
|
|
||||||
@apply relative cursor-pointer transition-opacity hover:opacity-90;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-video {
|
|
||||||
@apply h-auto max-h-[150px] w-full;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__media-video-overlay {
|
|
||||||
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-2xl font-bold text-white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__actions {
|
|
||||||
@apply mt-3 flex gap-2 border-t border-neutral-100 pt-3 dark:border-neutral-700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__approve-btn {
|
|
||||||
@apply inline-flex cursor-pointer items-center rounded bg-green-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-green-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__reject-btn {
|
|
||||||
@apply inline-flex cursor-pointer items-center rounded bg-red-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-red-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__void-btn {
|
|
||||||
@apply inline-flex cursor-pointer items-center rounded bg-gray-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-gray-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-mutation-list__empty {
|
.c-mutation-list__empty {
|
||||||
@apply mt-4 text-gray-500;
|
@apply mt-4 text-gray-500;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useForm } from '@inertiajs/vue3';
|
||||||
|
import { Paperclip } from '@lucide/vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
chatId: number;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null);
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
content: '',
|
||||||
|
media: [] as File[],
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleFileChange(event: Event) {
|
||||||
|
const files = (event.target as HTMLInputElement).files;
|
||||||
|
|
||||||
|
if (files) {
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
form.media.push(files[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFile(index: number) {
|
||||||
|
form.media.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
form.post(route('chats.messages.store', props.chatId), {
|
||||||
|
preserveScroll: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
form.reset();
|
||||||
|
|
||||||
|
if (fileInput.value) {
|
||||||
|
fileInput.value.value = '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<form @submit.prevent="submit" class="c-chat__form">
|
||||||
|
<div class="c-chat__form-group">
|
||||||
|
<label for="content" class="c-chat__label">Message</label>
|
||||||
|
<textarea
|
||||||
|
v-model="form.content"
|
||||||
|
id="content"
|
||||||
|
rows="3"
|
||||||
|
class="c-chat__textarea"
|
||||||
|
placeholder="Type a message... (Press Enter to send, Shift+Enter for newline)"
|
||||||
|
@keydown.enter.exact.prevent="submit"
|
||||||
|
></textarea>
|
||||||
|
<div v-if="form.errors.content" class="c-chat__error">
|
||||||
|
{{ form.errors.content }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Attachment Button & Hidden Input -->
|
||||||
|
<div class="c-chat__attachment-container">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="fileInput?.click()"
|
||||||
|
class="c-chat__attach-btn"
|
||||||
|
>
|
||||||
|
<Paperclip class="c-chat__attach-icon" />
|
||||||
|
Attach Photos/Videos
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
ref="fileInput"
|
||||||
|
type="file"
|
||||||
|
multiple
|
||||||
|
accept="image/*,video/*"
|
||||||
|
class="hidden"
|
||||||
|
@change="handleFileChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Previews List -->
|
||||||
|
<div v-if="form.media.length > 0" class="c-chat__preview-list">
|
||||||
|
<div
|
||||||
|
v-for="(file, index) in form.media"
|
||||||
|
:key="index"
|
||||||
|
class="c-chat__preview-item"
|
||||||
|
>
|
||||||
|
<span class="c-chat__preview-name">{{
|
||||||
|
file.name
|
||||||
|
}}</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
@click="removeFile(index)"
|
||||||
|
class="c-chat__preview-remove"
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="c-chat__submit-box">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
:disabled="form.processing"
|
||||||
|
class="c-chat__button"
|
||||||
|
>
|
||||||
|
Send
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { route } from 'ziggy-js';
|
||||||
|
import { Info } from '@lucide/vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
message: {
|
||||||
|
id: number;
|
||||||
|
content: string;
|
||||||
|
created_at: string;
|
||||||
|
subject_id?: number | null;
|
||||||
|
subject_type?: string | null;
|
||||||
|
subject?: any;
|
||||||
|
};
|
||||||
|
participantsById: Record<
|
||||||
|
number,
|
||||||
|
{
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
pivot?: { display_name: string | null } | null;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
dynamicId: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
function formatTimestamp(isoString: string): { full: string; time: string } {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
return {
|
||||||
|
full: date.toLocaleString(),
|
||||||
|
time: date.toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedContent = computed(() => {
|
||||||
|
let content = props.message.content;
|
||||||
|
|
||||||
|
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
||||||
|
const userRegex = /<user:([0-9a-f-]+)>/g;
|
||||||
|
content = content.replace(userRegex, (match, userId) => {
|
||||||
|
const user = props.participantsById[(userId)];
|
||||||
|
if (user) {
|
||||||
|
const url = route('dynamics.users.show', [props.dynamicId, (userId)]);
|
||||||
|
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
||||||
|
user.pivot?.display_name ?? user.name
|
||||||
|
}</a>`;
|
||||||
|
}
|
||||||
|
return `User #${userId}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Link subjects if found in the text
|
||||||
|
if (props.message.subject_id && props.message.subject_type) {
|
||||||
|
if (
|
||||||
|
props.message.subject_type === 'mutation' ||
|
||||||
|
props.message.subject_type === 'ledger'
|
||||||
|
) {
|
||||||
|
const ledgerId =
|
||||||
|
props.message.subject_type === 'mutation'
|
||||||
|
? props.message.subject?.ledger_id
|
||||||
|
: props.message.subject?.id;
|
||||||
|
|
||||||
|
const ledgerName =
|
||||||
|
props.message.subject_type === 'mutation'
|
||||||
|
? props.message.subject?.ledger?.name
|
||||||
|
: props.message.subject?.name;
|
||||||
|
|
||||||
|
if (ledgerId && ledgerName) {
|
||||||
|
const ledgerUrl = route('dynamics.ledgers.show', [
|
||||||
|
props.dynamicId,
|
||||||
|
ledgerId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const escapedName = ledgerName.replace(
|
||||||
|
/[-\/\\^$*+?.()|[\]{}]/g,
|
||||||
|
'\\$&',
|
||||||
|
);
|
||||||
|
|
||||||
|
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
||||||
|
content = content.replace(
|
||||||
|
nameRegex,
|
||||||
|
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="c-chat__system-inner">
|
||||||
|
<Info class="c-chat__system-icon" />
|
||||||
|
<span
|
||||||
|
class="c-chat__system-text"
|
||||||
|
v-html="parsedContent"
|
||||||
|
></span>
|
||||||
|
<span
|
||||||
|
class="c-chat__system-time"
|
||||||
|
:title="formatTimestamp(message.created_at).full"
|
||||||
|
>
|
||||||
|
{{ formatTimestamp(message.created_at).time }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
message: {
|
||||||
|
id: number;
|
||||||
|
user: { id: number; name: string } | null;
|
||||||
|
content: string;
|
||||||
|
created_at: string;
|
||||||
|
subject_id?: number | null;
|
||||||
|
subject_type?: string | null;
|
||||||
|
subject?: any;
|
||||||
|
media?: Array<{
|
||||||
|
id: number;
|
||||||
|
url: string;
|
||||||
|
file_name: string;
|
||||||
|
mime_type: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
participantsById: Record<
|
||||||
|
number,
|
||||||
|
{
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
pivot?: { display_name: string | null } | null;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
dynamicId: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'open-lightbox', url: string, mimeType: string): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
function formatTimestamp(isoString: string): { full: string; time: string } {
|
||||||
|
const date = new Date(isoString);
|
||||||
|
return {
|
||||||
|
full: date.toLocaleString(),
|
||||||
|
time: date.toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedContent = computed(() => {
|
||||||
|
let content = props.message.content;
|
||||||
|
|
||||||
|
// 1. Replace <user:id> placeholders with links to their dynamic profile
|
||||||
|
const userRegex = /<user:([0-9a-f-]+)>/g;
|
||||||
|
content = content.replace(userRegex, (match, userId) => {
|
||||||
|
const user = props.participantsById[(userId)];
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
const url = route('dynamics.users.show', [
|
||||||
|
props.dynamicId,
|
||||||
|
(userId),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
|
||||||
|
user.pivot?.display_name ?? user.name
|
||||||
|
}</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `User #${userId}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Link subjects if found in the text
|
||||||
|
if (props.message.subject_id && props.message.subject_type) {
|
||||||
|
if (
|
||||||
|
props.message.subject_type === 'mutation' ||
|
||||||
|
props.message.subject_type === 'ledger'
|
||||||
|
) {
|
||||||
|
const ledgerId =
|
||||||
|
props.message.subject_type === 'mutation'
|
||||||
|
? props.message.subject?.ledger_id
|
||||||
|
: props.message.subject?.id;
|
||||||
|
|
||||||
|
const ledgerName =
|
||||||
|
props.message.subject_type === 'mutation'
|
||||||
|
? props.message.subject?.ledger?.name
|
||||||
|
: props.message.subject?.name;
|
||||||
|
|
||||||
|
if (ledgerId && ledgerName) {
|
||||||
|
const ledgerUrl = route('dynamics.ledgers.show', [
|
||||||
|
props.dynamicId,
|
||||||
|
ledgerId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const escapedName = ledgerName.replace(
|
||||||
|
/[-\/\\^$*+?.()|[\]{}]/g,
|
||||||
|
'\\$&',
|
||||||
|
);
|
||||||
|
|
||||||
|
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
|
||||||
|
content = content.replace(
|
||||||
|
nameRegex,
|
||||||
|
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return content;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="c-chat__message-header">
|
||||||
|
<span class="c-chat__message-author">{{ message.user?.name }}</span>
|
||||||
|
<span
|
||||||
|
class="c-chat__message-time"
|
||||||
|
:title="formatTimestamp(message.created_at).full"
|
||||||
|
>
|
||||||
|
{{ formatTimestamp(message.created_at).time }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p class="c-chat__message-text" v-html="parsedContent"></p>
|
||||||
|
|
||||||
|
<!-- Attached Media Display -->
|
||||||
|
<div
|
||||||
|
v-if="message.media && message.media.length > 0"
|
||||||
|
class="c-chat__message-media"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="item in message.media"
|
||||||
|
:key="item.id"
|
||||||
|
class="c-chat__media-item"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="item.mime_type.startsWith('image/')"
|
||||||
|
:src="item.url"
|
||||||
|
:alt="item.file_name"
|
||||||
|
class="c-chat__image cursor-pointer transition-opacity hover:opacity-90"
|
||||||
|
@click="emit('open-lightbox', item.url, item.mime_type)"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-else-if="item.mime_type.startsWith('video/')"
|
||||||
|
class="relative cursor-pointer transition-opacity hover:opacity-90"
|
||||||
|
@click="emit('open-lightbox', item.url, item.mime_type)"
|
||||||
|
>
|
||||||
|
<video :src="item.url" class="c-chat__video"></video>
|
||||||
|
<div class="c-chat__play-overlay">▶</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -2,16 +2,22 @@
|
|||||||
import AppLayout from '@/layouts/app/AppSidebarLayout.vue';
|
import AppLayout from '@/layouts/app/AppSidebarLayout.vue';
|
||||||
import type { BreadcrumbItem } from '@/types';
|
import type { BreadcrumbItem } from '@/types';
|
||||||
import { usePushNotifications } from '@/composables/usePushNotifications';
|
import { usePushNotifications } from '@/composables/usePushNotifications';
|
||||||
|
import { computed } from 'vue';
|
||||||
|
import { usePage } from '@inertiajs/vue3';
|
||||||
|
|
||||||
const { breadcrumbs = [] } = defineProps<{
|
const props = defineProps<{
|
||||||
breadcrumbs?: BreadcrumbItem[];
|
breadcrumbs?: BreadcrumbItem[];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const resolvedBreadcrumbs = computed(() => {
|
||||||
|
return props.breadcrumbs || (usePage().props.breadcrumbs as BreadcrumbItem[]) || [];
|
||||||
|
});
|
||||||
|
|
||||||
const { isSubscribed, subscribe, unsubscribe } = usePushNotifications();
|
const { isSubscribed, subscribe, unsubscribe } = usePushNotifications();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AppLayout :breadcrumbs="breadcrumbs">
|
<AppLayout :breadcrumbs="resolvedBreadcrumbs">
|
||||||
<slot />
|
<slot />
|
||||||
<div class="fixed bottom-4 right-4">
|
<div class="fixed bottom-4 right-4">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ function formatTime(isoString: string): string {
|
|||||||
>
|
>
|
||||||
<div class="c-dashboard__card-header">
|
<div class="c-dashboard__card-header">
|
||||||
<div class="c-dashboard__entity-meta">
|
<div class="c-dashboard__entity-meta">
|
||||||
<span class="c-dashboard__badge-type c-dashboard__badge-type--dynamic">
|
<span
|
||||||
|
class="c-dashboard__badge-type c-dashboard__badge-type--dynamic"
|
||||||
|
>
|
||||||
Dynamic
|
Dynamic
|
||||||
</span>
|
</span>
|
||||||
<span class="c-dashboard__unread-count">
|
<span class="c-dashboard__unread-count">
|
||||||
@@ -102,9 +104,7 @@ function formatTime(isoString: string): string {
|
|||||||
v-if="dynamic.new_activities.length > 0"
|
v-if="dynamic.new_activities.length > 0"
|
||||||
class="c-dashboard__divider"
|
class="c-dashboard__divider"
|
||||||
>
|
>
|
||||||
<span class="c-dashboard__divider-text"
|
<span class="c-dashboard__divider-text">NEW</span>
|
||||||
>NEW</span
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- New / Unread Activities -->
|
<!-- New / Unread Activities -->
|
||||||
|
|||||||
@@ -2,22 +2,26 @@
|
|||||||
import { Head, useForm } from '@inertiajs/vue3';
|
import { Head, useForm } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: {
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Create',
|
||||||
|
href: route('dynamics.create'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
name: '',
|
name: '',
|
||||||
rules: '',
|
rules: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Create',
|
|
||||||
href: route('dynamics.create'),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
form.post(route('dynamics.store'));
|
form.post(route('dynamics.store'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,17 @@
|
|||||||
import { Head, Link } from '@inertiajs/vue3';
|
import { Head, Link } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: {
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
dynamics: Array<{
|
dynamics: Array<{
|
||||||
id: string;
|
id: string;
|
||||||
@@ -9,13 +20,6 @@ defineProps<{
|
|||||||
rules: string;
|
rules: string;
|
||||||
}>;
|
}>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -110,6 +114,7 @@ const breadcrumbs = [
|
|||||||
|
|
||||||
.c-dynamics-index__item-desc {
|
.c-dynamics-index__item-desc {
|
||||||
@apply mt-2 text-sm text-gray-600 dark:text-gray-400;
|
@apply mt-2 text-sm text-gray-600 dark:text-gray-400;
|
||||||
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-dynamics-index__empty {
|
.c-dynamics-index__empty {
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm } from '@inertiajs/vue3';
|
import { Head, useForm } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Invite User',
|
||||||
|
href: route('dynamics.invitations.create', props.dynamic.id),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamic: {
|
dynamic: {
|
||||||
@@ -15,21 +33,6 @@ const form = useForm({
|
|||||||
role: 'participant',
|
role: 'participant',
|
||||||
});
|
});
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Invite User',
|
|
||||||
href: route('dynamics.invitations.create', props.dynamic.id),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
form.post(route('dynamics.invitations.store', props.dynamic.id), {
|
form.post(route('dynamics.invitations.store', props.dynamic.id), {
|
||||||
onSuccess: () => form.reset(),
|
onSuccess: () => form.reset(),
|
||||||
|
|||||||
@@ -3,25 +3,25 @@ import { Head, Link } from '@inertiajs/vue3';
|
|||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
layout: {
|
layout: (props: any) => ({
|
||||||
breadcrumbs: [
|
breadcrumbs: [
|
||||||
{
|
{
|
||||||
name: 'Dynamics',
|
title: 'Dynamics',
|
||||||
href: route('dynamics.index'),
|
href: route('dynamics.index'),
|
||||||
isCurrent: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'dynamic.name',
|
title: props.dynamic.name,
|
||||||
href: 'route(\'dynamics.show\', dynamic.id)',
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
isCurrent: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'participant.display_name',
|
title: props.participant.display_name ?? props.participant.name,
|
||||||
href: 'route(\'dynamics.users.show\', { dynamic: dynamic.id, user: participant.id })',
|
href: route('dynamics.users.show', [
|
||||||
isCurrent: true,
|
props.dynamic.id,
|
||||||
|
props.participant.id,
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -44,21 +44,6 @@ const props = defineProps<{
|
|||||||
ledger: { id: number; name: string };
|
ledger: { id: number; name: string };
|
||||||
}>;
|
}>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.participant.display_name ?? props.participant.name,
|
|
||||||
href: route('dynamics.users.show', [props.dynamic.id, props.participant.id]),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -67,7 +52,10 @@ const breadcrumbs = [
|
|||||||
<div class="c-participant-show">
|
<div class="c-participant-show">
|
||||||
<div class="c-participant-show__container">
|
<div class="c-participant-show__container">
|
||||||
<h2 class="c-participant-show__title">
|
<h2 class="c-participant-show__title">
|
||||||
Activity for {{ participant.display_name ?? participant.name }} ({{ participant.role.toUpperCase() }}) in {{ dynamic.name }}
|
Activity for
|
||||||
|
{{ participant.display_name ?? participant.name }} ({{
|
||||||
|
participant.role.toUpperCase()
|
||||||
|
}}) in {{ dynamic.name }}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="c-participant-show__activity-list">
|
<div class="c-participant-show__activity-list">
|
||||||
@@ -76,16 +64,45 @@ const breadcrumbs = [
|
|||||||
:key="mutation.id"
|
:key="mutation.id"
|
||||||
class="c-participant-show__activity-item"
|
class="c-participant-show__activity-item"
|
||||||
>
|
>
|
||||||
<Link :href="route('dynamics.ledgers.show', [dynamic.id, mutation.ledger.id])" class="block">
|
<Link
|
||||||
|
:href="
|
||||||
|
route('dynamics.ledgers.show', [
|
||||||
|
dynamic.id,
|
||||||
|
mutation.ledger.id,
|
||||||
|
])
|
||||||
|
"
|
||||||
|
class="block"
|
||||||
|
>
|
||||||
<div class="c-participant-show__activity-meta">
|
<div class="c-participant-show__activity-meta">
|
||||||
<span class="c-participant-show__activity-time">
|
<span class="c-participant-show__activity-time">
|
||||||
{{ new Date(mutation.created_at).toLocaleString() }}
|
{{
|
||||||
|
new Date(
|
||||||
|
mutation.created_at,
|
||||||
|
).toLocaleString()
|
||||||
|
}}
|
||||||
</span>
|
</span>
|
||||||
<span class="font-semibold ml-2" :class="mutation.amount > 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'">
|
<span
|
||||||
{{ mutation.amount > 0 ? '+' : '' }}{{ mutation.amount }}
|
class="ml-2 font-semibold"
|
||||||
|
:class="
|
||||||
|
mutation.amount > 0
|
||||||
|
? 'text-green-600 dark:text-green-400'
|
||||||
|
: 'text-red-600 dark:text-red-400'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
{{ mutation.amount > 0 ? '+' : ''
|
||||||
|
}}{{ mutation.amount }}
|
||||||
</span>
|
</span>
|
||||||
<span class="text-neutral-400 ml-2">on {{ mutation.ledger.name }}</span>
|
<span class="ml-2 text-neutral-400"
|
||||||
<span class="uppercase text-xs px-1.5 py-0.5 rounded ml-auto" :class="mutation.status === 'approved' ? 'bg-green-100 text-green-700 dark:bg-green-950/30 dark:text-green-400' : 'bg-yellow-100 text-yellow-700 dark:bg-yellow-950/30 dark:text-yellow-400'">
|
>on {{ mutation.ledger.name }}</span
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="ml-auto rounded px-1.5 py-0.5 text-xs uppercase"
|
||||||
|
:class="
|
||||||
|
mutation.status === 'approved'
|
||||||
|
? 'bg-green-100 text-green-700 dark:bg-green-950/30 dark:text-green-400'
|
||||||
|
: 'bg-yellow-100 text-yellow-700 dark:bg-yellow-950/30 dark:text-yellow-400'
|
||||||
|
"
|
||||||
|
>
|
||||||
{{ mutation.status }}
|
{{ mutation.status }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -94,8 +111,12 @@ const breadcrumbs = [
|
|||||||
</p>
|
</p>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="mutations.length === 0" class="text-neutral-500 text-sm">
|
<div
|
||||||
No mutations recorded for this participant in this Dynamic yet.
|
v-if="mutations.length === 0"
|
||||||
|
class="text-sm text-neutral-500"
|
||||||
|
>
|
||||||
|
No mutations recorded for this participant in this Dynamic
|
||||||
|
yet.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -135,6 +156,6 @@ const breadcrumbs = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c-participant-show__activity-desc {
|
.c-participant-show__activity-desc {
|
||||||
@apply text-sm text-neutral-600 dark:text-neutral-400 mt-1;
|
@apply mt-1 text-sm text-neutral-600 dark:text-neutral-400;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,7 +1,25 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm, Link as InertiaLink } from '@inertiajs/vue3';
|
import { Head, useForm, Link as InertiaLink } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Settings',
|
||||||
|
href: route('dynamics.edit', props.dynamic.id),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamic: {
|
dynamic: {
|
||||||
@@ -16,21 +34,6 @@ const form = useForm({
|
|||||||
rules: props.dynamic.rules,
|
rules: props.dynamic.rules,
|
||||||
});
|
});
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Settings',
|
|
||||||
href: route('dynamics.edit', props.dynamic.id),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
form.patch(route('dynamics.update', props.dynamic.id));
|
form.patch(route('dynamics.update', props.dynamic.id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,18 @@ import { Head, Link as InertiaLink } from '@inertiajs/vue3';
|
|||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
layout: {
|
layout: (props: any) => ({
|
||||||
breadcrumbs: [
|
breadcrumbs: [
|
||||||
{
|
{
|
||||||
name: 'Dynamics',
|
title: 'Dynamics',
|
||||||
href: route('dynamics.index'),
|
href: route('dynamics.index'),
|
||||||
isCurrent: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'dynamic.name',
|
title: props.dynamic.name,
|
||||||
href: 'route(\'dynamics.show\', dynamic.id)',
|
href: route('dynamics.show', props.dynamic.uuid),
|
||||||
isCurrent: true,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -45,18 +43,6 @@ const props = defineProps<{
|
|||||||
update: boolean;
|
update: boolean;
|
||||||
}
|
}
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,30 +1,33 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm } from '@inertiajs/vue3';
|
import { Head, useForm } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
import CreateLedgerForm from '@/components/CreateLedgerForm.vue';
|
import CreateLedgerForm from '@/components/CreateLedgerForm.vue';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Create Ledger',
|
||||||
|
href: route('dynamics.ledgers.create', props.dynamic.id),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamic: {
|
dynamic: {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Create Ledger',
|
|
||||||
href: route('dynamics.ledgers.create', props.dynamic.id),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,7 +1,29 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm } from '@inertiajs/vue3';
|
import { Head, useForm, Link } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.ledger.name,
|
||||||
|
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Edit',
|
||||||
|
href: route('dynamics.ledgers.edit', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamic: {
|
dynamic: {
|
||||||
@@ -12,33 +34,16 @@ const props = defineProps<{
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
rules: string;
|
rules: string;
|
||||||
|
alignment: 'positive' | 'neutral' | 'negative';
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
name: props.ledger.name,
|
name: props.ledger.name,
|
||||||
rules: props.ledger.rules,
|
rules: props.ledger.rules,
|
||||||
|
alignment: props.ledger.alignment,
|
||||||
});
|
});
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.ledger.name,
|
|
||||||
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Edit',
|
|
||||||
href: route('dynamics.ledgers.edit', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
form.put(route('dynamics.ledgers.update', [props.dynamic.id, props.ledger.id]));
|
form.put(route('dynamics.ledgers.update', [props.dynamic.id, props.ledger.id]));
|
||||||
}
|
}
|
||||||
@@ -47,7 +52,6 @@ function submit() {
|
|||||||
<template>
|
<template>
|
||||||
<Head title="Edit Ledger" />
|
<Head title="Edit Ledger" />
|
||||||
|
|
||||||
<AppLayout :breadcrumbs="breadcrumbs">
|
|
||||||
<div class="c-ledger-edit">
|
<div class="c-ledger-edit">
|
||||||
<div class="c-ledger-edit__container">
|
<div class="c-ledger-edit__container">
|
||||||
<div class="c-ledger-edit__card">
|
<div class="c-ledger-edit__card">
|
||||||
@@ -67,6 +71,25 @@ function submit() {
|
|||||||
<textarea v-model="form.rules" id="rules" rows="4" class="c-ledger-edit__textarea"></textarea>
|
<textarea v-model="form.rules" id="rules" rows="4" class="c-ledger-edit__textarea"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="c-ledger-edit__field">
|
||||||
|
<label for="alignment" class="c-ledger-edit__label">Alignment</label>
|
||||||
|
<select
|
||||||
|
v-model="form.alignment"
|
||||||
|
id="alignment"
|
||||||
|
class="c-ledger-edit__select"
|
||||||
|
>
|
||||||
|
<option value="positive">
|
||||||
|
Positive (Higher Score is Better)
|
||||||
|
</option>
|
||||||
|
<option value="neutral">
|
||||||
|
Neutral (Frictionless / Standard)
|
||||||
|
</option>
|
||||||
|
<option value="negative">
|
||||||
|
Negative (Lower Score is Better / Demerits)
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="c-ledger-edit__actions">
|
<div class="c-ledger-edit__actions">
|
||||||
<button type="submit" :disabled="form.processing" class="c-ledger-edit__submit-btn">
|
<button type="submit" :disabled="form.processing" class="c-ledger-edit__submit-btn">
|
||||||
Save
|
Save
|
||||||
@@ -85,7 +108,6 @@ function submit() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AppLayout>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -128,13 +150,18 @@ function submit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.c-ledger-edit__textarea {
|
.c-ledger-edit__textarea {
|
||||||
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-ledger-edit__select {
|
||||||
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-ledger-edit__actions {
|
.c-ledger-edit__actions {
|
||||||
@apply flex items-center gap-4;
|
@apply mt-6 flex items-center justify-end gap-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.c-ledger-edit__submit-btn {
|
.c-ledger-edit__submit-btn {
|
||||||
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Head, useForm } from '@inertiajs/vue3';
|
||||||
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.ledger.name,
|
||||||
|
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Predefined Mutations',
|
||||||
|
href: route('dynamics.ledgers.predefined-mutations.index', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Edit',
|
||||||
|
href: route('dynamics.ledgers.predefined-mutations.edit', [props.dynamic.id, props.ledger.id, props.predefined_mutation.uuid]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
dynamic: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
ledger: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
predefined_mutation: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
amount: number;
|
||||||
|
uuid: string;
|
||||||
|
};
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
name: props.predefined_mutation.name,
|
||||||
|
description: props.predefined_mutation.description,
|
||||||
|
amount: props.predefined_mutation.amount,
|
||||||
|
});
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
form.put(route('dynamics.ledgers.predefined-mutations.update', [props.dynamic.id, props.ledger.id, props.predefined_mutation.uuid]));
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Head title="Edit Predefined Mutation" />
|
||||||
|
|
||||||
|
<div class="c-predefined-mutation-edit">
|
||||||
|
<div class="c-predefined-mutation-edit__container">
|
||||||
|
<div class="c-predefined-mutation-edit__card">
|
||||||
|
<div class="c-predefined-mutation-edit__body">
|
||||||
|
<h3 class="c-predefined-mutation-edit__title">
|
||||||
|
Edit {{ predefined_mutation.name }} on {{ ledger.name }}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<form @submit.prevent="submit" class="c-predefined-mutation-edit__form">
|
||||||
|
<div class="c-predefined-mutation-edit__field">
|
||||||
|
<label for="name" class="c-predefined-mutation-edit__label">Name</label>
|
||||||
|
<input v-model="form.name" id="name" type="text" class="c-predefined-mutation-edit__input" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="c-predefined-mutation-edit__field">
|
||||||
|
<label for="description" class="c-predefined-mutation-edit__label">Description</label>
|
||||||
|
<textarea v-model="form.description" id="description" rows="4" class="c-predefined-mutation-edit__textarea"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="c-predefined-mutation-edit__field">
|
||||||
|
<label for="amount" class="c-predefined-mutation-edit__label">Amount</label>
|
||||||
|
<input v-model="form.amount" id="amount" type="number" class="c-predefined-mutation-edit__input" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="c-predefined-mutation-edit__actions">
|
||||||
|
<button type="submit" :disabled="form.processing" class="c-predefined-mutation-edit__submit-btn">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
@reference "../../../../css/app.css";
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit {
|
||||||
|
@apply py-12;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__container {
|
||||||
|
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__card {
|
||||||
|
@apply overflow-hidden bg-white shadow-sm sm:rounded-lg dark:bg-gray-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__body {
|
||||||
|
@apply p-6 text-gray-900 dark:text-gray-100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__title {
|
||||||
|
@apply text-lg font-medium;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__form {
|
||||||
|
@apply mt-6 space-y-6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__field {
|
||||||
|
@apply block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__label {
|
||||||
|
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__input {
|
||||||
|
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__textarea {
|
||||||
|
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__actions {
|
||||||
|
@apply flex items-center gap-4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutation-edit__submit-btn {
|
||||||
|
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,9 +1,31 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm } from '@inertiajs/vue3';
|
import { Head, useForm, Link as InertiaLink } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
import { defineProps } from 'vue';
|
import { defineProps } from 'vue';
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{
|
||||||
|
title: 'Dynamics',
|
||||||
|
href: route('dynamics.index'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.dynamic.name,
|
||||||
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: props.ledger.name,
|
||||||
|
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Predefined Mutations',
|
||||||
|
href: route('dynamics.ledgers.predefined-mutations.index', [props.dynamic.id, props.ledger.id]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
dynamic: {
|
dynamic: {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -18,6 +40,7 @@ const props = defineProps<{
|
|||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
|
uuid: string;
|
||||||
}>;
|
}>;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -27,36 +50,23 @@ const form = useForm({
|
|||||||
amount: 0,
|
amount: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.ledger.name,
|
|
||||||
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Predefined Mutations',
|
|
||||||
href: route('dynamics.ledgers.predefined-mutations.index', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
form.post(route('dynamics.ledgers.predefined-mutations.store', [props.dynamic.id, props.ledger.id]), {
|
form.post(route('dynamics.ledgers.predefined-mutations.store', [props.dynamic.id, props.ledger.id]), {
|
||||||
onSuccess: () => form.reset(),
|
onSuccess: () => form.reset(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function destroy(uuid: string) {
|
||||||
|
if (confirm('Are you sure you want to delete this predefined mutation?')) {
|
||||||
|
const deleteForm = useForm({});
|
||||||
|
deleteForm.delete(route('dynamics.ledgers.predefined-mutations.destroy', [props.dynamic.id, props.ledger.id, uuid]));
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Head title="Predefined Mutations" />
|
<Head title="Predefined Mutations" />
|
||||||
|
|
||||||
<AppLayout :breadcrumbs="breadcrumbs">
|
|
||||||
<div class="c-predefined-mutations">
|
<div class="c-predefined-mutations">
|
||||||
<div class="c-predefined-mutations__container">
|
<div class="c-predefined-mutations__container">
|
||||||
<div class="c-predefined-mutations__card">
|
<div class="c-predefined-mutations__card">
|
||||||
@@ -79,9 +89,25 @@ function submit() {
|
|||||||
{{ mutation.description }}
|
{{ mutation.description }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center gap-6">
|
||||||
<div class="c-predefined-mutations__item-amount">
|
<div class="c-predefined-mutations__item-amount">
|
||||||
{{ mutation.amount }}
|
{{ mutation.amount }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<InertiaLink
|
||||||
|
:href="route('dynamics.ledgers.predefined-mutations.edit', [dynamic.id, ledger.id, mutation.uuid])"
|
||||||
|
class="c-predefined-mutations__edit-btn"
|
||||||
|
>
|
||||||
|
Edit
|
||||||
|
</InertiaLink>
|
||||||
|
<button
|
||||||
|
@click="destroy(mutation.uuid)"
|
||||||
|
class="c-predefined-mutations__delete-btn"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,7 +179,6 @@ function submit() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</AppLayout>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -203,6 +228,14 @@ function submit() {
|
|||||||
@apply text-lg font-semibold;
|
@apply text-lg font-semibold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutations__edit-btn {
|
||||||
|
@apply inline-flex cursor-pointer items-center rounded border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-semibold text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:hover:bg-gray-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-predefined-mutations__delete-btn {
|
||||||
|
@apply inline-flex cursor-pointer items-center rounded border border-transparent bg-red-600 px-2.5 py-1.5 text-xs font-semibold text-white shadow-sm hover:bg-red-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2;
|
||||||
|
}
|
||||||
|
|
||||||
.c-predefined-mutations__form {
|
.c-predefined-mutations__form {
|
||||||
@apply mt-6 space-y-6;
|
@apply mt-6 space-y-6;
|
||||||
}
|
}
|
||||||
@@ -223,10 +256,6 @@ function submit() {
|
|||||||
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-predefined-mutations__select {
|
|
||||||
@apply mt-1 block w-full rounded-md border-gray-300 bg-white p-2 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__actions {
|
.c-predefined-mutations__actions {
|
||||||
@apply flex items-center gap-4;
|
@apply flex items-center gap-4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,25 +8,22 @@ import Chat from '@/components/Chat.vue';
|
|||||||
import MutationList from '@/components/MutationList.vue';
|
import MutationList from '@/components/MutationList.vue';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
layout: {
|
layout: (props: any) => ({
|
||||||
breadcrumbs: [
|
breadcrumbs: [
|
||||||
{
|
{
|
||||||
name: 'Dynamics',
|
title: 'Dynamics',
|
||||||
href: route('dynamics.index'),
|
href: route('dynamics.index'),
|
||||||
isCurrent: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'dynamic.name',
|
title: props.dynamic.name,
|
||||||
href: 'route(\'dynamics.show\', dynamic.id)',
|
href: route('dynamics.show', props.dynamic.id),
|
||||||
isCurrent: false,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ledger.name',
|
title: props.ledger.name,
|
||||||
href: 'route(\'dynamics.ledgers.show\', { dynamic: dynamic.id, ledger: ledger.id })',
|
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
||||||
isCurrent: true,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
@@ -46,7 +43,14 @@ const props = defineProps<{
|
|||||||
score: number;
|
score: number;
|
||||||
rules: string;
|
rules: string;
|
||||||
alignment: string;
|
alignment: string;
|
||||||
|
status: string;
|
||||||
media?: Array<{ id: number; url: string; mime_type: string }>;
|
media?: Array<{ id: number; url: string; mime_type: string }>;
|
||||||
|
predefined_mutations?: Array<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
amount: number;
|
||||||
|
}>;
|
||||||
mutations: Array<{
|
mutations: Array<{
|
||||||
id: number;
|
id: number;
|
||||||
user_id: number;
|
user_id: number;
|
||||||
@@ -59,31 +63,16 @@ const props = defineProps<{
|
|||||||
media?: Array<{ id: number; url: string; mime_type: string }>;
|
media?: Array<{ id: number; url: string; mime_type: string }>;
|
||||||
}>;
|
}>;
|
||||||
};
|
};
|
||||||
isOwner: boolean;
|
can: {
|
||||||
|
update: boolean;
|
||||||
|
close: boolean;
|
||||||
|
};
|
||||||
messages: {
|
messages: {
|
||||||
data: Array<any>;
|
data: Array<any>;
|
||||||
next_page_url: string | null;
|
next_page_url: string | null;
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.ledger.name,
|
|
||||||
href: route('dynamics.ledgers.show', {
|
|
||||||
dynamic: props.dynamic.id,
|
|
||||||
ledger: props.ledger.id,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// Lightbox Modal state
|
// Lightbox Modal state
|
||||||
const activeLightboxUrl = ref<string | null>(null);
|
const activeLightboxUrl = ref<string | null>(null);
|
||||||
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
const activeLightboxType = ref<'image' | 'video' | null>(null);
|
||||||
@@ -205,7 +194,7 @@ function isOwnerUser(userId: number): boolean {
|
|||||||
{{ ledger.rules }}
|
{{ ledger.rules }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isOwner" class="flex flex-col gap-2">
|
<div v-if="can.update" class="flex flex-col gap-2">
|
||||||
<InertiaLink
|
<InertiaLink
|
||||||
:href="route('dynamics.ledgers.predefined-mutations.index', [dynamic.id, ledger.id])"
|
:href="route('dynamics.ledgers.predefined-mutations.index', [dynamic.id, ledger.id])"
|
||||||
class="c-ledger-show__manage-btn"
|
class="c-ledger-show__manage-btn"
|
||||||
@@ -279,7 +268,7 @@ function isOwnerUser(userId: number): boolean {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Mutation Form Component -->
|
<!-- Add Mutation Form Component -->
|
||||||
<AddMutationForm :dynamic-id="dynamic.id" :ledger-id="ledger.id" />
|
<AddMutationForm :dynamic-id="dynamic.id" :ledger-id="ledger.id" :predefined-mutations="ledger.predefined_mutations" />
|
||||||
|
|
||||||
<!-- Mutation List Component -->
|
<!-- Mutation List Component -->
|
||||||
<MutationList
|
<MutationList
|
||||||
@@ -287,12 +276,12 @@ function isOwnerUser(userId: number): boolean {
|
|||||||
:ledger-id="ledger.id"
|
:ledger-id="ledger.id"
|
||||||
:mutations="ledger.mutations"
|
:mutations="ledger.mutations"
|
||||||
:participants="dynamic.participants"
|
:participants="dynamic.participants"
|
||||||
:is-owner="isOwner"
|
:can-update="can.update"
|
||||||
:ledger-alignment="ledger.alignment"
|
:ledger-alignment="ledger.alignment"
|
||||||
@open-lightbox="openLightbox"
|
@open-lightbox="openLightbox"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Chat :chat="dynamic.chat" :initial-messages="messages" :participants="dynamic.participants" :dynamic-id="dynamic.id" />
|
<Chat :chat="dynamic.chat" :initial-messages="messages" :participants="dynamic.participants" :dynamic-id="dynamic.id" :ledger-id="ledger.id" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,308 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import Chat from '@/components/Chat.vue';
|
||||||
|
import { defineOptions } from 'vue';
|
||||||
|
import { useForm } from '@inertiajs/vue3';
|
||||||
|
import { route } from 'ziggy-js';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
mutation: {
|
||||||
|
id: string; // Updated to match serialization
|
||||||
|
user_id: number;
|
||||||
|
user: { name: string };
|
||||||
|
amount: number;
|
||||||
|
description: string;
|
||||||
|
status: string;
|
||||||
|
created_at: string;
|
||||||
|
chat: any;
|
||||||
|
media?: Array<{ id: number; url: string; mime_type: string }>;
|
||||||
|
can: {
|
||||||
|
update: boolean;
|
||||||
|
void: boolean;
|
||||||
|
};
|
||||||
|
ledger: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
dynamic_id: string;
|
||||||
|
alignment?: string;
|
||||||
|
dynamic: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
dynamic: {
|
||||||
|
id: string;
|
||||||
|
participants: any[];
|
||||||
|
};
|
||||||
|
can: {
|
||||||
|
update: boolean;
|
||||||
|
};
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const dynamicId = props.dynamic.id;
|
||||||
|
|
||||||
|
function updateStatus(mutationId: string, status: 'approved' | 'rejected') {
|
||||||
|
useForm({ status }).put(
|
||||||
|
route('dynamics.ledgers.mutations.update', {
|
||||||
|
dynamic: props.dynamic.id,
|
||||||
|
ledger: props.mutation.ledger.id,
|
||||||
|
mutation: mutationId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function voidMutation(mutationId: string) {
|
||||||
|
useForm({}).put(
|
||||||
|
route('dynamics.ledgers.mutations.void', {
|
||||||
|
dynamic: props.dynamic.id,
|
||||||
|
ledger: props.mutation.ledger.id,
|
||||||
|
mutation: mutationId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isOwnerUser(userId: number): boolean {
|
||||||
|
const participant = props.dynamic.participants?.find((p) => p.id === userId);
|
||||||
|
|
||||||
|
return participant?.pivot?.role === 'owner';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAmountClass(amount: number): string {
|
||||||
|
const alignment = props.mutation.ledger.alignment || 'neutral';
|
||||||
|
|
||||||
|
if (alignment === 'positive') {
|
||||||
|
return amount > 0
|
||||||
|
? 'c-mutation-list__item-amount--positive'
|
||||||
|
: 'c-mutation-list__item-amount--negative';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alignment === 'negative') {
|
||||||
|
return amount < 0
|
||||||
|
? 'c-mutation-list__item-amount--positive'
|
||||||
|
: 'c-mutation-list__item-amount--negative';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'c-mutation-list__item-amount--neutral';
|
||||||
|
}
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
layout: (props: any) => ({
|
||||||
|
breadcrumbs: [
|
||||||
|
{ title: 'Dynamics', href: route('dynamics.index') },
|
||||||
|
{ title: props.mutation.ledger.dynamic.name, href: route('dynamics.show', props.mutation.ledger.dynamic.id) },
|
||||||
|
{ title: props.mutation.ledger.name, href: route('dynamics.ledgers.show', [props.mutation.ledger.dynamic.id, props.mutation.ledger.id]) },
|
||||||
|
{ title: 'Mutation Details', href: '' },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="c-mutation-list__item">
|
||||||
|
<div class="c-mutation-list__item-header">
|
||||||
|
<div>
|
||||||
|
<span class="c-mutation-list__item-author">
|
||||||
|
{{
|
||||||
|
isOwnerUser(mutation.user_id)
|
||||||
|
? 'Added by'
|
||||||
|
: 'Suggested by'
|
||||||
|
}}
|
||||||
|
{{ mutation.user.name }}
|
||||||
|
</span>
|
||||||
|
<div class="c-mutation-list__item-meta">
|
||||||
|
<span
|
||||||
|
:class="getAmountClass(mutation.amount)"
|
||||||
|
class="c-mutation-list__item-amount"
|
||||||
|
>
|
||||||
|
{{ mutation.amount > 0 ? '+' : ''
|
||||||
|
}}{{ mutation.amount }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="!isOwnerUser(mutation.user_id)"
|
||||||
|
:class="{
|
||||||
|
'c-mutation-list__item-status--pending':
|
||||||
|
mutation.status === 'pending',
|
||||||
|
'c-mutation-list__item-status--approved':
|
||||||
|
mutation.status === 'approved',
|
||||||
|
'c-mutation-list__item-status--rejected':
|
||||||
|
mutation.status === 'rejected',
|
||||||
|
}"
|
||||||
|
class="c-mutation-list__item-status"
|
||||||
|
>
|
||||||
|
{{ mutation.status }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="c-mutation-list__item-time">
|
||||||
|
{{ new Date(mutation.created_at).toLocaleString() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="c-mutation-list__item-desc">
|
||||||
|
{{ mutation.description }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="mutation.media && mutation.media.length > 0"
|
||||||
|
class="c-mutation-list__media-list"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="item in mutation.media"
|
||||||
|
:key="item.id"
|
||||||
|
class="c-mutation-list__media-item"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="item.mime_type.startsWith('image/')"
|
||||||
|
:src="item.url"
|
||||||
|
class="c-mutation-list__media-img"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-else-if="item.mime_type.startsWith('video/')"
|
||||||
|
class="c-mutation-list__media-video-wrapper"
|
||||||
|
>
|
||||||
|
<video
|
||||||
|
:src="item.url"
|
||||||
|
class="c-mutation-list__media-video"
|
||||||
|
></video>
|
||||||
|
<div class="c-mutation-list__media-video-overlay">
|
||||||
|
▶
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Owner Approve/Reject/Void Actions -->
|
||||||
|
<div
|
||||||
|
v-if="mutation.can?.update || mutation.can?.void"
|
||||||
|
class="c-mutation-list__actions"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
v-if="mutation.can?.update"
|
||||||
|
@click="updateStatus(mutation.id, 'approved')"
|
||||||
|
class="c-mutation-list__approve-btn"
|
||||||
|
>
|
||||||
|
Approve
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="mutation.can?.update"
|
||||||
|
@click="updateStatus(mutation.id, 'rejected')"
|
||||||
|
class="c-mutation-list__reject-btn"
|
||||||
|
>
|
||||||
|
Reject
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="mutation.can?.void"
|
||||||
|
@click="voidMutation(mutation.id)"
|
||||||
|
class="c-mutation-list__void-btn"
|
||||||
|
>
|
||||||
|
Void
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Chat v-if="mutation.chat"
|
||||||
|
:chat="mutation.chat"
|
||||||
|
:participants="dynamic.participants"
|
||||||
|
:dynamic-id="dynamicId"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
@reference "../../../css/app.css";
|
||||||
|
|
||||||
|
.c-mutation-list__item {
|
||||||
|
@apply overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-header {
|
||||||
|
@apply flex items-start justify-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-author {
|
||||||
|
@apply font-semibold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-meta {
|
||||||
|
@apply mt-1 flex items-center gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-amount {
|
||||||
|
@apply text-sm font-bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-amount--positive {
|
||||||
|
@apply text-green-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-amount--negative {
|
||||||
|
@apply text-red-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-amount--neutral {
|
||||||
|
@apply text-gray-500 dark:text-gray-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-status {
|
||||||
|
@apply rounded px-1.5 py-0.5 text-[10px] font-medium tracking-wider uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-status--pending {
|
||||||
|
@apply bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-status--approved {
|
||||||
|
@apply bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-status--rejected {
|
||||||
|
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-time {
|
||||||
|
@apply text-xs text-gray-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__item-desc {
|
||||||
|
@apply mt-3 text-sm text-gray-600 dark:text-gray-400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-list {
|
||||||
|
@apply mt-3 flex flex-wrap gap-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-item {
|
||||||
|
@apply max-w-[200px] overflow-hidden rounded-md border border-neutral-200 bg-black dark:border-neutral-700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-img {
|
||||||
|
@apply h-auto max-h-[150px] w-full cursor-pointer object-cover transition-opacity hover:opacity-90;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-video-wrapper {
|
||||||
|
@apply relative cursor-pointer transition-opacity hover:opacity-90;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-video {
|
||||||
|
@apply h-auto max-h-[150px] w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__media-video-overlay {
|
||||||
|
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-2xl font-bold text-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__actions {
|
||||||
|
@apply mt-3 mb-3 flex gap-2 border-t border-neutral-100 pt-3 dark:border-neutral-700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__approve-btn {
|
||||||
|
@apply inline-flex cursor-pointer items-center rounded bg-green-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-green-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__reject-btn {
|
||||||
|
@apply inline-flex cursor-pointer items-center rounded bg-red-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-red-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.c-mutation-list__void-btn {
|
||||||
|
@apply inline-flex cursor-pointer items-center rounded bg-gray-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-gray-500;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,260 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { Head, Link as InertiaLink } from '@inertiajs/vue3';
|
|
||||||
import { route } from 'ziggy-js';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
dynamic: {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
participant: {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
display_name: string | null;
|
|
||||||
role: string;
|
|
||||||
};
|
|
||||||
mutations: Array<{
|
|
||||||
id: number;
|
|
||||||
ledger_id: number;
|
|
||||||
ledger: {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
alignment: string;
|
|
||||||
};
|
|
||||||
amount: number;
|
|
||||||
description: string;
|
|
||||||
status: string;
|
|
||||||
created_at: string;
|
|
||||||
}>;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.participant.display_name ?? props.participant.name,
|
|
||||||
href: route('dynamics.users.show', [props.dynamic.id, props.participant.id]),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function getAmountClass(amount: number, alignment: string): string {
|
|
||||||
if (alignment === 'positive') {
|
|
||||||
return amount > 0
|
|
||||||
? 'c-participant-show__activity-amount--positive'
|
|
||||||
: 'c-participant-show__activity-amount--negative';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alignment === 'negative') {
|
|
||||||
return amount < 0
|
|
||||||
? 'c-participant-show__activity-amount--positive'
|
|
||||||
: 'c-participant-show__activity-amount--negative';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'c-participant-show__activity-amount--neutral';
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Head :title="participant.display_name ?? participant.name" />
|
|
||||||
|
|
||||||
<div class="c-participant-show">
|
|
||||||
<div class="c-participant-show__container">
|
|
||||||
<!-- Header Card -->
|
|
||||||
<div class="c-participant-show__card">
|
|
||||||
<div class="c-participant-show__body">
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<div>
|
|
||||||
<span class="c-participant-show__role-badge">
|
|
||||||
{{ participant.role }}
|
|
||||||
</span>
|
|
||||||
<h3 class="c-participant-show__title mt-1">
|
|
||||||
{{ participant.display_name ?? participant.name }}
|
|
||||||
</h3>
|
|
||||||
<p v-if="participant.display_name" class="c-participant-show__subtitle">
|
|
||||||
Real Name: {{ participant.name }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<InertiaLink :href="route('dynamics.show', dynamic.id)" class="c-participant-show__back-btn">
|
|
||||||
Back to Dynamic
|
|
||||||
</InertiaLink>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Recent Activity Block -->
|
|
||||||
<div class="c-participant-show__activity mt-8">
|
|
||||||
<h4 class="c-participant-show__activity-title">Recent Activity</h4>
|
|
||||||
|
|
||||||
<div v-if="mutations.length > 0" class="c-participant-show__activity-list mt-4">
|
|
||||||
<div
|
|
||||||
v-for="mutation in mutations"
|
|
||||||
:key="mutation.id"
|
|
||||||
class="c-participant-show__activity-item"
|
|
||||||
>
|
|
||||||
<div class="flex justify-between items-start">
|
|
||||||
<div>
|
|
||||||
<InertiaLink
|
|
||||||
:href="route('dynamics.ledgers.show', [dynamic.id, mutation.ledger_id])"
|
|
||||||
class="c-participant-show__activity-ledger"
|
|
||||||
>
|
|
||||||
{{ mutation.ledger.name }}
|
|
||||||
</InertiaLink>
|
|
||||||
<p class="c-participant-show__activity-desc mt-1">
|
|
||||||
{{ mutation.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="text-right">
|
|
||||||
<span
|
|
||||||
:class="getAmountClass(mutation.amount, mutation.ledger.alignment)"
|
|
||||||
class="c-participant-show__activity-amount"
|
|
||||||
>
|
|
||||||
{{ mutation.amount > 0 ? '+' : '' }}{{ mutation.amount }}
|
|
||||||
</span>
|
|
||||||
<div class="c-participant-show__activity-meta mt-1">
|
|
||||||
<span
|
|
||||||
:class="{
|
|
||||||
'c-participant-show__activity-status--pending': mutation.status === 'pending',
|
|
||||||
'c-participant-show__activity-status--approved': mutation.status === 'approved',
|
|
||||||
'c-participant-show__activity-status--rejected': mutation.status === 'rejected',
|
|
||||||
}"
|
|
||||||
class="c-participant-show__activity-status"
|
|
||||||
>
|
|
||||||
{{ mutation.status }}
|
|
||||||
</span>
|
|
||||||
<span class="c-participant-show__activity-time ml-2">
|
|
||||||
{{ new Date(mutation.created_at).toLocaleDateString() }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else class="c-participant-show__empty mt-4">
|
|
||||||
No recent activity found for this participant.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
@reference "../../../css/app.css";
|
|
||||||
|
|
||||||
.c-participant-show {
|
|
||||||
@apply py-12;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__container {
|
|
||||||
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__card {
|
|
||||||
@apply overflow-hidden;
|
|
||||||
background-color: var(--card);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__body {
|
|
||||||
@apply p-6;
|
|
||||||
color: var(--foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__role-badge {
|
|
||||||
@apply inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold uppercase tracking-wider;
|
|
||||||
background-color: var(--primary);
|
|
||||||
color: var(--primary-foreground);
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__title {
|
|
||||||
@apply text-2xl font-bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__subtitle {
|
|
||||||
@apply mt-1 text-sm;
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__back-btn {
|
|
||||||
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-title {
|
|
||||||
@apply text-lg font-medium;
|
|
||||||
color: var(--foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-list {
|
|
||||||
@apply space-y-4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-item {
|
|
||||||
@apply p-4;
|
|
||||||
background-color: var(--card);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-ledger {
|
|
||||||
@apply font-semibold hover:underline text-sm;
|
|
||||||
color: var(--primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-desc {
|
|
||||||
@apply text-sm;
|
|
||||||
color: var(--foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-amount {
|
|
||||||
@apply font-bold text-sm;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-amount--positive {
|
|
||||||
@apply text-green-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-amount--negative {
|
|
||||||
@apply text-red-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-amount--neutral {
|
|
||||||
@apply text-neutral-500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-meta {
|
|
||||||
@apply flex items-center justify-end text-xs;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-status {
|
|
||||||
@apply rounded px-1.5 py-0.5 text-[9px] font-medium tracking-wider uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-status--pending {
|
|
||||||
@apply bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-status--approved {
|
|
||||||
@apply bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-status--rejected {
|
|
||||||
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__activity-time {
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-participant-show__empty {
|
|
||||||
@apply text-sm text-center py-8;
|
|
||||||
color: var(--muted-foreground);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
+1
-1
@@ -8,5 +8,5 @@ Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Broadcast::channel('chats.{chat}', function ($user, Chat $chat) {
|
Broadcast::channel('chats.{chat}', function ($user, Chat $chat) {
|
||||||
return $user->can('view', $chat->chatable);
|
return $user?->can('view', $chat);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
Route::put('/dynamics/{dynamic}/ledgers/{ledger}/close', [LedgerController::class, 'close'])->name('dynamics.ledgers.close');
|
Route::put('/dynamics/{dynamic}/ledgers/{ledger}/close', [LedgerController::class, 'close'])->name('dynamics.ledgers.close');
|
||||||
Route::resource('dynamics.ledgers', LedgerController::class)->scoped()->except(['create']);
|
Route::resource('dynamics.ledgers', LedgerController::class)->scoped()->except(['create']);
|
||||||
|
|
||||||
Route::resource('dynamics.predefined-mutations', PredefinedMutationController::class)->scoped();
|
Route::resource('dynamics.ledgers.predefined-mutations', PredefinedMutationController::class)->scoped();
|
||||||
|
|
||||||
Route::put('/dynamics/{dynamic}/ledgers/{ledger}/mutations/{mutation}/void', [MutationController::class, 'void'])->name('dynamics.ledgers.mutations.void');
|
Route::put('/dynamics/{dynamic}/ledgers/{ledger}/mutations/{mutation}/void', [MutationController::class, 'void'])->name('dynamics.ledgers.mutations.void');
|
||||||
Route::resource('dynamics.ledgers.mutations', MutationController::class)->scoped();
|
Route::resource('dynamics.ledgers.mutations', MutationController::class)->scoped();
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Browser;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
|
|
||||||
test('user can register, log in, and log out', function () {
|
|
||||||
$this->browse(function (Browser $browser) {
|
|
||||||
// 1. Test Registration
|
|
||||||
$browser->visit('/register')
|
|
||||||
->waitForText('Create an account')
|
|
||||||
->type('name', 'New Browser User')
|
|
||||||
->type('email', 'newbrowseruser@example.com')
|
|
||||||
->type('password', 'password')
|
|
||||||
->type('password_confirmation', 'password')
|
|
||||||
->press('Create account')
|
|
||||||
->waitForLocation('/dashboard')
|
|
||||||
->assertPathIs('/dashboard')
|
|
||||||
->assertSee('New Browser User');
|
|
||||||
|
|
||||||
// 2. Test Logout
|
|
||||||
// Open the user menu (trigger button shows initials or user name)
|
|
||||||
$browser->click('button[aria-haspopup="menu"]')
|
|
||||||
->waitForText('Log out')
|
|
||||||
->clickLink('Log out')
|
|
||||||
->waitForLocation('/login') // Fortify logs out and redirects to login or home
|
|
||||||
->assertPathIs('/login');
|
|
||||||
|
|
||||||
// 3. Test Login
|
|
||||||
$browser->type('email', 'newbrowseruser@example.com')
|
|
||||||
->type('password', 'password')
|
|
||||||
->press('Log in')
|
|
||||||
->waitForLocation('/dashboard')
|
|
||||||
->assertPathIs('/dashboard')
|
|
||||||
->assertSee('New Browser User');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Browser;
|
|
||||||
|
|
||||||
use App\Models\Dynamic;
|
|
||||||
use App\Models\Ledger;
|
|
||||||
use App\Models\Mutation;
|
|
||||||
use App\Models\User;
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
|
|
||||||
test('access control and actions are enforced for owners and participants', function () {
|
|
||||||
// Create database state
|
|
||||||
$owner = User::factory()->create([
|
|
||||||
'name' => 'Owner Alice',
|
|
||||||
'email' => 'alice-owner@example.com',
|
|
||||||
'password' => bcrypt('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$participant = User::factory()->create([
|
|
||||||
'name' => 'Participant Bob',
|
|
||||||
'email' => 'bob-sub@example.com',
|
|
||||||
'password' => bcrypt('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$outsider = User::factory()->create([
|
|
||||||
'name' => 'Outsider Charlie',
|
|
||||||
'email' => 'charlie-outsider@example.com',
|
|
||||||
'password' => bcrypt('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$dynamic = Dynamic::create([
|
|
||||||
'name' => 'Private Club',
|
|
||||||
'rules' => 'Strict access control.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
||||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
|
||||||
|
|
||||||
$ledger = Ledger::create([
|
|
||||||
'dynamic_id' => $dynamic->id,
|
|
||||||
'name' => 'Rules Compliance',
|
|
||||||
'rules' => 'Score rules.',
|
|
||||||
'score' => 100,
|
|
||||||
'alignment' => 'neutral',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->browse(function (Browser $sessionOwner, Browser $sessionParticipant, Browser $sessionOutsider) use ($dynamic, $ledger, $owner, $participant, $outsider) {
|
|
||||||
|
|
||||||
// 1. Test Outsider trying to access dynamic they DO NOT belong to (should be forbidden / 403)
|
|
||||||
$sessionOutsider->loginAs($outsider)
|
|
||||||
->visit(route('dynamics.show', $dynamic))
|
|
||||||
->assertSee('403') // Laravel / Inertia forbidden page
|
|
||||||
->assertDontSee('Private Club');
|
|
||||||
|
|
||||||
// 2. Test Participant accessing dynamic they DO belong to (should be allowed)
|
|
||||||
$sessionParticipant->loginAs($participant)
|
|
||||||
->visit(route('dynamics.show', $dynamic))
|
|
||||||
->waitForText('Private Club')
|
|
||||||
->assertSee('Private Club')
|
|
||||||
->assertSee('Participant Bob');
|
|
||||||
|
|
||||||
// 3. Test Participant adding a mutation suggestion
|
|
||||||
$sessionParticipant->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
|
||||||
->waitForText('Add Mutation')
|
|
||||||
->type('amount', '20')
|
|
||||||
->type('description', 'Cleaned the main room')
|
|
||||||
->press('Add Mutation')
|
|
||||||
->waitForText('PENDING')
|
|
||||||
->assertSee('PENDING') // Mutation should show up as pending
|
|
||||||
->assertDontSee('Approve'); // Standard participant should NOT see approve button!
|
|
||||||
|
|
||||||
// 4. Test Owner logging in, seeing the pending suggestion, and approving it!
|
|
||||||
$sessionOwner->loginAs($owner)
|
|
||||||
->visit(route('dynamics.ledgers.show', [$dynamic, $ledger]))
|
|
||||||
->waitForText('Cleaned the main room')
|
|
||||||
->assertSee('PENDING')
|
|
||||||
->assertSee('Approve') // Owner should see the Approve button!
|
|
||||||
->press('Approve')
|
|
||||||
->waitForText('Score: 120') // Score updated from 100 to 120 after approval!
|
|
||||||
->assertDontSee('PENDING'); // No longer pending!
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Browser;
|
||||||
|
|
||||||
|
use App\Models\Dynamic;
|
||||||
|
use App\Models\Ledger;
|
||||||
|
use App\Models\User;
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
use Tests\DuskTestCase;
|
||||||
|
|
||||||
|
class BasicViewsTest extends DuskTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that guests can visit the welcome page.
|
||||||
|
*/
|
||||||
|
public function test_guests_can_visit_the_welcome_page(): void
|
||||||
|
{
|
||||||
|
$this->browse(function (Browser $browser) {
|
||||||
|
$browser->visit('/')
|
||||||
|
->waitForText("Let's get started")
|
||||||
|
->assertSee("Let's get started");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that authenticated users can visit the dynamics index and see their dynamics.
|
||||||
|
*/
|
||||||
|
public function test_authenticated_users_can_visit_the_dynamics_index(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create([
|
||||||
|
'name' => 'Dusk Automated Dynamic Index Test',
|
||||||
|
]);
|
||||||
|
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user, $dynamic) {
|
||||||
|
$browser->loginAs($user)
|
||||||
|
->visit('/dynamics')
|
||||||
|
->waitForText('Your Dynamics')
|
||||||
|
->assertSee('Your Dynamics')
|
||||||
|
->assertSee($dynamic->name);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
$dynamic->participants()->detach();
|
||||||
|
$dynamic->delete();
|
||||||
|
$user->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that authenticated users can visit a dynamic show page.
|
||||||
|
*/
|
||||||
|
public function test_authenticated_users_can_visit_a_dynamic_show_page(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create([
|
||||||
|
'name' => 'Dusk Dynamic Show Test',
|
||||||
|
'rules' => 'Rule 1: Always obey the automation.',
|
||||||
|
]);
|
||||||
|
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user, $dynamic) {
|
||||||
|
$browser->loginAs($user)
|
||||||
|
->visit('/dynamics/' . $dynamic->uuid)
|
||||||
|
->waitForText($dynamic->name)
|
||||||
|
->assertSee($dynamic->name)
|
||||||
|
->assertSee($dynamic->rules);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
$dynamic->participants()->detach();
|
||||||
|
$dynamic->delete();
|
||||||
|
$user->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that authenticated users can visit a ledger show page.
|
||||||
|
*/
|
||||||
|
public function test_authenticated_users_can_visit_a_ledger_show_page(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create([
|
||||||
|
'name' => 'Dusk Dynamic Ledger Show Test',
|
||||||
|
]);
|
||||||
|
$dynamic->participants()->attach($user->id, ['role' => 'owner']);
|
||||||
|
|
||||||
|
$ledger = Ledger::factory()->create([
|
||||||
|
'dynamic_id' => $dynamic->id,
|
||||||
|
'name' => 'Dusk Ledger Test',
|
||||||
|
'score' => 42,
|
||||||
|
'rules' => 'Scores are tracked for Dusk automated verification.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user, $dynamic, $ledger) {
|
||||||
|
$browser->loginAs($user)
|
||||||
|
->visit('/dynamics/' . $dynamic->uuid . '/ledgers/' . $ledger->uuid)
|
||||||
|
->waitForText($ledger->name)
|
||||||
|
->assertSee($ledger->name)
|
||||||
|
->assertSee('Score: 42')
|
||||||
|
->assertSee($ledger->rules);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
$ledger->delete();
|
||||||
|
$dynamic->participants()->detach();
|
||||||
|
$dynamic->delete();
|
||||||
|
$user->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that authenticated users can visit a participant profile page.
|
||||||
|
*/
|
||||||
|
public function test_authenticated_users_can_visit_a_participant_profile_page(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create([
|
||||||
|
'name' => 'Dusk Participant Profile Test',
|
||||||
|
]);
|
||||||
|
$dynamic->participants()->attach($user->id, ['role' => 'owner', 'display_name' => 'The Master']);
|
||||||
|
|
||||||
|
$otherUser = User::factory()->create();
|
||||||
|
$dynamic->participants()->attach($otherUser->id, ['role' => 'participant', 'display_name' => 'Bitch Bob']);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user, $dynamic, $otherUser) {
|
||||||
|
$browser->loginAs($user)
|
||||||
|
->visit('/dynamics/' . $dynamic->uuid . '/users/' . $otherUser->uuid)
|
||||||
|
->waitForText('Bitch Bob')
|
||||||
|
->assertSee('Bitch Bob')
|
||||||
|
->assertSee('participant');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
$dynamic->participants()->detach();
|
||||||
|
$dynamic->delete();
|
||||||
|
$user->delete();
|
||||||
|
$otherUser->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
use Tests\DuskTestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class DashboardTest extends DuskTestCase
|
||||||
|
{
|
||||||
|
public function test_authenticated_users_can_visit_the_dashboard(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user) {
|
||||||
|
$browser->loginAs($user)
|
||||||
|
->visit('/dashboard')
|
||||||
|
->assertSee('Recent Activity');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
use Tests\DuskTestCase;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class LoginTest extends DuskTestCase
|
||||||
|
{
|
||||||
|
public function test_a_user_can_log_in(): void
|
||||||
|
{
|
||||||
|
User::where('email', 'dusk@example.com')->delete();
|
||||||
|
|
||||||
|
$user = User::factory()->create([
|
||||||
|
'email' => 'dusk@example.com',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->browse(function (Browser $browser) use ($user) {
|
||||||
|
$browser->visit('/login')
|
||||||
|
->waitFor('#email')
|
||||||
|
->type('email', $user->email)
|
||||||
|
->type('password', 'wrong-password')
|
||||||
|
->press('[data-test="login-button"]')
|
||||||
|
->assertPathIs('/login')
|
||||||
|
->screenshot('login-error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Browser\Pages;
|
||||||
|
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
class HomePage extends Page
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the URL for the page.
|
||||||
|
*/
|
||||||
|
public function url(): string
|
||||||
|
{
|
||||||
|
return '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the browser is on the page.
|
||||||
|
*/
|
||||||
|
public function assert(Browser $browser): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element shortcuts for the page.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function elements(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@element' => '#selector',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Browser\Pages;
|
||||||
|
|
||||||
|
use Laravel\Dusk\Page as BasePage;
|
||||||
|
|
||||||
|
abstract class Page extends BasePage
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the global element shortcuts for the site.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public static function siteElements(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@element' => '#selector',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,23 +5,30 @@ namespace Tests\Browser;
|
|||||||
use App\Models\Dynamic;
|
use App\Models\Dynamic;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Laravel\Dusk\Browser;
|
use Laravel\Dusk\Browser;
|
||||||
|
use Tests\DuskTestCase;
|
||||||
|
|
||||||
test('multiple sessions can communicate in real time through websockets', function () {
|
class RealtimeChatTest extends DuskTestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test that multiple browser sessions can communicate in real time through websockets.
|
||||||
|
*/
|
||||||
|
public function test_multiple_sessions_can_communicate_in_real_time(): void
|
||||||
|
{
|
||||||
// 1. Create realistic database state
|
// 1. Create realistic database state
|
||||||
$owner = User::factory()->create([
|
$owner = User::factory()->create([
|
||||||
'name' => 'TU Test User',
|
'name' => 'Owner Alice',
|
||||||
'email' => 'test-owner@example.com',
|
'email' => 'alice-owner-' . uniqid() . '@example.com',
|
||||||
'password' => bcrypt('password'),
|
'password' => bcrypt('password'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$participant = User::factory()->create([
|
$participant = User::factory()->create([
|
||||||
'name' => 'Submissive Bob',
|
'name' => 'Submissive Bob',
|
||||||
'email' => 'test-sub@example.com',
|
'email' => 'bob-participant-' . uniqid() . '@example.com',
|
||||||
'password' => bcrypt('password'),
|
'password' => bcrypt('password'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$dynamic = Dynamic::create([
|
$dynamic = Dynamic::create([
|
||||||
'name' => 'The Test Sanctuary',
|
'name' => 'The Velvet Realtime Test Sanctuary',
|
||||||
'rules' => 'Rules for realtime testing.',
|
'rules' => 'Rules for realtime testing.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -30,36 +37,50 @@ test('multiple sessions can communicate in real time through websockets', functi
|
|||||||
|
|
||||||
// 2. Spawn two separate browser sessions/browsers in parallel
|
// 2. Spawn two separate browser sessions/browsers in parallel
|
||||||
$this->browse(function (Browser $sessionA, Browser $sessionB) use ($dynamic, $owner, $participant) {
|
$this->browse(function (Browser $sessionA, Browser $sessionB) use ($dynamic, $owner, $participant) {
|
||||||
|
try {
|
||||||
// --- SESSION A: Owner ---
|
// --- SESSION A: Owner ---
|
||||||
$sessionA->loginAs($owner)
|
$sessionA->loginAs($owner)
|
||||||
->visit(route('dynamics.show', $dynamic))
|
->visit('/dynamics/' . $dynamic->uuid)
|
||||||
->waitForText('The Test Sanctuary')
|
->waitForText('The Velvet Realtime Test Sanctuary')
|
||||||
->assertSee('TU Test User'); // Verify loaded in as Owner
|
->assertSee('Owner Alice');
|
||||||
|
|
||||||
// --- SESSION B: Participant ---
|
// --- SESSION B: Participant ---
|
||||||
$sessionB->loginAs($participant)
|
$sessionB->loginAs($participant)
|
||||||
->visit(route('dynamics.show', $dynamic))
|
->visit('/dynamics/' . $dynamic->uuid)
|
||||||
->waitForText('The Test Sanctuary')
|
->waitForText('The Velvet Realtime Test Sanctuary')
|
||||||
->assertSee('Submissive Bob'); // Verify loaded in as Submissive/Participant
|
->assertSee('Submissive Bob');
|
||||||
|
|
||||||
// --- REAL-TIME COMMUNICATING ---
|
// --- REAL-TIME COMMUNICATING ---
|
||||||
// Owner types and sends a message in chat
|
// Owner types and sends a message in chat
|
||||||
$sessionA->type('#content', 'Hello Submissive Bob, did you complete your daily chores?')
|
$sessionA->type('#content', 'Hello Submissive Bob, did you complete your daily chores?')
|
||||||
->click('.c-chat__button')
|
->click('.c-chat__button')
|
||||||
->waitForText('Hello Submissive Bob');
|
->waitForText('Hello Submissive Bob, did you complete your daily chores?');
|
||||||
|
|
||||||
// Since websockets broadcast in real-time, Session B receives it without reloading
|
// Since websockets broadcast in real-time, Session B receives it without reloading
|
||||||
$sessionB->waitForText('Hello Submissive Bob', 5)
|
$sessionB->waitForText('Hello Submissive Bob, did you complete your daily chores?', 10)
|
||||||
->assertSee('Hello Submissive Bob, did you complete your daily chores?');
|
->assertSee('Hello Submissive Bob, did you complete your daily chores?');
|
||||||
|
|
||||||
// Participant replies in real-time
|
// Participant replies in real-time
|
||||||
$sessionB->type('#content', 'Yes Master, everything is complete and logged in the ledger!')
|
$sessionB->type('#content', 'Yes Master, everything is complete and logged!')
|
||||||
->click('.c-chat__button')
|
->click('.c-chat__button')
|
||||||
->waitForText('Yes Master, everything is complete');
|
->waitForText('Yes Master, everything is complete and logged!');
|
||||||
|
|
||||||
// Session A receives the reply in real-time without reloading
|
// Session A receives the reply in real-time without reloading
|
||||||
$sessionA->waitForText('Yes Master, everything is complete', 5)
|
$sessionA->waitForText('Yes Master, everything is complete and logged!', 10)
|
||||||
->assertSee('Yes Master, everything is complete and logged in the ledger!');
|
->assertSee('Yes Master, everything is complete and logged!');
|
||||||
});
|
} catch (\Exception $e) {
|
||||||
|
echo "\n=== SESSION A CONSOLE LOGS ===\n";
|
||||||
|
print_r($sessionA->driver->manage()->getLog('browser'));
|
||||||
|
echo "\n=== SESSION B CONSOLE LOGS ===\n";
|
||||||
|
print_r($sessionB->driver->manage()->getLog('browser'));
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
$dynamic->participants()->detach();
|
||||||
|
$dynamic->delete();
|
||||||
|
$owner->delete();
|
||||||
|
$participant->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ use Facebook\WebDriver\Remote\DesiredCapabilities;
|
|||||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||||
use Laravel\Dusk\TestCase as BaseTestCase;
|
use Laravel\Dusk\TestCase as BaseTestCase;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
abstract class DuskTestCase extends BaseTestCase
|
abstract class DuskTestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -26,13 +28,13 @@ abstract class DuskTestCase extends BaseTestCase
|
|||||||
*/
|
*/
|
||||||
protected function driver(): RemoteWebDriver
|
protected function driver(): RemoteWebDriver
|
||||||
{
|
{
|
||||||
$options = (new ChromeOptions)->addArguments(collect([
|
$options = (new ChromeOptions)->addArguments((new Collection([
|
||||||
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
|
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--headless=new',
|
// '--headless=new',
|
||||||
'--no-sandbox',
|
'--no-sandbox',
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
])->unless(static::runningInSail(), function (collect $arguments) {
|
]))->unless(static::runningInSail(), function (Collection $arguments) {
|
||||||
return $arguments->push('--disable-smooth-scrolling');
|
return $arguments->push('--disable-smooth-scrolling');
|
||||||
})->all());
|
})->all());
|
||||||
|
|
||||||
|
|||||||
@@ -99,5 +99,5 @@ test('only the user with the specified email address can accept the link', funct
|
|||||||
// Verify system notification is added to Dynamic activity chat
|
// Verify system notification is added to Dynamic activity chat
|
||||||
$chatMessages = $dynamic->chat->messages;
|
$chatMessages = $dynamic->chat->messages;
|
||||||
expect($chatMessages)->not->toBeEmpty();
|
expect($chatMessages)->not->toBeEmpty();
|
||||||
expect($chatMessages->last()->content)->toBe("<user:{$invitee->id}> joined the Dynamic as a EDITOR");
|
expect($chatMessages->last()->content)->toBe("<user:{$invitee->uuid}> joined the Dynamic as a EDITOR");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,3 +55,25 @@ test('non-owners cannot view ledger creation form or store ledgers', function ()
|
|||||||
'name' => 'Illegal Ledger',
|
'name' => 'Illegal Ledger',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('owner can edit a ledger', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->put(route('dynamics.ledgers.update', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
|
'name' => 'Updated Ledger Name',
|
||||||
|
'rules' => 'Updated rules.',
|
||||||
|
'alignment' => 'negative',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('dynamics.ledgers.show', [$dynamic->uuid, $ledger->uuid]));
|
||||||
|
$ledger->refresh();
|
||||||
|
|
||||||
|
expect($ledger->name)->toBe('Updated Ledger Name');
|
||||||
|
expect($ledger->rules)->toBe('Updated rules.');
|
||||||
|
expect($ledger->alignment)->toBe('negative');
|
||||||
|
});
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ test('owner can create a mutation which is automatically approved and does not s
|
|||||||
$mutationChatMessages = $mutation->chat->messages;
|
$mutationChatMessages = $mutation->chat->messages;
|
||||||
expect($mutationChatMessages)->toHaveCount(1);
|
expect($mutationChatMessages)->toHaveCount(1);
|
||||||
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
||||||
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->id}>.");
|
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->uuid}>.");
|
||||||
|
|
||||||
$dynamicChatMessages = $dynamic->chat->messages;
|
$dynamicChatMessages = $dynamic->chat->messages;
|
||||||
expect($dynamicChatMessages)->toHaveCount(1);
|
expect($dynamicChatMessages)->toHaveCount(1);
|
||||||
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
||||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->id}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
|
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->uuid}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('non-owner participant creates a suggestion which defaults to pending and says suggested', function () {
|
test('non-owner participant creates a suggestion which defaults to pending and says suggested', function () {
|
||||||
@@ -71,12 +71,12 @@ test('non-owner participant creates a suggestion which defaults to pending and s
|
|||||||
$mutationChatMessages = $mutation->chat->messages;
|
$mutationChatMessages = $mutation->chat->messages;
|
||||||
expect($mutationChatMessages)->toHaveCount(1);
|
expect($mutationChatMessages)->toHaveCount(1);
|
||||||
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
expect($mutationChatMessages->first()->user_id)->toBeNull();
|
||||||
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->id}>.");
|
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->uuid}>.");
|
||||||
|
|
||||||
$dynamicChatMessages = $dynamic->chat->messages;
|
$dynamicChatMessages = $dynamic->chat->messages;
|
||||||
expect($dynamicChatMessages)->toHaveCount(1);
|
expect($dynamicChatMessages)->toHaveCount(1);
|
||||||
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
expect($dynamicChatMessages->first()->user_id)->toBeNull();
|
||||||
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->id}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
|
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->uuid}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('owner can approve a pending suggestion and it is updated and logged', function () {
|
test('owner can approve a pending suggestion and it is updated and logged', function () {
|
||||||
@@ -115,9 +115,96 @@ test('owner can approve a pending suggestion and it is updated and logged', func
|
|||||||
// Note: one from boot created (empty or via seeder, but in our factory it starts with 0 messages if not manually logged,
|
// Note: one from boot created (empty or via seeder, but in our factory it starts with 0 messages if not manually logged,
|
||||||
// actually our model booted hook creates the chat but doesn't log on boot, the update method creates 1 message)
|
// actually our model booted hook creates the chat but doesn't log on boot, the update method creates 1 message)
|
||||||
expect($mutationChatMessages->last()->user_id)->toBeNull();
|
expect($mutationChatMessages->last()->user_id)->toBeNull();
|
||||||
expect($mutationChatMessages->last()->content)->toBe("Suggestion was APPROVED by <user:{$owner->id}>.");
|
expect($mutationChatMessages->last()->content)->toBe("<user:{$owner->uuid}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
||||||
|
|
||||||
$dynamicChatMessages = $dynamic->chat->messages;
|
$dynamicChatMessages = $dynamic->chat->messages;
|
||||||
expect($dynamicChatMessages->last()->user_id)->toBeNull();
|
expect($dynamicChatMessages->last()->user_id)->toBeNull();
|
||||||
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->uuid}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a mutation with 0 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'amount' => 0,
|
||||||
|
'description' => 'Zero point spam',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(Mutation::where('description', 'Zero point spam')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a mutation with more than 1000 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'amount' => 1001,
|
||||||
|
'description' => 'Abusive positive point reward',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(Mutation::where('description', 'Abusive positive point reward')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a mutation with less than -1000 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'amount' => -1001,
|
||||||
|
'description' => 'Abusive negative point demerit',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(Mutation::where('description', 'Abusive negative point demerit')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('participant can choose and request a predefined mutation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participant = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id, 'score' => 100]);
|
||||||
|
|
||||||
|
$predefined = \App\Models\PredefinedMutation::create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'name' => 'Wash the Motorbunny',
|
||||||
|
'amount' => 50,
|
||||||
|
'description' => 'Must be fully cleaned and dried.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($participant);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'amount' => 50,
|
||||||
|
'description' => 'Completed Wash the Motorbunny template chore.',
|
||||||
|
'predefined_mutation_id' => $predefined->uuid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('dynamics.ledgers.show', [$dynamic, $ledger]));
|
||||||
|
|
||||||
|
$mutation = Mutation::firstWhere('description', 'Completed Wash the Motorbunny template chore.');
|
||||||
|
|
||||||
|
expect($mutation)->not->toBeNull();
|
||||||
|
expect($mutation->status)->toBe('pending');
|
||||||
|
expect($mutation->predefined_mutation_id)->toBe($predefined->id);
|
||||||
|
|
||||||
|
// Score should NOT be updated since it is pending!
|
||||||
|
$ledger->refresh();
|
||||||
|
expect($ledger->score)->toBe(100);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Dynamic;
|
||||||
|
use App\Models\Ledger;
|
||||||
|
use App\Models\Mutation;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Notifications\NewActivityNotification;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class NotificationDispatchTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_notification_is_sent_on_mutation_suggestion()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participant = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($participant)
|
||||||
|
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'description' => 'A test suggestion',
|
||||||
|
'amount' => 10,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertSentTo($owner, NewActivityNotification::class);
|
||||||
|
Notification::assertNotSentTo($participant, NewActivityNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_notification_is_sent_on_mutation_approval()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participant = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
$mutation = Mutation::factory()->create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'user_id' => $participant->id,
|
||||||
|
'status' => 'pending',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->put(route('dynamics.ledgers.mutations.update', [$dynamic, $ledger, $mutation]), [
|
||||||
|
'status' => 'approved',
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertSentTo($participant, NewActivityNotification::class);
|
||||||
|
Notification::assertNotSentTo($owner, NewActivityNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_notification_is_sent_on_mutation_void()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participant = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
$mutation = Mutation::factory()->create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'user_id' => $participant->id,
|
||||||
|
'status' => 'approved',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->put(route('dynamics.ledgers.mutations.void', [$dynamic, $ledger, $mutation]));
|
||||||
|
|
||||||
|
Notification::assertSentTo($participant, NewActivityNotification::class);
|
||||||
|
Notification::assertNotSentTo($owner, NewActivityNotification::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_notification_is_sent_to_other_participants_when_owner_adds_mutation()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$participant1 = User::factory()->create();
|
||||||
|
$participant2 = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$dynamic->participants()->attach($participant1->id, ['role' => 'participant']);
|
||||||
|
$dynamic->participants()->attach($participant2->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner)
|
||||||
|
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
|
||||||
|
'description' => 'A test mutation from owner',
|
||||||
|
'amount' => 25,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertSentTo($participant1, NewActivityNotification::class);
|
||||||
|
Notification::assertSentTo($participant2, NewActivityNotification::class);
|
||||||
|
Notification::assertNotSentTo($owner, NewActivityNotification::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ test('authenticated participant can view another participant detail page in dyna
|
|||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Dynamics/Participants/Show')
|
->component('Dynamics/Participants/Show')
|
||||||
->has('dynamic')
|
->has('dynamic')
|
||||||
->where('participant.id', $participant->id)
|
->where('participant.id', $participant->uuid)
|
||||||
->where('participant.name', $participant->name)
|
->where('participant.name', $participant->name)
|
||||||
->where('participant.display_name', null)
|
->where('participant.display_name', null)
|
||||||
->where('participant.role', 'participant')
|
->where('participant.role', 'participant')
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Dynamic;
|
|
||||||
use App\Models\PredefinedMutation;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Dynamic;
|
||||||
|
use App\Models\Ledger;
|
||||||
|
use App\Models\PredefinedMutation;
|
||||||
|
|
||||||
test('owner can view predefined mutations for dynamic', function () {
|
test('owner can view predefined mutations for ledger', function () {
|
||||||
$owner = User::factory()->create();
|
$owner = User::factory()->create();
|
||||||
$dynamic = Dynamic::factory()->create();
|
$dynamic = Dynamic::factory()->create();
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
$predefined = PredefinedMutation::create([
|
$predefined = PredefinedMutation::create([
|
||||||
'dynamic_id' => $dynamic->id,
|
'ledger_id' => $ledger->id,
|
||||||
'name' => 'Weekly Room Cleaning',
|
'name' => 'Weekly Room Cleaning',
|
||||||
'description' => 'Cleaned up the master bedroom',
|
'description' => 'Cleaned up the master bedroom',
|
||||||
'amount' => 20,
|
'amount' => 20,
|
||||||
@@ -18,71 +20,198 @@ test('owner can view predefined mutations for dynamic', function () {
|
|||||||
|
|
||||||
$this->actingAs($owner);
|
$this->actingAs($owner);
|
||||||
|
|
||||||
$response = $this->get(route('dynamics.predefined-mutations.index', $dynamic->uuid));
|
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->uuid, $ledger->uuid]));
|
||||||
|
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
$response->assertInertia(fn ($page) => $page
|
$response->assertInertia(fn ($page) => $page
|
||||||
->component('Dynamics/PredefinedMutations/Index')
|
->component('Ledgers/PredefinedMutations/Index')
|
||||||
|
->where('dynamic.id', $dynamic->uuid)
|
||||||
|
->where('ledger.id', $ledger->uuid)
|
||||||
->has('predefined_mutations', 1)
|
->has('predefined_mutations', 1)
|
||||||
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('non-owner cannot view predefined mutations for dynamic', function () {
|
test('non-owner cannot view predefined mutations for ledger', function () {
|
||||||
$owner = User::factory()->create();
|
$owner = User::factory()->create();
|
||||||
$participant = User::factory()->create();
|
$participant = User::factory()->create();
|
||||||
$dynamic = Dynamic::factory()->create();
|
$dynamic = Dynamic::factory()->create();
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
$this->actingAs($participant);
|
$this->actingAs($participant);
|
||||||
|
|
||||||
$response = $this->get(route('dynamics.predefined-mutations.index', $dynamic->uuid));
|
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->uuid, $ledger->uuid]));
|
||||||
|
|
||||||
$response->assertStatus(403);
|
$response->assertStatus(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('owner can create predefined mutations for dynamic', function () {
|
test('owner can create predefined mutations for ledger', function () {
|
||||||
$owner = User::factory()->create();
|
$owner = User::factory()->create();
|
||||||
$dynamic = Dynamic::factory()->create();
|
$dynamic = Dynamic::factory()->create();
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
$this->actingAs($owner);
|
$this->actingAs($owner);
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.predefined-mutations.store', $dynamic->uuid), [
|
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
'name' => 'Polished mirrors',
|
'name' => 'Polished mirrors',
|
||||||
'description' => 'Mirror polishing in dungeon',
|
'description' => 'Mirror polishing in dungeon',
|
||||||
'amount' => 15,
|
'amount' => 15,
|
||||||
'type' => 'reward',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertRedirect();
|
$response->assertRedirect();
|
||||||
$this->assertDatabaseHas('predefined_mutations', [
|
$this->assertDatabaseHas('predefined_mutations', [
|
||||||
'dynamic_id' => $dynamic->id,
|
'ledger_id' => $ledger->id,
|
||||||
'name' => 'Polished mirrors',
|
'name' => 'Polished mirrors',
|
||||||
'amount' => 15,
|
'amount' => 15,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('non-owner cannot create predefined mutations for dynamic', function () {
|
test('non-owner cannot create predefined mutations for ledger', function () {
|
||||||
$owner = User::factory()->create();
|
$owner = User::factory()->create();
|
||||||
$participant = User::factory()->create();
|
$participant = User::factory()->create();
|
||||||
$dynamic = Dynamic::factory()->create();
|
$dynamic = Dynamic::factory()->create();
|
||||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
$this->actingAs($participant);
|
$this->actingAs($participant);
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.predefined-mutations.store', $dynamic->uuid), [
|
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
'name' => 'Polished mirrors',
|
'name' => 'Polished mirrors',
|
||||||
'description' => 'Mirror polishing in dungeon',
|
'description' => 'Mirror polishing in dungeon',
|
||||||
'amount' => 15,
|
'amount' => 15,
|
||||||
'type' => 'reward',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(403);
|
$response->assertStatus(403);
|
||||||
$this->assertDatabaseMissing('predefined_mutations', [
|
$this->assertDatabaseMissing('predefined_mutations', [
|
||||||
'dynamic_id' => $dynamic->id,
|
'ledger_id' => $ledger->id,
|
||||||
'name' => 'Polished mirrors',
|
'name' => 'Polished mirrors',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('owner can view edit form for predefined mutation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$predefined = PredefinedMutation::create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'name' => 'Polished mirrors',
|
||||||
|
'description' => 'Mirror polishing in dungeon',
|
||||||
|
'amount' => 15,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->get(route('dynamics.ledgers.predefined-mutations.edit', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertInertia(fn ($page) => $page
|
||||||
|
->component('Ledgers/PredefinedMutations/Edit')
|
||||||
|
->where('predefined_mutation.id', $predefined->uuid)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('owner can update predefined mutation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$predefined = PredefinedMutation::create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'name' => 'Old Name',
|
||||||
|
'amount' => 10,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->put(route('dynamics.ledgers.predefined-mutations.update', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]), [
|
||||||
|
'name' => 'New Name',
|
||||||
|
'amount' => 20,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertRedirect();
|
||||||
|
$this->assertDatabaseHas('predefined_mutations', [
|
||||||
|
'id' => $predefined->id,
|
||||||
|
'name' => 'New Name',
|
||||||
|
'amount' => 20,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('owner can delete predefined mutation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$predefined = PredefinedMutation::create([
|
||||||
|
'ledger_id' => $ledger->id,
|
||||||
|
'name' => 'To Delete',
|
||||||
|
'amount' => 10,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->delete(route('dynamics.ledgers.predefined-mutations.destroy', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]));
|
||||||
|
|
||||||
|
$response->assertRedirect();
|
||||||
|
$this->assertDatabaseMissing('predefined_mutations', [
|
||||||
|
'id' => $predefined->id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a predefined mutation with 0 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
|
'name' => 'Zero point predefined',
|
||||||
|
'amount' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(PredefinedMutation::where('name', 'Zero point predefined')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a predefined mutation with more than 1000 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
|
'name' => 'Abusive positive predefined',
|
||||||
|
'amount' => 1001,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(PredefinedMutation::where('name', 'Abusive positive predefined')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('creating a predefined mutation with less than -1000 points fails validation', function () {
|
||||||
|
$owner = User::factory()->create();
|
||||||
|
$dynamic = Dynamic::factory()->create();
|
||||||
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||||
|
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||||
|
|
||||||
|
$this->actingAs($owner);
|
||||||
|
|
||||||
|
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->uuid, $ledger->uuid]), [
|
||||||
|
'name' => 'Abusive negative predefined',
|
||||||
|
'amount' => -1001,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertSessionHasErrors(['amount']);
|
||||||
|
expect(PredefinedMutation::where('name', 'Abusive negative predefined')->exists())->toBeFalse();
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
pest()->extend(Tests\DuskTestCase::class)
|
||||||
|
// ->use(Illuminate\Foundation\Testing\DatabaseMigrations::class)
|
||||||
|
->in('Browser');
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user