versione 2.0.0
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\Individuo;
|
||||
use App\Models\Gruppo;
|
||||
use App\Models\Evento;
|
||||
use App\Models\StorageRepository;
|
||||
use App\Models\Tag;
|
||||
use App\Models\TipologiaDocumento;
|
||||
use App\Services\StorageRepositoryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -42,9 +43,14 @@ class DocumentoController extends Controller
|
||||
$folderId = $request->get('folder_id');
|
||||
$repoId = $request->get('repository_id');
|
||||
|
||||
$query = Documento::with(['user', 'target', 'cartella', 'repository'])
|
||||
$query = Documento::with(['user', 'target', 'cartella', 'repository', 'tags'])
|
||||
->orderByDesc('created_at');
|
||||
|
||||
if ($request->filled('tag')) {
|
||||
$tagSlugs = (array) $request->input('tag');
|
||||
$query->withAnyTags($tagSlugs);
|
||||
}
|
||||
|
||||
if ($repoId) {
|
||||
$query->where('repository_id', $repoId);
|
||||
} elseif ($folderId) {
|
||||
@@ -54,6 +60,7 @@ class DocumentoController extends Controller
|
||||
}
|
||||
|
||||
$documenti = $query->paginate(20);
|
||||
$allTags = Tag::orderBy('name')->get();
|
||||
$cartelle = DocumentoCartella::with('children')
|
||||
->whereNull('parent_id')
|
||||
->orderBy('nome')
|
||||
@@ -89,7 +96,7 @@ class DocumentoController extends Controller
|
||||
'documenti', 'cartelle', 'currentFolder', 'breadcrumb', 'sottoCartelle',
|
||||
'currentRepo', 'repositories',
|
||||
'individui', 'gruppi', 'eventi', 'mailingLists', 'tipologie',
|
||||
'cartelleMoveOptions'
|
||||
'cartelleMoveOptions', 'allTags'
|
||||
));
|
||||
}
|
||||
|
||||
@@ -106,13 +113,15 @@ class DocumentoController extends Controller
|
||||
public function edit($documento)
|
||||
{
|
||||
$this->authorizeWrite('documenti');
|
||||
$documento = Documento::with('target')->findOrFail($documento);
|
||||
$documento = Documento::with(['target', 'tags'])->findOrFail($documento);
|
||||
$individui = Individuo::orderBy('cognome')->orderBy('nome')->get();
|
||||
$gruppi = Gruppo::orderBy('nome')->get();
|
||||
$eventi = Evento::orderBy('nome_evento')->get();
|
||||
$mailingLists = \App\Models\MailingList::orderBy('nome')->get();
|
||||
$tipologie = TipologiaDocumento::attive();
|
||||
return view('documenti.edit', compact('documento', 'individui', 'gruppi', 'eventi', 'mailingLists', 'tipologie'));
|
||||
$tags = Tag::orderBy('name')->get();
|
||||
$selectedTags = $documento->tags->pluck('id')->toArray();
|
||||
return view('documenti.edit', compact('documento', 'individui', 'gruppi', 'eventi', 'mailingLists', 'tipologie', 'tags', 'selectedTags'));
|
||||
}
|
||||
|
||||
public function options(Request $request)
|
||||
@@ -165,6 +174,8 @@ class DocumentoController extends Controller
|
||||
'visibilita_target_id' => 'nullable|integer',
|
||||
'visibilita_target_type' => 'nullable|string',
|
||||
'note' => 'nullable|string',
|
||||
'tags' => 'nullable|array',
|
||||
'tags.*' => 'exists:tags,id',
|
||||
]);
|
||||
|
||||
$data['visibilita'] = $request->contesto_tipo ?: 'pubblico';
|
||||
@@ -185,6 +196,12 @@ class DocumentoController extends Controller
|
||||
|
||||
$documento->update($data);
|
||||
|
||||
if ($request->has('tags')) {
|
||||
$documento->tags()->sync($request->tags);
|
||||
} else {
|
||||
$documento->tags()->detach();
|
||||
}
|
||||
|
||||
return redirect('/documenti')->with('success', 'Documento aggiornato.');
|
||||
}
|
||||
|
||||
@@ -706,6 +723,41 @@ class DocumentoController extends Controller
|
||||
return back()->with('success', count($ids) . ' documenti associati.');
|
||||
}
|
||||
|
||||
public function massTag(Request $request)
|
||||
{
|
||||
$this->authorizeWrite('documenti');
|
||||
$idsInput = $request->input('ids', '');
|
||||
$ids = is_array($idsInput) ? $idsInput : (is_string($idsInput) ? explode(',', $idsInput) : []);
|
||||
|
||||
if (empty($ids)) {
|
||||
return back()->with('error', 'Nessun documento selezionato.');
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'tags' => 'required|array',
|
||||
'tags.*' => 'exists:tags,id',
|
||||
'mode' => 'required|in:assign,remove',
|
||||
]);
|
||||
|
||||
$tagIds = $data['tags'];
|
||||
$mode = $data['mode'];
|
||||
$count = 0;
|
||||
|
||||
Documento::whereIn('id', $ids)->chunk(100, function ($documenti) use ($tagIds, $mode, &$count) {
|
||||
foreach ($documenti as $documento) {
|
||||
if ($mode === 'assign') {
|
||||
$documento->tags()->syncWithoutDetaching($tagIds);
|
||||
} else {
|
||||
$documento->tags()->detach($tagIds);
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
});
|
||||
|
||||
$actionLabel = $mode === 'assign' ? 'assegnati' : 'rimossi';
|
||||
return back()->with('success', "Tag $actionLabel per $count documenti.");
|
||||
}
|
||||
|
||||
public function massMove(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeWrite('documenti');
|
||||
|
||||
Reference in New Issue
Block a user