Skip to content

Commit

Permalink
refactor: Add prev/next links to image tag edit view
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Jan 1, 2024
1 parent 530cda9 commit 561ac54
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function similarImages(Request $request): View
public function editTags(Image $image): View
{
return view(
'web.rsi.comm_links.tags.edit',
'web.rsi.comm_links.images.edit-tags',
[
'tags' => Tag::query()->orderByDesc('name')->get(),
'image' => $image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function edit(Tag $tag)
$this->authorize('web.rsi.comm-links.view');

return view(
'web.rsi.comm_links.tags.edit-tag',
'web.rsi.comm_links.tags.edit',
[
'tag' => $tag,
]
Expand Down
16 changes: 16 additions & 0 deletions app/Models/Rsi/CommLink/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,20 @@ public function getLocalPathAttribute()
{
return storage_path("app/public/comm_link_images/{$this->dir}/{$this->name}");
}

/**
* Previous Image
*/
public function getPrevAttribute()
{
return self::query()->where('id', '<', $this->id)->orderBy('id', 'desc')->first(['id']);
}

/**
* Next Image
*/
public function getNextAttribute()
{
return self::query()->where('id', '>', $this->id)->orderBy('id', 'desc')->first(['id']);
}
}
4 changes: 4 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@
"Monde": "Moons",
"Montiert": "Mounts",

"Nächstes Bild": "Next image",
"Name": "Name",
"Nein": "No",
"Neu importierte Comm-Links": "Newly imported Comm-Links",
"Neue Tags können durch Tippen in der Auswahl hinzugefügt werden.": "New tags can be added by typing into the input field.",
"Nicht gefunden": "Not found",
"Nicht vorhanden": "Not available",
"Nutzlast": "Payload",
Expand Down Expand Up @@ -333,6 +335,7 @@
"Veröffentlichung": "Publication",
"Vorhandene Versionen": "Existing versions",
"Vorheriger": "Previous",
"Vorheriges Bild": "Previous image",
"Vorschau": "Preview",
"Vorschau Version vom": "Preview version from",

Expand All @@ -353,6 +356,7 @@
"zu": "to",
"Zuletzt geändert": "Last modified",
"Zurück": "Back",
"Zufälliges Bild": "Random image",

"Ähnliche Dateien (alpha)": "Similar files (alpha)",
"Ähnlich": "Similar",
Expand Down
77 changes: 77 additions & 0 deletions resources/views/web/rsi/comm_links/images/edit-tags.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@extends('web.layouts.default')

@section('title', __('Bild').' - '.$image->id. ' ' . __('(bearbeiten)'))

@section('content')
<div class="d-flex mb-3 nav-bar justify-content-between">
@unless($image->prev === null)
<a href="{{ route('web.rsi.comm-links.images.edit-tags', $image->prev) }}" class="btn btn-outline-secondary d-block">@lang('Vorheriges Bild')</a>
@else
<a href="#" class="btn btn-outline-secondary disabled d-block">@lang('Vorheriges Bild')</a>
@endunless
<a href="{{ route('web.rsi.comm-links.images.start-edit') }}" class="btn btn-secondary d-block">@lang('Zufälliges Bild')</a>
@unless($image->next === null)
<a href="{{ route('web.rsi.comm-links.images.edit-tags', $image->next) }}" class="btn btn-outline-secondary d-block">@lang('Nächstes Bild')</a>
@else
<a href="#" class="btn btn-outline-secondary disabled d-block">@lang('Nächstes Bild')</a>
@endunless
</div>

@component('components.forms.form', [
'method' => 'PATCH',
'action' => route('web.rsi.comm-links.images.save-tags', $image->getRouteKey()),
'class' => '',
])
@include('components.errors')
<div class="row">
<div class="col-12 col-md-7">
@include('components.comm_links.image_info_card', ['image' => $image, 'noFooter' => true])
</div>
<div class="col-12 col-md-5 d-flex align-content-stretch flex-column">
<button type="submit" class="btn btn-block btn-primary mb-3">@lang('Speichern')</button>
<span class="alert alert-warning d-none" id="new-tag-warning"></span>
<span class="help-block d-block mb-2">@lang('Neue Tags können durch Tippen in der Auswahl hinzugefügt werden.')</span>
<select class="form-select custom-select form-control" multiple size="15" name="tags[]" id="tags">
@foreach($tags as $tag)
<option value="id:{{ $tag->id }}" @php if ($image_tags->contains($tag->name)) echo "selected"; @endphp>{{ $tag->translated_name }}</option>
@endforeach
</select>
</div>
</div>
@endcomponent
@endsection


@section('body__after')
@parent
<script>
(()=>{
const newTags = [];
$('#tags').select2({
allowClear: true,
closeOnSelect: false,
tags: true
});
$('#tags').select2('open');
$('#tags').on('select2:selecting', function(e) {
const datum = e.params.args.data;
if (datum?.id && (datum?.id ?? '').slice(0, 3) !== 'id:') {
if (!newTags.includes(datum.id)) {
newTags.push(datum.id);
}
}
if (newTags.length > 0) {
const container = document.querySelector('#new-tag-warning');
container.classList.remove('d-none');
container.innerText = `Die folgenden Tags existieren noch nicht in der Datenbank: ${newTags.join(', ')}.`
}
});
})();
</script>
@endsection
37 changes: 0 additions & 37 deletions resources/views/web/rsi/comm_links/tags/edit-tag.blade.php

This file was deleted.

77 changes: 25 additions & 52 deletions resources/views/web/rsi/comm_links/tags/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
@extends('web.layouts.default')

@section('title', __('Bild').' - '.$image->id. ' ' . __('(bearbeiten)'))
@section('title', __('Tag').' - '.$tag->translated_name. ' ' . __('(bearbeiten)'))

@section('content')
<a href="{{ route('web.rsi.comm-links.images.start-edit') }}" class="btn btn-block btn-secondary mb-3">@lang('Anderes Bild')</a>
@component('components.forms.form', [
'method' => 'PATCH',
'action' => route('web.rsi.comm-links.images.save-tags', $image->getRouteKey()),
'class' => '',
'action' => route('web.rsi.comm-links.image-tags.update', $tag->getRouteKey()),
'method' => 'POST',
'class' => 'card mb-4'
])
@include('components.errors')
<div class="row">
<div class="col-12 col-md-7">
@include('components.comm_links.image_info_card', ['image' => $image, 'noFooter' => true])
</div>
<div class="col-12 col-md-5 d-flex align-content-stretch flex-column">
<button type="submit" class="btn btn-block btn-primary mb-3">@lang('Speichern')</button>
<span class="alert alert-warning d-none" id="new-tag-warning"></span>
<span class="help-block d-block mb-2">@lang('Neue Einträge können durch Tippen in der Auswahl hinzugefügt werden.')</span>
<select class="form-select custom-select form-control" multiple size="15" name="tags[]" id="tags">
@foreach($tags as $tag)
<option value="id:{{ $tag->id }}" @php if ($image_tags->contains($tag->name)) echo "selected"; @endphp>{{ $tag->translated_name }}</option>
@endforeach
</select>
<div class="wrapper">
<h4 class="card-header">@lang('Tag Bearbeiten')</h4>
<div class="card-body">
@include('components.errors')
@include('components.messages')
@component('components.forms.form-group', [
'inputType' => 'text',
'label' => __('Name'),
'id' => 'name',
'value' => $tag->name,
'required' => true,
])@endcomponent
@component('components.forms.form-group', [
'inputType' => 'text',
'label' => __('Name') . ' ' . __('Englisch'),
'id' => 'name_en',
'value' => $tag->name_en,
'required' => true,
])@endcomponent

<button class="btn btn-outline-secondary" type="submit">@lang('Speichern')</button>
</div>
</div>
@endcomponent
@endsection


@section('body__after')
@parent
<script>
(()=>{
const newTags = [];
$('#tags').select2({
allowClear: true,
closeOnSelect: false,
tags: true
});
$('#tags').select2('open');
$('#tags').on('select2:selecting', function(e) {
const datum = e.params.args.data;
if (datum?.id && (datum?.id ?? '').slice(0, 3) !== 'id:') {
if (!newTags.includes(datum.id)) {
newTags.push(datum.id);
}
}
if (newTags.length > 0) {
const container = document.querySelector('#new-tag-warning');
container.classList.remove('d-none');
container.innerText = `Die folgenden Tags existieren noch nicht in der Datenbank: ${newTags.join(', ')}.`
}
});
})();
</script>
@endsection

0 comments on commit 561ac54

Please sign in to comment.