Allow task attach search across global tasks
This commit is contained in:
@@ -56,16 +56,7 @@ class TasksRelationManager extends RelationManager
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->recordTitle(fn (Task $record) => $this->formatTaskTitle($record->title))
|
||||
->recordSelectOptionsQuery(function (Builder $query): Builder {
|
||||
$collectionId = $this->getOwnerRecord()->getKey();
|
||||
|
||||
return $query
|
||||
->whereNull('tenant_id')
|
||||
->where(function (Builder $inner) use ($collectionId): void {
|
||||
$inner->whereNull('collection_id')
|
||||
->orWhere('collection_id', $collectionId);
|
||||
});
|
||||
})
|
||||
->recordSelectOptionsQuery(fn (Builder $query): Builder => $query->whereNull('tenant_id'))
|
||||
->multiple()
|
||||
->after(function (array $data): void {
|
||||
$collection = $this->getOwnerRecord();
|
||||
@@ -75,9 +66,7 @@ class TasksRelationManager extends RelationManager
|
||||
return;
|
||||
}
|
||||
|
||||
Task::query()
|
||||
->whereIn('id', $recordIds)
|
||||
->update(['collection_id' => $collection->getKey()]);
|
||||
$collection->reassignTasks($recordIds);
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TaskCollection extends Model
|
||||
{
|
||||
@@ -99,6 +100,27 @@ class TaskCollection extends Model
|
||||
return $value ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, int|string> $taskIds
|
||||
*/
|
||||
public function reassignTasks(array $taskIds): void
|
||||
{
|
||||
$ids = array_values(array_unique(array_map('intval', $taskIds)));
|
||||
|
||||
if ($ids === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('task_collection_task')
|
||||
->whereIn('task_id', $ids)
|
||||
->where('task_collection_id', '!=', $this->getKey())
|
||||
->delete();
|
||||
|
||||
Task::query()
|
||||
->whereIn('id', $ids)
|
||||
->update(['collection_id' => $this->getKey()]);
|
||||
}
|
||||
|
||||
protected function resolveTranslation(string $attribute, ?string $locale = null): string
|
||||
{
|
||||
$translations = $this->{$attribute} ?? [];
|
||||
|
||||
Reference in New Issue
Block a user