Skip to content

Commit

Permalink
feat: Add search by image name
Browse files Browse the repository at this point in the history
Try to make search view more clear
  • Loading branch information
octfx committed Dec 26, 2023
1 parent 51fcec9 commit e2fffbc
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 21 deletions.
36 changes: 36 additions & 0 deletions app/Http/Controllers/Api/V2/Rsi/CommLink/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use App\Http\Controllers\Api\V2\AbstractApiV2Controller;
use App\Http\Filters\ImageTagFilter;
use App\Http\Requests\AbstractSearchRequest;
use App\Http\Requests\Rsi\CommLink\Image\ImageSearchRequest;
use App\Http\Resources\AbstractBaseResource;
use App\Http\Resources\Rsi\CommLink\CommLinkResource;
use App\Http\Resources\Rsi\CommLink\Image\ImageResource;
Expand Down Expand Up @@ -85,4 +87,38 @@ public function random(Request $request): AnonymousResourceCollection

return ImageResource::collection($query);
}

#[OA\Post(
path: '/api/v2/comm-link-images/search',
tags: ['Comm-Links', 'RSI-Website', 'Images', 'Search'],
parameters: [
new OA\Parameter(ref: '#/components/parameters/limit'),
new OA\Parameter(name: 'filter[tags]', in: 'query', schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'Search for a Comm-Link Image by its filename.',
content: new OA\JsonContent(
type: 'array',
items: new OA\Items(ref: '#/components/schemas/comm_link_image_v2')
)
)
]
)]
public function search(ImageSearchRequest $request): AnonymousResourceCollection
{
$query = QueryBuilder::for(Image::class, $request)
->allowedFilters([
AllowedFilter::partial('tags', 'tags.name'),
])
->whereNull('base_image_id')
->whereRaw("LOWER(src) LIKE ?", [sprintf('%%%s%%', strtolower($request->get('query')))])
->whereRelation('metadata', 'size', '>', 0)
->limit($this->limit)
->orderByDesc('created_at')
->get();

return ImageResource::collection($query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Http\Controllers\Api\V2\Rsi\CommLink\CommLinkSearchController;
use App\Http\Controllers\Controller;
use App\Http\Requests\Rsi\CommLink\Image\AddImageTagsRequest;
use App\Http\Requests\Rsi\CommLink\Image\ImageSearchRequest;
use App\Http\Requests\Rsi\CommLink\Image\ImageUploadRequest;
use App\Models\Rsi\CommLink\Image\Image;
use App\Models\Rsi\CommLink\Image\ImageMetadata;
Expand Down Expand Up @@ -61,7 +62,6 @@ function (Builder $query) use ($request) {
'user.rsi.comm_links.images.index',
[
'images' => $query
->where('local', 1)
->orderByDesc('id')
->groupBy('src')
->paginate(50),
Expand Down Expand Up @@ -183,4 +183,22 @@ public function saveTags(Image $image, AddImageTagsRequest $request): RedirectRe

return redirect()->back();
}

/**
* Search for images by filename
*
* @param ImageSearchRequest $request
* @return View
*/
public function search(ImageSearchRequest $request): View {
$request->query->set('limit', 250);
$controller = new \App\Http\Controllers\Api\V2\Rsi\CommLink\ImageController($request);

return view(
'user.rsi.comm_links.images.index',
[
'images' => $controller->search($request),
]
);
}
}
12 changes: 12 additions & 0 deletions app/Http/Requests/Rsi/CommLink/Image/ImageSearchRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests\Rsi\CommLink\Image;

use App\Http\Requests\AbstractSearchRequest;

class ImageSearchRequest extends AbstractSearchRequest
{

}
1 change: 1 addition & 0 deletions app/Models/Rsi/CommLink/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function similarImages(int $similarity = 90, int $limit = 15): Collection
// Filter out small images
->where('size', '>=', 250 * 1024)
->where('comm_link_images.id', '!=', $this->id)
->where('comm_link_images.base_image_id', 'IS NULL')
->orderBy('pdq_distance')
->limit($limit)
->get()
Expand Down
10 changes: 7 additions & 3 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@
"Comm-Link bearbeiten": "Edit Comm-Link",
"Comm-Link Benachrichtigungen erhalten": "Comm-Link notifications received",
"Comm-Link Bild": "Comm-Link image",
"Comm-Link Bild URL": "Comm-Link image URL",
"Comm-Link Bild URL": "Comm-Link media URL",
"Comm-Link Bilder": "Comm-Link images",
"Comm-Link Bildlinksuche": "Comm-Link Image Link Search",
"Comm-Link Bildsuche": "Comm-Link Image Search",
"Comm-Link Channel": "Comm-Link Channel",
"Comm-Link Inhalt": "Comm-Link content",
"Comm-Link Kategorien": "Comm-Link categories",
"Comm-Link Metadaten": "Comm-Link Metadata",
"Comm-Link Rückwärtssuche": "Comm-Link Reverse Search",
"Comm-Link Serien": "Comm-Link Series",
"Comm-Link Titelsuche": "Search Comm-Links by Title",
"Comm-Links": "Comm-Links",
"Comm-Links mit geändertem Inhalt": "Comm-Links with modified content",
"Comm-Links mit neuem Inhalt": "Comm-Links with new content",
Expand Down Expand Up @@ -299,12 +299,16 @@
"Suche nach Bildern": "Search for images",
"Suche nach Comm-Links mit Bild": "Search for Comm-Links with image",
"Suche nach Comm-Links mit Bildlink": "Search for Comm-Links with image link",
"Suche nach Comm-Links mit Medienurl": "Search for Comm-Links containing a media url",
"Suche nach Comm-Link mit Text": "Search for Comm-Links containing some text",
"Suche nach Comm-Link mit Bild": "Reverse search a Comm-Link by an image",
"Suche nach Comm-Link Bildern": "Search for Comm-Link images by name",
"Systeme": "Systems",

"Tabelle leeren": "Empty table",
"Tags": "Tags",
"Textänderungen": "Text changes",
"Text, welcher in einem Comm-Link vorkommt": "Text which occurs in a Comm-Link",
"Text, welcher in einem Comm-Link vorkommt": "Text which occurs in the body of a Comm-Link",
"Titel": "Title",
"Transkript": "Transcript",
"Transkripte": "Transcripts",
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/forms/form-group.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class="{{ $inputClass ?? 'form-control' }} {{ $errors->has($id) ? 'is-invalid' :
class="{{ $inputClass ?? 'form-control' }} {{ $errors->has($id) ? 'is-invalid' : '' }}"
@if(isset($required) && $required == '1') required @endif
@if(isset($autofocus) && $autofocus == '1') autofocus @endif
@if(isset($placeholder)) placeholder="{{ $placeholder }}" @endif
{{ $inputOptions ?? '' }} />
@endif
{{ $slot }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
</a>
@endunless
<span class="file-type badge badge-{{ $image->metadata->mime_class }}">{{ $image->metadata->mime }}</span>
<img src="{{ str_replace('source', 'post', $image->url) }}"
<img src="{{ str_replace('source', 'post', $image->getLocalOrRemoteUrl()) }}"
alt="{{ empty($image->alt) ? __('Kein alt Text verfügbar') : $image->alt }}"
class="card-img-top"
loading="lazy" />
<small class="d-block">{{ $image->name }}</small>
</div>
@elseif(\Illuminate\Support\Str::contains($image->metadata->mime, 'audio'))
<audio class="card-img-top" controls>
Expand Down Expand Up @@ -103,7 +104,7 @@ class="card-img-top"
<p>@lang('Duplikate')</p>
<ul class="list-unstyled mb-0">
@foreach($image->duplicates as $duplicate)
<li><a class="url" href="{{ route('web.user.rsi.comm-links.images.show', $duplicate->getRouteKey()) }}">{{ $duplicate->name }} ({{ $duplicate->similarity }}%)</a></li>
<li><a class="url" href="{{ route('web.user.rsi.comm-links.images.show', $duplicate->getRouteKey()) }}">{{ $duplicate->name }}</a></li>
@endforeach
</ul>
</div>
Expand Down
14 changes: 8 additions & 6 deletions resources/views/user/rsi/comm_links/images/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@
})
}
mimeSelect.addEventListener('change', (ev) => {
currentUrl.searchParams.delete('page')
currentUrl.searchParams.delete('mime')
currentUrl.searchParams.append('mime', ev.target.value)
if (mimeSelect) {
mimeSelect.addEventListener('change', (ev) => {
currentUrl.searchParams.delete('page')
currentUrl.searchParams.delete('mime')
currentUrl.searchParams.append('mime', ev.target.value)
window.location = currentUrl.href
})
window.location = currentUrl.href
});
}
})();
</script>
@endsection
2 changes: 1 addition & 1 deletion resources/views/user/rsi/comm_links/images/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<td>
<ul class="list-unstyled mb-0">
@forelse($image->duplicates as $duplicate)
<li><a class="url" href="{{ route('web.user.rsi.comm.links.images.show', $duplicate->getRouteKey()) }}">{{ $duplicate->name }} ({{ $duplicate->similarity }}%)</a></li>
<li><a class="url" href="{{ route('web.user.rsi.comm-links.images.show', $duplicate->getRouteKey()) }}">{{ $duplicate->name }}</a></li>
@empty
<li>@lang('Keine')</li>
@endforelse
Expand Down
40 changes: 33 additions & 7 deletions resources/views/user/rsi/comm_links/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div class="card mb-3">
<div class="card-header">
<h4>
{{ __('Comm-Link Bildlinksuche') }}
{{ __('Suche nach Comm-Links mit Medienurl') }}
</h4>
</div>
<div class="card-body">
Expand All @@ -49,7 +49,7 @@
<small>@lang('URL der Form'): <br>https://robertsspaceindustries.com/media/...<br>https://media.robertsspaceindustries.com/...</small>
@endcomponent

<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche nach Comm-Links mit Bildlink')</button>
<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche')</button>
@endcomponent
</div>
</div>
Expand All @@ -58,7 +58,7 @@
<div class="card mb-3">
<div class="card-header">
<h4>
{{ __('Comm-Link Inhalt') }}
{{ __('Suche nach Comm-Link mit Text') }}
</h4>
</div>
<div class="card-body">
Expand All @@ -68,23 +68,26 @@
])
@component('components.forms.form-group', [
'inputType' => 'text',
'label' => __('Comm-Link Inhalt'),
'label' => __('Inhalt'),
'id' => 'query',
'inputOptions' => 'required',
'placeholder' => 'Welcome to the Comm-Link'
])
<small>@lang('Text, welcher in einem Comm-Link vorkommt')</small>
@endcomponent

<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche nach Bildern')</button>
<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche')</button>
@endcomponent
</div>
</div>
@endauth
</div>

<div class="card-deck">
<div class="card mb-3">
<div class="card-header">
<h4>
{{ __('Comm-Link Bildsuche') }}
{{ __('Suche nach Comm-Link mit Bild') }}
</h4>
</div>
<div class="card-body">
Expand Down Expand Up @@ -124,9 +127,32 @@
<label class="form-check-label" for="similarity5" title="75%">@lang('Sehr ungenau')</label>
</div>
</div>
<button class="btn btn-block btn-outline-secondary mt-3">@lang('Suche')</button>
@endcomponent
</div>
</div>

