table.blade.php 21 KB

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