table.blade.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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(isset((array_merge($filters, $ranges, $dates))[$headerName]) || ($headerName == $sortBy))
  35. <div class="text-end cursor-pointer dropdown" data-bs-auto-close="outside" aria-expanded="false">
  36. <i
  37. data-bs-auto-close="outside"
  38. aria-expanded="false"
  39. data-bs-toggle="dropdown"
  40. class="dropdown-toggle bi
  41. @if(isset(request()->filters[$headerName]) ||
  42. isset(request()->filters[str_replace('_txt', '', $headerName) . '_from']) ||
  43. isset(request()->filters[str_replace('_txt', '', $headerName) . '_to'])
  44. )
  45. bi-funnel-fill text-danger
  46. @else
  47. bi-funnel
  48. @endif
  49. " id="{{$headerName}}"></i>
  50. @php
  51. $mergedData = array_merge($filters, $ranges, $dates);
  52. $type = null;
  53. $data = (array_merge($filters, $ranges, $dates))[$headerName] ?? null;
  54. if (isset($filters[$headerName])) {
  55. $type = 'filters';
  56. } elseif (isset($ranges[$headerName])) {
  57. $type = 'ranges';
  58. } elseif (isset($dates[$headerName])) {
  59. $type = 'dates';
  60. }
  61. @endphp
  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. @else
  128. <p title="{!! $string->$headerName !!}">
  129. {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
  130. </p>
  131. @endif
  132. </td>
  133. @endforeach
  134. </tr>
  135. @endforeach
  136. </tbody>
  137. </table>
  138. </div>
  139. <!-- Модальное окно настроек таблицы -->
  140. <div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
  141. aria-hidden="true">
  142. <div class="modal-dialog modal-fullscreen-sm-down">
  143. <div class="modal-content">
  144. <div class="modal-header">
  145. <h1 class="modal-title fs-5" id="exampleModalLabel">Выбор отображаемых колонок</h1>
  146. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  147. </div>
  148. <div class="modal-body">
  149. @foreach($header as $headerName => $headerTitle)
  150. <div>
  151. <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
  152. class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
  153. </label>
  154. </div>
  155. @endforeach
  156. </div>
  157. <div class="modal-footer">
  158. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <!-- Модальное окно фильтров -->
  164. <div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
  165. aria-hidden="true">
  166. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  167. <div class="modal-content">
  168. <div class="modal-header">
  169. <h1 class="modal-title fs-5" id="exampleModalLabel">Фильтры по колонкам таблицы</h1>
  170. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  171. </div>
  172. <div class="modal-body">
  173. <form class="filters">
  174. @if(isset($filters) && is_array($filters))
  175. @foreach($filters as $filterName => $filter)
  176. @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
  177. @include('partials.select', [
  178. 'name' => 'filters[' . $filterName . ']',
  179. 'title' => $filter['title'],
  180. 'options' => $filter['values'],
  181. 'value' => request()->filters[$filterName] ?? '',
  182. ])
  183. @endforeach
  184. @endif
  185. @if(isset($ranges) && is_array($ranges))
  186. @foreach($ranges as $rangeName => $range)
  187. @include('partials.input', [
  188. 'name' => 'filters[' . $rangeName . '_from]',
  189. 'type' => 'number',
  190. 'title' => $range['title'] . ' с:',
  191. 'min' => $range['min'],
  192. 'max' => $range['max'],
  193. 'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
  194. ])
  195. @include('partials.input', [
  196. 'name' => 'filters[' . $rangeName . '_to]',
  197. 'type' => 'number',
  198. 'title' => ' по:',
  199. 'min' => $range['min'],
  200. 'max' => $range['max'],
  201. 'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
  202. ])
  203. @endforeach
  204. @endif
  205. @if(isset($dates) && is_array($dates))
  206. @foreach($dates as $rangeName => $range)
  207. @include('partials.input', [
  208. 'name' => 'filters[' . $rangeName . '_from]',
  209. 'type' => 'date',
  210. 'title' => $range['title'] . ' с:',
  211. 'min' => $range['min'],
  212. 'max' => $range['max'],
  213. 'value' => request()->filters[$rangeName . '_from'] ?? '',
  214. ])
  215. @include('partials.input', [
  216. 'name' => 'filters[' . $rangeName . '_to]',
  217. 'type' => 'date',
  218. 'title' => $range['title'] . ' по:',
  219. 'min' => $range['min'],
  220. 'max' => $range['max'],
  221. 'value' => request()->filters[$rangeName . '_to'] ?? '',
  222. ])
  223. @endforeach
  224. @endif
  225. </form>
  226. </div>
  227. <div class="modal-footer">
  228. <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
  229. <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
  230. </button>
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. <!-- Модальное окно поиска -->
  236. <div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
  237. aria-hidden="true">
  238. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  239. <div class="modal-content">
  240. <div class="modal-header">
  241. <h1 class="modal-title fs-5" id="exampleModalLabel">Поиск</h1>
  242. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  243. </div>
  244. <div class="modal-body">
  245. <div>
  246. Поиск ведётся по следующим колонкам:
  247. <span class="fst-italic">
  248. @foreach($searchFields as $searchField)
  249. {{ $header[$searchField] }}
  250. @if(!$loop->last)
  251. ,
  252. @endif
  253. @endforeach
  254. </span>
  255. </div>
  256. <form class="search-form">
  257. @include('partials.input', [
  258. 'name' => 's',
  259. 'title' => 'Поиск',
  260. 'placeholder' => 'что ищем?',
  261. 'value' => request()->s ?? '',
  262. ])
  263. </form>
  264. </div>
  265. <div class="modal-footer">
  266. <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
  267. <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
  268. </button>
  269. </div>
  270. </div>
  271. </div>
  272. </div>
  273. @push('scripts')
  274. <script type="module">
  275. // on page load set column visible
  276. let tbl = $('#tbl');
  277. let tableName = tbl.attr('data-table-name');
  278. let tables = JSON.parse(localStorage.getItem('table_' + tableName));
  279. // on first load create tables object
  280. if (!tables) {
  281. tables = {};
  282. }
  283. // hide disabled columns
  284. $.each(tables, function (colName, colStatus) {
  285. if (!colStatus) {
  286. $('.checkbox-' + colName).attr('checked', false);
  287. $('.column_' + colName).hide();
  288. }
  289. });
  290. // highlight search text
  291. let searchText = $('.search-form input').val();
  292. if (searchText !== '') {
  293. let innerHTML = tbl.html();
  294. let index = innerHTML.indexOf(searchText);
  295. if (index >= 0) {
  296. innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
  297. tbl.html(innerHTML);
  298. }
  299. }
  300. $('.table').fadeIn();
  301. $('.toggle-column').on('change', function () {
  302. let columnName = $(this).attr('data-name');
  303. let columnStatus = $(this).is(':checked');
  304. // save column status
  305. tables[columnName] = columnStatus;
  306. localStorage.setItem('table_' + tableName, JSON.stringify(tables));
  307. // show or hide column
  308. if (columnStatus) {
  309. $('.column_' + columnName).show('fast');
  310. } else {
  311. $('.column_' + columnName).hide('fast');
  312. }
  313. });
  314. $('.sort-by-column').on('click', function () {
  315. let columnName = $(this).attr('data-name');
  316. let currentUrl = new URL(document.location.href);
  317. let currentColumnName = currentUrl.searchParams.get('sortBy');
  318. currentUrl.searchParams.set('sortBy', columnName);
  319. if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
  320. currentUrl.searchParams.delete('order');
  321. } else {
  322. currentUrl.searchParams.set('order', 'desc');
  323. }
  324. document.location.href = currentUrl.href;
  325. });
  326. $('.accept-filters').on('click', function () {
  327. let filters = $('.filters').serializeArray();
  328. let currentUrl = new URL(document.location.href);
  329. $.each(filters, function (id, filter) {
  330. if (filter.value !== '') {
  331. currentUrl.searchParams.set(filter.name, filter.value);
  332. } else {
  333. currentUrl.searchParams.delete(filter.name);
  334. }
  335. });
  336. currentUrl.searchParams.delete('page');
  337. document.location.href = currentUrl.href;
  338. });
  339. $('.reset-filters').on('click', function () {
  340. let filters = $('.filters').serializeArray();
  341. let currentUrl = new URL(document.location.href);
  342. $.each(filters, function (id, filter) {
  343. currentUrl.searchParams.delete(filter.name);
  344. });
  345. currentUrl.searchParams.delete('page');
  346. document.location.href = currentUrl.href;
  347. });
  348. $('.accept-search').on('click', function () {
  349. let s = $('.search-form input').val();
  350. let currentUrl = new URL(document.location.href);
  351. if (s !== '') {
  352. currentUrl.searchParams.set('s', s);
  353. } else {
  354. currentUrl.searchParams.delete('s');
  355. }
  356. currentUrl.searchParams.delete('page');
  357. document.location.href = currentUrl.href;
  358. });
  359. $('.reset-search').on('click', function () {
  360. let currentUrl = new URL(document.location.href);
  361. currentUrl.searchParams.delete('s');
  362. currentUrl.searchParams.delete('page');
  363. document.location.href = currentUrl.href;
  364. });
  365. $('.change-order-status').on('change', function () {
  366. let orderStatusId = $(this).val();
  367. let orderId = $(this).attr('data-order-id');
  368. $.post(
  369. '{{ route('order.update') }}',
  370. {
  371. '_token' : '{{ csrf_token() }}',
  372. id: orderId,
  373. order_status_id: orderStatusId
  374. },
  375. function () {
  376. $('.alerts').append(
  377. '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
  378. );
  379. setTimeout(function () {
  380. $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
  381. $(".main-alert").slideUp(500);
  382. })
  383. }, 3000);
  384. }
  385. );
  386. });
  387. $(document).ready(async function () {
  388. let height1 = $('.das').innerHeight();
  389. let height2 = $('.catalog').innerHeight();
  390. let totalHeight = (Number(height1) || 0) + (Number(height2) || 0);
  391. $(".table-responsive").css('maxHeight', $(window).height() - totalHeight - 50);
  392. });
  393. </script>
  394. @endpush