Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Header: add tags #827

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions app/Http/Controllers/Entity/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers\Entity;

use App\Http\Controllers\Controller;
use App\Http\Requests\UpdateEntityTags;
use App\Models\Campaign;
use App\Models\Entity;
use App\Traits\CampaignAware;
use App\Traits\GuestAuthTrait;

class TagController extends Controller
{
use CampaignAware;
use GuestAuthTrait;

/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function create(Campaign $campaign, Entity $entity)
{
$this->authorize('update', $entity->child);
$formOptions = ['entity.tags-add.save', $campaign, 'entity' => $entity];

return view('entities.components.tags.create', [
'campaign' => $campaign,
'model' => $entity->child,
'formOptions' => $formOptions
]);
}

/**
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function store(UpdateEntityTags $request, Campaign $campaign, Entity $entity)
{
$this->authorize('update', $entity->child);

$entity->crudSaved();

return redirect()->route('entities.show', [$campaign, $entity])
->with('success', __('tags.children.create.attach_success_entity', ['name' => $entity->name]));
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/UpdateEntityTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateEntityTags extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'tags' => 'array',
'tags.*' => 'exists:tags,id',
];
}
}
1 change: 0 additions & 1 deletion app/Observers/EntityObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Services\Entity\TagService;
use App\Services\ImageService;
use App\Services\PermissionService;
use Illuminate\Support\Str;
use App\Facades\Domain;

class EntityObserver
Expand Down
9 changes: 6 additions & 3 deletions lang/en/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
return [
'children' => [
'actions' => [
'add' => 'Add to tag',
'add' => 'Add to tag',
'add_entity' => 'Add to entity',
],
'create' => [
'attach_success' => '{1} Added :count entity to tag :name.|[2,*] Added :count entities to tag :name.',
'modal_title' => 'Add entities to :name',
'attach_success' => '{1} Added :count entity to tag :name.|[2,*] Added :count entities to tag :name.',
'attach_success_entity' => 'Succesfully updated tags for :name.',
'modal_title' => 'Add entities to :name',
'entity' => 'Add tags to :name',
],
],
'create' => [
Expand Down
14 changes: 12 additions & 2 deletions resources/views/entities/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
$imagePathXL = Avatar::entity($entity ?? $model->entity)->size(400)->thumbnail();
$imagePathMobile = Avatar::entity($entity ?? $model->entity)->size(192)->thumbnail();

$addTagsUrl = route('entity.tags-add', [$campaign, $model->entity]);

/** @var \App\Models\Tag[] $entityTags */
$entityTags = $entity->tagsWithEntity();

Expand Down Expand Up @@ -264,8 +266,8 @@
</div>
@endif

@if($entityTags->count() > 0)
<div class="entity-tags entity-header-line text-xs flex flex-wrap gap-2">
@if($entityTags->count() > 0)
@foreach ($entityTags as $tag)
@if (!$tag->entity) @continue @endif
<a href="{{ route('tags.show', [$campaign, $tag]) }}" data-toggle="tooltip-ajax"
Expand All @@ -275,8 +277,16 @@
{!! $tag->html() !!}
</a>
@endforeach
</div>
@endif
@if(!($model instanceof \App\Models\Tag))
@can('update', $model)
<a href="{{ $addTagsUrl }}"
data-toggle="dialog" data-target="primary-dialog" data-url="{{ $addTagsUrl }}">
<x-icon class="fa-solid fa-plus-circle fa-2x" />
</a>
@endcan
@endif
</div>

@includeIf('entities.headers._' . $model->getEntityType())

Expand Down
7 changes: 7 additions & 0 deletions resources/views/entities/components/tags/_form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php /** @var \App\Models\Entity $model */?>
{{ csrf_field() }}
<x-grid type="1/1">
@include('cruds.fields.tags')
</x-grid>


29 changes: 29 additions & 0 deletions resources/views/entities/components/tags/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php /** @var \App\Models\MiscModel $model */ ?>
@extends('layouts.' . (request()->ajax() ? 'ajax' : 'app'), [
'title' => __('tags.children.create.entity', ['name' => $model->name]),
'description' => '',
'breadcrumbs' => [
Breadcrumb::entity($model->entity)->list(),
Breadcrumb::show($model),
],
'centered' => true,
])

@section('content')
{!! Form::open([
'route' => $formOptions,
'method' => 'POST',
'data-shortcut' => 1,
'class' => 'ajax-subform',
]) !!}

@include('partials.forms.form', [
'title' => __('tags.children.create.entity', ['name' => $model->name]),
'content' => 'entities.components.tags._form',
'submit' => __('tags.children.actions.add_entity'),
'dialog' => true,
])

{!! Form::hidden('entity_id', $model->entity->id) !!}
{!! Form::close() !!}
@endsection
3 changes: 3 additions & 0 deletions routes/campaigns/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
Route::get('/w/{campaign}/tags/{tag}/entity-add', 'Tags\ChildController@create')->name('tags.entity-add');
Route::post('/w/{campaign}/tags/{tag}/entity-add', 'Tags\ChildController@store')->name('tags.entity-add.save');

Route::get('/w/{campaign}/entities/{entity}/tags/add', 'Entity\TagController@create')->name('entity.tags-add');
Route::post('/w/{campaign}/entities/{entity}/tags/add', 'Entity\TagController@store')->name('entity.tags-add.save');

// Multi-delete for cruds
Route::post('/w/{campaign}/bulk/process', 'BulkController@index')->name('bulk.process');
Route::get('/w/{campaign}/bulk/modal', 'BulkController@modal')->name('bulk.modal');
Expand Down