AdvancedTable.vue 63 KB

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