AdvancedTable.vue 61 KB

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