Skip to content

Commit

Permalink
Switch to artist_title
Browse files Browse the repository at this point in the history
  • Loading branch information
driftingly committed Apr 29, 2024
1 parent bf08868 commit 7b655a7
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 205 deletions.
14 changes: 9 additions & 5 deletions app/Http/Controllers/Twill/ArtworkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Facades\App\Libraries\DamsImageService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class ArtworkController extends ModuleController
{
Expand All @@ -31,7 +32,7 @@ protected function setUpController(): void
$this->disableBulkRestore();
$this->disableBulkForceDelete();

$this->setSearchColumns(['title', 'artist_display']);
$this->setSearchColumns(['title', 'artist']);
}

public function getCreateForm(): Form
Expand Down Expand Up @@ -77,7 +78,7 @@ public function getForm(TwillModelContract $model): Form
->label('Override Image')
->note('This will replace the image above'),
Input::make()
->name('artist_display'),
->name('artist'),
Input::make()
->type('textarea')
->name('location_directions')
Expand All @@ -91,7 +92,7 @@ public function getForm(TwillModelContract $model): Form
'mainReferenceNumber' => $apiArtwork->main_reference_number ?? '',
'gallery' => $apiGallery->title ?? '',
'floor' => $apiGallery->floor ?? '',
])
]),
])
);
}
Expand Down Expand Up @@ -119,7 +120,7 @@ protected function additionalIndexTableColumns(): TableColumns
{
return parent::additionalIndexTableColumns()
->add(Text::make()
->field('artist_display'))
->field('artist'))
->add(Boolean::make()
->field('is_on_view'))
->add(Text::make()
Expand All @@ -140,8 +141,11 @@ public function queryArtwork(Request $request, ApiQueryBuilder $api): JsonRespon
],
'minimum_should_match' => 1,
]])
->get(['id', 'title', 'artist_display', 'image_id'], '/api/v1/artworks/search')
->get(['id', 'main_reference_number', 'is_on_view', 'title', 'artist_title', 'artist_display', 'image_id'], '/api/v1/artworks/search')
->map(function ($artwork) {
$artwork->artist = Str::of($artwork->artist_title?: $artwork->artist_display)
->before("\n")->trim()->__toString();

$artwork->thumbnail = $artwork->image_id
? DamsImageService::getUrl($artwork->image_id, [
'name' => 'thumbnail',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/ThemePromptArtworkResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function toArray(Request $request): array
'id' => $this->id,
'title' => $this->artwork->title,
...$images,
'artist' => $this->artwork->artist_display,
'artist' => $this->artwork->artist,
'year' => $this->artwork->date_display,
'medium' => $this->artwork->medium_display,
'credit' => $this->artwork->credit_line,
Expand Down
5 changes: 3 additions & 2 deletions app/Models/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Artwork extends Model
public const ARTWORK_API_FIELDS = [
'id',
'main_reference_number',
'artist_title',
'artist_display',
'medium_display',
'date_display',
Expand All @@ -50,7 +51,7 @@ class Artwork extends Model
'published',
'datahub_id',
'title',
'artist_display',
'artist',
'location_directions',
'is_on_view',
'image_id',
Expand All @@ -64,7 +65,7 @@ class Artwork extends Model

public $translatedAttributes = [
'title',
'artist_display',
'artist',
'location_directions',
];

Expand Down
9 changes: 6 additions & 3 deletions app/Repositories/ArtworkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use A17\Twill\Repositories\ModuleRepository;
use App\Libraries\Api\Builders\ApiQueryBuilder;
use App\Models\Artwork;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class ArtworkRepository extends ModuleRepository
{
Expand Down Expand Up @@ -38,9 +38,12 @@ public function prepareFieldsBeforeCreate(array $fields): array
$apiFields['floor'] = $galleryFields['floor'] ?? null;
}

$artist = Str::of($apiFields['artist_title'] ?: $apiFields['artist_display'])
->before("\n")->trim()->__toString();

$translatedFields = [
'artist_display' => [
'en' => Arr::pull($apiFields, 'artist_display'),
'artist' => [
'en' => $artist,
],
];

Expand Down
2 changes: 1 addition & 1 deletion config/twill.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'activity' => true,
'draft' => true,
'search' => true,
'search_fields' => ['title', 'artist_display'],
'search_fields' => ['title', 'artist'],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up()
Schema::create('artwork_translations', function (Blueprint $table) {
createDefaultTranslationsTableFields($table, 'artwork');
$table->string('title')->nullable();
$table->string('artist_display')->nullable();
$table->string('artist')->nullable();
$table->string('location_directions')->nullable();
});

Expand Down
4 changes: 2 additions & 2 deletions database/seeders/ArtworkSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function run(ThemePrompt $themePrompt, array $artworks): void
['datahub_id' => $apiFields['datahub_id']],
[
'title' => $rawArtwork['title'],
'artist_display' => $rawArtwork['artist'],
'artist' => $rawArtwork['artist'],
'location_directions' => $rawArtwork['locationDirections'],
'published' => true,
...$apiFields,
Expand All @@ -57,7 +57,7 @@ public function run(ThemePrompt $themePrompt, array $artworks): void
$artwork,
[
'title' => $translation['title'],
'artist_display' => $translation['artist'],
'artist' => $translation['artist'],
'location_directions' => $translation['locationDirections'],
],
$locale
Expand Down
4 changes: 2 additions & 2 deletions database/seeders/TestSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function run(): void
['datahub_id' => $artwork->id],
[
'title' => $artwork->title,
'artist_display' => $artwork->artist_display,
'artist' => $artwork->artist_title,
'location_directions' => 'Test Location Directions',
'is_on_view' => $artwork->is_on_view,
'image_id' => $artwork->image_id,
Expand All @@ -70,7 +70,7 @@ public function run(): void

$artworks->each(fn ($artwork) => $this->addTranslations(
$artwork,
['title', 'artist_display', 'location_directions']
['title', 'artist', 'location_directions']
)
);

Expand Down
Loading

0 comments on commit 7b655a7

Please sign in to comment.