<div class="card mb-3">
<div class="card-header">
<h4>
{{ __('Suche nach Comm-Link Bildern') }}
</h4>
</div>
<div class="card-body">
@component('components.forms.form', [
'action' => route('web.user.rsi.comm-links.images.search'),
'class' => 'd-flex h-100 flex-column',
])
@component('components.forms.form-group', [
'inputType' => 'text',
'label' => __('Dateiname'),
'id' => 'query',
'placeholder' => 'Carrack',
'required' => true
])
@endcomponent

<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche nach Comm-Links mit Bild')</button>
<button class="btn btn-block btn-outline-secondary mt-auto">@lang('Suche')</button>
@endcomponent
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion routes/api/api_v2.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static function () {

Route::get('comm-link-images', 'ImageController@index')->name('cli.index');
Route::get('comm-link-images/random', 'ImageController@random')->name('cli.random');
#Route::post('comm-link-images/search', 'ImageController@search')->name('cli.search');
Route::post('comm-link-images/search', 'ImageController@search')->name('cli.search');
#Route::get('comm-link-images/{image}', 'ImageController@show')->name('cli.show');
Route::get('comm-link-images/{image}/similar', 'CommLinkSearchController@similarSearch')->name('cli.similar');
}
Expand Down
1 change: 1 addition & 0 deletions routes/web/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ static function () {

Route::get('images', 'Image\ImageController@index')->name('images.index');
Route::post('images/upload-wiki', 'Image\ImageController@upload')->name('images.upload-wiki');
Route::post('images/search', 'Image\ImageController@search')->name('images.search');
Route::get('images/{image}/similar', 'Image\ImageController@similarImages')->name('images.similar');
Route::get('images/{image}/tags', 'Image\ImageController@editTags')->name('images.edit-tags');
Route::patch('images/{image}/tags', 'Image\ImageController@saveTags')->name('images.save-tags');
Expand Down

0 comments on commit e2fffbc

Please sign in to comment.