1
0

AdvancedTable.vue 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878
  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 === 'array'
  117. "
  118. class="control is-expanded select"
  119. >
  120. <select
  121. v-model="filter.data"
  122. :disabled="!filter.filterType"
  123. >
  124. <option
  125. v-for="filterValue in filter.filter
  126. .filterValues"
  127. :key="filterValue"
  128. :value="filterValue"
  129. >
  130. {{ filterValue }}
  131. </option>
  132. </select>
  133. </div>
  134. <p v-else class="control is-expanded">
  135. <input
  136. v-if="
  137. filter.filterType.name &&
  138. filter.filterType.name.startsWith(
  139. 'datetime'
  140. )
  141. "
  142. v-model="filter.data"
  143. class="input"
  144. type="datetime-local"
  145. />
  146. <input
  147. v-else-if="
  148. filter.filterType.name &&
  149. filter.filterType.name.startsWith(
  150. 'number'
  151. )
  152. "
  153. v-model="filter.data"
  154. class="input"
  155. type="number"
  156. :disabled="!filter.filterType"
  157. @keydown.enter="applyFilterAndGetData()"
  158. />
  159. <input
  160. v-else
  161. v-model="filter.data"
  162. class="input"
  163. type="text"
  164. placeholder="Search value"
  165. :disabled="!filter.filterType"
  166. @keydown.enter="applyFilterAndGetData()"
  167. />
  168. </p>
  169. <div class="control">
  170. <button
  171. class="button material-icons is-danger"
  172. @click="removeFilterItem(index)"
  173. >
  174. remove_circle_outline
  175. </button>
  176. </div>
  177. </div>
  178. <div
  179. v-if="editingFilters.length > 0"
  180. class="control is-expanded is-grouped"
  181. >
  182. <label class="control label"
  183. >Filter operator</label
  184. >
  185. <div class="control select is-expanded">
  186. <select v-model="filterOperator">
  187. <option
  188. v-for="operator in filterOperators"
  189. :key="operator.name"
  190. :value="operator.name"
  191. >
  192. {{ operator.displayName }}
  193. </option>
  194. </select>
  195. </div>
  196. </div>
  197. <div
  198. class="advanced-filter-bottom"
  199. v-if="editingFilters.length > 0"
  200. >
  201. <div class="control is-expanded">
  202. <button
  203. class="button is-info"
  204. @click="applyFilterAndGetData()"
  205. >
  206. <i
  207. class="
  208. material-icons
  209. icon-with-button
  210. "
  211. >filter_list</i
  212. >
  213. Apply filters
  214. </button>
  215. </div>
  216. </div>
  217. <div
  218. class="advanced-filter-bottom"
  219. v-else-if="editingFilters.length === 0"
  220. >
  221. <div class="control is-expanded">
  222. <button
  223. class="button is-info"
  224. @click="applyFilterAndGetData()"
  225. >
  226. <i
  227. class="
  228. material-icons
  229. icon-with-button
  230. "
  231. >filter_list</i
  232. >
  233. Apply filters
  234. </button>
  235. </div>
  236. </div>
  237. </template>
  238. </tippy>
  239. <tippy
  240. v-if="appliedFilters.length > 0"
  241. :touch="true"
  242. :interactive="true"
  243. theme="info"
  244. ref="activeFilters"
  245. >
  246. <div class="filters-indicator">
  247. {{ appliedFilters.length }}
  248. <i class="material-icons" @click.prevent="true"
  249. >filter_list</i
  250. >
  251. </div>
  252. <template #content>
  253. <p
  254. v-for="(filter, index) in appliedFilters"
  255. :key="`filter-${index}`"
  256. >
  257. {{ filter.filter.displayName }}
  258. {{
  259. appliedFilters.length === 1 &&
  260. appliedFilterOperator === "nor"
  261. ? "not"
  262. : ""
  263. }}
  264. {{
  265. filter.filterType.displayName.toLowerCase()
  266. }}
  267. "{{ filter.data }}"
  268. {{
  269. appliedFilters.length === index + 1
  270. ? ""
  271. : appliedFilterOperator
  272. }}
  273. </p>
  274. </template>
  275. </tippy>
  276. <i
  277. v-else
  278. class="filters-indicator material-icons"
  279. content="No active filters"
  280. v-tippy="{ theme: 'info' }"
  281. >
  282. filter_list_off
  283. </i>
  284. </div>
  285. <div>
  286. <tippy
  287. v-if="hidableSortedColumns.length > 0"
  288. :touch="true"
  289. :interactive="true"
  290. placement="bottom-end"
  291. theme="dropdown"
  292. ref="editColumns"
  293. trigger="click"
  294. @show="
  295. () => {
  296. showColumnsDropdown = true;
  297. }
  298. "
  299. @hide="
  300. () => {
  301. showColumnsDropdown = false;
  302. }
  303. "
  304. >
  305. <div class="control has-addons" ref="trigger">
  306. <button class="button is-primary">
  307. <i class="material-icons icon-with-button"
  308. >tune</i
  309. >
  310. Columns
  311. </button>
  312. <button class="button">
  313. <i class="material-icons">
  314. {{
  315. showColumnsDropdown
  316. ? "expand_more"
  317. : "expand_less"
  318. }}
  319. </i>
  320. </button>
  321. </div>
  322. <template #content>
  323. <draggable
  324. item-key="name"
  325. v-model="orderedColumns"
  326. v-bind="columnDragOptions"
  327. tag="div"
  328. draggable=".item-draggable"
  329. class="nav-dropdown-items"
  330. @change="columnOrderChanged"
  331. >
  332. <template #item="{ element: column }">
  333. <button
  334. v-if="
  335. column.name !== 'select' &&
  336. column.name !== 'placeholder'
  337. "
  338. :class="{
  339. sortable: column.sortable,
  340. 'item-draggable': column.draggable,
  341. 'nav-item': true
  342. }"
  343. @click.prevent="
  344. toggleColumnVisibility(column)
  345. "
  346. >
  347. <p
  348. class="
  349. control
  350. is-expanded
  351. checkbox-control
  352. "
  353. >
  354. <label class="switch">
  355. <input
  356. type="checkbox"
  357. :id="index"
  358. :checked="
  359. shownColumns.indexOf(
  360. column.name
  361. ) !== -1
  362. "
  363. @click="
  364. toggleColumnVisibility(
  365. column
  366. )
  367. "
  368. />
  369. <span
  370. :class="{
  371. slider: true,
  372. round: true,
  373. disabled:
  374. !column.hidable
  375. }"
  376. ></span>
  377. </label>
  378. <label :for="index">
  379. <span></span>
  380. <p>{{ column.displayName }}</p>
  381. </label>
  382. </p>
  383. </button>
  384. </template>
  385. </draggable>
  386. </template>
  387. </tippy>
  388. </div>
  389. </div>
  390. <div class="table-container">
  391. <table
  392. :class="{
  393. table: true,
  394. 'has-checkboxes': hasCheckboxes
  395. }"
  396. >
  397. <thead>
  398. <draggable
  399. item-key="name"
  400. v-model="orderedColumns"
  401. v-bind="columnDragOptions"
  402. tag="tr"
  403. handle=".handle"
  404. draggable=".item-draggable"
  405. @change="columnOrderChanged"
  406. >
  407. <template #item="{ element: column }">
  408. <th
  409. v-if="
  410. !(
  411. column.name === 'select' &&
  412. data.length === 0
  413. ) &&
  414. shownColumns.indexOf(column.name) !== -1
  415. "
  416. :class="{
  417. sortable: column.sortable,
  418. 'item-draggable': column.draggable
  419. }"
  420. :style="{
  421. minWidth: Number.isNaN(column.minWidth)
  422. ? column.minWidth
  423. : `${column.minWidth}px`,
  424. width: Number.isNaN(column.width)
  425. ? column.width
  426. : `${column.width}px`,
  427. maxWidth: Number.isNaN(column.maxWidth)
  428. ? column.maxWidth
  429. : `${column.maxWidth}px`
  430. }"
  431. >
  432. <div v-if="column.name === 'select'">
  433. <p class="checkbox">
  434. <input
  435. type="checkbox"
  436. :checked="
  437. data.length ===
  438. selectedRows.length
  439. "
  440. @click="toggleAllRows()"
  441. />
  442. </p>
  443. </div>
  444. <div v-else class="handle">
  445. <span>
  446. {{ column.displayName }}
  447. </span>
  448. <span
  449. v-if="column.sortable"
  450. :content="`Sort by ${column.displayName}`"
  451. v-tippy
  452. >
  453. <span
  454. v-if="
  455. !sort[column.sortProperty]
  456. "
  457. class="material-icons"
  458. @click="changeSort(column)"
  459. >
  460. unfold_more
  461. </span>
  462. <span
  463. v-if="
  464. sort[
  465. column.sortProperty
  466. ] === 'ascending'
  467. "
  468. class="material-icons active"
  469. @click="changeSort(column)"
  470. >
  471. expand_more
  472. </span>
  473. <span
  474. v-if="
  475. sort[
  476. column.sortProperty
  477. ] === 'descending'
  478. "
  479. class="material-icons active"
  480. @click="changeSort(column)"
  481. >
  482. expand_less
  483. </span>
  484. </span>
  485. </div>
  486. <div
  487. class="resizer"
  488. v-if="column.resizable"
  489. @mousedown.prevent.stop="
  490. columnResizingStart(column, $event)
  491. "
  492. @touchstart.prevent.stop="
  493. columnResizingStart(column, $event)
  494. "
  495. @mouseup="columnResizingStop()"
  496. @touchend="columnResizingStop()"
  497. @dblclick="columnResetWidth(column)"
  498. ></div>
  499. </th>
  500. </template>
  501. </draggable>
  502. </thead>
  503. <tbody>
  504. <tr
  505. v-for="(item, itemIndex) in data"
  506. :key="item._id"
  507. :class="{
  508. selected: item.selected,
  509. highlighted: item.highlighted
  510. }"
  511. >
  512. <td
  513. v-for="column in sortedFilteredColumns"
  514. :key="`${item._id}-${column.name}`"
  515. >
  516. <slot
  517. :name="`column-${column.name}`"
  518. :item="item"
  519. v-if="
  520. column.properties.length === 0 ||
  521. column.properties.every(property =>
  522. property
  523. .split('.')
  524. .reduce(
  525. (previous, current) =>
  526. (previous &&
  527. previous[
  528. current
  529. ]) ||
  530. null,
  531. item
  532. )
  533. )
  534. "
  535. ></slot>
  536. <p
  537. class="checkbox"
  538. v-if="column.name === 'select'"
  539. >
  540. <input
  541. type="checkbox"
  542. :checked="item.selected"
  543. @click="
  544. toggleSelectedRow(itemIndex, $event)
  545. "
  546. />
  547. </p>
  548. <div
  549. class="resizer"
  550. v-if="column.resizable"
  551. @mousedown.prevent.stop="
  552. columnResizingStart(column, $event)
  553. "
  554. @touchstart.prevent.stop="
  555. columnResizingStart(column, $event)
  556. "
  557. @mouseup="columnResizingStop()"
  558. @touchend="columnResizingStop()"
  559. @dblclick="columnResetWidth(column)"
  560. ></div>
  561. </td>
  562. </tr>
  563. </tbody>
  564. </table>
  565. </div>
  566. <div class="table-footer">
  567. <div class="page-controls">
  568. <button
  569. :class="{ disabled: page === 1 }"
  570. class="button is-primary material-icons"
  571. :disabled="page === 1"
  572. @click="changePage(1)"
  573. content="First Page"
  574. v-tippy
  575. >
  576. skip_previous
  577. </button>
  578. <button
  579. :class="{ disabled: page === 1 }"
  580. class="button is-primary material-icons"
  581. :disabled="page === 1"
  582. @click="changePage(page - 1)"
  583. content="Previous Page"
  584. v-tippy
  585. >
  586. fast_rewind
  587. </button>
  588. <p>Page {{ page }} / {{ lastPage }}</p>
  589. <button
  590. :class="{ disabled: page === lastPage }"
  591. class="button is-primary material-icons"
  592. :disabled="page === lastPage"
  593. @click="changePage(page + 1)"
  594. content="Next Page"
  595. v-tippy
  596. >
  597. fast_forward
  598. </button>
  599. <button
  600. :class="{ disabled: page === lastPage }"
  601. class="button is-primary material-icons"
  602. :disabled="page === lastPage"
  603. @click="changePage(lastPage)"
  604. content="Last Page"
  605. v-tippy
  606. >
  607. skip_next
  608. </button>
  609. </div>
  610. <div class="page-size">
  611. <div class="control">
  612. <label class="label">Items per page</label>
  613. <p class="control select">
  614. <select
  615. v-model.number="pageSize"
  616. @change="changePageSize()"
  617. >
  618. <option value="10">10</option>
  619. <option value="25">25</option>
  620. <option value="50">50</option>
  621. <option value="100">100</option>
  622. <option value="250">250</option>
  623. <option value="500">500</option>
  624. <option value="1000">1000</option>
  625. </select>
  626. </p>
  627. </div>
  628. </div>
  629. </div>
  630. </div>
  631. <div
  632. v-if="hasCheckboxes && selectedRows.length > 0"
  633. class="bulk-popup"
  634. :style="{
  635. top: bulkPopup.top + 'px',
  636. left: bulkPopup.left + 'px'
  637. }"
  638. >
  639. <button
  640. class="button is-primary"
  641. :content="
  642. selectedRows.length === 1
  643. ? `${selectedRows.length} row selected`
  644. : `${selectedRows.length} rows selected`
  645. "
  646. v-tippy="{ theme: 'info' }"
  647. >
  648. {{ selectedRows.length }}
  649. </button>
  650. <slot name="bulk-actions" :item="selectedRows" />
  651. <div class="right">
  652. <slot name="bulk-actions-right" :item="selectedRows" />
  653. <span
  654. class="material-icons drag-icon"
  655. @mousedown.left="onDragBox"
  656. @touchstart="onDragBox"
  657. @dblclick="resetBulkActionsPosition()"
  658. >
  659. drag_indicator
  660. </span>
  661. </div>
  662. </div>
  663. </div>
  664. </template>
  665. <script>
  666. import { mapGetters } from "vuex";
  667. import draggable from "vuedraggable";
  668. import Toast from "toasters";
  669. import ws from "@/ws";
  670. export default {
  671. components: {
  672. draggable
  673. },
  674. props: {
  675. /*
  676. Column properties:
  677. name: Unique lowercase name
  678. displayName: Nice name for the column header
  679. properties: The properties this column needs to show data
  680. sortable: Boolean for whether the order of a particular column can be changed
  681. sortProperty: The property the backend will sort on if this column gets sorted, e.g. title
  682. hidable: Boolean for whether a column can be hidden
  683. defaultVisibility: Default visibility for a column, either "shown" or "hidden"
  684. draggable: Boolean for whether a column can be dragged/reordered,
  685. resizable: Boolean for whether a column can be resized
  686. minWidth: Minimum width of column, e.g. 50px
  687. width: Width of column, e.g. 100px
  688. maxWidth: Maximum width of column, e.g. 150px
  689. */
  690. columnDefault: { type: Object, default: () => {} },
  691. columns: { type: Array, default: null },
  692. filters: { type: Array, default: null },
  693. dataAction: { type: String, default: null },
  694. name: { type: String, default: null },
  695. maxWidth: { type: Number, default: 1880 },
  696. query: { type: Boolean, default: true }
  697. },
  698. data() {
  699. return {
  700. page: 1,
  701. pageSize: 10,
  702. data: [],
  703. count: 0, // TODO Rename
  704. sort: {},
  705. orderedColumns: [],
  706. shownColumns: [],
  707. columnDragOptions() {
  708. return {
  709. animation: 200,
  710. group: "columns",
  711. disabled: false,
  712. ghostClass: "draggable-list-ghost",
  713. filter: ".ignore-elements",
  714. fallbackTolerance: 50
  715. };
  716. },
  717. editingFilters: [],
  718. appliedFilters: [],
  719. filterOperator: "or",
  720. appliedFilterOperator: "or",
  721. filterOperators: [
  722. {
  723. name: "or",
  724. displayName: "OR"
  725. },
  726. {
  727. name: "and",
  728. displayName: "AND"
  729. },
  730. {
  731. name: "nor",
  732. displayName: "NOR"
  733. }
  734. ],
  735. resizing: {},
  736. allFilterTypes: {
  737. contains: {
  738. name: "contains",
  739. displayName: "Contains"
  740. },
  741. exact: {
  742. name: "exact",
  743. displayName: "Exact"
  744. },
  745. regex: {
  746. name: "regex",
  747. displayName: "Regex"
  748. },
  749. datetimeBefore: {
  750. name: "datetimeBefore",
  751. displayName: "Before"
  752. },
  753. datetimeAfter: {
  754. name: "datetimeAfter",
  755. displayName: "After"
  756. },
  757. numberLesser: {
  758. name: "numberLesser",
  759. displayName: "Less than"
  760. },
  761. numberGreater: {
  762. name: "numberGreater",
  763. displayName: "Greater than"
  764. },
  765. numberEquals: {
  766. name: "numberEquals",
  767. displayName: "Equals"
  768. },
  769. array: {
  770. name: "array",
  771. displayName: "Is"
  772. }
  773. },
  774. bulkPopup: {
  775. top: 0,
  776. left: 0,
  777. pos1: 0,
  778. pos2: 0,
  779. pos3: 0,
  780. pos4: 0
  781. },
  782. addFilterValue: null,
  783. showFiltersDropdown: false,
  784. showColumnsDropdown: false,
  785. lastColumnResizerTapped: null,
  786. lastColumnResizerTappedDate: 0,
  787. lastBulkActionsTappedDate: 0
  788. };
  789. },
  790. computed: {
  791. properties() {
  792. return Array.from(
  793. new Set(
  794. this.sortedFilteredColumns.flatMap(
  795. column => column.properties
  796. )
  797. )
  798. );
  799. },
  800. lastPage() {
  801. return Math.ceil(this.count / this.pageSize);
  802. },
  803. sortedFilteredColumns() {
  804. return this.orderedColumns.filter(
  805. column => this.shownColumns.indexOf(column.name) !== -1
  806. );
  807. },
  808. hidableSortedColumns() {
  809. return this.orderedColumns.filter(column => column.hidable);
  810. },
  811. lastSelectedItemIndex() {
  812. return this.data.findIndex(item => item.highlighted);
  813. },
  814. selectedRows() {
  815. return this.data.filter(data => data.selected);
  816. },
  817. hasCheckboxes() {
  818. return (
  819. this.$slots["bulk-actions"] != null ||
  820. this.$slots["bulk-actions-right"] != null
  821. );
  822. },
  823. ...mapGetters({
  824. socket: "websockets/getSocket"
  825. })
  826. },
  827. watch: {
  828. selectedRows(newSelectedRows, oldSelectedRows) {
  829. // If selected rows goes from zero to one or more selected, trigger onWindowResize, as otherwise the popup could be out of bounds
  830. if (oldSelectedRows.length === 0 && newSelectedRows.length > 0)
  831. this.onWindowResize();
  832. }
  833. },
  834. mounted() {
  835. const tableSettings = this.getTableSettings();
  836. this.orderedColumns = [
  837. {
  838. name: "select",
  839. displayName: "",
  840. properties: [],
  841. sortable: false,
  842. hidable: false,
  843. draggable: false,
  844. resizable: false,
  845. minWidth: 47,
  846. defaultWidth: 47,
  847. maxWidth: 47
  848. },
  849. ...this.columns.map(column => ({
  850. ...this.columnDefault,
  851. ...column
  852. })),
  853. {
  854. name: "placeholder",
  855. displayName: "",
  856. properties: [],
  857. sortable: false,
  858. hidable: false,
  859. draggable: false,
  860. resizable: false,
  861. minWidth: "auto",
  862. width: "auto",
  863. maxWidth: "auto"
  864. }
  865. ].sort((columnA, columnB) => {
  866. // Always places select column in the first position
  867. if (columnA.name === "select") return -1;
  868. // Always places placeholder column in the last position
  869. if (columnB.name === "placeholder") return -1;
  870. // If there are no table settings stored, use default ordering
  871. if (!tableSettings || !tableSettings.columnOrder) return 0;
  872. const indexA = tableSettings.columnOrder.indexOf(columnA.name);
  873. const indexB = tableSettings.columnOrder.indexOf(columnB.name);
  874. // If either of the columns is not stored in the table settings, use default ordering
  875. if (indexA === -1 || indexB === -1) return 0;
  876. return indexA - indexB;
  877. });
  878. this.shownColumns = this.orderedColumns
  879. .filter(column => {
  880. // If table settings exist, use shownColumns from settings to determine which columns to show
  881. if (tableSettings && tableSettings.shownColumns)
  882. return (
  883. tableSettings.shownColumns.indexOf(column.name) !== -1
  884. );
  885. // Table settings don't exist, only show if the default visibility isn't hidden
  886. return column.defaultVisibility !== "hidden";
  887. })
  888. .map(column => column.name);
  889. this.recalculateWidths();
  890. if (tableSettings) {
  891. // If table settings' page is an integer, use it for the page
  892. if (Number.isInteger(tableSettings?.page))
  893. this.page = tableSettings.page;
  894. // If table settings' pageSize is an integer, use it for the pageSize
  895. if (Number.isInteger(tableSettings?.pageSize))
  896. this.pageSize = tableSettings.pageSize;
  897. // If table settings' columnSort exists, sort all still existing columns based on table settings' columnSort object
  898. if (tableSettings.columnSort) {
  899. Object.entries(tableSettings.columnSort).forEach(
  900. ([columnName, sortDirection]) => {
  901. if (
  902. this.columns.find(
  903. column => column.name === columnName
  904. )
  905. )
  906. this.sort[columnName] = sortDirection;
  907. }
  908. );
  909. }
  910. // If table settings' columnWidths exists, load the stored widths into the columns
  911. if (tableSettings.columnWidths) {
  912. this.orderedColumns = this.orderedColumns.map(orderedColumn => {
  913. const columnWidth = tableSettings.columnWidths.find(
  914. column => column.name === orderedColumn.name
  915. )?.width;
  916. if (columnWidth)
  917. return { ...orderedColumn, width: columnWidth };
  918. return orderedColumn;
  919. });
  920. }
  921. if (
  922. tableSettings.filter &&
  923. tableSettings.filter.appliedFilters &&
  924. tableSettings.filter.appliedFilterOperator
  925. ) {
  926. const { appliedFilters, appliedFilterOperator } =
  927. tableSettings.filter;
  928. // Set the applied filter operator and filter operator to the value stored in table settings
  929. this.appliedFilterOperator = this.filterOperator =
  930. appliedFilterOperator;
  931. // Set the applied filters and editing filters to the value stored in table settings, for all filters that are allowed
  932. this.appliedFilters = appliedFilters.filter(appliedFilter =>
  933. this.filters.find(
  934. filter => appliedFilter.filter.name === filter.name
  935. )
  936. );
  937. this.editingFilters = appliedFilters.filter(appliedFilter =>
  938. this.filters.find(
  939. filter => appliedFilter.filter.name === filter.name
  940. )
  941. );
  942. }
  943. }
  944. this.resetBulkActionsPosition();
  945. this.$nextTick(() => {
  946. this.onWindowResize();
  947. window.addEventListener("resize", this.onWindowResize);
  948. });
  949. ws.onConnect(this.init);
  950. },
  951. unmounted() {
  952. window.removeEventListener("resize", this.onWindowResize);
  953. if (this.storeTableSettingsDebounceTimeout)
  954. clearTimeout(this.storeTableSettingsDebounceTimeout);
  955. },
  956. methods: {
  957. init() {
  958. this.getData();
  959. if (this.query) this.setQuery();
  960. },
  961. getData() {
  962. this.socket.dispatch(
  963. this.dataAction,
  964. this.page,
  965. this.pageSize,
  966. this.properties,
  967. this.sort,
  968. JSON.parse(
  969. JSON.stringify(
  970. this.appliedFilters.map(filter => ({
  971. ...filter,
  972. filterType: filter.filterType.name
  973. }))
  974. )
  975. ),
  976. this.appliedFilterOperator,
  977. res => {
  978. console.log(111, res);
  979. if (res.status === "success") {
  980. const { data, count } = res.data;
  981. this.data = data.map(row => ({
  982. ...row,
  983. selected: false
  984. }));
  985. this.count = count;
  986. } else {
  987. new Toast(res.message);
  988. }
  989. }
  990. );
  991. },
  992. changePageSize() {
  993. this.page = 1;
  994. this.getData();
  995. this.storeTableSettings();
  996. },
  997. changePage(page) {
  998. if (page < 1) return;
  999. if (page > this.lastPage) return;
  1000. if (page === this.page) return;
  1001. this.page = page;
  1002. this.getData();
  1003. if (this.query) this.setQuery();
  1004. },
  1005. changeSort(column) {
  1006. if (column.sortable) {
  1007. const { sortProperty } = column;
  1008. if (this.sort[sortProperty] === undefined)
  1009. this.sort[sortProperty] = "ascending";
  1010. else if (this.sort[sortProperty] === "ascending")
  1011. this.sort[sortProperty] = "descending";
  1012. else if (this.sort[sortProperty] === "descending")
  1013. delete this.sort[sortProperty];
  1014. this.getData();
  1015. this.storeTableSettings();
  1016. }
  1017. },
  1018. toggleColumnVisibility(column) {
  1019. if (!column.hidable) return false;
  1020. if (this.shownColumns.indexOf(column.name) !== -1) {
  1021. if (this.shownColumns.length <= 3)
  1022. return new Toast(
  1023. `Unable to hide column ${column.displayName}, there must be at least 1 visibile column`
  1024. );
  1025. this.shownColumns.splice(
  1026. this.shownColumns.indexOf(column.name),
  1027. 1
  1028. );
  1029. } else {
  1030. this.shownColumns.push(column.name);
  1031. }
  1032. this.recalculateWidths();
  1033. this.getData();
  1034. return this.storeTableSettings();
  1035. },
  1036. toggleSelectedRow(itemIndex, event) {
  1037. const { shiftKey, ctrlKey } = event;
  1038. // Shift was pressed, so attempt to select all items between the clicked item and last clicked item
  1039. if (shiftKey) {
  1040. // If the clicked item is already selected, prevent default, otherwise the checkbox will be unchecked
  1041. if (this.data[itemIndex].selected) event.preventDefault();
  1042. // If there is a last clicked item
  1043. if (this.lastSelectedItemIndex >= 0) {
  1044. // Clicked item is lower than last item, so select upwards until it reaches the last selected item
  1045. if (itemIndex > this.lastSelectedItemIndex) {
  1046. for (
  1047. let itemIndexUp = itemIndex;
  1048. itemIndexUp > this.lastSelectedItemIndex;
  1049. itemIndexUp -= 1
  1050. ) {
  1051. this.data[itemIndexUp].selected = true;
  1052. }
  1053. }
  1054. // Clicked item is higher than last item, so select downwards until it reaches the last selected item
  1055. else if (itemIndex < this.lastSelectedItemIndex) {
  1056. for (
  1057. let itemIndexDown = itemIndex;
  1058. itemIndexDown < this.lastSelectedItemIndex;
  1059. itemIndexDown += 1
  1060. ) {
  1061. this.data[itemIndexDown].selected = true;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. // Ctrl was pressed, so attempt to unselect all items between the clicked item and last clicked item
  1067. else if (ctrlKey) {
  1068. // If the clicked item is already unselected, prevent default, otherwise the checkbox will be checked
  1069. if (!this.data[itemIndex].selected) event.preventDefault();
  1070. // If there is a last clicked item
  1071. if (this.lastSelectedItemIndex >= 0) {
  1072. // Clicked item is lower than last item, so unselect upwards until it reaches the last selected item
  1073. if (itemIndex > this.lastSelectedItemIndex) {
  1074. for (
  1075. let itemIndexUp = itemIndex;
  1076. itemIndexUp >= this.lastSelectedItemIndex;
  1077. itemIndexUp -= 1
  1078. ) {
  1079. this.data[itemIndexUp].selected = false;
  1080. }
  1081. }
  1082. // Clicked item is higher than last item, so unselect downwards until it reaches the last selected item
  1083. else if (itemIndex < this.lastSelectedItemIndex) {
  1084. for (
  1085. let itemIndexDown = itemIndex;
  1086. itemIndexDown <= this.lastSelectedItemIndex;
  1087. itemIndexDown += 1
  1088. ) {
  1089. this.data[itemIndexDown].selected = false;
  1090. }
  1091. }
  1092. }
  1093. }
  1094. // Neither ctrl nor shift were pressed, so toggle clicked item
  1095. else {
  1096. this.data[itemIndex].selected = !this.data[itemIndex].selected;
  1097. }
  1098. // Set the last clicked item to no longer be highlighted, if it exists
  1099. if (this.lastSelectedItemIndex >= 0)
  1100. this.data[this.lastSelectedItemIndex].highlighted = false;
  1101. // Set the clicked item to be highlighted
  1102. this.data[itemIndex].highlighted = true;
  1103. },
  1104. toggleAllRows() {
  1105. if (this.data.length > this.selectedRows.length) {
  1106. this.data = this.data.map(row => ({ ...row, selected: true }));
  1107. } else {
  1108. this.data = this.data.map(row => ({ ...row, selected: false }));
  1109. }
  1110. },
  1111. addFilterItem() {
  1112. this.editingFilters.push({
  1113. data: "",
  1114. filter: this.addFilterValue,
  1115. filterType:
  1116. this.allFilterTypes[this.addFilterValue.defaultFilterType]
  1117. });
  1118. },
  1119. removeFilterItem(index) {
  1120. this.editingFilters.splice(index, 1);
  1121. },
  1122. columnResizingStart(column, event) {
  1123. const eventIsTouch = event.type === "touchstart";
  1124. if (eventIsTouch) {
  1125. // Handle double click from touch (if this method is called for the same column twice in a row within one second)
  1126. if (
  1127. this.lastColumnResizerTapped === column &&
  1128. Date.now() - this.lastColumnResizerTappedDate <= 1000
  1129. ) {
  1130. this.columnResetWidth(column);
  1131. this.lastColumnResizerTapped = null;
  1132. this.lastColumnResizerTappedDate = 0;
  1133. return;
  1134. }
  1135. this.lastColumnResizerTapped = column;
  1136. this.lastColumnResizerTappedDate = Date.now();
  1137. }
  1138. this.resizing.resizing = true;
  1139. this.resizing.resizingColumn = column;
  1140. this.resizing.width = event.target.parentElement.offsetWidth;
  1141. this.resizing.lastX = eventIsTouch
  1142. ? event.targetTouches[0].clientX
  1143. : event.x;
  1144. },
  1145. columnResizing(event) {
  1146. if (this.resizing.resizing) {
  1147. const eventIsTouch = event.type === "touchmove";
  1148. if (!eventIsTouch && event.buttons !== 1) {
  1149. this.resizing.resizing = false;
  1150. this.storeTableSettings();
  1151. }
  1152. const x = eventIsTouch
  1153. ? event.changedTouches[0].clientX
  1154. : event.x;
  1155. this.resizing.width -= this.resizing.lastX - x;
  1156. this.resizing.lastX = x;
  1157. if (
  1158. this.resizing.resizingColumn.minWidth &&
  1159. this.resizing.resizingColumn.maxWidth
  1160. ) {
  1161. this.resizing.resizingColumn.width = Math.max(
  1162. Math.min(
  1163. this.resizing.resizingColumn.maxWidth,
  1164. this.resizing.width
  1165. ),
  1166. this.resizing.resizingColumn.minWidth
  1167. );
  1168. } else if (this.resizing.resizingColumn.minWidth) {
  1169. this.resizing.resizingColumn.width = Math.max(
  1170. this.resizing.width,
  1171. this.resizing.resizingColumn.minWidth
  1172. );
  1173. } else if (this.resizing.resizingColumn.maxWidth) {
  1174. this.resizing.resizingColumn.width = Math.min(
  1175. this.resizing.resizingColumn.maxWidth,
  1176. this.resizing.width
  1177. );
  1178. } else {
  1179. this.resizing.resizingColumn.width = this.resizing.width;
  1180. }
  1181. this.resizing.width = this.resizing.resizingColumn.width;
  1182. console.log(`New width: ${this.resizing.width}px`);
  1183. this.storeTableSettings();
  1184. }
  1185. },
  1186. columnResizingStop() {
  1187. this.resizing.resizing = false;
  1188. this.storeTableSettings();
  1189. },
  1190. columnResetWidth(column) {
  1191. const index = this.orderedColumns.indexOf(column);
  1192. if (column.defaultWidth && !Number.isNaN(column.defaultWidth))
  1193. this.orderedColumns[index].width = column.defaultWidth;
  1194. else if (
  1195. column.calculatedWidth &&
  1196. !Number.isNaN(column.calculatedWidth)
  1197. )
  1198. this.orderedColumns[index].width = column.calculatedWidth;
  1199. this.storeTableSettings();
  1200. },
  1201. filterTypes(filter) {
  1202. if (!filter || !filter.filterTypes) return [];
  1203. return filter.filterTypes.map(
  1204. filterType => this.allFilterTypes[filterType]
  1205. );
  1206. },
  1207. changeFilterType(index) {
  1208. this.editingFilters[index].filterType =
  1209. this.allFilterTypes[
  1210. this.editingFilters[index].filter.defaultFilterType
  1211. ];
  1212. },
  1213. onDragBox(e) {
  1214. const e1 = e || window.event;
  1215. const e1IsTouch = e1.type === "touchstart";
  1216. e1.preventDefault();
  1217. if (e1IsTouch) {
  1218. // Handle double click from touch (if this method is twice in a row within one second)
  1219. if (Date.now() - this.lastBulkActionsTappedDate <= 1000) {
  1220. this.resetBulkActionsPosition();
  1221. this.lastBulkActionsTappedDate = 0;
  1222. return;
  1223. }
  1224. this.lastBulkActionsTappedDate = Date.now();
  1225. }
  1226. this.bulkPopup.pos3 = e1IsTouch
  1227. ? e1.changedTouches[0].clientX
  1228. : e1.clientX;
  1229. this.bulkPopup.pos4 = e1IsTouch
  1230. ? e1.changedTouches[0].clientY
  1231. : e1.clientY;
  1232. document.onmousemove = document.ontouchmove = e => {
  1233. const e2 = e || window.event;
  1234. const e2IsTouch = e2.type === "touchmove";
  1235. if (!e2IsTouch) e2.preventDefault();
  1236. // Get the clientX and clientY
  1237. const e2ClientX = e2IsTouch
  1238. ? e2.changedTouches[0].clientX
  1239. : e2.clientX;
  1240. const e2ClientY = e2IsTouch
  1241. ? e2.changedTouches[0].clientY
  1242. : e2.clientY;
  1243. // calculate the new cursor position:
  1244. this.bulkPopup.pos1 = this.bulkPopup.pos3 - e2ClientX;
  1245. this.bulkPopup.pos2 = this.bulkPopup.pos4 - e2ClientY;
  1246. this.bulkPopup.pos3 = e2ClientX;
  1247. this.bulkPopup.pos4 = e2ClientY;
  1248. // set the element's new position:
  1249. this.bulkPopup.top -= this.bulkPopup.pos2;
  1250. this.bulkPopup.left -= this.bulkPopup.pos1;
  1251. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1252. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1253. this.bulkPopup.top = document.body.clientHeight - 50;
  1254. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1255. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1256. this.bulkPopup.left = document.body.clientWidth - 400;
  1257. };
  1258. document.onmouseup = document.ontouchend = () => {
  1259. document.onmouseup = null;
  1260. document.ontouchend = null;
  1261. document.onmousemove = null;
  1262. document.ontouchmove = null;
  1263. };
  1264. },
  1265. resetBulkActionsPosition() {
  1266. this.bulkPopup.top = document.body.clientHeight - 56;
  1267. this.bulkPopup.left = document.body.clientWidth / 2 - 200;
  1268. },
  1269. applyFilterAndGetData() {
  1270. this.appliedFilters = JSON.parse(
  1271. JSON.stringify(this.editingFilters)
  1272. );
  1273. this.appliedFilterOperator = this.filterOperator;
  1274. this.getData();
  1275. this.storeTableSettings();
  1276. },
  1277. recalculateWidths() {
  1278. let noWidthCount = 0;
  1279. let calculatedWidth = 0;
  1280. this.orderedColumns.forEach(column => {
  1281. if (
  1282. this.shownColumns.indexOf(column.name) !== -1 &&
  1283. (column.name !== "select" || this.hasCheckboxes)
  1284. )
  1285. if (
  1286. Number.isFinite(column.width) &&
  1287. !Number.isFinite(column.calculatedWidth)
  1288. ) {
  1289. calculatedWidth += column.width;
  1290. } else if (Number.isFinite(column.defaultWidth)) {
  1291. calculatedWidth += column.defaultWidth;
  1292. } else {
  1293. noWidthCount += 1;
  1294. }
  1295. });
  1296. calculatedWidth = Math.floor(
  1297. (Math.min(this.maxWidth, document.body.clientWidth) -
  1298. calculatedWidth) /
  1299. (noWidthCount - 1)
  1300. );
  1301. this.orderedColumns = this.orderedColumns.map(column => {
  1302. const orderedColumn = column;
  1303. if (this.shownColumns.indexOf(orderedColumn.name) !== -1) {
  1304. let newWidth;
  1305. if (Number.isFinite(orderedColumn.defaultWidth)) {
  1306. newWidth = orderedColumn.defaultWidth;
  1307. } else {
  1308. // eslint-disable-next-line no-param-reassign
  1309. newWidth = orderedColumn.calculatedWidth = Math.min(
  1310. Math.max(
  1311. orderedColumn.minWidth || 100, // fallback 100px min width
  1312. calculatedWidth
  1313. ),
  1314. orderedColumn.maxWidth || 1000 // fallback 1000px max width
  1315. );
  1316. }
  1317. if (newWidth && !Number.isFinite(orderedColumn.width))
  1318. orderedColumn.width = newWidth;
  1319. }
  1320. return orderedColumn;
  1321. });
  1322. },
  1323. columnOrderChanged() {
  1324. this.storeTableSettings();
  1325. },
  1326. getTableSettings() {
  1327. const urlTableSettings = {};
  1328. if (this.query) {
  1329. if (this.$route.query.page)
  1330. urlTableSettings.page = Number.parseInt(
  1331. this.$route.query.page
  1332. );
  1333. if (this.$route.query.pageSize)
  1334. urlTableSettings.pageSize = Number.parseInt(
  1335. this.$route.query.pageSize
  1336. );
  1337. if (this.$route.query.shownColumns)
  1338. urlTableSettings.shownColumns = JSON.parse(
  1339. this.$route.query.shownColumns
  1340. );
  1341. if (this.$route.query.columnOrder)
  1342. urlTableSettings.columnOrder = JSON.parse(
  1343. this.$route.query.columnOrder
  1344. );
  1345. if (this.$route.query.columnWidths)
  1346. urlTableSettings.columnWidths = JSON.parse(
  1347. this.$route.query.columnWidths
  1348. );
  1349. if (this.$route.query.columnSort)
  1350. urlTableSettings.columnSort = JSON.parse(
  1351. this.$route.query.columnSort
  1352. );
  1353. if (this.$route.query.filter)
  1354. urlTableSettings.filter = JSON.parse(
  1355. this.$route.query.filter
  1356. );
  1357. }
  1358. const localStorageTableSettings = JSON.parse(
  1359. localStorage.getItem(`advancedTableSettings:${this.name}`)
  1360. );
  1361. return {
  1362. ...localStorageTableSettings,
  1363. ...urlTableSettings
  1364. };
  1365. },
  1366. storeTableSettings() {
  1367. // Clear debounce timeout
  1368. if (this.storeTableSettingsDebounceTimeout)
  1369. clearTimeout(this.storeTableSettingsDebounceTimeout);
  1370. // Resizing calls this function a lot, so rather than saving dozens of times a second, use debouncing
  1371. this.storeTableSettingsDebounceTimeout = setTimeout(() => {
  1372. if (this.query) this.setQuery();
  1373. this.setLocalStorage();
  1374. }, 250);
  1375. },
  1376. setQuery() {
  1377. const queryObject = {
  1378. ...this.$route.query,
  1379. page: this.page,
  1380. pageSize: this.pageSize,
  1381. filter: JSON.stringify({
  1382. appliedFilters: this.appliedFilters,
  1383. appliedFilterOperator: this.appliedFilterOperator
  1384. }),
  1385. columnSort: JSON.stringify(this.sort),
  1386. columnOrder: JSON.stringify(
  1387. this.orderedColumns.map(column => column.name)
  1388. ),
  1389. columnWidths: JSON.stringify(
  1390. this.orderedColumns.map(column => ({
  1391. name: column.name,
  1392. width: column.width
  1393. }))
  1394. ),
  1395. shownColumns: JSON.stringify(this.shownColumns)
  1396. };
  1397. const queryString = `?${Object.keys(queryObject)
  1398. .map(key => `${key}=${queryObject[key]}`)
  1399. .join("&")}`;
  1400. window.history.replaceState(null, null, queryString);
  1401. },
  1402. setLocalStorage() {
  1403. localStorage.setItem(
  1404. `advancedTableSettings:${this.name}`,
  1405. JSON.stringify({
  1406. pageSize: this.pageSize,
  1407. filter: {
  1408. appliedFilters: this.appliedFilters,
  1409. appliedFilterOperator: this.appliedFilterOperator
  1410. },
  1411. columnSort: this.sort,
  1412. columnOrder: this.orderedColumns.map(column => column.name),
  1413. columnWidths: this.orderedColumns.map(column => ({
  1414. name: column.name,
  1415. width: column.width
  1416. })),
  1417. shownColumns: this.shownColumns
  1418. })
  1419. );
  1420. },
  1421. onWindowResize() {
  1422. // Only change the position if the popup is actually visible
  1423. if (this.selectedRows.length === 0) return;
  1424. if (this.bulkPopup.top < 0) this.bulkPopup.top = 0;
  1425. if (this.bulkPopup.top > document.body.clientHeight - 50)
  1426. this.bulkPopup.top = document.body.clientHeight - 50;
  1427. if (this.bulkPopup.left < 0) this.bulkPopup.left = 0;
  1428. if (this.bulkPopup.left > document.body.clientWidth - 400)
  1429. this.bulkPopup.left = document.body.clientWidth - 400;
  1430. }
  1431. }
  1432. };
  1433. </script>
  1434. <style lang="scss" scoped>
  1435. .night-mode {
  1436. .table-outer-container {
  1437. .table-container .table {
  1438. &,
  1439. thead th {
  1440. background-color: var(--dark-grey-3);
  1441. color: var(--light-grey-2);
  1442. }
  1443. tr {
  1444. th,
  1445. td {
  1446. border-color: var(--dark-grey) !important;
  1447. &:first-child {
  1448. background-color: var(--dark-grey-3) !important;
  1449. }
  1450. }
  1451. &:nth-child(even) {
  1452. &,
  1453. td:first-child {
  1454. background-color: var(--dark-grey-2) !important;
  1455. }
  1456. }
  1457. &:hover,
  1458. &:focus,
  1459. &.highlighted {
  1460. th,
  1461. td {
  1462. &,
  1463. &:first-child {
  1464. background-color: var(--dark-grey-4) !important;
  1465. }
  1466. }
  1467. }
  1468. }
  1469. }
  1470. .table-header,
  1471. .table-footer {
  1472. background-color: var(--dark-grey-3);
  1473. color: var(--light-grey-2);
  1474. }
  1475. .label.control {
  1476. background-color: var(--dark-grey) !important;
  1477. border-color: var(--grey-3) !important;
  1478. color: var(--white) !important;
  1479. }
  1480. }
  1481. .bulk-popup {
  1482. border: 0;
  1483. background-color: var(--dark-grey-2);
  1484. color: var(--white);
  1485. .material-icons {
  1486. color: var(--white);
  1487. }
  1488. }
  1489. }
  1490. .table-outer-container {
  1491. border-radius: 5px;
  1492. box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
  1493. margin: 10px 0;
  1494. overflow: hidden;
  1495. .table-container {
  1496. overflow-x: auto;
  1497. table {
  1498. border-collapse: separate;
  1499. table-layout: fixed;
  1500. thead {
  1501. tr {
  1502. th {
  1503. height: 40px;
  1504. line-height: 40px;
  1505. border: 1px solid var(--light-grey-2);
  1506. border-width: 1px 1px 1px 0;
  1507. padding: 0;
  1508. &:last-child {
  1509. border-width: 1px 0 1px;
  1510. }
  1511. &.sortable {
  1512. cursor: pointer;
  1513. }
  1514. & > div {
  1515. display: flex;
  1516. white-space: nowrap;
  1517. padding: 8px 10px;
  1518. & > span {
  1519. margin-left: 5px;
  1520. &:first-child {
  1521. margin-left: 0;
  1522. margin-right: auto;
  1523. }
  1524. & > .material-icons {
  1525. font-size: 22px;
  1526. position: relative;
  1527. top: 6px;
  1528. cursor: pointer;
  1529. &.active {
  1530. color: var(--primary-color);
  1531. }
  1532. &:hover,
  1533. &:focus {
  1534. filter: brightness(90%);
  1535. }
  1536. }
  1537. }
  1538. }
  1539. }
  1540. }
  1541. }
  1542. tbody {
  1543. tr {
  1544. &.highlighted {
  1545. background-color: var(--light-grey);
  1546. }
  1547. td {
  1548. border: 1px solid var(--light-grey-2);
  1549. border-width: 0 1px 1px 0;
  1550. &:last-child {
  1551. border-width: 0 0 1px;
  1552. }
  1553. /deep/ .row-options {
  1554. display: flex;
  1555. justify-content: space-between;
  1556. .icon-with-button {
  1557. height: 30px;
  1558. width: 30px;
  1559. }
  1560. }
  1561. }
  1562. }
  1563. }
  1564. }
  1565. table {
  1566. thead tr,
  1567. tbody tr {
  1568. th,
  1569. td {
  1570. position: relative;
  1571. white-space: nowrap;
  1572. text-overflow: ellipsis;
  1573. overflow: hidden;
  1574. &:first-child {
  1575. display: none;
  1576. }
  1577. .resizer {
  1578. height: 100%;
  1579. width: 5px;
  1580. background-color: transparent;
  1581. cursor: col-resize;
  1582. position: absolute;
  1583. right: 0;
  1584. top: 0;
  1585. }
  1586. }
  1587. &:nth-child(even) td:first-child {
  1588. background-color: #fafafa;
  1589. }
  1590. &:hover,
  1591. &:focus,
  1592. &.highlighted {
  1593. th,
  1594. td {
  1595. &,
  1596. &:first-child {
  1597. background-color: var(--light-grey);
  1598. }
  1599. }
  1600. }
  1601. }
  1602. &.has-checkboxes {
  1603. thead tr,
  1604. tbody tr {
  1605. th,
  1606. td {
  1607. &:first-child {
  1608. display: table-cell;
  1609. position: sticky;
  1610. left: 0;
  1611. background-color: var(--white);
  1612. z-index: 2;
  1613. }
  1614. }
  1615. }
  1616. }
  1617. }
  1618. }
  1619. .table-header,
  1620. .table-footer {
  1621. display: flex;
  1622. flex-direction: row;
  1623. flex-wrap: wrap;
  1624. justify-content: space-between;
  1625. line-height: 36px;
  1626. background-color: var(--white);
  1627. }
  1628. .table-header > div {
  1629. display: flex;
  1630. flex-direction: row;
  1631. > span > .control {
  1632. margin: 5px;
  1633. }
  1634. .filters-indicator {
  1635. line-height: 46px;
  1636. display: flex;
  1637. align-items: center;
  1638. column-gap: 4px;
  1639. }
  1640. }
  1641. .table-footer {
  1642. .page-controls,
  1643. .page-size > .control {
  1644. display: flex;
  1645. flex-direction: row;
  1646. margin-bottom: 0 !important;
  1647. button {
  1648. margin: 5px;
  1649. font-size: 20px;
  1650. }
  1651. p,
  1652. label {
  1653. margin: 5px;
  1654. font-size: 14px;
  1655. font-weight: 600;
  1656. }
  1657. &.select::after {
  1658. top: 18px;
  1659. }
  1660. }
  1661. }
  1662. }
  1663. .control.is-grouped {
  1664. display: flex;
  1665. & > .control {
  1666. &.label {
  1667. height: 36px;
  1668. background-color: var(--white);
  1669. border: 1px solid var(--light-grey-2);
  1670. color: var(--dark-grey-2);
  1671. appearance: none;
  1672. border-radius: 3px;
  1673. font-size: 14px;
  1674. line-height: 34px;
  1675. padding-left: 8px;
  1676. padding-right: 8px;
  1677. }
  1678. &.select.is-expanded > select {
  1679. width: 100%;
  1680. }
  1681. & > input,
  1682. & > select,
  1683. & > .button,
  1684. &.label {
  1685. border-radius: 0;
  1686. }
  1687. &:first-child {
  1688. & > input,
  1689. & > select,
  1690. & > .button,
  1691. &.label {
  1692. border-radius: 5px 0 0 5px;
  1693. }
  1694. }
  1695. &:last-child {
  1696. & > input,
  1697. & > select,
  1698. & > .button,
  1699. &.label {
  1700. border-radius: 0 5px 5px 0;
  1701. }
  1702. }
  1703. & > .button {
  1704. font-size: 22px;
  1705. }
  1706. }
  1707. @media screen and (max-width: 500px) {
  1708. &.advanced-filter {
  1709. flex-wrap: wrap;
  1710. .control.select {
  1711. width: 50%;
  1712. select {
  1713. width: 100%;
  1714. }
  1715. }
  1716. .control {
  1717. margin-bottom: 0 !important;
  1718. &:nth-child(1) select {
  1719. border-radius: 5px 0 0 0;
  1720. }
  1721. &:nth-child(2) select {
  1722. border-radius: 0 5px 0 0;
  1723. }
  1724. &:nth-child(3) input {
  1725. border-radius: 0 0 0 5px;
  1726. }
  1727. &:nth-child(4) button {
  1728. border-radius: 0 0 5px 0;
  1729. }
  1730. }
  1731. }
  1732. }
  1733. }
  1734. .advanced-filter-bottom {
  1735. display: flex;
  1736. .button {
  1737. font-size: 16px !important;
  1738. width: 100%;
  1739. }
  1740. .control {
  1741. margin: 0 !important;
  1742. }
  1743. }
  1744. /deep/ .bulk-popup {
  1745. display: flex;
  1746. position: fixed;
  1747. flex-direction: row;
  1748. width: 100%;
  1749. max-width: 400px;
  1750. line-height: 36px;
  1751. z-index: 5;
  1752. border: 1px solid var(--light-grey-3);
  1753. border-radius: 5px;
  1754. box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  1755. background-color: var(--white);
  1756. color: var(--dark-grey);
  1757. padding: 5px;
  1758. .right {
  1759. display: flex;
  1760. flex-direction: row;
  1761. margin-left: auto;
  1762. }
  1763. .drag-icon {
  1764. position: relative;
  1765. top: 6px;
  1766. color: var(--dark-grey);
  1767. cursor: move;
  1768. }
  1769. .bulk-actions {
  1770. display: flex;
  1771. flex-direction: row;
  1772. width: 100%;
  1773. justify-content: space-evenly;
  1774. .material-icons {
  1775. position: relative;
  1776. top: 6px;
  1777. margin-left: 5px;
  1778. cursor: pointer;
  1779. color: var(--primary-color);
  1780. &:hover,
  1781. &:focus {
  1782. filter: brightness(90%);
  1783. }
  1784. }
  1785. .delete-icon {
  1786. color: var(--dark-red);
  1787. }
  1788. }
  1789. }
  1790. </style>