table.blade.php 20 KB

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