AdvancedTable.vue 60 KB

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