Option to mass delete tags #2064

This commit is contained in:
James Cole 2019-12-28 09:59:41 +01:00
parent 156e2e79c7
commit 58c6ec8a8c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 110 additions and 74 deletions

View File

@ -62,6 +62,31 @@ class TagController extends Controller
);
}
/**
*
*/
public function massDestroy(Request $request)
{
$tags = $request->get('tags');
if (null === $tags || !is_array($tags)) {
session()->flash('info', (string)trans('firefly.select_tags_to_delete'));
return redirect(route('tags.index'));
}
$count = 0;
foreach ($tags as $tagId) {
$tagId = (int)$tagId;
$tag = $this->repository->findNull($tagId);
if (null !== $tag) {
$this->repository->destroy($tag);
$count++;
}
}
session()->flash('success', (string)trans('firefly.deleted_x_tags', ['count' => $count]));
return redirect(route('tags.index'));
}
/**
* Create a new tag.
*

View File

@ -505,6 +505,9 @@ return [
'mapbox_api_key' => 'To use map, get an API key from <a href="https://www.mapbox.com/">Mapbox</a>. Open your <code>.env</code> file and enter this code after <code>MAPBOX_API_KEY=</code>.',
'press_tag_location' => 'Right click or long press to set the tag\'s location.',
'clear_location' => 'Clear location',
'delete_all_selected_tags' => 'Delete all selected tags',
'select_tags_to_delete' => 'Don\'t forget to select some tags.',
'deleted_x_tags' => 'Deleted :count tag(s).',
// preferences
'pref_home_screen_accounts' => 'Home screen accounts',

View File

@ -15,6 +15,8 @@
</p>
</div>
</div>
<form action="{{ route('tags.mass-destroy') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
{% for period,entries in clouds %}
{% if entries|length > 0 %}
<div class="row">
@ -28,6 +30,7 @@
<div class="box-body">
<p class="tagcloud">
{% for tagInfo in entries %}
<input type="checkbox" name="tags[]" value="{{ tagInfo.id }}">
<a style="font-size:{{ tagInfo.size }}px;" class="label label-success"
title="{{ tagInfo.created_at.formatLocalized(monthAndDayFormat) }}"
href="{{ route('tags.show',tagInfo.id) }}"><i class="fa fa-fw fa-tag"></i> {{ tagInfo.tag }}</a>
@ -43,9 +46,13 @@
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p>
<a class="btn btn-success" href="{{ route('tags.create') }}"><i class="fa fa-plus fa-fw"></i> {{ ('no_tags_create_default')|_ }}</a>
<button type="submit" class="btn pull-right btn-danger" onclick="return confirm('{{ 'are_you_sure'|_|escape('js') }}');">
<i class="fa fa-fw fa-trash"></i> {{ 'delete_all_selected_tags'|_ }}
</button>
</p>
</div>
</div>
</form>
{% endif %}
{% endblock %}

View File

@ -937,6 +937,7 @@ Route::group(
Route::post('store', ['uses' => 'TagController@store', 'as' => 'store']);
Route::post('update/{tag}', ['uses' => 'TagController@update', 'as' => 'update']);
Route::post('destroy/{tag}', ['uses' => 'TagController@destroy', 'as' => 'destroy']);
Route::post('mass-destroy', ['uses' => 'TagController@massDestroy', 'as' => 'mass-destroy']);
}
);