AdvancedTable.vue 60 KB

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