Fix: Загрузка существующих групп при инициализации
✅ API возвращает группы при пустом запросе с user_id ✅ Фильтрация по названию только если query не пустой ✅ Компонент передаёт user_id при загрузке тегов Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
3dfe1e5a2c
commit
3b390c8358
|
|
@ -13,11 +13,6 @@ class GroupSearchController extends Controller
|
||||||
$query = $request->get('q', '');
|
$query = $request->get('q', '');
|
||||||
$userId = $request->get('user_id', null);
|
$userId = $request->get('user_id', null);
|
||||||
|
|
||||||
// Если запрос пустой - возвращаем пустой массив
|
|
||||||
if (empty(trim($query))) {
|
|
||||||
return response()->json([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$groupsQuery = Group::query()->with('organization');
|
$groupsQuery = Group::query()->with('organization');
|
||||||
|
|
||||||
// Если указан user_id - фильтруем по доступным группам
|
// Если указан user_id - фильтруем по доступным группам
|
||||||
|
|
@ -37,8 +32,12 @@ class GroupSearchController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Если запрос не пустой - фильтруем по названию
|
||||||
|
if (!empty(trim($query))) {
|
||||||
|
$groupsQuery->where('name', 'like', "%{$query}%");
|
||||||
|
}
|
||||||
|
|
||||||
$groups = $groupsQuery
|
$groups = $groupsQuery
|
||||||
->where('name', 'like', "%{$query}%")
|
|
||||||
->orderBy('name')
|
->orderBy('name')
|
||||||
->limit(50)
|
->limit(50)
|
||||||
->get()
|
->get()
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||||
@if(count($value) > 0)
|
@if(count($value) > 0)
|
||||||
const existingIds = {!! json_encode(array_map('strval', is_array($value) ? $value : [])) !!};
|
const existingIds = {!! json_encode(array_map('strval', is_array($value) ? $value : [])) !!};
|
||||||
if (existingIds.length > 0) {
|
if (existingIds.length > 0) {
|
||||||
// Загружаем все группы и фильтруем нужные
|
// Загружаем все доступные группы (с user_id для фильтрации)
|
||||||
fetch('{{ $url }}?q=')
|
let url = '{{ $url }}?q=';
|
||||||
|
@if(isset($user_id) && $user_id)url += '&user_id={{ $user_id }}';@endif
|
||||||
|
|
||||||
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(allItems => {
|
.then(allItems => {
|
||||||
|
// Фильтруем только нужные группы
|
||||||
const items = allItems.filter(item => existingIds.includes(String(item.id)));
|
const items = allItems.filter(item => existingIds.includes(String(item.id)));
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
select.addOption(item);
|
select.addOption(item);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue