table.blade.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <div class="table-responsive">
  2. <div class="table-buttons py-2 bg-primary rounded-start d-flex flex-column ">
  3. <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal"
  4. data-bs-target="#table_{{ $id }}_modal_search">
  5. <i class="bi bi-search-heart @if(request()->has('s')) text-danger @endif"></i>
  6. </button>
  7. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  8. data-bs-target="#table_{{ $id }}_modal_filters">
  9. <i class="bi bi-funnel-fill @if(request()->has('filters')) text-danger @endif"></i>
  10. </button>
  11. <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
  12. data-bs-target="#table_{{ $id }}_modal_settings">
  13. <i class="bi bi-gear-fill"></i>
  14. </button>
  15. </div>
  16. <table class="table" id="tbl" data-table-name="{{ $id }}" style="display: none; min-height: 380px;">
  17. <thead>
  18. <tr>
  19. @foreach($header as $headerName => $headerTitle)
  20. <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
  21. <div class="d-flex align-items-center justify-content-between">
  22. <div class="cursor-pointer sort-by-column" data-name="{{ $headerName }}">
  23. {{ $headerTitle }}
  24. </div>
  25. <div class="text-center mx-1 cursor-pointer" data-name="{{ $headerName }}">
  26. @if(($headerName== $sortBy))
  27. @if($orderBy === 'asc')
  28. <i class="bi bi-arrow-down-square-fill text-primary"></i>
  29. @else
  30. <i class="bi bi-arrow-up-square-fill text-primary"></i>
  31. @endif
  32. @endif
  33. </div>
  34. @if($headerName !== 'image')
  35. @php
  36. $type = null;
  37. $data = (array_merge($filters, $ranges, $dates))[$headerName] ?? null;
  38. if (isset($filters[$headerName])) {
  39. $type = 'filters';
  40. } elseif (isset($ranges[$headerName])) {
  41. // Для dropdown фильтров вместо диапазона используем список всех вариантов
  42. $type = 'filters';
  43. } elseif (isset($dates[$headerName])) {
  44. $type = 'dates';
  45. }
  46. @endphp
  47. <div class="text-end cursor-pointer dropdown" data-bs-auto-close="outside" aria-expanded="false">
  48. <i
  49. data-bs-auto-close="outside"
  50. aria-expanded="false"
  51. data-bs-toggle="dropdown"
  52. class="dropdown-toggle bi
  53. @if(isset(request()->filters[$headerName]) ||
  54. isset(request()->filters[str_replace('_txt', '', $headerName) . '_from']) ||
  55. isset(request()->filters[str_replace('_txt', '', $headerName) . '_to'])
  56. )
  57. bi-funnel-fill text-danger
  58. @else
  59. bi-funnel
  60. @endif
  61. " id="{{$headerName}}"></i>
  62. @include('partials.newFilterElement', ['id' => $headerName, 'data' => $data, 'type' => $type, 'table' => $id, 'isSort' => $headerName == $sortBy, '$orderBy' => $orderBy])
  63. </div>
  64. @endif
  65. </div>
  66. </th>
  67. @endforeach
  68. </tr>
  69. </thead>
  70. <tbody>
  71. @foreach($strings as $string)
  72. <tr>
  73. @foreach($header as $headerName => $headerTitle)
  74. <td class="column_{{$headerName}}"
  75. @if(isset($routeName) && !str_contains($headerName, 'image') && !str_contains($headerName, 'order_status_name')) onclick="location.href='{{ route($routeName, $string->id) }}'" @endif>
  76. @if(str_contains($headerName, '-'))
  77. @php
  78. list($rel, $field) = explode('-', $headerName);
  79. @endphp
  80. @if(isset($string->$rel->$field))
  81. @if(str_ends_with($field, '_id'))
  82. @php
  83. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $field));
  84. @endphp
  85. {!! $string->$rel->$relation?->name; !!}
  86. @else
  87. @if(str_contains($field, 'image') && $string->$rel->$field)
  88. <a href="{{ $string->$rel->$field }}" data-toggle="lightbox"
  89. data-gallery="photos" data-size="fullscreen">
  90. <img src="{{ $string->$rel->$field }}" alt="" class="img-thumbnail maf-img">
  91. </a>
  92. @else
  93. {!! $string->$rel->$field !!}
  94. @endif
  95. @endif
  96. @else
  97. <ul class="small mb-0 list-group list-group-flush bg-secondary">
  98. @foreach($string->$rel ?? [] as $item)
  99. <li class="list-group-item py-0 bg-body-secondary">
  100. {!! $item->$field !!}
  101. </li>
  102. @endforeach
  103. </ul>
  104. @endif
  105. @elseif(str_ends_with($headerName, '_id'))
  106. @php
  107. $relation = \Illuminate\Support\Str::camel(str_replace('_id', '', $headerName));
  108. @endphp
  109. @if($headerName == 'order_status_id')
  110. <div class="badge fs-5 text-bg-{{ App\Models\Order::STATUS_COLOR[$string->order_status_id] }}">{{ $string->$relation?->name }}</div>
  111. @else
  112. {!! $string->$relation?->name; !!}
  113. @endif
  114. @elseif(str_ends_with($headerName, '_date') && ($string->$headerName))
  115. {{ \App\Helpers\DateHelper::getHumanDate($string->$headerName, true) }}
  116. @elseif(str_contains($headerName, 'image') && $string->$headerName)
  117. <a href="{{ $string->$headerName }}" data-toggle="lightbox" data-gallery="photos"
  118. data-size="fullscreen">
  119. <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
  120. </a>
  121. @elseif(str_contains($headerName, 'order_status_name'))
  122. <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
  123. @foreach($statuses as $statusId => $statusName)
  124. <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
  125. @endforeach
  126. </select>
  127. @elseif($headerName === 'tsn_number' && $string->$headerName)
  128. <span data-bs-toggle="tooltip"
  129. data-bs-placement="top"
  130. title="{{ $string->tsn_number_description ?? 'Нет расшифровки' }}"
  131. style="cursor: help; text-decoration: underline dotted;">
  132. {{ $string->$headerName }}
  133. </span>
  134. @elseif($headerName === 'pricing_code' && $string->$headerName)
  135. <span data-bs-toggle="tooltip"
  136. data-bs-placement="top"
  137. title="{{ $string->pricing_code_description ?? 'Нет расшифровки' }}"
  138. style="cursor: help; text-decoration: underline dotted;">
  139. {{ $string->$headerName }}
  140. </span>
  141. @elseif($headerName === 'pricing_codes_list' && $string->pricingCodes->count() > 0)
  142. @foreach($string->pricingCodes as $pricingCode)
  143. <span data-bs-toggle="tooltip"
  144. data-bs-placement="top"
  145. title="{{ $pricingCode->description ?? 'Нет расшифровки' }}"
  146. style="cursor: help; text-decoration: underline dotted;">
  147. {{ $pricingCode->code }}
  148. </span>@if(!$loop->last)<br>@endif
  149. @endforeach
  150. @else
  151. <p title="{!! $string->$headerName !!}">
  152. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  153. </p>
  154. @endif
  155. </td>
  156. @endforeach
  157. </tr>
  158. @endforeach
  159. </tbody>
  160. </table>
  161. </div>
  162. <!-- Модальное окно настроек таблицы -->
  163. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
  164. aria-hidden="true">
  165. <div class="modal-dialog modal-fullscreen-sm-down">
  166. <div class="modal-content">
  167. <div class="modal-header">
  168. <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
  169. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  170. </div>
  171. <div class="modal-body">
  172. @foreach($header as $headerName => $headerTitle)
  173. <div>
  174. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  175. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  176. </label>
  177. </div>
  178. @endforeach
  179. </div>
  180. <div class="modal-footer">
  181. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  182. </div>
  183. </div>
  184. </div>
  185. </div>
  186. <!-- Модальное окно фильтров -->
  187. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
  188. aria-hidden="true">
  189. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  190. <div class="modal-content">
  191. <div class="modal-header">
  192. <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
  193. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  194. </div>
  195. <div class="modal-body">
  196. <form class="filters">
  197. @if(isset($filters) && is_array($filters))
  198. @foreach($filters as $filterName => $filter)
  199. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  200. @include('partials.select', [
  201. 'name' => 'filters[' . $filterName . ']',
  202. 'title' => $filter['title'],
  203. 'options' => $filter['values'],
  204. 'value' => request()->filters[$filterName] ?? '',
  205. ])
  206. @endforeach
  207. @endif
  208. @if(isset($ranges) && is_array($ranges))
  209. @foreach($ranges as $rangeName => $range)
  210. @include('partials.input', [
  211. 'name' => 'filters[' . $rangeName . '_from]',
  212. 'type' => 'number',
  213. 'title' => $range['title'] . ' с:',
  214. 'min' => $range['min'],
  215. 'max' => $range['max'],
  216. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  217. ])
  218. @include('partials.input', [
  219. 'name' => 'filters[' . $rangeName . '_to]',
  220. 'type' => 'number',
  221. 'title' => ' по:',
  222. 'min' => $range['min'],
  223. 'max' => $range['max'],
  224. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  225. ])
  226. @endforeach
  227. @endif
  228. @if(isset($dates) && is_array($dates))
  229. @foreach($dates as $rangeName => $range)
  230. @include('partials.input', [
  231. 'name' => 'filters[' . $rangeName . '_from]',
  232. 'type' => 'date',
  233. 'title' => $range['title'] . ' с:',
  234. 'min' => $range['min'],
  235. 'max' => $range['max'],
  236. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  237. ])
  238. @include('partials.input', [
  239. 'name' => 'filters[' . $rangeName . '_to]',
  240. 'type' => 'date',
  241. 'title' => $range['title'] . ' по:',
  242. 'min' => $range['min'],
  243. 'max' => $range['max'],
  244. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  245. ])
  246. @endforeach
  247. @endif
  248. </form>
  249. </div>
  250. <div class="modal-footer">
  251. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  252. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  253. </button>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. <!-- Модальное окно поиска -->
  259. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
  260. aria-hidden="true">
  261. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  262. <div class="modal-content">
  263. <div class="modal-header">
  264. <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
  265. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  266. </div>
  267. <div class="modal-body">
  268. <div>
  269. Поиск ведётся по следующим колонкам:
  270. <span class="fst-italic">
  271. @foreach($searchFields as $searchField)
  272. {{ $header[$searchField] }}
  273. @if(!$loop->last)
  274. ,
  275. @endif
  276. @endforeach
  277. </span>
  278. </div>
  279. <form class="search-form">
  280. @include('partials.input', [
  281. 'name' => 's',
  282. 'title' => 'Поиск',
  283. 'placeholder' => 'что ищем?',
  284. 'value' => request()->s ?? '',
  285. ])
  286. </form>
  287. </div>
  288. <div class="modal-footer">
  289. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  290. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  291. </button>
  292. </div>
  293. </div>
  294. </div>
  295. </div>
  296. @push('scripts')
  297. <script type="module">
  298. // Ждём загрузки jQuery через Vite
  299. function waitForJQuery(callback) {
  300. if (typeof window.$ !== 'undefined') {
  301. callback();
  302. } else {
  303. setTimeout(() => waitForJQuery(callback), 50);
  304. }
  305. }
  306. waitForJQuery(function () {
  307. // on page load set column visible
  308. let tbl = $('#tbl');
  309. let tableName = tbl.attr('data-table-name');
  310. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  311. // on first load create tables object
  312. if (!tables) {
  313. tables = {};
  314. }
  315. // hide disabled columns
  316. $.each(tables, function (colName, colStatus) {
  317. if (!colStatus) {
  318. $('.checkbox-' + colName).attr('checked', false);
  319. $('.column_' + colName).hide();
  320. }
  321. });
  322. // highlight search text
  323. let searchText = $('.search-form input').val();
  324. if (searchText !== '') {
  325. let innerHTML = tbl.html();
  326. let index = innerHTML.indexOf(searchText);
  327. if (index >= 0) {
  328. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  329. tbl.html(innerHTML);
  330. }
  331. }
  332. $('.table').fadeIn();
  333. $('.toggle-column').on('change', function () {
  334. let columnName = $(this).attr('data-name');
  335. let columnStatus = $(this).is(':checked');
  336. // save column status
  337. tables[columnName] = columnStatus;
  338. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  339. // show or hide column
  340. if (columnStatus) {
  341. $('.column_' + columnName).show('fast');
  342. } else {
  343. $('.column_' + columnName).hide('fast');
  344. }
  345. });
  346. $('.sort-by-column').on('click', function () {
  347. let columnName = $(this).attr('data-name');
  348. let currentUrl = new URL(document.location.href);
  349. let currentColumnName = currentUrl.searchParams.get('sortBy');
  350. currentUrl.searchParams.set('sortBy', columnName);
  351. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  352. currentUrl.searchParams.delete('order');
  353. } else {
  354. currentUrl.searchParams.set('order', 'desc');
  355. }
  356. document.location.href = currentUrl.href;
  357. });
  358. $('.accept-filters').on('click', function () {
  359. let filters = $('.filters').serializeArray();
  360. let currentUrl = new URL(document.location.href);
  361. $.each(filters, function (id, filter) {
  362. if (filter.value !== '') {
  363. currentUrl.searchParams.set(filter.name, filter.value);
  364. } else {
  365. currentUrl.searchParams.delete(filter.name);
  366. }
  367. });
  368. currentUrl.searchParams.delete('page');
  369. document.location.href = currentUrl.href;
  370. });
  371. $('.reset-filters').on('click', function () {
  372. let filters = $('.filters').serializeArray();
  373. let currentUrl = new URL(document.location.href);
  374. $.each(filters, function (id, filter) {
  375. currentUrl.searchParams.delete(filter.name);
  376. });
  377. currentUrl.searchParams.delete('page');
  378. document.location.href = currentUrl.href;
  379. });
  380. $('.accept-search').on('click', function () {
  381. let s = $('.search-form input').val();
  382. let currentUrl = new URL(document.location.href);
  383. if (s !== '') {
  384. currentUrl.searchParams.set('s', s);
  385. } else {
  386. currentUrl.searchParams.delete('s');
  387. }
  388. currentUrl.searchParams.delete('page');
  389. document.location.href = currentUrl.href;
  390. });
  391. $('.reset-search').on('click', function () {
  392. let currentUrl = new URL(document.location.href);
  393. currentUrl.searchParams.delete('s');
  394. currentUrl.searchParams.delete('page');
  395. document.location.href = currentUrl.href;
  396. });
  397. $('.change-order-status').on('change', function () {
  398. let orderStatusId = $(this).val();
  399. let orderId = $(this).attr('data-order-id');
  400. $.post(
  401. '{{ route('order.update') }}',
  402. {
  403. '_token' : '{{ csrf_token() }}',
  404. id: orderId,
  405. order_status_id: orderStatusId
  406. },
  407. function () {
  408. $('.alerts').append(
  409. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  410. );
  411. setTimeout(function () {
  412. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  413. $(".main-alert").slideUp(500);
  414. })
  415. }, 3000);
  416. }
  417. );
  418. });
  419. $(document).ready(async function () {
  420. let height1 = $('.das').innerHeight();
  421. let height2 = $('.catalog').innerHeight();
  422. let totalHeight = (Number(height1) || 0) + (Number(height2) || 0);
  423. $(".table-responsive").css('maxHeight', $(window).height() - totalHeight - 50);
  424. // Инициализация tooltips для полей tsn_number и pricing_code
  425. const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
  426. const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
  427. });
  428. }); // end waitForJQuery
  429. </script>
  430. @endpush