Skip to content

Commit

Permalink
Objects now have weight
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Jan 9, 2025
1 parent bb30c73 commit a347a02
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/Datagrids/Bulks/ItemBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ItemBulk extends Bulk
'type',
'price',
'size',
'weight',
'item_id',
'location_id',
'character_id',
Expand Down
1 change: 1 addition & 0 deletions app/Datagrids/Filters/ItemFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function build()
->add('type')
->add('price')
->add('size')
->add('weight')
->add('is_equipped')
->add([
'field' => 'item_id',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/StoreItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function rules()
'template_id' => 'nullable',
'price' => 'nullable|string|max:191',
'size' => 'nullable|string|max:191',
'weight' => 'nullable|string|max:191',
];

/** @var Item $self */
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/ItemResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function toArray($request)
'type' => $model->type,
'price' => $model->price,
'size' => $model->size,
'weight' => $model->weight,
'item_id' => $model->item_id,
]);
}
Expand Down
14 changes: 12 additions & 2 deletions app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Item extends MiscModel
'entry',
'price',
'size',
'weight',
'item_id',
'character_id',
'location_id',
Expand All @@ -64,6 +65,7 @@ class Item extends MiscModel
'type',
'price',
'size',
'weight',
'parent.name',
];

Expand All @@ -78,6 +80,7 @@ class Item extends MiscModel
protected array $sortableColumns = [
'price',
'size',
'weight',
'location.name',
'character.name',
];
Expand All @@ -86,6 +89,7 @@ class Item extends MiscModel
'name',
'type',
'size',
'weight',
'price',
];

Expand Down Expand Up @@ -120,6 +124,7 @@ class Item extends MiscModel
'item_id',
'price',
'size',
'weight',
'location_id',
'character_id'
];
Expand All @@ -136,6 +141,9 @@ public function tooltipSubtitle(): string
if (!empty($this->size)) {
$extra[] = __('items.fields.size') . ': ' . e($this->size);
}
if (!empty($this->weight)) {
$extra[] = __('items.fields.weight') . ': ' . e($this->weight);
}
if (empty($extra)) {
return '';
}
Expand Down Expand Up @@ -190,7 +198,7 @@ public function scopePreparedWith(Builder $query): Builder
*/
public function datagridSelectFields(): array
{
return ['character_id', 'location_id', 'price', 'size', 'item_id'];
return ['character_id', 'location_id', 'price', 'size', 'item_id', 'weight'];
}
public function character(): BelongsTo
{
Expand Down Expand Up @@ -227,7 +235,7 @@ public function entityTypeId(): int
*/
public function showProfileInfo(): bool
{
if (!empty($this->type) || !empty($this->price) || !empty($this->size)) {
if (!empty($this->type) || !empty($this->price) || !empty($this->size) || !empty($this->weight)) {
return true;
}

Expand All @@ -245,6 +253,7 @@ public function filterableColumns(): array
'character_id',
'price',
'size',
'weight',
'item_id',
'is_equipped',
];
Expand All @@ -260,6 +269,7 @@ public function datagridSortableColumns(): array
'type' => __('crud.fields.type'),
'price' => __('items.fields.price'),
'size' => __('items.fields.size'),
'weight' => __('items.fields.weight'),
];

if (auth()->check() && auth()->user()->isAdmin()) {
Expand Down
4 changes: 4 additions & 0 deletions app/Renderers/Layouts/Item/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public function columns(): array
'key' => 'size',
'label' => 'items.fields.size',
],
'weight' => [
'key' => 'weight',
'label' => 'items.fields.weight',
],
];

return $columns;
Expand Down
Original file line number Diff line number Diff line change
@@ -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('items', function (Blueprint $table) {
$table->text('weight')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('items', function (Blueprint $table) {
$table->dropColumn('weight');
});
}
};
4 changes: 3 additions & 1 deletion lang/en/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
'is_equipped' => 'Equipped',
'price' => 'Price',
'size' => 'Size',
'weight' => 'Weight',
],
'hints' => [
'items' => 'Organise items by using the parent item field.',
],
'placeholders' => [
'price' => 'Price of the item',
'size' => 'Size, Weight, Dimensions',
'size' => 'Size, Dimensions, Capacity',
'weight' => 'Weight of the item',
'type' => 'Weapon, Potion, Artefact',
],
'show' => [
Expand Down
7 changes: 5 additions & 2 deletions resources/api-docs/1.0/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ The list of returned entities can be filtered. The available filters are [availa
"character_id": 2,
"type": "Weapon",
"price": "25 gp",
"size": "1 lb.",
"size": "40 in.",
"weight": "1 lb.",
"item_id": 2
}
]
Expand Down Expand Up @@ -86,7 +87,8 @@ To get the details of a single item, use the following endpoint.
"character_id": 2,
"type": "Weapon",
"price": "25 gp",
"size": "1 lb.",
"size": "30 in.",
"weight": "1 lb.",
"item_id": 2
}

Expand Down Expand Up @@ -114,6 +116,7 @@ To create a item, use the following endpoint.
| `character_id` | `integer` | The item's owner |
| `price` | `string` | The item's price |
| `size` | `string` | The item's size |
| `weight` | `string` | The item's weight |
| `tags` | `array` | Array of tag ids |
| `is_private` | `boolean` | If the item is only visible to `admin` members of the campaign |
| `item_id` | `integer` | The ID of the item's parent item, if it has one |
Expand Down
5 changes: 5 additions & 0 deletions resources/views/cruds/fields/weight.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<x-forms.field
field="weight"
label="{{ __($trans . '.fields.weight') }}">
<input type="text" name="weight" value="{{ old('weight', $source->weight ?? $model->weight ?? null) }}" placeholder="{{ __($trans . '.placeholders.weight') }}" maxlength="191" class="w-full" />
</x-forms.field>
7 changes: 7 additions & 0 deletions resources/views/entities/components/profile/items.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
</div>
@endif

@if ($model->weight)
<div class="element profile-weight">
<div class="title text-uppercase text-xs">{{ __('items.fields.weight') }}</div>
{!! $model->weight !!}
</div>
@endif

@include('entities.components.profile._location')

@if ($model->character)
Expand Down
8 changes: 7 additions & 1 deletion resources/views/entities/pages/inventory/_item.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@php /** @var \App\Models\Inventory $item **/ @endphp
<div class="w-full lg:w-80 h-60 bg-base-100 rounded relative"
@if ($item->item) data-object-size="{{ $item->item->size }}" data-object-price="{{ $item->item->price }}" @endif
@if ($item->item) data-object-size="{{ $item->item->size }}" data-object-price="{{ $item->item->price }}" data-object-weight="{{ $item->item->weight }}" @endif
data-visibility="{{ $item->visibility_id }}"
>

Expand Down Expand Up @@ -45,6 +45,12 @@
{{ $item->item->size }}
</div>
@endif
@if (!empty($item->item->weight))
<div class="object-weight text-xs text-neutral-content text-center hidden">
<x-icon class="fa-duotone fa-weight-hanging" />
{{ $item->item->weight }}
</div>
@endif
@endif
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions resources/views/entities/pages/inventory/details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@
</div>
@endif

@if ($inventory->item->weight)
<div class="flex gap-2 items-center">
<div class="text-accent text-3xl">
<x-icon class="fa-duotone fa-weight-hanging" />
</div>
<div class="flex flex-col gap-0">
<div class="font-extrabold text-xl">
{{ $inventory->item->weight }}
</div>
<div class="text-neutral-content">
{{ __('items.fields.weight') }}
</div>
</div>
</div>
@endif

@if ($inventory->item->location)
<div class="flex gap-2 items-center">
<div class="text-accent text-3xl">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/entities/pages/print/profile/items.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
@if ($model->size)
| {{ __('items.fields.size') }} | {{ $model->size }} |
@endif
@if ($model->weight)
| {{ __('items.fields.weight') }} | {{ $model->weight }} |
@endif
@include('entities.components.profile._location')
@if ($model->character)
| {{ __('items.fields.character') }} | {!! $model->character->name !!} |
Expand Down
7 changes: 7 additions & 0 deletions resources/views/items/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
return $model->size;
}
],
[
'label' => '<i class="fa-solid fa-weight-hanging" aria-hidden="true" title="' . __('items.fields.weight') . '"></i> <span class="sr-only">' . __('items.fields.weight') . '</span>',
'field' => 'weight',
'render' => function($model) {
return $model->weight;
}
],
[
'type' => 'location',
'visible' => $campaign->enabled('locations'),
Expand Down
1 change: 1 addition & 0 deletions resources/views/items/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@include('cruds.fields.item', ['isParent' => true])
@include('cruds.fields.price', ['trans' => 'items'])
@include('cruds.fields.size', ['trans' => 'items'])
@include('cruds.fields.weight', ['trans' => 'items'])

@include('cruds.fields.location')

Expand Down

0 comments on commit a347a02

Please sign in to comment.