AdvancedTable.vue 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434
  1. <template>
  2. <div>
  3. <div
  4. class="table-outer-container"
  5. @mousemove="columnResizing($event)"
  6. @touchmove="columnResizing($event)"
  7. >
  8. <div class="table-header">
  9. <div>
  10. <tippy
  11. v-if="filters.length > 0"
  12. :touch="true"
  13. :interactive="true"
  14. placement="bottom-start"
  15. theme="search"
  16. ref="search"
  17. trigger="click"
  18. @show="
  19. () => {
  20. showFiltersDropdown = true;
  21. }
  22. "
  23. @hide="
  24. () => {
  25. showFiltersDropdown = false;
  26. }
  27. "
  28. >
  29. <div class="control has-addons" ref="trigger">
  30. <button class="button is-primary">
  31. <i class="material-icons icon-with-button"
  32. >filter_list</i
  33. >
  34. Filters
  35. </button>
  36. <button class="button dropdown-toggle">
  37. <i class="material-icons">
  38. {{
  39. showFiltersDropdown
  40. ? "expand_less"
  41. : "expand_more"
  42. }}
  43. </i>
  44. </button>
  45. </div>
  46. <template #content>
  47. <div class="control is-grouped input-with-button">
  48. <p class="control select is-expanded">
  49. <select v-model="addFilterValue">
  50. <option
  51. v-for="type in filters"
  52. :key="type.name"
  53. :value="type"
  54. >
  55. {{ type.displayName }}
  56. </option>
  57. </select>
  58. </p>
  59. <p class="control">
  60. <button
  61. :disabled="!addFilterValue"
  62. class="button material-icons is-success"
  63. @click="addFilterItem()"
  64. >
  65. control_point
  66. </button>
  67. </p>
  68. </div>
  69. <div
  70. v-for="(filter, index) in editingFilters"
  71. :key="`filter-${index}`"
  72. class="advanced-filter control is-grouped is-expanded"
  73. >
  74. <div class="control select">
  75. <select
  76. v-model="filter.filter"
  77. @change="changeFilterType(index)"
  78. >
  79. <option
  80. v-for="type in filters"
  81. :key="type.name"
  82. :value="type"
  83. >
  84. {{ type.displayName }}
  85. </option>
  86. </select>
  87. </div>
  88. <div class="control select">
  89. <select
  90. v-model="filter.filterType"
  91. :disabled="!filter.filterType"
  92. >
  93. <option
  94. v-for="filterType in filterTypes(
  95. filter.filter
  96. )"
  97. :key="filterType.name"
  98. :value="filterType"
  99. :selected="
  100. filter.filter
  101. .defaultFilterType ===
  102. filterType.name
  103. "
  104. >
  105. {{ filterType.displayName }}
  106. </option>
  107. </select>
  108. </div>
  109. <div
  110. v-if="
  111. filter.filterType.name &&
  112. (filter.filterType.name === 'exact' ||
  113. filter.filterType.name ===
  114. 'boolean') &&
  115. filter.filter.dropdown
  116. "
  117. class="control is-expanded select"
  118. >
  119. <select
  120. v-model="filter.data"
  121. :disabled="!filter.filterType"
  122. >
  123. <option
  124. v-for="[
  125. dropdownValue,
  126. dropdownDisplay
  127. ] in filter.filter.dropdown"
  128. :key="dropdownValue"
  129. :value="dropdownValue"
  130. >
  131. {{ dropdownDisplay }}
  132. </option>
  133. </select>
  134. </div>
  135. <div
  136. v-else-if="
  137. filter.filterType.name &&
  138. filter.filterType.name === 'boolean'
  139. "
  140. class="control is-expanded select"
  141. >
  142. <select
  143. v-model="filter.data"
  144. :disabled="!filter.filterType"
  145. >
  146. <option :value="true">true</option>
  147. <option :value="false">false</option>
  148. </select>
  149. </div>
  150. <div v-else class="control is-expanded">
  151. <input
  152. v-if="
  153. filter.filterType.name &&
  154. filter.filterType.name.startsWith(
  155. 'datetime'
  156. )
  157. "
  158. v-model="filter.data"
  159. class="input"
  160. type="datetime-local"
  161. />
  162. <input
  163. v-else-if="
  164. filter.filterType.name &&
  165. filter.filterType.name.startsWith(
  166. 'number'
  167. )
  168. "
  169. v-model="filter.data"
  170. class="input"
  171. type="number"
  172. :disabled="!filter.filterType"
  173. @keydown.enter="applyFilterAndGetData()"
  174. />
  175. <auto-suggest
  176. v-else
  177. v-model="filter.data"
  178. placeholder="Search value"
  179. :disabled="!filter.filterType"
  180. :all-items="
  181. autosuggest.allItems[
  182. filter.filter.name
  183. ]
  184. "
  185. @submitted="applyFilterAndGetData()"
  186. />
  187. </div>
  188. <div class="control">
  189. <button
  190. class="button material-icons is-danger"
  191. @click="removeFilterItem(index)"
  192. >
  193. remove_circle_outline
  194. </button>
  195. </div>
  196. </div>
  197. <div
  198. v-if="editingFilters.length > 0"
  199. class="control is-expanded is-grouped"
  200. >
  201. <label class="control label"
  202. >Filter operator</label
  203. >
  204. <div class="control select is-expanded">
  205. <select v-model="filterOperator">
  206. <option
  207. v-for="operator in filterOperators"
  208. :key="operator.name"
  209. :value="operator.name"
  210. >
  211. {{ operator.displayName }}
  212. </option>
  213. </select>
  214. </div>
  215. </div>
  216. <div
  217. class="advanced-filter-bottom"
  218. v-if="editingFilters.length > 0"
  219. >
  220. <div class="control is-expanded">
  221. <button
  222. class="button is-info"
  223. @click="applyFilterAndGetData()"
  224. >
  225. <i
  226. class="material-icons icon-with-button"
  227. >filter_list</i
  228. >
  229. Apply filters
  230. </button>
  231. </div>
  232. </div>
  233. <div
  234. class="advanced-filter-bottom"
  235. v-else-if="editingFilters.length === 0"
  236. >
  237. <div class="control is-expanded">
  238. <button
  239. class="button is-info"
  240. @click="applyFilterAndGetData()"
  241. >
  242. <i
  243. class="material-icons icon-with-button"
  244. >filter_list</i
  245. >
  246. Apply filters
  247. </button>
  248. </div>
  249. </div>
  250. </template>
  251. </tippy>
  252. <tippy
  253. v-if="appliedFilters.length > 0"
  254. :touch="true"
  255. :interactive="true"
  256. theme="info"
  257. ref="activeFilters"
  258. >
  259. <div class="filters-indicator">
  260. {{ appliedFilters.length }}
  261. <i class="material-icons" @click.prevent="true"
  262. >filter_list</i
  263. >
  264. </div>
  265. <template #content>
  266. <p
  267. v-for="(filter, index) in appliedFilters"
  268. :key="`filter-${index}`"
  269. >
  270. {{ filter.filter.displayName }}
  271. {{
  272. appliedFilters.length === 1 &&
  273. appliedFilterOperator === "nor"
  274. ? "not"
  275. : ""
  276. }}
  277. {{
  278. filter.filterType.displayName.toLowerCase()
  279. }}
  280. "{{ filter.data }}"
  281. {{
  282. appliedFilters.length === index + 1
  283. ? ""
  284. : appliedFilterOperator
  285. }}
  286. </p>
  287. </template>
  288. </tippy>
  289. <i
  290. v-else
  291. class="filters-indicator material-icons"
  292. content="No active filters"
  293. v-tippy="{ theme: 'info' }"
  294. >
  295. filter_list_off
  296. </i>
  297. </div>
  298. <div>
  299. <tippy
  300. v-if="hidableSortedColumns.length > 0"
  301. :touch="true"
  302. :interactive="true"
  303. placement="bottom-end"
  304. theme="dropdown"
  305. ref="editColumns"
  306. trigger="click"
  307. @show="
  308. () => {
  309. showColumnsDropdown = true;
  310. }
  311. "
  312. @hide="
  313. () => {
  314. showColumnsDropdown = false;
  315. }
  316. "
  317. >
  318. <div class="control has-addons" ref="trigger">
  319. <button class="button is-primary">
  320. <i class="material-icons icon-with-button"
  321. >tune</i
  322. >
  323. Columns
  324. </button>
  325. <button class="button dropdown-toggle">
  326. <i class="material-icons">
  327. {{
  328. showColumnsDropdown
  329. ? "expand_less"
  330. : "expand_more"
  331. }}
  332. </i>
  333. </button>
  334. </div>
  335. <template #content>
  336. <draggable
  337. item-key="name"
  338. v-model="orderedColumns"
  339. v-bind="columnDragOptions"
  340. tag="div"
  341. draggable=".item-draggable"
  342. class="nav-dropdown-items"
  343. @change="columnOrderChanged"
  344. >
  345. <template #item="{ element: column }">
  346. <button
  347. v-if="
  348. column.name !== 'select' &&
  349. column.name !== 'placeholder' &&
  350. column.name !== 'updatedPlaceholder'
  351. "
  352. :class="{
  353. sortable: column.sortable,
  354. 'item-draggable': column.draggable,
  355. 'nav-item': true
  356. }"
  357. @click.prevent="
  358. toggleColumnVisibility(column)
  359. "
  360. >
  361. <p
  362. class="control is-expanded checkbox-control"
  363. >
  364. <label class="switch">
  365. <input
  366. type="checkbox"
  367. :id="`column-dropdown-checkbox-${column.name}`"
  368. :checked="
  369. shownColumns.indexOf(
  370. column.name
  371. ) !== -1
  372. "
  373. @click="
  374. toggleColumnVisibility(
  375. column
  376. )
  377. "
  378. />
  379. <span
  380. :class="{
  381. slider: true,
  382. round: true,
  383. disabled:
  384. !column.hidable
  385. }"
  386. ></span>
  387. </label>
  388. <label
  389. :for="`column-dropdown-checkbox-${column.name}`"
  390. >
  391. <span></span>
  392. <p>{{ column.displayName }}</p>
  393. </label>
  394. </p>
  395. </button>
  396. </template>
  397. </draggable>
  398. </template>
  399. </tippy>
  400. </div>
  401. </div>
  402. <div class="table-container">
  403. <table
  404. :class="{
  405. table: true,
  406. 'has-checkboxes': hasCheckboxes
  407. }"
  408. >
  409. <thead>
  410. <draggable
  411. item-key="name"
  412. v-model="orderedColumns"
  413. v-bind="columnDragOptions"
  414. tag="tr"
  415. handle=".handle"
  416. draggable=".item-draggable"
  417. @change="columnOrderChanged"
  418. >
  419. <template #item="{ element: column }">
  420. <th
  421. v-if="
  422. shownColumns.indexOf(column.name) !==
  423. -1 &&
  424. (column.name !== 'updatedPlaceholder' ||
  425. rows.length > 0)
  426. "
  427. :class="{
  428. sortable: column.sortable,
  429. 'item-draggable': column.draggable
  430. }"
  431. :style="{
  432. minWidth: Number.isNaN(column.minWidth)
  433. ? column.minWidth
  434. : `${column.minWidth}px`,
  435. width: Number.isNaN(column.width)
  436. ? column.width
  437. : `${column.width}px`,
  438. maxWidth: Number.isNaN(column.maxWidth)
  439. ? column.maxWidth
  440. : `${column.maxWidth}px`
  441. }"
  442. >
  443. <div v-if="column.name === 'select'">
  444. <p class="checkbox">
  445. <input
  446. v-if="rows.length === 0"
  447. type="checkbox"
  448. disabled
  449. />
  450. <input
  451. v-else
  452. type="checkbox"
  453. :checked="
  454. rows.filter(
  455. row => !row.removed
  456. ).length ===
  457. selectedRows.length
  458. "
  459. @click="toggleAllRows()"
  460. />
  461. </p>
  462. </div>
  463. <div v-else class="handle">
  464. <span>
  465. {{ column.displayName }}
  466. </span>
  467. <span
  468. v-if="column.sortable"
  469. :content="`Sort by ${column.displayName}`"
  470. v-tippy
  471. >
  472. <span
  473. v-if="
  474. !sort[column.sortProperty]
  475. "
  476. class="material-icons"
  477. @click="changeSort(column)"
  478. >
  479. unfold_more
  480. </span>
  481. <span
  482. v-if="
  483. sort[
  484. column.sortProperty
  485. ] === 'ascending'
  486. "
  487. class="material-icons active"
  488. @click="changeSort(column)"
  489. >
  490. expand_more
  491. </span>
  492. <span
  493. v-if="
  494. sort[
  495. column.sortProperty
  496. ] === 'descending'
  497. "
  498. class="material-icons active"
  499. @click="changeSort(column)"
  500. >
  501. expand_less
  502. </span>
  503. </span>
  504. </div>
  505. <div
  506. class="resizer"
  507. v-if="column.resizable"
  508. @mousedown.prevent.stop="
  509. columnResizingStart(column, $event)
  510. "
  511. @touchstart.prevent.stop="
  512. columnResizingStart(column, $event)
  513. "
  514. @mouseup="columnResizingStop()"
  515. @touchend="columnResizingStop()"
  516. @dblclick="columnResetWidth(column)"
  517. ></div>
  518. </th>
  519. </template>
  520. </draggable>
  521. </thead>
  522. <tbody>
  523. <tr
  524. v-for="(item, itemIndex) in rows"
  525. :key="item._id"
  526. :class="{
  527. selected: item.selected,
  528. highlighted: item.highlighted,
  529. updated: item.updated,
  530. removed: item.removed
  531. }"
  532. :ref="`row-${itemIndex}`"
  533. tabindex="0"
  534. @blur="unhighlightRow(itemIndex)"
  535. @keydown.up.prevent
  536. @keydown.down.prevent
  537. @keydown.space.prevent
  538. @click="highlightRow(itemIndex)"
  539. @keyup.up.exact="highlightUp(itemIndex)"
  540. @keyup.down.exact="highlightDown(itemIndex)"
  541. @keyup.shift.up.exact="selectUp(itemIndex)"
  542. @keyup.shift.down.exact="selectDown(itemIndex)"
  543. @keyup.ctrl.up.exact="unselectUp(itemIndex)"
  544. @keyup.ctrl.down.exact="unselectDown(itemIndex)"
  545. @keyup.space.exact="
  546. toggleSelectedRow(itemIndex, {})
  547. "
  548. >
  549. <td
  550. v-for="column in sortedFilteredColumns"
  551. :key="`${item._id}-${column.name}`"
  552. >
  553. <slot
  554. :name="`column-${column.name}`"
  555. :item="item"
  556. v-if="
  557. column.properties.length === 0 ||
  558. column.properties.every(
  559. property =>
  560. property
  561. .split('.')
  562. .reduce(
  563. (previous, current) =>
  564. previous &&
  565. previous[
  566. current
  567. ] !== null &&
  568. previous[
  569. current
  570. ] !== undefined
  571. ? previous[
  572. current
  573. ]
  574. : null,
  575. item
  576. ) !== null
  577. )
  578. "
  579. ></slot>
  580. <div
  581. v-if="
  582. column.name === 'updatedPlaceholder' &&
  583. item.updated
  584. "
  585. class="updated-tooltip"
  586. content="Row updated"
  587. v-tippy="{
  588. theme: 'info',
  589. placement: 'right'
  590. }"
  591. ></div>
  592. <p
  593. class="checkbox"
  594. v-if="column.name === 'select'"
  595. >
  596. <input
  597. type="checkbox"
  598. :checked="item.selected"
  599. @click="
  600. toggleSelectedRow(itemIndex, $event)
  601. "
  602. :disabled="item.removed"
  603. />
  604. </p>
  605. <span
  606. v-if="item.removed"
  607. class="removed-overlay"
  608. content="Item removed"
  609. v-tippy="{ theme: 'info' }"
  610. ></span>
  611. <div
  612. class="resizer"
  613. v-if="column.resizable"
  614. @mousedown.prevent.stop="
  615. columnResizingStart(column, $event)
  616. "
  617. @touchstart.prevent.stop="
  618. columnResizingStart(column, $event)
  619. "
  620. @mouseup="columnResizingStop()"
  621. @touchend="columnResizingStop()"
  622. @dblclick="columnResetWidth(column)"
  623. ></div>
  624. </td>
  625. </tr>
  626. </tbody>
  627. </table>
  628. </div>
  629. <div v-if="rows.length === 0" class="table-no-results">
  630. No results found
  631. </div>
  632. <div class="table-footer">
  633. <div class="page-controls">
  634. <button
  635. :class="{ disabled: page === 1 }"
  636. class="button is-primary material-icons"
  637. :disabled="page === 1"
  638. @click="changePage(1)"
  639. content="First Page"
  640. v-tippy
  641. >
  642. skip_previous
  643. </button>
  644. <button
  645. :class="{ disabled: page === 1 }"
  646. class="button is-primary material-icons"
  647. :disabled="page === 1"
  648. @click="changePage(page - 1)"
  649. content="Previous Page"
  650. v-tippy
  651. >
  652. fast_rewind
  653. </button>
  654. <p>Page {{ page }} / {{ lastPage > 0 ? lastPage : 1 }}</p>
  655. <button
  656. :class="{
  657. disabled: page === lastPage || lastPage === 0
  658. }"
  659. class="button is-primary material-icons"
  660. :disabled="page === lastPage"
  661. @click="changePage(page + 1)"
  662. content="Next Page"
  663. v-tippy
  664. >
  665. fast_forward
  666. </button>
  667. <button
  668. :class="{
  669. disabled: page === lastPage || lastPage === 0
  670. }"
  671. class="button is-primary material-icons"
  672. :disabled="page === lastPage"
  673. @click="changePage(lastPage)"
  674. content="Last Page"
  675. v-tippy
  676. >
  677. skip_next
  678. </button>
  679. </div>
  680. <div class="page-size">
  681. <div class="control">
  682. <label class="label">Items per page</label>
  683. <p class="control select">
  684. <select
  685. v-model.number="pageSize"
  686. @change="changePageSize()"
  687. >
  688. <option value="10">10</option>
  689. <option value="25">25</option>
  690. <option value="50">50</option>
  691. <option value="100">100</option>
  692. <option value="250">250</option>
  693. <option value="500">500</option>
  694. <option value="1000">1000</option>
  695. </select>
  696. </p>
  697. </div>
  698. </div>
  699. </div>
  700. </div>
  701. <div
  702. v-if="hasCheckboxes && selectedRows.length > 0"
  703. class="bulk-popup"
  704. :style="{
  705. top: bulkPopup.top + 'px',
  706. left: bulkPopup.left + 'px'
  707. }"
  708. ref="bulk-popup"
  709. >
  710. <button
  711. class="button is-primary"
  712. :content="
  713. selectedRows.length === 1
  714. ? `${selectedRows.length} row selected`
  715. : `${selectedRows.length} rows selected`
  716. "
  717. v-tippy="{ theme: 'info' }"
  718. >
  719. {{ selectedRows.length }}
  720. </button>
  721. <slot name="bulk-actions" :item="selectedRows" />
  722. <div class="right">
  723. <span
  724. class="material-icons drag-icon"
  725. @mousedown.left="onDragBox"
  726. @touchstart="onDragBox"
  727. @dblclick="resetBulkActionsPosition()"
  728. >
  729. drag_indicator
  730. </span>
  731. </div>
  732. </div>
  733. </div>
  734. </template>
  735. <script>
  736. import { mapGetters, mapState } from "vuex";
  737. import draggable from "vuedraggable";
  738. import Toast from "toasters";
  739. import AutoSuggest from "@/components/AutoSuggest.vue";
  740. import keyboardShortcuts from "@/keyboardShortcuts";
  741. import ws from "@/ws";
  742. export default {
  743. components: {
  744. draggable,
  745. AutoSuggest
  746. },
  747. props: {
  748. /*
  749. Column properties:
  750. name: Unique lowercase name
  751. displayName: Nice name for the column header
  752. properties: The properties this column needs to show data
  753. sortable: Boolean for whether the order of a particular column can be changed
  754. sortProperty: The property the backend will sort on if this column gets sorted, e.g. title
  755. hidable: Boolean for whether a column can be hidden
  756. defaultVisibility: Default visibility for a column, either "shown" or "hidden"
  757. draggable: Boolean for whether a column can be dragged/reordered,
  758. resizable: Boolean for whether a column can be resized
  759. minWidth: Minimum width of column, e.g. 50px
  760. width: Width of column, e.g. 100px
  761. maxWidth: Maximum width of column, e.g. 150px
  762. */
  763. columnDefault: { type: Object, default: () => {} },
  764. columns: { type: Array, default: null },
  765. filters: { type: Array, default: null },
  766. dataAction: { type: String, default: null },
  767. name: { type: String, default: null },
  768. maxWidth: { type: Number, default: 1880 },
  769. query: { type: Boolean, default: true },
  770. keyboardShortcuts: { type: Boolean, default: true },
  771. events: { type: Object, default: () => {} }
  772. },
  773. data() {
  774. return {
  775. page: 1,
  776. pageSize: 10,
  777. rows: [],
  778. count: 0, // TODO Rename
  779. sort: {},
  780. orderedColumns: [],
  781. shownColumns: [],
  782. columnDragOptions() {
  783. return {
  784. animation: 200,
  785. group: "columns",
  786. disabled: false,
  787. ghostClass: "draggable-list-ghost",
  788. filter: ".ignore-elements",
  789. fallbackTolerance: 50
  790. };
  791. },
  792. editingFilters: [],
  793. appliedFilters: [],
  794. filterOperator: "or",
  795. appliedFilterOperator: "or",
  796. filterOperators: [
  797. {
  798. name: "or",
  799. displayName: "OR"
  800. },
  801. {
  802. name: "and",
  803. displayName: "AND"
  804. },
  805. {
  806. name: "nor",
  807. displayName: "NOR"
  808. }
  809. ],
  810. resizing: {},
  811. allFilterTypes: {
  812. contains: {
  813. name: "contains",
  814. displayName: "Contains"
  815. },
  816. exact: {
  817. name: "exact",
  818. displayName: "Exact"
  819. },
  820. regex: {
  821. name: "regex",
  822. displayName: "Regex"
  823. },
  824. datetimeBefore: {
  825. name: "datetimeBefore",
  826. displayName: "Before"
  827. },
  828. datetimeAfter: {
  829. name: "datetimeAfter",
  830. displayName: "After"
  831. },
  832. numberLesserEqual: {
  833. name: "numberLesserEqual",
  834. displayName: "Less than or equal to"
  835. },
  836. numberLesser: {
  837. name: "numberLesser",
  838. displayName: "Less than"
  839. },
  840. numberGreater: {
  841. name: "numberGreater",
  842. displayName: "Greater than"
  843. },
  844. numberGreaterEqual: {
  845. name: "numberGreaterEqual",
  846. displayName: "Greater than or equal to"
  847. },
  848. numberEquals: {
  849. name: "numberEquals",
  850. displayName: "Equals"
  851. },
  852. boolean: {
  853. name: "boolean",
  854. displayName: "Boolean"
  855. }
  856. },
  857. bulkPopup: {
  858. top: 0,
  859. left: 0,
  860. pos1: 0,
  861. pos2: 0,
  862. pos3: 0,
  863. pos4: 0,
  864. initial: {
  865. top: null,
  866. left: null
  867. },
  868. debounceTimeout: null
  869. },
  870. addFilterValue: null,
  871. showFiltersDropdown: false,
  872. showColumnsDropdown: false,
  873. lastColumnResizerTapped: null,
  874. lastColumnResizerTappedDate: 0,
  875. lastBulkActionsTappedDate: 0,
  876. autosuggest: {
  877. allItems: {}
  878. }
  879. };
  880. },
  881. computed: {
  882. properties() {
  883. return Array.from(
  884. new Set(
  885. this.sortedFilteredColumns.flatMap(
  886. column => column.properties
  887. )
  888. )
  889. );
  890. },
  891. lastPage() {
  892. return Math.ceil(this.count / this.pageSize);
  893. },
  894. sortedFilteredColumns() {
  895. return this.orderedColumns.filter(
  896. column => this.shownColumns.indexOf(column.name) !== -1
  897. );
  898. },
  899. hidableSortedColumns() {
  900. return this.orderedColumns.filter(column => column.hidable);
  901. },
  902. lastSelectedItemIndex() {
  903. return this.rows.findIndex(item => item.highlighted);
  904. },
  905. selectedRows() {
  906. return this.rows.filter(row => row.selected);
  907. },
  908. hasCheckboxes() {
  909. return (
  910. this.$slots["bulk-actions"] != null ||
  911. this.$slots["bulk-actions-right"] != null
  912. );
  913. },
  914. aModalIsOpen() {
  915. return Object.keys(this.activeModals).length > 0;
  916. },
  917. ...mapState({
  918. activeModals: state => state.modalVisibility.activeModals
  919. }),
  920. ...mapGetters({
  921. socket: "websockets/getSocket"
  922. })
  923. },
  924. watch: {
  925. selectedRows(newSelectedRows, oldSelectedRows) {
  926. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  927. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  928. this.onWindowResize();
  929. }
  930. },
  931. mounted() {
  932. const tableSettings = this.getTableSettings();
  933. const columns = [
  934. ...this.columns.map(column => ({
  935. ...this.columnDefault,
  936. ...column
  937. })),
  938. {
  939. name: "placeholder",
  940. displayName: "",
  941. properties: [],
  942. sortable: false,
  943. hidable: false,
  944. draggable: false,
  945. resizable: false,
  946. minWidth: "auto",
  947. width: "auto",
  948. maxWidth: "auto"
  949. }
  950. ];
  951. if (this.hasCheckboxes)
  952. columns.unshift({
  953. name: "select",
  954. displayName: "",
  955. properties: [],
  956. sortable: false,
  957. hidable: false,
  958. draggable: false,
  959. resizable: false,
  960. minWidth: 47,
  961. defaultWidth: 47,
  962. maxWidth: 47
  963. });
  964. if (this.events && this.events.updated)
  965. columns.unshift({
  966. name: "updatedPlaceholder",
  967. displayName: "",
  968. properties: [],
  969. sortable: false,
  970. hidable: false,
  971. draggable: false,
  972. resizable: false,
  973. minWidth: 5,
  974. width: 5,
  975. maxWidth: 5
  976. });
  977. this.orderedColumns = columns.sort((columnA, columnB) => {
  978. // Always places updatedPlaceholder column in the first position
  979. if (columnA.name === "updatedPlaceholder") return -1;
  980. if (columnB.name === "updatedPlaceholder") return 1;
  981. // Always places select column in the second position
  982. if (columnA.name === "select") return -1;
  983. if (columnB.name === "select") return 1;
  984. // Always places placeholder column in the last position
  985. if (columnA.name === "placeholder") return 1;
  986. if (columnB.name === "placeholder") return -1;
  987. // If there are no table settings stored, use default ordering
  988. if (!tableSettings || !tableSettings.columnOrder) return 0;
  989. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  990. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  991. // If either of the columns is not stored in the table settings, use default ordering
  992. if (indexA === -1 || indexB === -1) return 0;
  993. return indexA - indexB;
  994. });
  995. this.shownColumns = this.orderedColumns
  996. .filter(column => {
  997. // If table settings exist, use shownColumns from settings to determine which columns to show
  998. if (tableSettings && tableSettings.shownColumns)
  999. return (
  1000. tableSettings.shownColumns.indexOf(column.name) !== -1
  1001. );
  1002. // Table settings don't exist, only show if the default visibility isn't hidden
  1003. return column.defaultVisibility !== "hidden";
  1004. })
  1005. .map(column => column.name);
  1006. this.recalculateWidths();
  1007. if (tableSettings) {
  1008. // If table settings' page is an integer, use it for the page
  1009. if (Number.isInteger(tableSettings?.page))
  1010. this.page = tableSettings.page;
  1011. // If table settings' pageSize is an integer, use it for the pageSize
  1012. if (Number.isInteger(tableSettings?.pageSize))
  1013. this.pageSize = tableSettings.pageSize;
  1014. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  1015. if (tableSettings.columnSort) {
  1016. Object.entries(tableSettings.columnSort).forEach(
  1017. ([columnName, sortDirection]) => {
  1018. if (
  1019. this.columns.find(
  1020. column => column.name === columnName
  1021. )
  1022. )
  1023. this.sort[columnName] = sortDirection;
  1024. }
  1025. );
  1026. }
  1027. // If table settings' columnWidths exists, load the stored widths into the columns
  1028. if (tableSettings.columnWidths) {
  1029. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  1030. const columnWidth = tableSettings.columnWidths.find(
  1031. column => column.name === orderedColumn.name
  1032. )?.width;
  1033. if (orderedColumn.resizable && columnWidth)
  1034. return { ...orderedColumn, width: columnWidth };
  1035. return orderedColumn;
  1036. });
  1037. }
  1038. if (
  1039. tableSettings.filter &&
  1040. tableSettings.filter.appliedFilters &&
  1041. tableSettings.filter.appliedFilterOperator
  1042. ) {
  1043. const { appliedFilters, appliedFilterOperator } =
  1044. tableSettings.filter;
  1045. // Set the applied filter operator and filter operator to the value stored in table settings
  1046. this.appliedFilterOperator = this.filterOperator =
  1047. appliedFilterOperator;
  1048. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  1049. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  1050. this.filters.find(
  1051. filter => appliedFilter.filter.name === filter.name
  1052. )
  1053. );
  1054. this.editingFilters = appliedFilters.filter(appliedFilter =>
  1055. this.filters.find(
  1056. filter => appliedFilter.filter.name === filter.name
  1057. )
  1058. );
  1059. }
  1060. }
  1061. this.resetBulkActionsPosition();
  1062. this.$nextTick(() => {
  1063. this.onWindowResize();
  1064. window.addEventListener("resize", this.onWindowResize);
  1065. });
  1066. ws.onConnect(this.init);
  1067. if (this.events && this.events.updated)
  1068. this.socket.on(`event:${this.events.updated.event}`, res => {
  1069. const index = this.rows
  1070. .map(row => row._id)
  1071. .indexOf(
  1072. this.events.updated.id
  1073. .split(".")
  1074. .reduce(
  1075. (previous, current) =>
  1076. previous &&
  1077. previous[current] !== null &&
  1078. previous[current] !== undefined
  1079. ? previous[current]
  1080. : null,
  1081. res.data
  1082. )
  1083. );
  1084. const row = this.events.updated.item
  1085. .split(".")
  1086. .reduce(
  1087. (previous, current) =>
  1088. previous &&
  1089. previous[current] !== null &&
  1090. previous[current] !== undefined
  1091. ? previous[current]
  1092. : null,
  1093. res.data
  1094. );
  1095. this.updateData(index, row);
  1096. });
  1097. if (this.events && this.events.removed)
  1098. this.socket.on(`event:${this.events.removed.event}`, res => {
  1099. const index = this.rows
  1100. .map(row => row._id)
  1101. .indexOf(
  1102. this.events.removed.id
  1103. .split(".")
  1104. .reduce(
  1105. (previous, current) =>
  1106. previous &&
  1107. previous[current] !== null &&
  1108. previous[current] !== undefined
  1109. ? previous[current]
  1110. : null,
  1111. res.data
  1112. )
  1113. );
  1114. this.removeData(index);
  1115. });
  1116. if (this.keyboardShortcuts) {
  1117. // Navigation section
  1118. // Page navigation section
  1119. keyboardShortcuts.registerShortcut("advancedTable.previousPage", {
  1120. keyCode: 37, // 'Left arrow' key
  1121. ctrl: true,
  1122. preventDefault: false,
  1123. handler: event => {
  1124. // Previous page
  1125. if (this.aModalIsOpen) return;
  1126. if (
  1127. document.activeElement.nodeName === "INPUT" ||
  1128. document.activeElement.nodeName === "TEXTAREA"
  1129. )
  1130. return;
  1131. event.preventDefault();
  1132. this.changePage(this.page - 1);
  1133. }
  1134. });
  1135. keyboardShortcuts.registerShortcut("advancedTable.nextPage", {
  1136. keyCode: 39, // 'Right arrow' key
  1137. ctrl: true,
  1138. preventDefault: false,
  1139. handler: event => {
  1140. // Next page
  1141. if (this.aModalIsOpen) return;
  1142. if (
  1143. document.activeElement.nodeName === "INPUT" ||
  1144. document.activeElement.nodeName === "TEXTAREA"
  1145. )
  1146. return;
  1147. event.preventDefault();
  1148. this.changePage(this.page + 1);
  1149. }
  1150. });
  1151. keyboardShortcuts.registerShortcut("advancedTable.firstPage", {
  1152. keyCode: 37, // 'Left arrow' key
  1153. ctrl: true,
  1154. shift: true,
  1155. preventDefault: false,
  1156. handler: event => {
  1157. // First page
  1158. if (this.aModalIsOpen) return;
  1159. if (
  1160. document.activeElement.nodeName === "INPUT" ||
  1161. document.activeElement.nodeName === "TEXTAREA"
  1162. )
  1163. return;
  1164. event.preventDefault();
  1165. this.changePage(1);
  1166. }
  1167. });
  1168. keyboardShortcuts.registerShortcut("advancedTable.lastPage", {
  1169. keyCode: 39, // 'Right arrow' key
  1170. ctrl: true,
  1171. shift: true,
  1172. preventDefault: false,
  1173. handler: event => {
  1174. // Last page
  1175. if (this.aModalIsOpen) return;
  1176. if (
  1177. document.activeElement.nodeName === "INPUT" ||
  1178. document.activeElement.nodeName === "TEXTAREA"
  1179. )
  1180. return;
  1181. event.preventDefault();
  1182. this.changePage(this.lastPage);
  1183. }
  1184. });
  1185. // Reset localStorage section
  1186. keyboardShortcuts.registerShortcut(
  1187. "advancedTable.resetLocalStorage",
  1188. {
  1189. keyCode: 116, // 'F5' key
  1190. ctrl: true,
  1191. preventDefault: false,
  1192. handler: () => {
  1193. // Reset local storage
  1194. if (this.aModalIsOpen) return;
  1195. console.log("Reset local storage");
  1196. localStorage.removeItem(
  1197. `advancedTableSettings:${this.name}`
  1198. );
  1199. this.$router.push({ query: "" });
  1200. }
  1201. }
  1202. );
  1203. // Selecting section
  1204. keyboardShortcuts.registerShortcut("advancedTable.selectAll", {
  1205. keyCode: 65, // 'A' key
  1206. ctrl: true,
  1207. preventDefault: false,
  1208. handler: event => {
  1209. if (this.aModalIsOpen) return;
  1210. if (
  1211. document.activeElement.nodeName === "INPUT" ||
  1212. document.activeElement.nodeName === "TEXTAREA"
  1213. )
  1214. return;
  1215. event.preventDefault();
  1216. this.toggleAllRows();
  1217. }
  1218. });
  1219. // Popup actions section
  1220. for (let i = 1; i <= 9; i += 1) {
  1221. keyboardShortcuts.registerShortcut(
  1222. `advancedTable.executePopupAction${i}`,
  1223. {
  1224. keyCode: 48 + i, // '1-9' keys, where 49 is 1 and 57 is 9
  1225. ctrl: true,
  1226. preventDefault: true,
  1227. handler: () => {
  1228. // Execute popup action 1-9
  1229. if (this.aModalIsOpen) return;
  1230. if (this.selectedRows.length === 0) return;
  1231. const bulkActionsElement =
  1232. this.$refs["bulk-popup"].querySelector(
  1233. ".bulk-actions"
  1234. );
  1235. bulkActionsElement.children[i - 1].click();
  1236. }
  1237. }
  1238. );
  1239. }
  1240. keyboardShortcuts.registerShortcut(
  1241. `advancedTable.selectPopupAction1`,
  1242. {
  1243. keyCode: 48, // '0' key
  1244. ctrl: true,
  1245. preventDefault: true,
  1246. handler: () => {
  1247. // Select popup action 0
  1248. if (this.aModalIsOpen) return;
  1249. if (this.selectedRows.length === 0) return;
  1250. const bulkActionsElement =
  1251. this.$refs["bulk-popup"].querySelector(
  1252. ".bulk-actions"
  1253. );
  1254. bulkActionsElement.children[
  1255. bulkActionsElement.children.length - 1
  1256. ].focus();
  1257. }
  1258. }
  1259. );
  1260. }
  1261. },
  1262. unmounted() {
  1263. window.removeEventListener("resize", this.onWindowResize);
  1264. if (this.storeTableSettingsDebounceTimeout)
  1265. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1266. if (this.keyboardShortcuts) {
  1267. const shortcutNames = [
  1268. // Navigation
  1269. "advancedTable.previousPage",
  1270. "advancedTable.nextPage",
  1271. "advancedTable.firstPage",
  1272. "advancedTable.lastPage",
  1273. // Reset localStorage
  1274. "advancedTable.resetLocalStorage",
  1275. // Selecting
  1276. "advancedTable.selectAll",
  1277. // Popup actions
  1278. "advancedTable.executePopupAction1",
  1279. "advancedTable.executePopupAction2",
  1280. "advancedTable.executePopupAction3",
  1281. "advancedTable.executePopupAction4",
  1282. "advancedTable.executePopupAction5",
  1283. "advancedTable.executePopupAction6",
  1284. "advancedTable.executePopupAction7",
  1285. "advancedTable.executePopupAction8",
  1286. "advancedTable.executePopupAction9",
  1287. "advancedTable.selectPopupAction1"
  1288. ];
  1289. shortcutNames.forEach(shortcutName => {
  1290. keyboardShortcuts.unregisterShortcut(shortcutName);
  1291. });
  1292. }
  1293. },
  1294. methods: {
  1295. init() {
  1296. this.getData();
  1297. if (this.query) this.setQuery();
  1298. if (this.events) {
  1299. if (this.events.room)
  1300. this.socket.dispatch(
  1301. "apis.joinRoom",
  1302. this.events.room,
  1303. () => {}
  1304. );
  1305. if (this.events.adminRoom)
  1306. this.socket.dispatch(
  1307. "apis.joinAdminRoom",
  1308. this.events.adminRoom,
  1309. () => {}
  1310. );
  1311. }
  1312. this.filters.forEach(filter => {
  1313. if (filter.autosuggest && filter.autosuggestDataAction) {
  1314. this.socket.dispatch(filter.autosuggestDataAction, res => {
  1315. if (res.status === "success") {
  1316. const { items } = res.data;
  1317. this.autosuggest.allItems[filter.name] = items;
  1318. } else {
  1319. new Toast(res.message);
  1320. }
  1321. });
  1322. }
  1323. });
  1324. },
  1325. getData() {
  1326. this.socket.dispatch(
  1327. this.dataAction,
  1328. this.page,
  1329. this.pageSize,
  1330. this.properties,
  1331. this.sort,
  1332. this.appliedFilters.map(filter => ({
  1333. ...filter,
  1334. filterType: filter.filterType.name
  1335. })),
  1336. this.appliedFilterOperator,
  1337. res => {
  1338. if (res.status === "success") {
  1339. const { data, count } = res.data;
  1340. this.rows = data.map(row => ({
  1341. ...row,
  1342. selected: false
  1343. }));
  1344. this.count = count;
  1345. } else {
  1346. new Toast(res.message);
  1347. }
  1348. }
  1349. );
  1350. },
  1351. changePageSize() {
  1352. this.page = 1;
  1353. this.getData();
  1354. this.storeTableSettings();
  1355. },
  1356. changePage(page) {
  1357. if (page < 1) return;
  1358. if (page > this.lastPage) return;
  1359. if (page === this.page) return;
  1360. this.page = page;
  1361. this.getData();
  1362. if (this.query) this.setQuery();
  1363. },
  1364. changeSort(column) {
  1365. if (column.sortable) {
  1366. const { sortProperty } = column;
  1367. if (this.sort[sortProperty] === undefined)
  1368. this.sort[sortProperty] = "ascending";
  1369. else if (this.sort[sortProperty] === "ascending")
  1370. this.sort[sortProperty] = "descending";
  1371. else if (this.sort[sortProperty] === "descending")
  1372. delete this.sort[sortProperty];
  1373. this.getData();
  1374. this.storeTableSettings();
  1375. }
  1376. },
  1377. toggleColumnVisibility(column) {
  1378. if (!column.hidable) return false;
  1379. if (this.shownColumns.indexOf(column.name) !== -1) {
  1380. if (this.shownColumns.length <= 3)
  1381. return new Toast(
  1382. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  1383. );
  1384. this.shownColumns.splice(
  1385. this.shownColumns.indexOf(column.name),
  1386. 1
  1387. );
  1388. } else {
  1389. this.shownColumns.push(column.name);
  1390. }
  1391. this.recalculateWidths();
  1392. this.getData();
  1393. return this.storeTableSettings();
  1394. },
  1395. toggleSelectedRow(itemIndex, event) {
  1396. const { shiftKey, ctrlKey } = event;
  1397. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  1398. if (shiftKey && !ctrlKey) {
  1399. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  1400. if (this.rows[itemIndex].selected) event.preventDefault();
  1401. // If there is a last clicked item
  1402. if (this.lastSelectedItemIndex >= 0) {
  1403. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  1404. if (itemIndex > this.lastSelectedItemIndex) {
  1405. for (
  1406. let itemIndexUp = itemIndex;
  1407. itemIndexUp > this.lastSelectedItemIndex;
  1408. itemIndexUp -= 1
  1409. ) {
  1410. if (!this.rows[itemIndexUp].removed)
  1411. this.rows[itemIndexUp].selected = true;
  1412. }
  1413. }
  1414. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  1415. else if (itemIndex < this.lastSelectedItemIndex) {
  1416. for (
  1417. let itemIndexDown = itemIndex;
  1418. itemIndexDown < this.lastSelectedItemIndex;
  1419. itemIndexDown += 1
  1420. ) {
  1421. if (!this.rows[itemIndexDown].removed)
  1422. this.rows[itemIndexDown].selected = true;
  1423. }
  1424. }
  1425. }
  1426. }
  1427. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  1428. else if (!shiftKey && ctrlKey) {
  1429. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  1430. if (!this.rows[itemIndex].selected) event.preventDefault();
  1431. // If there is a last clicked item
  1432. if (this.lastSelectedItemIndex >= 0) {
  1433. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  1434. if (itemIndex >= this.lastSelectedItemIndex) {
  1435. for (
  1436. let itemIndexUp = itemIndex;
  1437. itemIndexUp >= this.lastSelectedItemIndex;
  1438. itemIndexUp -= 1
  1439. ) {
  1440. if (!this.rows[itemIndexUp].removed)
  1441. this.rows[itemIndexUp].selected = false;
  1442. }
  1443. }
  1444. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  1445. else if (itemIndex < this.lastSelectedItemIndex) {
  1446. for (
  1447. let itemIndexDown = itemIndex;
  1448. itemIndexDown <= this.lastSelectedItemIndex;
  1449. itemIndexDown += 1
  1450. ) {
  1451. if (!this.rows[itemIndexDown].removed)
  1452. this.rows[itemIndexDown].selected = false;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. // Neither ctrl nor shift were pressed, so toggle clicked item
  1458. else {
  1459. this.rows[itemIndex].selected = !this.rows[itemIndex].selected;
  1460. }
  1461. // Set the last clicked item to no longer be highlighted, if it exists
  1462. if (this.lastSelectedItemIndex >= 0)
  1463. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1464. // Set the clicked item to be highlighted
  1465. this.rows[itemIndex].highlighted = true;
  1466. },
  1467. toggleAllRows() {
  1468. if (
  1469. this.rows.filter(row => !row.removed).length >
  1470. this.selectedRows.length
  1471. ) {
  1472. this.rows = this.rows.map(row => {
  1473. if (row.removed) return row;
  1474. return { ...row, selected: true };
  1475. });
  1476. } else {
  1477. this.rows = this.rows.map(row => {
  1478. if (row.removed) return row;
  1479. return { ...row, selected: false };
  1480. });
  1481. }
  1482. },
  1483. highlightUp(itemIndex) {
  1484. if (itemIndex === 0) return;
  1485. const newItemIndex = itemIndex - 1;
  1486. this.highlightRow(newItemIndex);
  1487. },
  1488. highlightDown(itemIndex) {
  1489. if (itemIndex === this.rows.length - 1) return;
  1490. const newItemIndex = itemIndex + 1;
  1491. this.highlightRow(newItemIndex);
  1492. },
  1493. highlightRow(itemIndex) {
  1494. const rowElement = this.$refs[`row-${itemIndex}`];
  1495. // Set the last clicked item to no longer be highlighted, if it exists
  1496. if (this.lastSelectedItemIndex >= 0)
  1497. this.rows[this.lastSelectedItemIndex].highlighted = false;
  1498. if (rowElement)
  1499. this.$nextTick(() => {
  1500. rowElement.focus();
  1501. });
  1502. // Set the item to be highlighted
  1503. this.rows[itemIndex].highlighted = true;
  1504. },
  1505. unhighlightRow(itemIndex) {
  1506. const rowElement = this.$refs[`row-${itemIndex}`];
  1507. if (rowElement)
  1508. this.$nextTick(() => {
  1509. rowElement.blur();
  1510. });
  1511. // Set the item to no longer be highlighted
  1512. this.rows[itemIndex].highlighted = false;
  1513. },
  1514. selectUp(itemIndex) {
  1515. if (itemIndex === 0) return;
  1516. const newItemIndex = itemIndex - 1;
  1517. if (!this.rows[itemIndex].removed)
  1518. this.rows[itemIndex].selected = true;
  1519. if (!this.rows[newItemIndex].removed)
  1520. this.rows[newItemIndex].selected = true;
  1521. this.highlightRow(newItemIndex);
  1522. },
  1523. selectDown(itemIndex) {
  1524. if (itemIndex === this.rows.length - 1) return;
  1525. const newItemIndex = itemIndex + 1;
  1526. if (!this.rows[itemIndex].removed)
  1527. this.rows[itemIndex].selected = true;
  1528. if (!this.rows[newItemIndex].removed)
  1529. this.rows[newItemIndex].selected = true;
  1530. this.highlightRow(newItemIndex);
  1531. },
  1532. unselectUp(itemIndex) {
  1533. if (itemIndex === 0) return;
  1534. const newItemIndex = itemIndex - 1;
  1535. if (!this.rows[itemIndex].removed)
  1536. this.rows[itemIndex].selected = false;
  1537. if (!this.rows[newItemIndex].removed)
  1538. this.rows[newItemIndex].selected = false;
  1539. this.highlightRow(newItemIndex);
  1540. },
  1541. unselectDown(itemIndex) {
  1542. if (itemIndex === this.rows.length - 1) return;
  1543. const newItemIndex = itemIndex + 1;
  1544. if (!this.rows[itemIndex].removed)
  1545. this.rows[itemIndex].selected = false;
  1546. if (!this.rows[newItemIndex].removed)
  1547. this.rows[newItemIndex].selected = false;
  1548. this.highlightRow(newItemIndex);
  1549. },
  1550. addFilterItem() {
  1551. let data = "";
  1552. if (this.addFilterValue.defaultFilterType.startsWith("datetime")) {
  1553. const now = new Date();
  1554. now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
  1555. data = now.toISOString().slice(0, 16);
  1556. }
  1557. this.editingFilters.push({
  1558. data,
  1559. filter: this.addFilterValue,
  1560. filterType:
  1561. this.allFilterTypes[this.addFilterValue.defaultFilterType]
  1562. });
  1563. },
  1564. removeFilterItem(index) {
  1565. this.editingFilters.splice(index, 1);
  1566. },
  1567. columnResizingStart(column, event) {
  1568. const eventIsTouch = event.type === "touchstart";
  1569. if (eventIsTouch) {
  1570. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1571. if (
  1572. this.lastColumnResizerTapped === column &&
  1573. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1574. ) {
  1575. this.columnResetWidth(column);
  1576. this.lastColumnResizerTapped = null;
  1577. this.lastColumnResizerTappedDate = 0;
  1578. return;
  1579. }
  1580. this.lastColumnResizerTapped = column;
  1581. this.lastColumnResizerTappedDate = Date.now();
  1582. }
  1583. this.resizing.resizing = true;
  1584. this.resizing.resizingColumn = column;
  1585. this.resizing.width = event.target.parentElement.offsetWidth;
  1586. this.resizing.lastX = eventIsTouch
  1587. ? event.targetTouches[0].clientX
  1588. : event.x;
  1589. },
  1590. columnResizing(event) {
  1591. if (this.resizing.resizing) {
  1592. const eventIsTouch = event.type === "touchmove";
  1593. if (!eventIsTouch && event.buttons !== 1) {
  1594. this.resizing.resizing = false;
  1595. this.storeTableSettings();
  1596. }
  1597. const x = eventIsTouch
  1598. ? event.changedTouches[0].clientX
  1599. : event.x;
  1600. this.resizing.width -= this.resizing.lastX - x;
  1601. this.resizing.lastX = x;
  1602. if (
  1603. this.resizing.resizingColumn.minWidth &&
  1604. this.resizing.resizingColumn.maxWidth
  1605. ) {
  1606. this.resizing.resizingColumn.width = Math.max(
  1607. Math.min(
  1608. this.resizing.resizingColumn.maxWidth,
  1609. this.resizing.width
  1610. ),
  1611. this.resizing.resizingColumn.minWidth
  1612. );
  1613. } else if (this.resizing.resizingColumn.minWidth) {
  1614. this.resizing.resizingColumn.width = Math.max(
  1615. this.resizing.width,
  1616. this.resizing.resizingColumn.minWidth
  1617. );
  1618. } else if (this.resizing.resizingColumn.maxWidth) {
  1619. this.resizing.resizingColumn.width = Math.min(
  1620. this.resizing.resizingColumn.maxWidth,
  1621. this.resizing.width
  1622. );
  1623. } else {
  1624. this.resizing.resizingColumn.width = this.resizing.width;
  1625. }
  1626. this.resizing.width = this.resizing.resizingColumn.width;
  1627. console.log(`New width: ${this.resizing.width}px`);
  1628. this.storeTableSettings();
  1629. }
  1630. },
  1631. columnResizingStop() {
  1632. this.resizing.resizing = false;
  1633. this.storeTableSettings();
  1634. },
  1635. columnResetWidth(column) {
  1636. const index = this.orderedColumns.indexOf(column);
  1637. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1638. this.orderedColumns[index].width = column.defaultWidth;
  1639. else if (
  1640. column.calculatedWidth &&
  1641. !Number.isNaN(column.calculatedWidth)
  1642. )
  1643. this.orderedColumns[index].width = column.calculatedWidth;
  1644. this.storeTableSettings();
  1645. },
  1646. filterTypes(filter) {
  1647. if (!filter || !filter.filterTypes) return [];
  1648. return filter.filterTypes.map(
  1649. filterType => this.allFilterTypes[filterType]
  1650. );
  1651. },
  1652. changeFilterType(index) {
  1653. this.editingFilters[index].filterType =
  1654. this.allFilterTypes[
  1655. this.editingFilters[index].filter.defaultFilterType
  1656. ];
  1657. },
  1658. onDragBox(e) {
  1659. const e1 = e || window.event;
  1660. const e1IsTouch = e1.type === "touchstart";
  1661. e1.preventDefault();
  1662. if (e1IsTouch) {
  1663. // Handle double click from touch (if this method is twice in a row within one second)
  1664. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1665. this.resetBulkActionsPosition();
  1666. this.lastBulkActionsTappedDate = 0;
  1667. return;
  1668. }
  1669. this.lastBulkActionsTappedDate = Date.now();
  1670. }
  1671. this.bulkPopup.pos3 = e1IsTouch
  1672. ? e1.changedTouches[0].clientX
  1673. : e1.clientX;
  1674. this.bulkPopup.pos4 = e1IsTouch
  1675. ? e1.changedTouches[0].clientY
  1676. : e1.clientY;
  1677. document.onmousemove = document.ontouchmove = e => {
  1678. const e2 = e || window.event;
  1679. const e2IsTouch = e2.type === "touchmove";
  1680. if (!e2IsTouch) e2.preventDefault();
  1681. // Get the clientX and clientY
  1682. const e2ClientX = e2IsTouch
  1683. ? e2.changedTouches[0].clientX
  1684. : e2.clientX;
  1685. const e2ClientY = e2IsTouch
  1686. ? e2.changedTouches[0].clientY
  1687. : e2.clientY;
  1688. // calculate the new cursor position:
  1689. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1690. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1691. this.bulkPopup.pos3 = e2ClientX;
  1692. this.bulkPopup.pos4 = e2ClientY;
  1693. // set the element's new position:
  1694. this.bulkPopup.top -= this.bulkPopup.pos2;
  1695. this.bulkPopup.left -= this.bulkPopup.pos1;
  1696. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1697. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1698. this.bulkPopup.top = document.body.clientHeight - 50;
  1699. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1700. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1701. this.bulkPopup.left = document.body.clientWidth - 400;
  1702. };
  1703. document.onmouseup = document.ontouchend = () => {
  1704. document.onmouseup = null;
  1705. document.ontouchend = null;
  1706. document.onmousemove = null;
  1707. document.ontouchmove = null;
  1708. };
  1709. },
  1710. resetBulkActionsPosition() {
  1711. this.bulkPopup.top = document.body.clientHeight - 56;
  1712. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1713. this.bulkPopup.initial.top = this.bulkPopup.top;
  1714. this.bulkPopup.initial.left = this.bulkPopup.left;
  1715. },
  1716. applyFilterAndGetData() {
  1717. this.appliedFilters = JSON.parse(
  1718. JSON.stringify(this.editingFilters)
  1719. );
  1720. this.appliedFilterOperator = this.filterOperator;
  1721. this.page = 1;
  1722. this.getData();
  1723. this.storeTableSettings();
  1724. },
  1725. recalculateWidths() {
  1726. let noWidthCount = 0;
  1727. let calculatedWidth = 0;
  1728. this.orderedColumns.forEach(column => {
  1729. if (this.shownColumns.indexOf(column.name) !== -1)
  1730. if (
  1731. Number.isFinite(column.width) &&
  1732. !Number.isFinite(column.calculatedWidth)
  1733. ) {
  1734. calculatedWidth += column.width;
  1735. } else if (Number.isFinite(column.defaultWidth)) {
  1736. calculatedWidth += column.defaultWidth;
  1737. } else {
  1738. noWidthCount += 1;
  1739. }
  1740. });
  1741. calculatedWidth = Math.floor(
  1742. (Math.min(this.maxWidth, document.body.clientWidth) -
  1743. calculatedWidth) /
  1744. (noWidthCount - 1)
  1745. );
  1746. this.orderedColumns = this.orderedColumns.map(column => {
  1747. const orderedColumn = column;
  1748. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1749. let newWidth;
  1750. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1751. newWidth = orderedColumn.defaultWidth;
  1752. } else {
  1753. // eslint-disable-next-line no-param-reassign
  1754. newWidth = orderedColumn.calculatedWidth = Math.min(
  1755. Math.max(
  1756. orderedColumn.minWidth || 100, // fallback 100px min width
  1757. calculatedWidth
  1758. ),
  1759. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1760. );
  1761. }
  1762. if (newWidth && !Number.isFinite(orderedColumn.width))
  1763. orderedColumn.width = newWidth;
  1764. }
  1765. return orderedColumn;
  1766. });
  1767. },
  1768. columnOrderChanged() {
  1769. this.storeTableSettings();
  1770. },
  1771. getTableSettings() {
  1772. const urlTableSettings = {};
  1773. if (this.query) {
  1774. if (this.$route.query.page)
  1775. urlTableSettings.page = Number.parseInt(
  1776. this.$route.query.page
  1777. );
  1778. if (this.$route.query.pageSize)
  1779. urlTableSettings.pageSize = Number.parseInt(
  1780. this.$route.query.pageSize
  1781. );
  1782. if (this.$route.query.shownColumns)
  1783. urlTableSettings.shownColumns = JSON.parse(
  1784. this.$route.query.shownColumns
  1785. );
  1786. if (this.$route.query.columnOrder)
  1787. urlTableSettings.columnOrder = JSON.parse(
  1788. this.$route.query.columnOrder
  1789. );
  1790. if (this.$route.query.columnWidths)
  1791. urlTableSettings.columnWidths = JSON.parse(
  1792. this.$route.query.columnWidths
  1793. );
  1794. if (this.$route.query.columnSort)
  1795. urlTableSettings.columnSort = JSON.parse(
  1796. this.$route.query.columnSort
  1797. );
  1798. if (this.$route.query.filter)
  1799. urlTableSettings.filter = JSON.parse(
  1800. this.$route.query.filter
  1801. );
  1802. }
  1803. const localStorageTableSettings = JSON.parse(
  1804. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1805. );
  1806. return {
  1807. ...localStorageTableSettings,
  1808. ...urlTableSettings
  1809. };
  1810. },
  1811. storeTableSettings() {
  1812. // Clear debounce timeout
  1813. if (this.storeTableSettingsDebounceTimeout)
  1814. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1815. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1816. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1817. if (this.query) this.setQuery();
  1818. this.setLocalStorage();
  1819. }, 250);
  1820. },
  1821. setQuery() {
  1822. const queryObject = {
  1823. ...this.$route.query,
  1824. page: this.page,
  1825. pageSize: this.pageSize,
  1826. filter: JSON.stringify({
  1827. appliedFilters: this.appliedFilters,
  1828. appliedFilterOperator: this.appliedFilterOperator
  1829. }),
  1830. columnSort: JSON.stringify(this.sort),
  1831. columnOrder: JSON.stringify(
  1832. this.orderedColumns.map(column => column.name)
  1833. ),
  1834. columnWidths: JSON.stringify(
  1835. this.orderedColumns.map(column => ({
  1836. name: column.name,
  1837. width: column.width
  1838. }))
  1839. ),
  1840. shownColumns: JSON.stringify(this.shownColumns)
  1841. };
  1842. const queryString = `?${Object.keys(queryObject)
  1843. .map(key => `${key}=${queryObject[key]}`)
  1844. .join("&")}`;
  1845. window.history.replaceState(null, null, queryString);
  1846. },
  1847. setLocalStorage() {
  1848. localStorage.setItem(
  1849. `advancedTableSettings:${this.name}`,
  1850. JSON.stringify({
  1851. pageSize: this.pageSize,
  1852. filter: {
  1853. appliedFilters: this.appliedFilters,
  1854. appliedFilterOperator: this.appliedFilterOperator
  1855. },
  1856. columnSort: this.sort,
  1857. columnOrder: this.orderedColumns.map(column => column.name),
  1858. columnWidths: this.orderedColumns.map(column => ({
  1859. name: column.name,
  1860. width: column.width
  1861. })),
  1862. shownColumns: this.shownColumns
  1863. })
  1864. );
  1865. },
  1866. onWindowResize() {
  1867. if (this.bulkPopup.debounceTimeout)
  1868. clearTimeout(this.bulkPopup.debounceTimeout);
  1869. this.bulkPopup.debounceTimeout = setTimeout(() => {
  1870. // Only change the position if the popup is actually visible
  1871. if (this.selectedRows.length === 0) return;
  1872. if (
  1873. this.bulkPopup.top === this.bulkPopup.initial.top &&
  1874. this.bulkPopup.left === this.bulkPopup.initial.left
  1875. )
  1876. this.resetBulkActionsPosition();
  1877. else {
  1878. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1879. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1880. this.bulkPopup.top = document.body.clientHeight - 50;
  1881. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1882. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1883. this.bulkPopup.left = document.body.clientWidth - 400;
  1884. }
  1885. }, 50);
  1886. },
  1887. updateData(index, data) {
  1888. this.rows[index] = { ...this.rows[index], ...data, updated: true };
  1889. },
  1890. removeData(index) {
  1891. this.rows[index] = {
  1892. ...this.rows[index],
  1893. selected: false,
  1894. removed: true
  1895. };
  1896. }
  1897. }
  1898. };
  1899. </script>
  1900. <style lang="less" scoped>
  1901. .night-mode {
  1902. .table-outer-container {
  1903. .table-container .table {
  1904. &,
  1905. thead th {
  1906. background-color: var(--dark-grey-3) !important;
  1907. color: var(--light-grey-2);
  1908. }
  1909. tr {
  1910. th,
  1911. td {
  1912. border-color: var(--dark-grey) !important;
  1913. background-color: var(--dark-grey-3) !important;
  1914. }
  1915. &:nth-child(even) td {
  1916. background-color: var(--dark-grey-2) !important;
  1917. }
  1918. &:hover,
  1919. &:focus,
  1920. &.highlighted {
  1921. th,
  1922. td {
  1923. background-color: var(--dark-grey-4) !important;
  1924. }
  1925. }
  1926. &.updated td:first-child {
  1927. background-color: var(--primary-color) !important;
  1928. }
  1929. }
  1930. &.has-checkboxes tbody tr {
  1931. td:nth-child(2) {
  1932. background-color: var(--dark-grey-3) !important;
  1933. }
  1934. &:nth-child(even) td:nth-child(2) {
  1935. background-color: var(--dark-grey-2) !important;
  1936. }
  1937. &.updated td:first-child {
  1938. background-color: var(--primary-color) !important;
  1939. }
  1940. &:hover,
  1941. &:focus,
  1942. &.highlighted {
  1943. th,
  1944. td {
  1945. &:nth-child(2) {
  1946. background-color: var(--dark-grey-4) !important;
  1947. }
  1948. }
  1949. }
  1950. }
  1951. }
  1952. .table-header,
  1953. .table-footer {
  1954. background-color: var(--dark-grey-3);
  1955. color: var(--light-grey-2);
  1956. }
  1957. .table-no-results {
  1958. background-color: var(--dark-grey-3);
  1959. color: var(--light-grey-2);
  1960. border-color: var(--dark-grey) !important;
  1961. }
  1962. .label.control {
  1963. background-color: var(--dark-grey) !important;
  1964. border-color: var(--grey-3) !important;
  1965. color: var(--white) !important;
  1966. }
  1967. }
  1968. .bulk-popup {
  1969. border: 0;
  1970. background-color: var(--dark-grey-2);
  1971. color: var(--white);
  1972. .material-icons {
  1973. color: var(--white);
  1974. }
  1975. }
  1976. }
  1977. .table-outer-container {
  1978. border-radius: @border-radius;
  1979. box-shadow: @box-shadow;
  1980. margin: 10px 0;
  1981. overflow: hidden;
  1982. .table-container {
  1983. overflow-x: auto;
  1984. table {
  1985. border-collapse: separate;
  1986. table-layout: fixed;
  1987. thead {
  1988. tr {
  1989. th {
  1990. height: 40px;
  1991. line-height: 40px;
  1992. border: 1px solid var(--light-grey-2);
  1993. border-width: 1px 1px 1px 0;
  1994. padding: 0;
  1995. &:last-child {
  1996. border-width: 1px 0 1px;
  1997. }
  1998. &.sortable {
  1999. cursor: pointer;
  2000. }
  2001. & > div {
  2002. display: flex;
  2003. white-space: nowrap;
  2004. padding: 8px 10px;
  2005. & > span {
  2006. margin-left: 5px;
  2007. &:first-child {
  2008. margin-left: 0;
  2009. margin-right: auto;
  2010. }
  2011. & > .material-icons {
  2012. font-size: 22px;
  2013. position: relative;
  2014. top: 6px;
  2015. cursor: pointer;
  2016. &.active {
  2017. color: var(--primary-color);
  2018. }
  2019. &:hover,
  2020. &:focus {
  2021. filter: brightness(90%);
  2022. }
  2023. }
  2024. }
  2025. }
  2026. }
  2027. }
  2028. }
  2029. tbody {
  2030. tr {
  2031. &.updated {
  2032. td:first-child {
  2033. background-color: var(--primary-color) !important;
  2034. }
  2035. }
  2036. &:nth-child(even) td {
  2037. background-color: rgb(250, 250, 250);
  2038. }
  2039. td {
  2040. border: 1px solid var(--light-grey-2);
  2041. border-width: 0 1px 1px 0;
  2042. &:last-child {
  2043. border-width: 0 0 1px;
  2044. }
  2045. :deep(.row-options) {
  2046. display: flex;
  2047. justify-content: space-evenly;
  2048. .icon-with-button {
  2049. height: 30px;
  2050. width: 30px;
  2051. }
  2052. }
  2053. }
  2054. &.removed {
  2055. filter: grayscale(100%);
  2056. cursor: not-allowed;
  2057. user-select: none;
  2058. td .removed-overlay {
  2059. position: absolute;
  2060. top: 0;
  2061. left: 0;
  2062. bottom: 0;
  2063. right: 5px;
  2064. z-index: 5;
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. table {
  2071. thead tr,
  2072. tbody tr {
  2073. th,
  2074. td {
  2075. position: relative;
  2076. white-space: nowrap;
  2077. text-overflow: ellipsis;
  2078. overflow: hidden;
  2079. background-color: var(--white);
  2080. &:first-child {
  2081. display: table-cell;
  2082. position: sticky;
  2083. left: 0;
  2084. z-index: 2;
  2085. & > .updated-tooltip {
  2086. position: absolute;
  2087. top: 0;
  2088. left: 0;
  2089. bottom: 0;
  2090. right: 0;
  2091. }
  2092. }
  2093. .resizer {
  2094. height: 100%;
  2095. width: 5px;
  2096. background-color: transparent;
  2097. cursor: col-resize;
  2098. position: absolute;
  2099. right: 0;
  2100. top: 0;
  2101. }
  2102. }
  2103. &:hover,
  2104. &:focus,
  2105. &.highlighted {
  2106. th,
  2107. td {
  2108. background-color: rgb(240, 240, 240);
  2109. }
  2110. }
  2111. }
  2112. &.has-checkboxes {
  2113. thead,
  2114. tbody {
  2115. tr {
  2116. th,
  2117. td {
  2118. &:nth-child(2) {
  2119. display: table-cell;
  2120. position: sticky;
  2121. left: 5px;
  2122. z-index: 2;
  2123. }
  2124. }
  2125. &.updated td:first-child {
  2126. background-color: var(--primary-color);
  2127. }
  2128. }
  2129. }
  2130. }
  2131. }
  2132. }
  2133. .table-header,
  2134. .table-footer {
  2135. display: flex;
  2136. flex-direction: row;
  2137. flex-wrap: wrap;
  2138. justify-content: space-between;
  2139. line-height: 36px;
  2140. background-color: var(--white);
  2141. }
  2142. .table-header {
  2143. & > div {
  2144. display: flex;
  2145. flex-direction: row;
  2146. > span > .control {
  2147. margin: 5px;
  2148. }
  2149. .filters-indicator {
  2150. line-height: 46px;
  2151. display: flex;
  2152. align-items: center;
  2153. column-gap: 4px;
  2154. }
  2155. }
  2156. @media screen and (max-width: 400px) {
  2157. flex-direction: column;
  2158. & > div {
  2159. justify-content: center;
  2160. }
  2161. }
  2162. }
  2163. .table-footer {
  2164. .page-controls,
  2165. .page-size > .control {
  2166. display: flex;
  2167. flex-direction: row;
  2168. margin-bottom: 0 !important;
  2169. button {
  2170. margin: 5px;
  2171. font-size: 20px;
  2172. }
  2173. p,
  2174. label {
  2175. margin: 5px;
  2176. font-size: 14px;
  2177. font-weight: 600;
  2178. }
  2179. &.select::after {
  2180. top: 18px;
  2181. }
  2182. }
  2183. @media screen and (max-width: 600px) {
  2184. flex-direction: column;
  2185. .page-controls,
  2186. .page-size > .control {
  2187. justify-content: center;
  2188. }
  2189. }
  2190. }
  2191. .table-no-results {
  2192. display: flex;
  2193. flex-direction: row;
  2194. justify-content: center;
  2195. border-bottom: 1px solid var(--light-grey-2);
  2196. font-size: 18px;
  2197. line-height: 50px;
  2198. background-color: var(--white);
  2199. }
  2200. }
  2201. .control.is-grouped {
  2202. display: flex;
  2203. & > .control {
  2204. &.label {
  2205. height: 36px;
  2206. background-color: var(--white);
  2207. border: 1px solid var(--light-grey-2);
  2208. color: var(--dark-grey-2);
  2209. appearance: none;
  2210. border-radius: @border-radius;
  2211. font-size: 14px;
  2212. line-height: 34px;
  2213. padding-left: 8px;
  2214. padding-right: 8px;
  2215. }
  2216. :deep(& > div > input) {
  2217. border-radius: 0;
  2218. }
  2219. & > .button {
  2220. font-size: 22px;
  2221. }
  2222. }
  2223. @media screen and (max-width: 600px) {
  2224. &.advanced-filter {
  2225. flex-wrap: wrap;
  2226. .control.select {
  2227. width: 50%;
  2228. }
  2229. .control {
  2230. margin-bottom: 0 !important;
  2231. &:nth-child(1) > select {
  2232. border-radius: @border-radius 0 0 0;
  2233. }
  2234. &:nth-child(2) > select {
  2235. border-radius: 0 @border-radius 0 0;
  2236. }
  2237. :deep(&:nth-child(3)) {
  2238. & > input,
  2239. & > div > input,
  2240. & > select {
  2241. border-radius: 0 0 0 @border-radius;
  2242. }
  2243. }
  2244. &:nth-child(4) > button {
  2245. border-radius: 0 0 @border-radius 0;
  2246. }
  2247. }
  2248. }
  2249. }
  2250. }
  2251. .advanced-filter {
  2252. .control {
  2253. position: relative;
  2254. }
  2255. }
  2256. .advanced-filter-bottom {
  2257. display: flex;
  2258. .button {
  2259. font-size: 16px !important;
  2260. width: 100%;
  2261. }
  2262. .control {
  2263. margin: 0 !important;
  2264. }
  2265. }
  2266. :deep(.bulk-popup) {
  2267. display: flex;
  2268. position: fixed;
  2269. flex-direction: row;
  2270. width: 100%;
  2271. max-width: 400px;
  2272. line-height: 36px;
  2273. z-index: 5;
  2274. border: 1px solid var(--light-grey-3);
  2275. border-radius: @border-radius;
  2276. box-shadow: @box-shadow-dropdown;
  2277. background-color: var(--white);
  2278. color: var(--dark-grey);
  2279. padding: 5px;
  2280. .right {
  2281. display: flex;
  2282. flex-direction: row;
  2283. margin-left: auto;
  2284. }
  2285. .drag-icon {
  2286. position: relative;
  2287. top: 6px;
  2288. color: var(--dark-grey);
  2289. cursor: move;
  2290. }
  2291. .bulk-actions {
  2292. display: flex;
  2293. flex-direction: row;
  2294. width: 100%;
  2295. justify-content: space-evenly;
  2296. .material-icons {
  2297. position: relative;
  2298. top: 6px;
  2299. margin-left: 5px;
  2300. cursor: pointer;
  2301. color: var(--primary-color);
  2302. height: 25px;
  2303. &:hover,
  2304. &:focus {
  2305. filter: brightness(90%);
  2306. }
  2307. }
  2308. .delete-icon {
  2309. color: var(--dark-red);
  2310. }
  2311. }
  2312. }
  2313. </style>